Index: sources/view/settings/VSettings.cpp =================================================================== diff -u -re961fc7bcdeba8ffab9c96da20244b07405f8f99 -r30d7e9993624feb138e7532ad2feaefc592f6a63 --- sources/view/settings/VSettings.cpp (.../VSettings.cpp) (revision e961fc7bcdeba8ffab9c96da20244b07405f8f99) +++ sources/view/settings/VSettings.cpp (.../VSettings.cpp) (revision 30d7e9993624feb138e7532ad2feaefc592f6a63) @@ -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,14 @@ { // 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; + updateInstructions(group, keys, values); } 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 +98,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 +108,80 @@ adjustment(true); } + +void VSettings::updateReplacements(const QString &vGroup, QStringList &vKeys) +{ + for ( quint16 keyIndex = 0; keyIndex < vKeys.count(); keyIndex++ ) { + QRegExp regx("\\{\\w+:\\d+\\}"); + QString key = vKeys[keyIndex]; + int replacementCount = key.count(regx); + int oLen = 0; + for ( int j = 0; j < replacementCount; j++ ) { + int cLen = 0; + int pos = key.indexOf(regx); + cLen = regx.matchedLength(); + QString blk = key.mid(pos+1, cLen-2); + key.remove(pos, regx.matchedLength()); + QStringList lst = blk.split(":"); + quint16 id = lst[0].toUInt(); + quint8 ix = lst[1].toUInt(); + TLocation loc; + loc.group = vGroup ; + loc.keyIndex = keyIndex ; + loc.locIndex = pos - oLen ; + loc.prmIndex = ix ; + + _replacements[id] += loc; + qDebug() << "#" << replacementCount << id << ix << loc.group << loc.keyIndex << loc.locIndex << loc.prmIndex << oLen << cLen ; + oLen = cLen; + } + vKeys[keyIndex] = key; + } +} + +void VSettings::updateInstructions(const QString &vGroup, QStringList &vKeys, const QVariantList &vValues) +{ + // DEBUG : + // qDebug() << " ##### " + // << group + // << keys + // << values + // << location ; + QVariantMap details; + QString location = QString(Storage::Settings_Category_InstructionsImagesLoc).arg(Storage::Settings_Path_Name); + + updateReplacements(vGroup, vKeys); + + details["location"] = location ; + details["keys" ] = vKeys ; + details["values" ] = vValues ; + + _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 &) +{ + bool isChanged = false; + QVariantMap mInstructions = _instructions; // the original should be kept unchanged since all the posIndexes will change if values added. + quint16 id = qFromBigEndian((quint16)vAction); + if (_replacements.contains(id)) { + isChanged = true; + qDebug() << _replacements[id].count(); + for ( auto item : _replacements[id]) { + qDebug() << id << item.group << item.keyIndex << item.locIndex << item.prmIndex; + QVariantMap details = mInstructions[item.group].toMap(); + // QStringList keys = details["keys" ].toStringList(); + // qDebug() << keys.at(item.keyIndex).insert(); + + } + qDebug() << "\n"; + } + if ( isChanged ) emit instructionsChanged(mInstructions); +}