/*! * * Copyright (c) 2021-2024 Diality Inc. - All Rights Reserved. * \copyright * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * * \file VAdjustmentResponseBase.cpp * \author (last) Behrouz NematiPour * \date (last) 16-Apr-2021 * \author (original) Behrouz NematiPour * \date (original) 16-Apr-2021 * */ #include "VAdjustmentResponseBase.h" // Project #include "GuiController.h" #include "Settings.h" VIEW_DEF_CLASS(VAdjustmentResponseBase) void View::VAdjustmentResponseBase::initConnections() { ACTION_VIEW_CONNECTION(SettingsData); } /*! * \brief View::VAdjustmentResponseBase::text * \details The slot to get the Reason Description * \return Reason description as string */ QString View::VAdjustmentResponseBase::text() { QString text; 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. }