From e777727be96dff1f949e7f920495b8093dbd9589 Mon Sep 17 00:00:00 2001 From: Max Lapan Date: Wed, 17 Mar 2010 18:45:34 +0300 Subject: [PATCH] Make settings a singleton. --- mainwidget.cpp | 2 +- settings.cpp | 11 +++++++++++ settings.hpp | 3 ++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/mainwidget.cpp b/mainwidget.cpp index 2a97dbc..f4aa592 100644 --- a/mainwidget.cpp +++ b/mainwidget.cpp @@ -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); diff --git a/settings.cpp b/settings.cpp index a08f07f..021ea4f 100644 --- a/settings.cpp +++ b/settings.cpp @@ -2,6 +2,17 @@ #include +static Settings* _settings; + + +Settings* Settings::instance () +{ + if (!_settings) + _settings = new Settings; + return _settings; +} + + Settings::Settings () { load (); diff --git a/settings.hpp b/settings.hpp index 1953f76..19b00f4 100644 --- a/settings.hpp +++ b/settings.hpp @@ -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 (); -- 1.7.9.5