Index: sources/storage/TreatmentLog.cpp =================================================================== diff -u -ra9a506f16293b28e582395f90a0cba2bcdc0b34c -r85c0a859a587d035997f3d163dcf4303afb86d05 --- sources/storage/TreatmentLog.cpp (.../TreatmentLog.cpp) (revision a9a506f16293b28e582395f90a0cba2bcdc0b34c) +++ sources/storage/TreatmentLog.cpp (.../TreatmentLog.cpp) (revision 85c0a859a587d035997f3d163dcf4303afb86d05) @@ -23,6 +23,7 @@ #include "ApplicationController.h" #include "Logger.h" #include "MSettings.h" +#include "Settings.h" #include "CloudSyncController.h" #include "GuiGlobals.h" @@ -52,15 +53,25 @@ */ void TreatmentLog::initConnections() { connect(&_ApplicationController , + QOverload< const SettingsData & >::of( &ApplicationController::didActionReceive ), + [ this ] ( const SettingsData & ) + { + readAlarmTitles(); + readEventTitles(); + }); + + connect(&_ApplicationController , QOverload< const AdjustSerialNumberHDResponseData & >::of( &ApplicationController::didActionReceive ), - [ this ] ( const AdjustSerialNumberHDResponseData &vData ) { + [ this ] ( const AdjustSerialNumberHDResponseData &vData ) + { // The serial number is going to be recieved from HD // on POST or on request // and will be used for the device ID // which we designed initially to be different. _deviceID = vData.mSerialNumber; }); + connect(&_Logger , SIGNAL(didLogPathSet(Logger::LogType, const QString &)), this , SLOT( onLogPathSet(Logger::LogType, const QString &))); @@ -80,6 +91,85 @@ } /*! + * \brief TreatmentLog::readAlarmTitles + * \details Reads the ListTitle text from the Alarms.conf for the titles of the alarms going to be written in the TxReport. + */ +void TreatmentLog::readAlarmTitles() +{ + //NOTE: It currently is the duplicate of VAlarmActiveList titles, + // but intentionally kept it separated to be able to implement a different text/titles in case on cloud we would want something different. + 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 Tx Alarm ID [%1]").arg(group)); continue; } + + for (const QString &key : _Settings.keys(category, group)) { + if (Storage::Settings::isKeyListTitle ( key ) ) { + _treatmentLogAlarmTitles[id] = _Settings.value(category, group, key).toString(); + } + } + } +} + +/*! + * \brief TreatmentLog::readEventTitles + * \details Reads the Title text from the Events.conf for the titles of the events going to be written in the TxReport. + */ +void TreatmentLog::readEventTitles() +{ + QString category = Storage::Settings_Category_Events; + QStringList groups = _Settings.groups(category); + for (const auto &group : groups) { + bool ok = true; + quint32 id = group.toInt( &ok ); + if ( ! ok ) { LOG_DEBUG(QString("Undefined Tx Events ID [%1]").arg(group)); continue; } + + for (const QString &key : _Settings.keys(category, group)) { + if (Storage::Settings::isKeyTitle ( key ) ) { + _treatmentLogEventTitles[id] = _Settings.value(category, group, key).toString(); + } + } + } +} + +/*! + * \brief TreatmentLog::alarmTitle + * \details prepares the alarm title and returns. + * \param vID - the alarm ID + * \return the alarm title + */ +QString TreatmentLog::alarmTitle(quint32 vID) { + QString str = "%1-%2"; + QString title = "undefined"; + if ( _treatmentLogAlarmTitles.contains(vID) ) { + title = _treatmentLogAlarmTitles[vID] + .replace("," , "-") // the Txr is a csv file and any ',' in the title will break it. + .replace("\n" , "-"); // removing any new line since this will break the Txr as well. + } + return str.arg(vID, 3).arg(title); +} + +/*! + * \brief TreatmentLog::eventTitle + * \details prepares the event title and returns. + * \param vID - the event ID + * \return the event title + */ +QString TreatmentLog::eventTitle(quint32 vID) { + QString str = "%1 - %2"; + QString title = "undefined"; + if ( _treatmentLogEventTitles.contains(vID) ) { + title = _treatmentLogEventTitles[vID] + .replace("," , "-") // the Txr is a csv file and any ',' in the title will break it. + .replace("\n" , "-"); // removing any new line since this will break the Txr as well. + } + return str.arg(vID, 3).arg(title); +} + + +/*! * \brief TreatmentLog::timerEvent * \details The overloaded method of the main class to capture the QObject timer. */ @@ -313,20 +403,20 @@ for ( const TreatmentLogAlarmData &item : _treatmentLogAlarmData ) { QString line; // TODO : QString alarmText = Model::MAlarmStatus::toText(static_cast(item.mAlarmID)); - line += csv.arg(item.mTimeStamp ); - line += csv.arg(item.mAlarmID ); // may need to change, during our discussion with Sean and I 04/11/2022. to alarmText - line += csv.arg(item.mParam1 ); // may need to remove, during our discussion with Sean and I 04/11/2022. - line += end.arg(item.mParam2 ); // may need to remove, during our discussion with Sean and I 04/11/2022. + line += csv.arg( item.mTimeStamp ); + line += csv.arg( alarmTitle(item.mAlarmID )); + line += csv.arg( item.mParam1 ); + line += end.arg( item.mParam2 ); ADDALINE(line); } ADDTITLE("Treatment Events" ); for ( const TreatmentLogEventData &item : _treatmentLogEventData ) { QString line; - line += csv.arg(item.mTimeStamp ); - line += csv.arg(item.mEventID ); - line += csv.arg(item.mOldValue ,FLOAT3 ); - line += end.arg(item.mNewValue ,FLOAT3 ); + line += csv.arg( item.mTimeStamp ); + line += csv.arg( eventTitle(item.mEventID )); + line += csv.arg( item.mOldValue ,FLOAT3 ); + line += end.arg( item.mNewValue ,FLOAT3 ); ADDALINE(line); } ADDALINE("");