Index: sources/model/settings/MSettings.cpp =================================================================== diff -u -r265ce7409a0ea99a4ae059f5ce7978c9cdb10631 -r40c09957821fb3779fa06214a856c20cca110e56 --- sources/model/settings/MSettings.cpp (.../MSettings.cpp) (revision 265ce7409a0ea99a4ae059f5ce7978c9cdb10631) +++ sources/model/settings/MSettings.cpp (.../MSettings.cpp) (revision 40c09957821fb3779fa06214a856c20cca110e56) @@ -18,6 +18,7 @@ #include // Project +#include "StorageGlobals.h" // name spaces using namespace Storage; @@ -30,31 +31,25 @@ MSettings::MSettings(QObject *parent) : QObject(parent) { } /*! - * \brief MSettings::groups - * \details Returns all the groups of the settings - * \return list of the groups as list of strings - */ -QStringList MSettings::groups() -{ - QMutexLocker locker(&_mutex); - return _settings.keys(); -} - -/*! * \brief MSettings::keys * \details returns all keys in a group * \param vGroup - the group to look for all the keys * \return list of the keys in QString for the group vGroup */ -QStringList MSettings::keys(const QString &vGroup) +QStringList MSettings::keys(const QString &vCategory, const QString &vGroup) { const QMutexLocker locker(&_mutex); - return _settings[vGroup].keys; + QStringList mKeys; + TKeyValues keyValues = _settings[vCategory][vGroup]; + for (const auto &keyValue: keyValues ) { + mKeys += keyValue.key(); + } + return mKeys; } -QString MSettings::key(const QString &vGroup, uint vIndex) +QString MSettings::key(const QString &vCategory, const QString &vGroup, uint vIndex) { - QStringList mKeys = keys(vGroup); + QStringList mKeys = keys(vCategory, vGroup); QString mKey = "[Unknown %1]"; if ( vIndex < (unsigned)mKeys.count() ) { mKey = mKeys [vIndex]; @@ -70,10 +65,15 @@ * \param vGroup - the group to look for all the values * \return list of the values in QString for the group vGroup */ -QVariantList MSettings::values(const QString &vGroup) +QVariantList MSettings::values(const QString &vCategory, const QString &vGroup) { QMutexLocker locker(&_mutex); - return _settings[vGroup].values; + QVariantList mValues; + TKeyValues keyValues = _settings[vCategory][vGroup]; + for (const auto &keyValue: keyValues ) { + mValues += keyValue.val(); + } + return mValues; } /*! @@ -83,28 +83,17 @@ * \param vKey - the key to look for the value * \return the values in QString for the group vGroup */ -QVariant MSettings::value(const QString &vGroup, const QString &vKey) +QVariant MSettings::value(const QString &vCategory, const QString &vGroup, const QString &vKey) { QMutexLocker locker(&_mutex); - int index = _settings[vGroup].keys.indexOf(vKey); - if ( index >= 0 ) - return _settings[vGroup].values.at(index); + TKeyValues mKeyValues = _settings[vCategory][vGroup]; + for (const auto &keyValue: mKeyValues ) { + if ( vKey == keyValue.key() ) return keyValue.val(); + } return QVariant(); } /*! - * \brief MSettings::location - * \details The locations where the settings have been read for the group vGroup - * \param vGroup - the group to look for the location - * \return the location in QString - */ -QString MSettings::location(const QString &vGroup) -{ - QMutexLocker locker(&_mutex); - return _settings[vGroup].location; -} - -/*! * \brief MSettings::groups * \details The groups where have been read from the location vLocation * \param vLocation - The location to look for the group(s) @@ -113,7 +102,7 @@ QStringList MSettings::groups(const QString &vCategory) { QMutexLocker locker(&_mutex); - return _category[vCategory]; + return _settings[vCategory].keys(); } /*! @@ -124,7 +113,7 @@ QStringList MSettings::categorys() { QMutexLocker locker(&_mutex); - return _category.keys(); + return _settings.keys(); } /*! @@ -133,31 +122,24 @@ * \param vGroup - the group of the settings * \param vKey - the key to be added under the group vGroup * \param vValue - the value of the key to be added under group vGroup for the key vKey - * \param vLocation - the location of the setting data if is different will be set. - * \param vLocation - the category of the setting data which by default is the base location if has extra folder + filename. */ -void MSettings::add(const QString &vGroup, const QString &vKey, const QVariant &vValue, const QString &vLocation, const QString &vCategory, bool vEnableDuplicateKeys) +void MSettings::add(const QString &vCategory, const QString &vGroup, const QString &vKey, const QVariant &vValue, bool vEnableDuplicateKeys) { QMutexLocker locker(&_mutex); - if ( ! _category[vCategory].contains(vGroup) ) _category[vCategory] += vGroup; - - KeyValue mGroup = _settings[vGroup]; - if ( mGroup.location != vLocation ) mGroup.location = vLocation; - if ( mGroup.category != vCategory ) mGroup.category = vCategory; if ( vEnableDuplicateKeys ) { - mGroup.keys += vKey ; - mGroup.values += vValue ; - } else { - if ( mGroup.keys.contains(vKey)) { - int index = mGroup.keys.indexOf(vKey); - mGroup.values[index] = vValue; + _settings[vCategory][vGroup] += TKeyValue (vKey, vValue); + } + else { + TKeyValue keyValue (vKey, vValue); + TKeyValues keyValues = _settings[vCategory][vGroup]; + int index = keyValues.indexOf(keyValue); + if ( index >= 0 ) { + _settings[vCategory][vGroup].replace( index, keyValue ); } else { - mGroup.keys += vKey ; - mGroup.values += vValue ; + _settings[vCategory][vGroup] += keyValue; } } - _settings[vGroup] = mGroup; } /********** The common helper functions **********/ @@ -169,8 +151,9 @@ */ void MSettings::datetimeFormat() { - QVariant dateFotmat = _Settings.value("Date", "Format"); - QVariant timeFotmat = _Settings.value("Time", "Format"); + QString category = Storage::Settings_Category_SettingsSystem; + QVariant dateFotmat = _Settings.value(category, "Date", "Format"); + QVariant timeFotmat = _Settings.value(category, "Time", "Format"); if (dateFotmat.isValid() && timeFotmat.isValid()) _datetimeFormat = dateFotmat.toString() + " " + timeFotmat.toString(); }