Make settings a singleton.
authorMax Lapan <max.lapan@gmail.com>
Wed, 17 Mar 2010 15:45:34 +0000 (18:45 +0300)
committerMax Lapan <max.lapan@gmail.com>
Wed, 17 Mar 2010 15:45:34 +0000 (18:45 +0300)
mainwidget.cpp
settings.cpp
settings.hpp

index 2a97dbc..f4aa592 100644 (file)
@@ -24,7 +24,7 @@ MainWidget::MainWidget ()
 
     _traffic = new Traffic;
     _regions = new RegionsTable;
-    _settings = new Settings;
+    _settings = Settings::instance ();
 
     QHBoxLayout *layout = new QHBoxLayout;
     layout->addWidget (_light);
index a08f07f..021ea4f 100644 (file)
@@ -2,6 +2,17 @@
 #include <settings.hpp>
 
 
+static Settings* _settings;
+
+
+Settings* Settings::instance ()
+{
+    if (!_settings)
+        _settings = new Settings;
+    return _settings;
+}
+
+
 Settings::Settings ()
 {
     load ();
index 1953f76..19b00f4 100644 (file)
@@ -58,8 +58,9 @@ private:
     int intervalIndex2Minutes (int index) const;
     int minutes2IntervalIndex (int minutes) const;
 
-public:
     Settings ();
+public:
+    static Settings* instance ();
 
     void load ();
     void save ();