Index: denali.pro.user =================================================================== diff -u -ra82ee4f326b26c4369f1306f867edc1bca6dabbe -ra04fd119778f0483cba5139a11e3c6bad7f2324a --- denali.pro.user (.../denali.pro.user) (revision a82ee4f326b26c4369f1306f867edc1bca6dabbe) +++ denali.pro.user (.../denali.pro.user) (revision a04fd119778f0483cba5139a11e3c6bad7f2324a) @@ -1,6 +1,6 @@ - + EnvironmentId Index: sources/canbus/MessageDispatcher.cpp =================================================================== diff -u -r2d0bacfbe1b70055247eb40743405a5f9acb15e3 -ra04fd119778f0483cba5139a11e3c6bad7f2324a --- sources/canbus/MessageDispatcher.cpp (.../MessageDispatcher.cpp) (revision 2d0bacfbe1b70055247eb40743405a5f9acb15e3) +++ sources/canbus/MessageDispatcher.cpp (.../MessageDispatcher.cpp) (revision a04fd119778f0483cba5139a11e3c6bad7f2324a) @@ -349,8 +349,7 @@ void MessageDispatcher::onAdjustment(const AdjustHDAlarmVolumeRequestData &vData) { QVariantList mData; - const int hw2ui = 20; // HD vol range is [1-5] and we show [20%-100%] to user (100 / 5). - mData += vData.volume / hw2ui; + mData += vData.volume2HD(); onActionTransmit(GuiActionType::ID_AlarmVolumeSetReq, mData); } Index: sources/gui/qml/main.qml =================================================================== diff -u -ra82ee4f326b26c4369f1306f867edc1bca6dabbe -ra04fd119778f0483cba5139a11e3c6bad7f2324a --- sources/gui/qml/main.qml (.../main.qml) (revision a82ee4f326b26c4369f1306f867edc1bca6dabbe) +++ sources/gui/qml/main.qml (.../main.qml) (revision a04fd119778f0483cba5139a11e3c6bad7f2324a) @@ -341,7 +341,6 @@ // TODO: disable this later. this is only for diagnostic purpose. onDoubleClicked : { _diagnosticsDialog.open() - // WIP: vSettings.doSave("Configurations/Formats", "Navigation", "_KEY_", "-VAL~"); } } Index: sources/gui/qml/pages/settings/SettingsStack.qml =================================================================== diff -u -r3caffb866d4c84ac6282dcd36fc2d8f7cad9584d -ra04fd119778f0483cba5139a11e3c6bad7f2324a --- sources/gui/qml/pages/settings/SettingsStack.qml (.../SettingsStack.qml) (revision 3caffb866d4c84ac6282dcd36fc2d8f7cad9584d) +++ sources/gui/qml/pages/settings/SettingsStack.qml (.../SettingsStack.qml) (revision a04fd119778f0483cba5139a11e3c6bad7f2324a) @@ -245,11 +245,11 @@ _settingsHome.notificationText = "" } onConfirmClicked: { - if ( vSettings.settings["Service Password"] === undefined ) { + if ( vSettings.servicePass === "" ) { _settingsHome.notificationText = qsTr("No service password defined") } else { - if ( password === vSettings.settings["Service Password"].keys[0] ) { + if ( password === vSettings.servicePass ) { _settingsHome.notificationText = "" vAdjustmentServiceMode.doAdjustment() } Index: sources/gui/qml/pages/settings/SettingsVolumeBrightness.qml =================================================================== diff -u -r27cc308ff5113a9386899d3c8f8b29962a8498e1 -ra04fd119778f0483cba5139a11e3c6bad7f2324a --- sources/gui/qml/pages/settings/SettingsVolumeBrightness.qml (.../SettingsVolumeBrightness.qml) (revision 27cc308ff5113a9386899d3c8f8b29962a8498e1) +++ sources/gui/qml/pages/settings/SettingsVolumeBrightness.qml (.../SettingsVolumeBrightness.qml) (revision a04fd119778f0483cba5139a11e3c6bad7f2324a) @@ -79,6 +79,7 @@ text: qsTr("Alarm Volume") } Slider { id : _alarmVolume + property bool adjustment: false anchors.verticalCenter: parent.verticalCenter width : 500 step : 20 // no zero @@ -87,12 +88,34 @@ height : 5 ticks : true unit : qsTr("%") - onReleased : vAdjustmentAlarmVolume.doAdjustment( _alarmVolume.value ) + onReleased : { + _alarmVolume.adjustment = true + vAdjustmentAlarmVolume.doAdjustment( _alarmVolume.value ) + } + Connections { target: vSettings + onAlarmVolumeChanged: { + if ( ! _alarmVolume.adjustment ) { + vAdjustmentAlarmVolume.doAdjustment( vSettings.alarmVolume ) + } + _alarmVolume.value = vSettings.alarmVolume + } + } Connections { target: vAdjustmentAlarmVolume // in case the value is rejecte it will be set to the previous value // also the init value shall be set when navigate to the screen - onHdAlarmVolumeChanged : _alarmVolume.value = vAdjustmentAlarmVolume.hdAlarmVolume - onStatusChanged : _root.notificationText = vstatus + onAdjustmentTriggered : { + _alarmVolume.adjustment = false + if ( vAdjustmentAlarmVolume.adjustment_Accepted ) { + vSettings.alarmVolume = vAdjustmentAlarmVolume.hdAlarmVolume + _root.notificationText = "" + } + else { + _root.notificationText = vAdjustmentAlarmVolume.adjustment_ReasonText + } + } + onHdAlarmVolumeChanged : { + _alarmVolume.value = vAdjustmentAlarmVolume.hdAlarmVolume + } } } Label { Index: sources/main.h =================================================================== diff -u -rec7f919fdb70ff29a8de627937e4ad7008e59c1c -ra04fd119778f0483cba5139a11e3c6bad7f2324a --- sources/main.h (.../main.h) (revision ec7f919fdb70ff29a8de627937e4ad7008e59c1c) +++ sources/main.h (.../main.h) (revision a04fd119778f0483cba5139a11e3c6bad7f2324a) @@ -138,6 +138,10 @@ } \ } //--------------------------------------------------------------------------------// +#define PROPERTY_POST_CONNECTION( vCLASS, vVARIABLE ) \ + connect(this, &vCLASS::vVARIABLE##Changed \ + , &vCLASS::vVARIABLE##_post ); + #define PROPERTY_BASE(vTYPE , vVARIABLE , vDEFVALUE, vSIGNAL) \ /*! \brief Qt Property declaration \details The Qt Property definition by Q_PROPERTY documentation. @@ -156,6 +160,8 @@ */\ void vVARIABLE##vSIGNAL( const vTYPE & v##vVARIABLE ); \ private: \ + void vVARIABLE##_post ( const vTYPE & v##vVARIABLE ); \ + private: \ vTYPE _##vVARIABLE = vDEFVALUE; \ bool _##vVARIABLE##Changed = false; \ protected: \ @@ -259,7 +265,46 @@ emit vVARIABLE##Notified( _##vVARIABLE ); \ } //--------------------------------------------------------------------------------// +#define SETTINGS_BASE( vVARIABLE , vCATEGORY , vGROUP , vKEY) \ + private: \ + /*! \brief Settings identifier + \details identifies the settings by the given information + \param vCategory - The category of the setting which includes on-level folder and the file name (without .conf extension) + \param vGroup - The group setting key/value belongs to + \param vKey - The key of the setting + */\ + bool is##vVARIABLE(const QString &vCategory , \ + const QString &vGroup , \ + const QString &vKey ) { \ + return vCategory == vVARIABLE##Category() && \ + vGroup == vVARIABLE##Group () && \ + vKey == vVARIABLE##Key (); \ + } \ + /*! \brief Settings property category getter + \details returns the category of the setting + */\ + QString vVARIABLE##Category() { \ + return vCATEGORY; \ + } \ + /*! \brief Settings property group getter + \details returns the group of the setting + */\ + QString vVARIABLE##Group() { \ + return vGROUP; \ + } \ + /*! \brief Settings property key getter + \details returns the key of the setting + */\ + QString vVARIABLE##Key() { \ + return vKEY; \ + } //--------------------------------------------------------------------------------// +#define SETTINGS( vTYPE , vVARIABLE , vDEFVALUE , vCATEGORY , vGROUP , vKEY) \ + PROPERTY_BASE( vTYPE , vVARIABLE , vDEFVALUE , Changed ) \ + PROPERTY_SLOT( vTYPE , vVARIABLE ) \ + SETTINGS_BASE( vVARIABLE , vCATEGORY , vGROUP , vKEY) +//--------------------------------------------------------------------------------// +//--------------------------------------------------------------------------------// #define ACTION_VIEW_CONNECTION(vTYPE) \ connect(&_GuiController, SIGNAL(didActionReceive(const vTYPE &)), \ this, SLOT( onActionReceive(const vTYPE &))); Index: sources/model/hd/adjustment/settings/MAdjustHDRequests.h =================================================================== diff -u -r2d0bacfbe1b70055247eb40743405a5f9acb15e3 -ra04fd119778f0483cba5139a11e3c6bad7f2324a --- sources/model/hd/adjustment/settings/MAdjustHDRequests.h (.../MAdjustHDRequests.h) (revision 2d0bacfbe1b70055247eb40743405a5f9acb15e3) +++ sources/model/hd/adjustment/settings/MAdjustHDRequests.h (.../MAdjustHDRequests.h) (revision a04fd119778f0483cba5139a11e3c6bad7f2324a) @@ -74,14 +74,27 @@ * */ class MAdjustHDAlarmVolumeReq : public MModel { + + const int hw2ui = 20; // HD vol range is [1-5] and we show [20%-100%] to user (100 / 5). + quint32 _volume =100; // values in range of [20, 40, 60, 80, 100] or [1..5]*20 + public: - quint32 volume; + quint32 volume2HD() const { + return _volume / hw2ui; + } + quint32 volume() { + return _volume; + } + void volume(quint32 vVolume) { + _volume = vVolume; + } + // disabled coco begin validated : Has been validated manually. // This object is used statically for now, kept the logic for later usage. QString toString() { - return toString( { volume } ); + return toString( { _volume } ); } // disabled coco end static QString toString(const QVariantList &vParameters) { Index: sources/model/hd/alarm/MAlarmMapping.cpp =================================================================== diff -u -ra82ee4f326b26c4369f1306f867edc1bca6dabbe -ra04fd119778f0483cba5139a11e3c6bad7f2324a --- sources/model/hd/alarm/MAlarmMapping.cpp (.../MAlarmMapping.cpp) (revision a82ee4f326b26c4369f1306f867edc1bca6dabbe) +++ sources/model/hd/alarm/MAlarmMapping.cpp (.../MAlarmMapping.cpp) (revision a04fd119778f0483cba5139a11e3c6bad7f2324a) @@ -7,7 +7,7 @@ * * \file MAlarmMapping.cpp * \author (last) Behrouz NematiPour - * \date (last) 22-Jul-2022 + * \date (last) 25-Jul-2022 * \author (original) Behrouz NematiPour * \date (original) 03-May-2021 * Index: sources/storage/Settings.cpp =================================================================== diff -u -ra82ee4f326b26c4369f1306f867edc1bca6dabbe -ra04fd119778f0483cba5139a11e3c6bad7f2324a --- sources/storage/Settings.cpp (.../Settings.cpp) (revision a82ee4f326b26c4369f1306f867edc1bca6dabbe) +++ sources/storage/Settings.cpp (.../Settings.cpp) (revision a04fd119778f0483cba5139a11e3c6bad7f2324a) @@ -144,7 +144,6 @@ // << vKey // << vValue; QString mFileName = fileName(vCategory); - // qDebug() << " ~~~~~ " << mFileName; QString mContent; _Settings.add(vGroup, vKey, vValue,"", vCategory); QString mPath = QFileInfo(mFileName).absolutePath(); @@ -153,23 +152,18 @@ return 1; // TODO: define enum } - // qDebug() << " ~~~~~ " << mPath; if ( ! FileHandler::makeFolder(mPath) ) { LOG_DEBUG(QString("The settings path %1 can't be created.").arg(mPath)); return 2; // TODO: define enum } - qDebug() << " ~~~~~ " << _Settings.groups(vCategory); - for ( const auto &group : _Settings.groups(vCategory) ) { mContent += QString("[%1]\n").arg(group); for ( const auto &key : _Settings.keys(group) ) { mContent += QString("%1 = %2\n").arg(key).arg(_Settings.value(group, key).toString()); } } - qDebug() << mContent; - if ( ! FileHandler::write(mFileName,mContent, false) ) { LOG_DEBUG(QString("The settings file %1 can't be written.").arg(mFileName)); return 3; // TODO: define enum Index: sources/storage/Settings.h =================================================================== diff -u -ra82ee4f326b26c4369f1306f867edc1bca6dabbe -ra04fd119778f0483cba5139a11e3c6bad7f2324a --- sources/storage/Settings.h (.../Settings.h) (revision a82ee4f326b26c4369f1306f867edc1bca6dabbe) +++ sources/storage/Settings.h (.../Settings.h) (revision a04fd119778f0483cba5139a11e3c6bad7f2324a) @@ -30,8 +30,12 @@ namespace Storage { // TODO - IMPORTANT: this MVC needs to change to configurations in oppose to Settings. -// It named settings because it suppose to be like QSettings, -// but since we have settings it is mixing up with that and is very confusing. +// It named settings because it suppose to be like QSettings, +// but since we have settings it is mixing up with that and is very confusing. +// FIXME- IMPORTANT: This set of Settings (MVC) design is not correct: +// - the data structure should change in Model from column based (keys, values) to tree/map based +// - the singleton should be the controller not the Model, to protect the model usage, and avoid the shared memory issues. +// - the model class should be private class, or an object defined in this class, not a global class. class Settings { Index: sources/view/settings/VAdjustmentAlarmVolume.cpp =================================================================== diff -u -r27cc308ff5113a9386899d3c8f8b29962a8498e1 -ra04fd119778f0483cba5139a11e3c6bad7f2324a --- sources/view/settings/VAdjustmentAlarmVolume.cpp (.../VAdjustmentAlarmVolume.cpp) (revision 27cc308ff5113a9386899d3c8f8b29962a8498e1) +++ sources/view/settings/VAdjustmentAlarmVolume.cpp (.../VAdjustmentAlarmVolume.cpp) (revision a04fd119778f0483cba5139a11e3c6bad7f2324a) @@ -41,7 +41,7 @@ // Please notice that it works but we are just predicting what the FW has and the GUI is totally agnostic about the FW current value, // so we get easily out of sync with FW. if (vData.mAccepted) { - hdAlarmVolume( _data.volume ); + hdAlarmVolume( _data.volume() ); status(""); } else { @@ -58,6 +58,6 @@ void View::VAdjustmentAlarmVolume::doAdjustment(quint8 vVolume) { - _data.volume = vVolume; + _data.volume(vVolume); emit didAdjustment(_data); } Index: sources/view/settings/VSettings.cpp =================================================================== diff -u -ra82ee4f326b26c4369f1306f867edc1bca6dabbe -ra04fd119778f0483cba5139a11e3c6bad7f2324a --- sources/view/settings/VSettings.cpp (.../VSettings.cpp) (revision a82ee4f326b26c4369f1306f867edc1bca6dabbe) +++ sources/view/settings/VSettings.cpp (.../VSettings.cpp) (revision a04fd119778f0483cba5139a11e3c6bad7f2324a) @@ -21,10 +21,28 @@ #include "MSettings.h" #include "Settings.h" -VIEW_DEF(VSettings, SettingsData) +VIEW_DEF_CLASS(VSettings) +void VSettings::initConnections() { + ACTION_RECEIVE_BRIDGE_CONNECTION(Gui::_GuiController, SettingsData); + PROPERTY_POST_CONNECTION(VSettings, servicePass); + PROPERTY_POST_CONNECTION(VSettings, alarmVolume); +} + +void VSettings::servicePass_post(const QString &vservicePass) { + Storage::Settings settings; + settings.save(servicePassCategory(), servicePassGroup(), servicePassKey(), vservicePass); +} + +void VSettings::alarmVolume_post(const quint8 &valarmVolume) { + Storage::Settings settings; + settings.save(alarmVolumeCategory(), alarmVolumeGroup(), alarmVolumeKey(), QString::number(valarmVolume)); +} + void VSettings::onActionReceive(const SettingsData &) { + // TODO: this function needs to be moved to the controller, to execute in settings thread not the main thread. + // it should then send the output here to update the specific properties defined. QVariantMap mSettings; QVariantMap mData; QStringList mCategorys = _Settings.categorys(); @@ -47,10 +65,22 @@ mSettings[group] = details; for (const auto &key : keys) { - QVariantMap keyValue; - keyValue[key] = _Settings.value(group, key); - + if ( isservicePass(category, group, key) ) { + QString mServicePass; + mServicePass = _Settings.value(group, key).toString(); + keyValue[key] = mServicePass ; + servicePass (mServicePass); + } + else if ( isalarmVolume(category, group, key) ) { + quint8 mAlarmVolume; + mAlarmVolume = _Settings.value(group, key).toInt(); // returns 0 if fails, so no error checking needed. + keyValue[key] = mAlarmVolume ; + alarmVolume (mAlarmVolume); + } + else { + keyValue[key] = _Settings.value(group, key); + } QVariantMap groups; groups [group] = keyValue; mData [category] = groups; @@ -62,12 +92,10 @@ settings(mSettings); data(mData); + // If the configuration exits, then it has been set, and this call internally will be neutral, + // otherwise will use the default value and will notify the update. + servicePass( _servicePass ); + alarmVolume( _alarmVolume ); + adjustment(true); } - - -void VSettings::doSave(const QString &vCategory, const QString &vGroup, const QString &vKey, const QString &vValue) -{ - Storage::Settings settings; - settings.save(vCategory, vGroup, vKey, vValue); -} Index: sources/view/settings/VSettings.h =================================================================== diff -u -ra82ee4f326b26c4369f1306f867edc1bca6dabbe -ra04fd119778f0483cba5139a11e3c6bad7f2324a --- sources/view/settings/VSettings.h (.../VSettings.h) (revision a82ee4f326b26c4369f1306f867edc1bca6dabbe) +++ sources/view/settings/VSettings.h (.../VSettings.h) (revision a04fd119778f0483cba5139a11e3c6bad7f2324a) @@ -31,17 +31,19 @@ TRIGGER ( bool , adjustment , 0 ) - // Don't use QVariantHash, qml don't like it and won't show the values. + // TODO: This view needs modification and it needs to isolate the settings and have its own specific properties, not the complete settings exposed to QML and let QML access it. + // Don't use QVariantHash, qml doesn't like it and won't show the values, *** and not even complains/errors ***. CONSTANT(QString , groupFormat , "%1^%2" ) PROPERTY(bool , initialized , false ) PROPERTY(QStringList , categorys , {} ) PROPERTY(QVariantMap , settings , {} ) PROPERTY(QVariantMap , data , {} ) + SETTINGS(QString , servicePass ,"123", "Settings/System", "Service", "Password") + SETTINGS(quint8 , alarmVolume , 100 , "Settings/System", "Alarm" , "Volume" ) + VIEW_DEC(VSettings, SettingsData) -public slots: - void doSave(const QString &vCategory, const QString &vGroup, const QString &vKey, const QString &vValue); }; }