]> vaikene.ee Git - evaf/blobdiff - src/libs/Common/prop.cpp
Mac OS changes and switched to c++11.
[evaf] / src / libs / Common / prop.cpp
index f6cfec6395b2813131aa91103d071dcd33cde47b..b76c3c5417d54ae4942d16912d491602c76ea689 100644 (file)
@@ -3,7 +3,7 @@
  * @brief Implementation of the iProp interface
  * @author Enar Vaikene
  *
- * Copyright (c) 2011 Enar Vaikene
+ * Copyright (c) 2011-2019 Enar Vaikene
  *
  * This file is part of the eVaf C++ cross-platform application development framework.
  *
 
 using namespace eVaf::Common;
 
+namespace
+{
+    static Internal::Prop * singleton = nullptr;
+}
+
 iProp * iProp::instance()
 {
-    static Internal::Prop singleton;
-    return singleton._interface();
+    if (nullptr == singleton)
+    {
+        singleton = new Internal::Prop;
+    }
+    return singleton->_interface();
 }
 
 
@@ -42,19 +50,30 @@ iProp * iProp::instance()
 
 using namespace eVaf::Common::Internal;
 
+void Prop::destroyInstance()
+{
+    if (nullptr != singleton)
+    {
+        delete singleton;
+        singleton = nullptr;
+    }
+}
+
 Prop::Prop()
     : iProp()
-    , mPersistentProps(0)
 {
     setObjectName(QString("%1.iProp").arg(VER_MODULE_NAME_STR));
 
     // Register the iProp interface
     iRegistry::instance()->registerInterface("iProp", this);
+
+    EVAF_INFO("%s-Prop created", VER_MODULE_NAME_STR);
 }
 
 Prop::~Prop()
 {
     done();
+    EVAF_INFO("%s-Prop destroyed", VER_MODULE_NAME_STR);
 }
 
 iProp * Prop::_interface() const
@@ -80,7 +99,7 @@ bool Prop::init()
                     isProp = true;
                 }
                 else if (isProp && xml.name() == "property") {
-#ifdef Q_OS_LINUX
+#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS)
                     if (isTrue(xml.attributes().value("windowsonly").toString()))
                         continue;
 #endif
@@ -116,9 +135,10 @@ bool Prop::init()
     }
 
     // Initialize persistent properties
-    if (mPersistentProps)
-        delete mPersistentProps;
-    mPersistentProps = new QSettings(QString("%1/.%2.dat").arg(iApp::instance()->dataRootDir()).arg(iApp::instance()->name()), QSettings::IniFormat);
+    mPersistentProps.reset(new QSettings(QString("%1/.%2.dat")
+                                            .arg(iApp::instance()->dataRootDir())
+                                            .arg(iApp::instance()->name()),
+                                         QSettings::IniFormat));
     QStringList keys = mPersistentProps->allKeys();
     for (int i = 0; i < keys.size(); ++i) {
         QString key = keys.at(i);
@@ -130,10 +150,7 @@ bool Prop::init()
 
 void Prop::done()
 {
-    if (mPersistentProps) {
-        delete mPersistentProps;
-        mPersistentProps = 0;
-    }
+    mPersistentProps.reset();
 }
 
 QVariant Prop::getValue(QString const & name, QVariant const & defaultValue) const