diff options
Diffstat (limited to 'inisingleton.h')
| -rw-r--r-- | inisingleton.h | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/inisingleton.h b/inisingleton.h new file mode 100644 index 0000000..6650c11 --- /dev/null +++ b/inisingleton.h @@ -0,0 +1,51 @@ +#pragma once + +// qt +#include <QMutex> +#include <QVariant> + +// goodies +#include "g_property.h" + +#define INI_SINGLETON(type) IniSingleton<type>::get() + +template <class T> class IniSingleton +{ +public: + static T get() + { + static QMutex mtx; + QMutexLocker l(&mtx); + + auto variant = + GlobalSettings::instance()->value(T::staticMetaObject.className()); + qDebug() << "classname" << T::staticMetaObject.className(); + qDebug() << "VARIANT" << variant; + + return T(variant); + } + + static void set(const T& value) + { + static QMutex mtx; + QMutexLocker l(&mtx); + + GlobalSettings::instance()->setValue( + T::staticMetaObject.className(), + QVariant(value) + ); + GlobalSettings::instance()->sync(); + } + + static void cleanup() + { + static QMutex mtx; + QMutexLocker l(&mtx); + + GlobalSettings::instance()->setValue( + T::staticMetaObject.className(), + QVariant() + ); + GlobalSettings::instance()->sync(); + } +}; |
