Index: leahi.pro =================================================================== diff -u -rc6c42296a6cb4a9c3cd7e4cc1505ddc0475a5a18 -r8c7b9550b05f223be9d094e850e06f9ed80adb70 --- leahi.pro (.../leahi.pro) (revision c6c42296a6cb4a9c3cd7e4cc1505ddc0475a5a18) +++ leahi.pro (.../leahi.pro) (revision 8c7b9550b05f223be9d094e850e06f9ed80adb70) @@ -170,13 +170,13 @@ sources/model/MModel.h \ sources/model/MAbstract.h \ sources/model/MAbstractDynamic.h \ + sources/model/MListModel.h \ sources/device/DeviceModels.h \ \ # ---------- Models - TD - Data //// ----- @LEAHIZED sources/model/td/data/MTDOpModeData.h \ \ # ---------- Views - TD - Data - States //// ----- @LEAHIZED sources/view/dd/data/VDDConductivityData.h \ sources/view/dd/data/VDDGenDialysateData.h \ - sources/view/hd/alarm/VAlarmInstructionsModel.h \ sources/view/hd/data/VTreatmentRanges.h \ sources/view/td/data/VTDAirTrapData.h \ sources/view/td/data/VTDBatteryData.h \ @@ -465,13 +465,13 @@ sources/storage/TreatmentLog.cpp \ sources/view/dd/data/VDDConductivityData.cpp \ sources/view/dd/data/VDDGenDialysateData.cpp \ - sources/view/hd/alarm/VAlarmInstructionsModel.cpp \ sources/view/hd/data/post/VHDPOSTData.cpp \ sources/bluetooth/BluetoothInterface.cpp \ sources/cloudsync/CloudSyncController.cpp \ \ # ---------- Models ---------- sources/model/MAbstract.cpp \ sources/model/MAbstractDynamic.cpp \ + sources/model/MListModel.cpp \ sources/device/DeviceModels.cpp \ \ # ---------- Models - TD - Data - States sources/model/td/data/MTDOpModeData.cpp \ Index: sources/gui/qml/AlarmItem.qml =================================================================== diff -u -rb45c898bb2fef51abb9460a1306f07eaa8dcbab0 -r8c7b9550b05f223be9d094e850e06f9ed80adb70 --- sources/gui/qml/AlarmItem.qml (.../AlarmItem.qml) (revision b45c898bb2fef51abb9460a1306f07eaa8dcbab0) +++ sources/gui/qml/AlarmItem.qml (.../AlarmItem.qml) (revision 8c7b9550b05f223be9d094e850e06f9ed80adb70) @@ -114,7 +114,7 @@ titleText : vAlarmStatus.title titlePixelSize : Fonts.fontPixelAlarmTitle - instructionModel : vAlarmStatus.instructionModel + instructionModel : vAlarmStatus.instructions alarmID : vAlarmStatus.alarm_AlarmID isSilenced : vAlarmStatus.alarm_Flag_alarmsSilenced timeout : vAlarmStatus.alarm_MuteTimeout @@ -142,6 +142,7 @@ } AlarmListDialog { id : _alarmListDialog + titleText : vAlarmStatus.listTitle isSilenced : vAlarmStatus.alarm_Flag_alarmsSilenced timeout : vAlarmStatus.alarm_MuteTimeout minVisible : ! vAlarmStatus.alarm_Flag_noMinimize Index: sources/model/MListModel.cpp =================================================================== diff -u --- sources/model/MListModel.cpp (revision 0) +++ sources/model/MListModel.cpp (revision 8c7b9550b05f223be9d094e850e06f9ed80adb70) @@ -0,0 +1,118 @@ +#include "MListModel.h" + +/*! + * \brief Retrieve the role names set for this list model. + * \return Role names used for this model. + */ +QHash View::MListModel::roleNames() const +{ + return _roleNames; +} + +/*! + * \brief Set the role names for the data in this list model. + * \param[in] roleNames New role names for this list model. + * \note This will clear the list model of any data. + */ +void View::MListModel::setRoleNames(const QHash& vRoleNames) +{ + if (_roleNames != vRoleNames) + { + clear(); + _roleNames = vRoleNames; + } +} + +/*! + * \brief Get the number of rows in this list model. + * \return Number of rows in this list model. + */ +int View::MListModel::rowCount(const QModelIndex &) const +{ + return _data.size(); +} + +/*! + * \brief Retrieve the data stored at the given index for the specified role. + * \param[in] index Index of the data in the list model. + * \param[in] role Role of the data to fetch. + * \return Data at index for role or Invalid if index or role are not valid. + */ +QVariant View::MListModel::data(const QModelIndex &vIndex, int vRole) const +{ + // check for invalid or out of bounds index + if ( ! vIndex.isValid() || vIndex.row() >= rowCount()) { + return QVariant(); + } + + // ensure the role is in the data and return it, otherwise return invalid + return (_data[vIndex.row()].find(vRole) != _data[vIndex.row()].end()) + ? _data[vIndex.row()][vRole] + : QVariant(); +} + +/*! + * \brief Retrieve the data stored at the given index for the specified role and expose to QML + * \param[in] vRow Index of the data in the list model. + */ +QVariantMap View::MListModel::get(int vRow) const +{ + if (vRow < 0 || vRow >= rowCount()) { + return {}; + } + + QHash roles = roleNames(); + QVariantMap map; + for (auto it = roles.begin(); it != roles.end(); ++it) { + map[it.value()] = data(index(vRow, 0), it.key()); + } + return map; +} + +/*! + * \brief Clear any data contained in this list model. + */ +void View::MListModel::clear() { + beginRemoveRows(QModelIndex(), 0, rowCount()); + _data.clear(); + endRemoveRows(); +} + +/*! + * \brief Sets the value of the data in this list model at the given index and for the given role. + * \param[in] index Location of data to update. + * \param[in] value Value to set. + * \param[in] role The role of the data at the given index to set. + * \return Return true if data was set properly, otherwise false. + */ +bool View::MListModel::setData(const QModelIndex &vIndex, const QVariant& vValue, int vRole) { + if (! vIndex.isValid() || vIndex.row() >= _data.count()) { + return false; + } + + if (_data[vIndex.row()][vRole] != vValue) + { + _data[vIndex.row()][vRole] = vValue; + // explicitly emit a dataChanged signal to notify anybody bound to this property (vRole) + emit dataChanged(vIndex, vIndex, QVector(1, vRole)); + } + + return true; +} + +/*! + * \brief Assignment operator + * \return A reference to this object. + */ +View::MListModel& View::MListModel::operator = (const QList> &src) +{ + clear(); + + if (_data != src) + { + beginInsertRows(QModelIndex(), 0, src.count() - 1); + _data = src; + endInsertRows(); + } + return *this; +} Index: sources/model/MListModel.h =================================================================== diff -u --- sources/model/MListModel.h (revision 0) +++ sources/model/MListModel.h (revision 8c7b9550b05f223be9d094e850e06f9ed80adb70) @@ -0,0 +1,39 @@ +#pragma once + +// Qt +#include +#include +#include +#include + +// Project +#include "main.h" // Doxygen : do not remove +#include "VView.h" + +// namespace +namespace View { + +class MListModel : public QAbstractListModel +{ + Q_OBJECT + +public: + explicit MListModel(QObject *parent = nullptr) : QAbstractListModel (parent) { } + + QHash roleNames ( ) const override; + int rowCount (const QModelIndex & = QModelIndex() ) const override; + QVariant data (const QModelIndex &vIndex, int vRole = Qt::DisplayRole ) const override; + bool setData (const QModelIndex &vIndex, const QVariant& vValue, int vRole = Qt::EditRole) override; + void clear ( ); + void setRoleNames(const QHash& vRoleNames ); + MListModel &operator = (const QList> &src ); + +public slots: + QVariantMap get (int vRow ) const; // Exposed to QML + +private: + QList> _data; + QHash _roleNames; + +}; +} Fisheye: Tag 8c7b9550b05f223be9d094e850e06f9ed80adb70 refers to a dead (removed) revision in file `sources/view/hd/alarm/VAlarmInstructionsModel.cpp'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 8c7b9550b05f223be9d094e850e06f9ed80adb70 refers to a dead (removed) revision in file `sources/view/hd/alarm/VAlarmInstructionsModel.h'. Fisheye: No comparison available. Pass `N' to diff? Index: sources/view/hd/alarm/VAlarmStatus.cpp =================================================================== diff -u -rb45c898bb2fef51abb9460a1306f07eaa8dcbab0 -r8c7b9550b05f223be9d094e850e06f9ed80adb70 --- sources/view/hd/alarm/VAlarmStatus.cpp (.../VAlarmStatus.cpp) (revision b45c898bb2fef51abb9460a1306f07eaa8dcbab0) +++ sources/view/hd/alarm/VAlarmStatus.cpp (.../VAlarmStatus.cpp) (revision 8c7b9550b05f223be9d094e850e06f9ed80adb70) @@ -25,6 +25,11 @@ ACTION_VIEW_CONNECTION(SettingsData ); ADJUST_VIEW_CONNECTION(AlarmSilenceRequestData ); ADJUST_VIEW_CONNECTION(AlarmUserActionRequestData ); + + _instructionsList.setRoleNames({ + { eRole_Instruction , "instruction" }, + { eRole_Image , "image" }, + }); } /*! @@ -154,7 +159,7 @@ || ( _alarm_Flag_alarmsSilencedChanged && ! _alarm_Flag_alarmsSilenced ) ){ - _alarmInstructionsList = _alarms[_alarm_AlarmID].instructions; + _instructionsList = _alarms[_alarm_AlarmID].instructions; emit didAlarmRaise(); } } @@ -179,7 +184,8 @@ return alarmIDText(static_cast(alarm_AlarmID())); } -QString VAlarmStatus::title () { if ( ! _alarm_AlarmID ) return {}; QString s = _alarms[_alarm_AlarmID].title ; if ( ! s.isEmpty()) return s; else return tr("Alarm") ; } +QString VAlarmStatus::title () { if ( ! _alarm_AlarmID ) return {}; QString s = _alarms[_alarm_AlarmID].title ; if ( ! s.isEmpty()) return s; else return tr("Alarm") ; } +QString VAlarmStatus::listTitle () { if ( ! _alarm_AlarmID ) return {}; QString s = _alarms[_alarm_AlarmID].listTitle ; if ( ! s.isEmpty()) return s; else return tr("Alarm") ; } /*! * \brief View::VAlarmStatus::onActionReceive @@ -200,12 +206,14 @@ for (const QString &key : _Settings.keys(category, group)) { if (Storage::Settings::isKeyTitle ( key ) ) { alarmData.title = _Settings.value(category, group, key).toString(); + } else if (Storage::Settings::isKeyListTitle ( key ) ) { + alarmData.listTitle = _Settings.value(category, group, key).toString(); } else { const QString imagePath = QStringLiteral("%1%2").arg(_location) .arg(_Settings.value(category, group, key).toString()); QHash instructionStep; - instructionStep.insert(VAlarmInstructionsModel::eRole_Instruction, key); - instructionStep.insert(VAlarmInstructionsModel::eRole_Image, QFile::exists(imagePath) ? "file:" + imagePath : + instructionStep.insert(eRole_Instruction, key); + instructionStep.insert(eRole_Image, QFile::exists(imagePath) ? "file:" + imagePath : QStringLiteral("file:%1%2").arg(_location) .arg("defaultImage.png")); Index: sources/view/hd/alarm/VAlarmStatus.h =================================================================== diff -u -r053733c0980921ac85961bbf9c0076e2dd65c96c -r8c7b9550b05f223be9d094e850e06f9ed80adb70 --- sources/view/hd/alarm/VAlarmStatus.h (.../VAlarmStatus.h) (revision 053733c0980921ac85961bbf9c0076e2dd65c96c) +++ sources/view/hd/alarm/VAlarmStatus.h (.../VAlarmStatus.h) (revision 8c7b9550b05f223be9d094e850e06f9ed80adb70) @@ -27,7 +27,7 @@ #include "MessageGlobals.h" #include "format.h" #include "VAdjustmentResponseBase.h" -#include "VAlarmInstructionsModel.h" +#include "MListModel.h" // forward declarations class tst_views; @@ -53,7 +53,8 @@ typedef QList> InstructionData; struct AlarmData { - QString title = ""; + QString title = ""; + QString listTitle = ""; InstructionData instructions; }; @@ -82,8 +83,9 @@ // ********** STATIC PROPERTIES: The properties which need to be updated by each alarm message received. ********** // Q_PROPERTY(QString title READ title NOTIFY alarm_AlarmIDChanged ) + Q_PROPERTY(QString listTitle READ listTitle NOTIFY alarm_AlarmIDChanged ) Q_PROPERTY(QString text READ text NOTIFY alarm_AlarmIDChanged ) - Q_PROPERTY(VAlarmInstructionsModel* instructionModel READ instructionModel NOTIFY alarm_AlarmIDChanged) + Q_PROPERTY(MListModel* instructions READ instructions NOTIFY alarm_AlarmIDChanged) VIEW_DEC_CLASS ( VAlarmStatus ) VIEW_DEC_SLOT ( AlarmStatusData ) @@ -92,13 +94,20 @@ ADJUST_TRANSMT_SIGNAL ( AlarmSilenceRequestData ) ADJUST_TRANSMT_SIGNAL ( AlarmUserActionRequestData ) +public: + enum { + eRole_Instruction = Qt::UserRole, + eRole_Image , + } DataRole; + private: QString title (); + QString listTitle (); QString text (); QString alarmIDText (GuiAlarmID vEnum); - VAlarmInstructionsModel* instructionModel() { return &_alarmInstructionsList; } ; + MListModel* instructions() { return &_instructionsList; } ; - VAlarmInstructionsModel _alarmInstructionsList; + MListModel _instructionsList; signals: void didAlarmRaise();