/*! * * 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 VAlarmActiveList.cpp * \author (last) Behrouz NematiPour * \date (last) 13-Sep-2023 * \author (original) Behrouz NematiPour * \date (original) 27-May-2021 * */ #include "VAlarmActiveList.h" // Project #include "GuiController.h" #include "Settings.h" #define PROPERTY_ALARM_SET(vIndex) \ a##vIndex##ID ( vData.mAlarmID##vIndex ) ; \ if ( vData.mAlarmID##vIndex ) { \ a##vIndex##Text ( alarmIDText ( vData.mAlarmID##vIndex ) ); \ aListID += QString::number ( _a##vIndex##ID ); \ aListText += _a##vIndex##Text ; \ } \ else { a##vIndex##Text ( "" ); } \ #define PROPERTY_ALARM_RESET(vIndex) \ a##vIndex##ID ( 0 ) ; \ a##vIndex##Text ( "" ); \ VIEW_DEF_CLASS_ADJUSTMENT(VAlarmActiveList) /*! \brief Connection Initializer \details All the class signal/slot connections are defined here. */ void View::VAlarmActiveList::initConnections() { ADJUST_VIEW_CONNECTION(AlarmActiveListRequestData ); ACTION_VIEW_CONNECTION(AlarmActiveListResponseData ); ACTION_VIEW_CONNECTION(SettingsData ); } /*! * \brief VAlarmActiveList::onActionReceive * \details received response model data handler * \param vData - model data */ void View::VAlarmActiveList::onActionReceive(const AlarmActiveListResponseData &vData) { adjustment_Accepted ( vData.mAccepted ); adjustment_Reason ( vData.mReason ); QStringList aListID ; QStringList aListText; QString aStatus ; if (vData.mAccepted) { PROPERTY_ALARM_SET ( 0 ); PROPERTY_ALARM_SET ( 1 ); PROPERTY_ALARM_SET ( 2 ); PROPERTY_ALARM_SET ( 3 ); PROPERTY_ALARM_SET ( 4 ); PROPERTY_ALARM_SET ( 5 ); PROPERTY_ALARM_SET ( 6 ); PROPERTY_ALARM_SET ( 7 ); PROPERTY_ALARM_SET ( 8 ); PROPERTY_ALARM_SET ( 9 ); } else { aStatus = tr("No Active Alarm List\n%1").arg(text()); PROPERTY_ALARM_RESET ( 0 ); PROPERTY_ALARM_RESET ( 1 ); PROPERTY_ALARM_RESET ( 2 ); PROPERTY_ALARM_RESET ( 3 ); PROPERTY_ALARM_RESET ( 4 ); PROPERTY_ALARM_RESET ( 5 ); PROPERTY_ALARM_RESET ( 6 ); PROPERTY_ALARM_RESET ( 7 ); PROPERTY_ALARM_RESET ( 8 ); PROPERTY_ALARM_RESET ( 9 ); } status ( aStatus ); alarmIDs ( aListID ); alarmTexts ( aListText ); // *** has to be the last to let the information to be set and then emit the signal *** // *** otherwise will use the Previous values before being set. *** adjustment ( true ); } /*! * \brief VAlarmActiveList::alarmIDText * \details Looks up the alarm text from the alarm ID * \param vID - The Alarm ID * \return The alarm text (QString) */ QString View::VAlarmActiveList::alarmIDText(quint32 vID) { if ( _alarmTitles.contains(vID) ) { return _alarmTitles[vID]; } return Model::MAlarmStatusData::toText(static_cast(vID)); } /*! * \brief View::VAlarmActiveList::onActionReceive * \details This function updates the list of titles for each AlarmID to be used as the text in activeAlarmList screen, * when the settings controller is done reading the Alarms.conf and signaling this class. * \todo This function with the same one in VAlarmStatus needs to be moved to a Controller Model structure, for a better performance and memory management. */ void View::VAlarmActiveList::onActionReceive(const SettingsData &) { QString category = Storage::Settings_Category_Alarms; QStringList groups = _Settings.groups(category); for (const auto &group : groups) { bool ok = true; quint32 id = group.toInt( &ok ); if ( ! ok ) { LOG_DEBUG(QString("Invalid Alarm List ID [%1]").arg(group)); continue; } for (const QString &key : _Settings.keys(category, group)) { if (Storage::Settings::isKeyListTitle ( key ) ) { _alarmTitles[id] = _Settings.value(category, group, key).toString(); } } } } /*! * \brief View::VAlarmActiveList::doRequest * \details Sends the request to get the list of active alarms */ void View::VAlarmActiveList::doRequest() { AlarmActiveListRequestData data; emit didAdjustment(data); }