Index: sources/view/settings/VSettings.cpp =================================================================== diff -u -r9c4f0c53c40656e8a7442d6739cc77454678d2d6 -rfde18b0e9684a491bdef054b9057159ca36afad7 --- sources/view/settings/VSettings.cpp (.../VSettings.cpp) (revision 9c4f0c53c40656e8a7442d6739cc77454678d2d6) +++ sources/view/settings/VSettings.cpp (.../VSettings.cpp) (revision fde18b0e9684a491bdef054b9057159ca36afad7) @@ -15,6 +15,7 @@ #include "VSettings.h" // Qt +#include // Project #include "GuiController.h" @@ -28,6 +29,10 @@ PROPERTY_POST_CONNECTION(VSettings, servicePass ); PROPERTY_POST_CONNECTION(VSettings, alarmVolume ); PROPERTY_POST_CONNECTION(VSettings, noCANBus ); + + connect(&_GuiController, SIGNAL(didActionReceive (GuiActionType, const QVariantList &)), + this , SLOT( onActionReceive (GuiActionType, const QVariantList &))); + } void VSettings::servicePass_post(const QString &vservicePass) { @@ -49,27 +54,16 @@ { // 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 mInstructions; QStringList mCategorys = _Settings.categorys(); for (const auto &category : mCategorys) { QStringList groups = _Settings.groups(category); for (const auto &group : groups) { QStringList keys = _Settings.keys (category, group); QVariantList values = _Settings.values (category, group); if ( Storage::Settings::isCategoryInstructions( category ) ) { - // DEBUG : - // qDebug() << " ##### " - // << group - // << keys - // << values - // << location ; - QVariantMap details; - QString location = QString(Storage::Settings_Category_InstructionsImagesLoc).arg(Storage::Settings_Path_Name); - details["location"] = location; - details["keys" ] = keys ; - details["values" ] = values ; - - mInstructions[group] = details; + TKeysList keysList = updateReplacements(group, keys ); + updateInstructions(group, keysList, values ); + updateInstructions(group ); } else { //TODO: Since it is global system settings, move this to the settings controller so the C++ backend can also use it. like Date/Time formats. for (const auto &key : keys) { @@ -106,7 +100,7 @@ } categorys (mCategorys); - instructions(mInstructions); + emit instructionsChanged(_instructions); // 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. @@ -116,3 +110,102 @@ adjustment(true); } + +VSettings::TKeysList VSettings::updateReplacements(const QString &vGroup, const QStringList &vKeys) +{ + TKeysList keysList; + for ( quint16 keyIndex = 0; keyIndex < vKeys.count(); keyIndex++ ) { + QRegExp regx("\\{\\s*\\d+\\s*:\\s*\\d+\\s*:\\s*\\w*\\s*:\\s*\\d*\\s*\\}"); + QString key = vKeys[keyIndex]; + int replacementCount = key.count(regx); + QStringList keyList; + for ( int j = 0; j < replacementCount; j++ ) { + int pos = key.indexOf(regx); + int len = regx.matchedLength(); + QString blk = key.mid(pos+1, len-2); + keyList += key.mid(0, pos); + keyList += ""; // value placeholder + key.remove(0, pos + regx.matchedLength()); + QStringList lst = blk.split(":"); + quint16 id = lst[0].toUInt(); + quint16 ix = lst[1].toUInt(); + QString ex = lst[2] ; + quint16 rd = lst[3].toUInt(); + TLocation loc; + loc.group = vGroup ; + loc.keyIndex = keyIndex ; + loc.locIndex = j * 2 + 1 ; + loc.prmIndex = ix ; + loc.prmExtra = ex ; + loc.prmRound = rd ; + _replacements[id] += loc; + //DEBUG: qDebug() << "#" << replacementCount << id << loc.group << loc.keyIndex << loc.locIndex << loc.prmIndex; + } + keyList += key; + keysList += keyList; + } + return keysList; +} + +void VSettings::updateInstructions(const QString &vGroup, const TKeysList &vKeysList, const QVariantList &vValues) +{ + TInstruction mInstruction; + mInstruction.location = _location; + mInstruction.keys = vKeysList; + mInstruction.values = vValues ; + _instructionMap[vGroup] = mInstruction; +} + +void VSettings::updateInstructions(const QString &vGroup) +{ + //TODO: this function or even the structure may need to update to send less data to qml and only the updated part. + TKeysList keysList = _instructionMap[vGroup].keys ; + QVariantList values = _instructionMap[vGroup].values; + QStringList keyList; + for ( const auto &keys : keysList) { + keyList += keys.join(""); + } + QVariantMap details; + details["location"] = _location ; + details["keys" ] = keyList ; + details["values" ] = values ; + _instructions[vGroup] = details ; +} + +/*! + * \brief VSettings::onActionReceive + * \details emits didActionReceive signal to notify other classes (Gui) + * , an action has been received. + * \param vAction - the action + * \param vData - the action data + */ +void VSettings::onActionReceive (GuiActionType vAction, const QVariantList &vData) +{ + bool isChanged = false; + quint16 id = qFromBigEndian((quint16)vAction); + if (_replacements.contains(id)) { + isChanged = true; + //DEBUG: qDebug() << _replacements[id].count(); + for ( auto item : _replacements[id]) { + //DEBUG: qDebug() << id << item.group << item.keyIndex << item.locIndex << item.prmIndex; + QString value; + quint16 len = vData.length(); + if ( 0 < item.prmIndex && item.prmIndex <= len ) { + if ( item.prmRound > 0 ) { + value = QString::number(vData[item.prmIndex - 1].toFloat(), 'f', item.prmRound) + item.prmExtra; + } + else { + value = vData[item.prmIndex - 1].toString() + item.prmExtra; + } + } + else { + LOG_DEBUG(QString("Given prmIndex %1 is out of message %2 parameters count %3 on instruction group '%4' and key index %5") + .arg(item.prmIndex).arg(id).arg(len).arg(item.group).arg(item.keyIndex)); + continue; + } + _instructionMap[item.group].keys[item.keyIndex][item.locIndex] = value; + updateInstructions(item.group); + } + } + if ( isChanged ) emit instructionsChanged(_instructions); +}