Index: sources/view/hd/alarm/VAlarmStatus.cpp =================================================================== diff -u -r0f83de066c8a116195a3cc60577d597ef9654c55 -ra6b0dd1e380125fc9128dbe882c6eaf488098c3d --- sources/view/hd/alarm/VAlarmStatus.cpp (.../VAlarmStatus.cpp) (revision 0f83de066c8a116195a3cc60577d597ef9654c55) +++ sources/view/hd/alarm/VAlarmStatus.cpp (.../VAlarmStatus.cpp) (revision a6b0dd1e380125fc9128dbe882c6eaf488098c3d) @@ -14,6 +14,10 @@ */ #include "VAlarmStatus.h" +// Qt +#include +#include + // Project #include "GuiController.h" #include "Settings.h" @@ -26,6 +30,9 @@ ADJUST_VIEW_CONNECTION(AlarmSilenceRequestData ); ADJUST_VIEW_CONNECTION(AlarmUserActionRequestData ); + connect(&_GuiController, SIGNAL(didActionReceive (GuiActionType, const QVariantList &)), + this , SLOT( onActionReceive (GuiActionType, const QVariantList &))); + _instructionsList.setRoleNames({ { eRole_Instruction , "instruction" }, { eRole_Image , "image" }, @@ -228,11 +235,10 @@ QFileInfo fileInfo(imagePath); - QHash instructionStep; - instructionStep.insert(eRole_Instruction, key); + QStringList updatedKey = updateReplacements(group, key, id, instructionData.count()); + instructionStep.insert(eRole_Instruction, updatedKey); instructionStep.insert(eRole_Image, fileInfo.exists() && fileInfo.isFile() ? "file:" + imagePath : "") ; - instructionData.append(instructionStep); alarmData.instructions = instructionData; } @@ -249,3 +255,82 @@ } emit alarm_AlarmIDChanged(_alarm_AlarmID); // to get the dialog content in sync with the Alarm.conf in case there is an early alarm. } + +QStringList VAlarmStatus::updateReplacements(const QString &vGroup, const QString &vKey, const int &vAlarmID, const int &vIndex) +{ + QRegExp regx("\\{\\s*\\d+\\s*:\\s*\\d+\\s*:\\s*\\w*\\s*:\\s*\\d*\\s*\\}"); + QString key = vKey; + 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(); + Q_UNUSED(vGroup); + TLocation loc; + loc.group = vGroup ; + loc.alarmID = vAlarmID ; + loc.index = vIndex ; + loc.locIndex = j * 2 + 1 ; + loc.prmIndex = ix ; + loc.prmExtra = ex ; + loc.prmRound = rd ; + + _replacements[id] += loc; + } + keyList += key; + + return keyList; +} + +/*! + * \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 VAlarmStatus::onActionReceive (GuiActionType vAction, const QVariantList &vData) +{ + bool isChanged = false; + quint16 id = qFromBigEndian((quint16)vAction); + quint32 alarmID; + if (_replacements.contains(id)) { + isChanged = true; + for ( const auto &item : _replacements[id]) { + 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 { + qDebug() << QString("Given prmIndex %1 is out of message %2 parameters count %3 on alarm id '%4'") + .arg(item.prmIndex).arg(id).arg(len).arg(item.alarmID); + continue; + } + + // update alarm instruction step + alarmID = item.alarmID; + QStringList step = _alarms[alarmID].instructions[item.index][eRole_Instruction].toStringList(); + step[item.locIndex] = value; + _alarms[alarmID].instructions[item.index][eRole_Instruction] = step; + } + } + + if ( isChanged ) emit alarm_AlarmIDChanged(alarmID); +}