diff --git a/include/fastdds_monitor/model/tree/StatusTreeItem.h b/include/fastdds_monitor/model/tree/StatusTreeItem.h index 42fe0799..095397ea 100644 --- a/include/fastdds_monitor/model/tree/StatusTreeItem.h +++ b/include/fastdds_monitor/model/tree/StatusTreeItem.h @@ -86,13 +86,6 @@ class StatusTreeItem //! Destroy the item. It will destroy every child. ~StatusTreeItem(); - //! Return the stored data of the node. - const QVariant& data() const; - - //! Return the stored data of the node. - const QVariant& data( - int role) const; - const QVariant& entity_id() const; const QVariant& status_kind() const; diff --git a/include/fastdds_monitor/model/tree/StatusTreeModel.h b/include/fastdds_monitor/model/tree/StatusTreeModel.h index 1611209b..b22a61fd 100644 --- a/include/fastdds_monitor/model/tree/StatusTreeModel.h +++ b/include/fastdds_monitor/model/tree/StatusTreeModel.h @@ -55,7 +55,6 @@ namespace models { class StatusTreeModel : public QAbstractItemModel { Q_OBJECT - //Q_ENUMS(models::StatusTreeItem::ModelItemRoles) public: explicit StatusTreeModel( @@ -66,21 +65,6 @@ class StatusTreeModel : public QAbstractItemModel // Overriden method from QAbstractItemModel public: - - //! Role names to allow queries to get some specific information from the Item - enum ModelItemRoles - { - idRole = Qt::UserRole + 1, //! Role for attribute Id - statusRole, //! Role for attribute Status - kindRole, //! Role for attribute Kind - valueRole, //! Role for attribute Value - descriptionRole, //! Role for attribute Description - aliveRole, //! Role for attribute Alive - nameRole //! Role for attribute Name - // The nameRole must always be the last one as it is used in child classes - // as the initial role of the enumeration) - }; - int rowCount( const QModelIndex& index) const override; int columnCount( @@ -98,6 +82,34 @@ class StatusTreeModel : public QAbstractItemModel const QModelIndex& index, int role = 0) const override; + Q_INVOKABLE QVariant name( + const QModelIndex& index, + int role = 0) const; + + Q_INVOKABLE QVariant id( + const QModelIndex& index, + int role = 0) const; + + Q_INVOKABLE QVariant status( + const QModelIndex& index, + int role = 0) const; + + Q_INVOKABLE QVariant kind( + const QModelIndex& index, + int role = 0) const; + + Q_INVOKABLE QVariant value( + const QModelIndex& index, + int role = 0) const; + + Q_INVOKABLE QVariant description( + const QModelIndex& index, + int role = 0) const; + + Q_INVOKABLE QVariant alive( + const QModelIndex& index, + int role = 0) const; + bool setData( const QModelIndex& index, const QVariant& value, @@ -107,8 +119,6 @@ class StatusTreeModel : public QAbstractItemModel int row, const QModelIndex &index = QModelIndex()); - QHash roleNames() const override; - public: //! Add an item to the top level. void addTopLevelItem( diff --git a/qml/StatusTreeViewItem.qml b/qml/StatusTreeViewItem.qml index cc2762fa..09395ea6 100644 --- a/qml/StatusTreeViewItem.qml +++ b/qml/StatusTreeViewItem.qml @@ -80,7 +80,6 @@ Item { font.pointSize: Theme.font.pointSize } property alias font: root.fontMetrics.font - enum Role { Id=257, Status, Kind, Value, Description, Alive, Name } // private (internal) signals signal filter_(int entityId) @@ -202,12 +201,12 @@ Item { property var currentIndex: root.model.index(index, 0, parentIndex) property var currentData: root.model.data(currentIndex) - property var currentId: root.model.data(currentIndex, StatusTreeViewItem.Role.Id) - property var currentStatus: root.model.data(currentIndex, StatusTreeViewItem.Role.Status) - property var currentKind: root.model.data(currentIndex, StatusTreeViewItem.Role.Kind) - property var currentValue: root.model.data(currentIndex, StatusTreeViewItem.Role.Value) - property var currentDescription: root.model.data(currentIndex, StatusTreeViewItem.Role.Description) - property var currentAlive: root.model.data(currentIndex, StatusTreeViewItem.Role.Alive) + property var currentId: root.model.id(currentIndex) + property var currentStatus: root.model.status(currentIndex) + property var currentKind: root.model.kind(currentIndex) + property var currentValue: root.model.value(currentIndex) + property var currentDescription: root.model.description(currentIndex) + property var currentAlive: root.model.alive(currentIndex) property Item currentItem: repeater.itemAt(index) property bool expanded: true property bool selected: false @@ -240,7 +239,7 @@ Item { const parent = root.model.index(index, 0, parentIndex) _prop.itemChildCount = root.model.rowCount(parent) // refresh counter - var new_value = root.model.data(_prop.currentIndex, StatusTreeViewItem.Role.Value) + var new_value = root.model.value(_prop.currentIndex) if (new_value != undefined) { _prop.currentValue = new_value diff --git a/src/model/tree/StatusTreeItem.cpp b/src/model/tree/StatusTreeItem.cpp index 45bb171b..73826b08 100644 --- a/src/model/tree/StatusTreeItem.cpp +++ b/src/model/tree/StatusTreeItem.cpp @@ -181,34 +181,6 @@ int StatusTreeItem::childCount() const return child_items_.count(); } -const QVariant& StatusTreeItem::data() const -{ - return this->data(models::StatusTreeModel::ModelItemRoles::nameRole); -} - -const QVariant& StatusTreeItem::data( - int role) const -{ - switch (role) - { - case models::StatusTreeModel::ModelItemRoles::idRole: - return this->entity_id(); - case models::StatusTreeModel::ModelItemRoles::statusRole: - return this->status(); - case models::StatusTreeModel::ModelItemRoles::kindRole: - return this->status_kind(); - case models::StatusTreeModel::ModelItemRoles::valueRole: - return this->value(); - case models::StatusTreeModel::ModelItemRoles::descriptionRole: - return this->description(); - case models::StatusTreeModel::ModelItemRoles::aliveRole: - return this->alive(); - case models::StatusTreeModel::ModelItemRoles::nameRole: - default: - return this->name(); - } -} - const QVariant& StatusTreeItem::entity_id() const { return id_variant_; diff --git a/src/model/tree/StatusTreeModel.cpp b/src/model/tree/StatusTreeModel.cpp index 9bd17384..777c8f3c 100644 --- a/src/model/tree/StatusTreeModel.cpp +++ b/src/model/tree/StatusTreeModel.cpp @@ -187,16 +187,97 @@ QModelIndex StatusTreeModel::parent( return createIndex(parentItem->row(), 0, parentItem); } + QVariant StatusTreeModel::data( const QModelIndex& index, - const int role) const + const int role) const +{ + return name(index, role); +} + +QVariant StatusTreeModel::name( + const QModelIndex& index, + const int /*role*/) const +{ + if (!index.isValid()) + { + return QVariant(); + } + + return internalPointer(index)->name(); +} + + +QVariant StatusTreeModel::id( + const QModelIndex& index, + const int /*role*/) const +{ + if (!index.isValid()) + { + return QVariant(); + } + + return internalPointer(index)->entity_id(); +} + +QVariant StatusTreeModel::status( + const QModelIndex& index, + const int /*role*/) const { - if (!index.isValid()/* || role != Qt::DisplayRole*/) + if (!index.isValid()) + { + return QVariant(); + } + + return internalPointer(index)->status(); +} + +QVariant StatusTreeModel::kind( + const QModelIndex& index, + const int /*role*/) const +{ + if (!index.isValid()) { return QVariant(); } - return internalPointer(index)->data(role); + return internalPointer(index)->status_kind(); +} + +QVariant StatusTreeModel::value( + const QModelIndex& index, + const int /*role*/) const +{ + if (!index.isValid()) + { + return QVariant(); + } + + return internalPointer(index)->value(); +} + +QVariant StatusTreeModel::description( + const QModelIndex& index, + const int /*role*/) const +{ + if (!index.isValid()) + { + return QVariant(); + } + + return internalPointer(index)->description(); +} + +QVariant StatusTreeModel::alive( + const QModelIndex& index, + const int /*role*/) const +{ + if (!index.isValid()) + { + return QVariant(); + } + + return internalPointer(index)->alive(); } bool StatusTreeModel::setData( @@ -444,21 +525,4 @@ StatusTreeItem* StatusTreeModel::getTopLevelItem( return new_entity_item; } - -QHash StatusTreeModel::roleNames() const -{ - // TODO Jesus this roles are not currently used in the QML, find out why - QHash roles; - - roles[idRole] = "id"; - roles[statusRole] = "status"; - roles[kindRole] = "kind"; - roles[valueRole] = "value"; - roles[descriptionRole] = "description"; - roles[aliveRole] = "alive"; - roles[nameRole] = "name"; - - return roles; -} - } // namespace models