Index: sources/view/hd/alarm/VAlarmInstructionsModel.cpp =================================================================== diff -u -rf7d7e8b10c7626f3c6b8450876721a452ebd730f -rac9c658e925728918ccf010670d67f00fc0a8c08 --- sources/view/hd/alarm/VAlarmInstructionsModel.cpp (.../VAlarmInstructionsModel.cpp) (revision f7d7e8b10c7626f3c6b8450876721a452ebd730f) +++ sources/view/hd/alarm/VAlarmInstructionsModel.cpp (.../VAlarmInstructionsModel.cpp) (revision ac9c658e925728918ccf010670d67f00fc0a8c08) @@ -14,12 +14,6 @@ */ QHash View::VAlarmInstructionsModel::roleNames() const { -// static const QHash roles { -// { eRole_Instruction, "instruction" }, -// { eRole_Image, "image" }, -// }; -// return roles; - return _dataRoles; } @@ -33,27 +27,45 @@ } /*! - * \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. + * \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::VAlarmInstructionsModel::data(const QModelIndex &vIndex, int vRole) const { // check for invalid or out of bounds index - if (vIndex.isValid() == false || vIndex.row() >= rowCount() || vIndex.column() > 0) - { + if ( ! vIndex.isValid() || vIndex.row() >= rowCount()) { return QVariant(); } - else - { - // 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(); + + switch (vRole) { + case eRole_Instruction : return _data[vIndex.row()].value(eRole_Instruction) ; + case eRole_Image : return _data[vIndex.row()].value(eRole_Image) ; } + + return QString("Alarm %1").arg(vIndex.row()); } /*! + * \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::VAlarmInstructionsModel::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::VAlarmInstructionsModel::clear() { @@ -63,20 +75,6 @@ } /*! - * \brief Get an index for this list model from the given row, column, and parent. - * \param[in] row Index row - * \param[in] column Index column - * \param[in] parent Index parent - * \return An index for the given row, column, and parent, or an invalid index if row, column, - * or parent are not valid. - */ -QModelIndex View::VAlarmInstructionsModel::index(int vRow, int vColumn, const QModelIndex &vParent) const { - return hasIndex(vRow, vColumn, vParent) - ? createIndex(vRow, vColumn) - : QModelIndex(); -} - -/*! * \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. @@ -92,7 +90,7 @@ { _data[vIndex.row()][vRole] = vValue; // explicitly emit a dataChanged signal to notify anybody bound to this property (vRole) - Q_EMIT dataChanged(vIndex, vIndex, QVector(1, vRole)); + emit dataChanged(vIndex, vIndex, QVector(1, vRole)); } return true;