Index: sources/view/settings/VSettings.cpp =================================================================== diff -u -r30d7e9993624feb138e7532ad2feaefc592f6a63 -raacab152859bb82a439a0a01e951e0ced2aac76e --- sources/view/settings/VSettings.cpp (.../VSettings.cpp) (revision 30d7e9993624feb138e7532ad2feaefc592f6a63) +++ sources/view/settings/VSettings.cpp (.../VSettings.cpp) (revision aacab152859bb82a439a0a01e951e0ced2aac76e) @@ -61,7 +61,9 @@ QStringList keys = _Settings.keys (category, group); QVariantList values = _Settings.values (category, group); if ( Storage::Settings::isCategoryInstructions( category ) ) { - updateInstructions(group, keys, values); + 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) { @@ -109,54 +111,65 @@ adjustment(true); } -void VSettings::updateReplacements(const QString &vGroup, QStringList &vKeys) +VSettings::TKeysList VSettings::updateReplacements(const QString &vGroup, const QStringList &vKeys) { + TKeysList keysList; for ( quint16 keyIndex = 0; keyIndex < vKeys.count(); keyIndex++ ) { - QRegExp regx("\\{\\w+:\\d+\\}"); + QRegExp regx("\\{\\s*\\d+\\s*:\\s*\\d+\\s*:\\s*\\w*\\s*:\\s*\\d*\\s*\\}"); QString key = vKeys[keyIndex]; int replacementCount = key.count(regx); - int oLen = 0; + QStringList keyList; 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()); + 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(); - quint8 ix = lst[1].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 = pos - oLen ; + loc.locIndex = j * 2 + 1 ; loc.prmIndex = ix ; - + loc.prmExtra = ex ; + loc.prmRound = rd ; _replacements[id] += loc; - qDebug() << "#" << replacementCount << id << ix << loc.group << loc.keyIndex << loc.locIndex << loc.prmIndex << oLen << cLen ; - oLen = cLen; + //DEBUG: qDebug() << "#" << replacementCount << id << loc.group << loc.keyIndex << loc.locIndex << loc.prmIndex; } - vKeys[keyIndex] = key; + keyList += key; + keysList += keyList; } + return keysList; } -void VSettings::updateInstructions(const QString &vGroup, QStringList &vKeys, const QVariantList &vValues) +void VSettings::updateInstructions(const QString &vGroup, const TKeysList &vKeysList, const QVariantList &vValues) { - // DEBUG : - // qDebug() << " ##### " - // << group - // << keys - // << values - // << location ; - QVariantMap details; - QString location = QString(Storage::Settings_Category_InstructionsImagesLoc).arg(Storage::Settings_Path_Name); + TInstruction mInstruction; + mInstruction.location = _location; + mInstruction.keys = vKeysList; + mInstruction.values = vValues ; + _instructionMap[vGroup] = mInstruction; +} - updateReplacements(vGroup, vKeys); - - details["location"] = location ; - details["keys" ] = vKeys ; - details["values" ] = vValues ; - - _instructions[vGroup] = details; +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 ; } /*! @@ -166,22 +179,33 @@ * \param vAction - the action * \param vData - the action data */ -void VSettings::onActionReceive (GuiActionType vAction, const QVariantList &) +void VSettings::onActionReceive (GuiActionType vAction, const QVariantList &vData) { 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(); + //DEBUG: 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(); - + //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); } - qDebug() << "\n"; } - if ( isChanged ) emit instructionsChanged(mInstructions); + if ( isChanged ) emit instructionsChanged(_instructions); }