Index: sources/view/VAdjustmentResponseBase.cpp =================================================================== diff -u -r2ef03b2ce51b4dc507f66e9671953a8e0824bde9 -r7a3067893b8133d0f47bbdddd3268439e722d37d --- sources/view/VAdjustmentResponseBase.cpp (.../VAdjustmentResponseBase.cpp) (revision 2ef03b2ce51b4dc507f66e9671953a8e0824bde9) +++ sources/view/VAdjustmentResponseBase.cpp (.../VAdjustmentResponseBase.cpp) (revision 7a3067893b8133d0f47bbdddd3268439e722d37d) @@ -16,9 +16,12 @@ // Project #include "GuiController.h" +#include "Settings.h" VIEW_DEF_CLASS(VAdjustmentResponseBase) -void View::VAdjustmentResponseBase::initConnections() { } +void View::VAdjustmentResponseBase::initConnections() { + ACTION_VIEW_CONNECTION(SettingsData); +} /*! * \brief View::VAdjustmentResponseBase::text @@ -28,7 +31,66 @@ QString View::VAdjustmentResponseBase::text() { QString text; - if (_adjustment_Reason != GuiRequestReasons::REQUEST_REJECT_REASON_NONE) - text = Gui::enumString(static_cast(_adjustment_Reason), "[%1] Unknown Error"); + if (_adjustment_Reason != GuiRequestReasons::REQUEST_REJECT_REASON_NONE) { + text = title(); + } return text; } + +/*! + * \brief View::VAdjustmentResponseBase::title + * \details The slot to get the Rejection Title + * \return Rejection Title as string + */ +QString View::VAdjustmentResponseBase::title () +{ + if ( ! _adjustment_Reason ) + return {}; + + QString s = _rejects[_adjustment_Reason].title; + + if ( ! s.isEmpty()) + return s; + else + return tr("Rejected") ; +} + +/*! + * \brief View::onActionReceive + * \details This function updates the reject structure defined here to be used on the AlarmDialogs, + * when the settings controller is done reading the Alarms.conf and signaling this class. + * \todo This function with the same one in VActiveAlarmList needs to be moved to a Controller Model structure, for a better performance and memory management. + */ +void View::VAdjustmentResponseBase::onActionReceive(const SettingsData &) { + QString category = Storage::Settings_Category_Rejects; + QStringList groups = _Settings.groups(category); + + for (const auto &group : groups) { + bool ok = true; + quint32 id = group.toInt( &ok ); + if ( ! ok ) { LOG_DEBUG(QString("Invalid Reject ID [%1]").arg(group)); continue; } + + RejectData rejectData; + InstructionData instructionData; + for (const QString &key : _Settings.keys(category, group)) { + if (Storage::Settings::isKeyTitle ( key ) ) { + rejectData.title = _Settings.value(category, group, key).toString(); + } else if (Storage::Settings::isKeyMessage ( key ) ) { + rejectData.message = _Settings.value(category, group, key).toString(); + } else { + instructionData[key] = _Settings.value(category, group, key).toString(); + rejectData.instructions = instructionData; + } + } + _rejects[id] = rejectData; + + /// DEBUG: + /// TODO: the MSettings model should do the same has been done here and use map instead of separate structure to iterate vertically, while map supports, keys, values. + /// qDebug() << "@TR: category:" << category << ":" << id << _rejects[id].title << _rejects[id].message << _rejects[id].instructions.keys() << _rejects[id].instructions.values(); + /// for (const auto &key : _rejects[id].instructions.keys()) { + /// qDebug() << "-" << key << _rejects[id].instructions.value(key); + /// } + } + + emit adjustment_ReasonTriggered (_adjustment_Reason); // to get the dialog content in sync with the Rejects.conf in case there is an early reject. +}