#include "VAlarmInstructionsModel.h" VIEW_DEF_CLASS_EX(VAlarmInstructionsModel, QAbstractListModel) void VAlarmInstructionsModel::initConnections() { } /*! * \brief Retrieve the role names set for this list model. * \return Role names used for this model. */ QHash View::VAlarmInstructionsModel::roleNames() const { // static const QHash roles { // { eRole_Instruction, "instruction" }, // { eRole_Image, "image" }, // }; // return roles; return _dataRoles; } /*! * \brief Get the number of rows in this list model. * \return Number of rows in this list model. */ int View::VAlarmInstructionsModel::rowCount(const QModelIndex &) const { return _data.size(); } /*! * \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. */ 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) { 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(); } } /*! * \brief Clear any data contained in this list model. */ void View::VAlarmInstructionsModel::clear() { beginRemoveRows(QModelIndex(), 0, rowCount()); _data.clear(); endRemoveRows(); } /*! * \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. * \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::VAlarmInstructionsModel::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) Q_EMIT dataChanged(vIndex, vIndex, QVector(1, vRole)); } return true; } /*! * \brief Appends a row of data to the end of the model. * \param[in] data The data to append. */ void View::VAlarmInstructionsModel::appendData(const QHash &vData) { auto index = std::clamp(rowCount(), 0, rowCount()); beginInsertRows(QModelIndex(), index, index); _data.insert(rowCount(), vData); endInsertRows(); }