/*! * * Copyright (c) 2021-2024 Diality Inc. - All Rights Reserved. * \copyright * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * * \file MSettings.h * \author (last) Behrouz NematiPour * \date (last) 13-Sep-2023 * \author (original) Behrouz NematiPour * \date (original) 29-Mar-2021 * */ #pragma once // Qt #include #include #include // Project #include "main.h" // Doxygen : do not remove // Define #define _Settings Storage::MSettings::I() // namespace namespace Storage { // FixMe: the model and controller need review and some functionalities need to be moved. // FixMe: the controller should be the Singleton not the model. class MSettings : public QObject { Q_OBJECT typedef QString TCategory ; typedef QString TGroup ; typedef QString TKey ; typedef QVariant TVal ; class KeyValue { TKey _key ; TVal _val ; public: KeyValue(const TKey &vKey, const TVal &vVal) : _key(vKey), _val(vVal) {} TKey key() const { return _key.trimmed(); } TVal val() const { return _val ; } void operator = (const TKey &vKey) { _key = vKey.trimmed(); } void operator = (const TVal &vVal) { _val = vVal ; } // void operator = (const KeyValue &vKeyValue) { // _key = vKeyValue.key(); // _val = vKeyValue.val(); // } bool operator == (const KeyValue &vKeyValue) const { return key() == vKeyValue.key(); } }; typedef KeyValue TKeyValue ; typedef QList < TKeyValue > TKeyValues; typedef QMap < TGroup , TKeyValues > TData ; typedef QMap < TCategory , TData > TSettings ; TSettings _settings ; QMutex _mutex; // Singleton SINGLETON(MSettings) public: QStringList categorys(); QStringList groups (const QString &vCategory); QStringList keys (const QString &vCategory, const QString &vGroup ); QString key (const QString &vCategory, const QString &vGroup , uint vIndex); QVariantList values (const QString &vCategory, const QString &vGroup ); QVariant value (const QString &vCategory, const QString &vGroup , const QString &vKey); void add (const QString &vCategory, const QString &vGroup , const QString &vKey, const QVariant &vValue, bool vEnableDuplicateKeys); QString systemLocale (); QString systemLanguage (); // the utility functions private : QString _datetimeFormat = "MM/dd/yyyy HH:mm:ss"; private : QString _dateFormat = "MM/dd/yyyy"; private : QString _timeFormat = "HH:mm:ss"; public : void datetimeFormat(); public : QString getDatetimeFormat() { return _datetimeFormat;} public : QString timeFormat() { return _timeFormat;} public : QString dateFormat() { return _dateFormat;} }; } typedef struct{} SettingsData; // it has literally been defined to be used for overloading