|
QGroundControl
Ground Control Station for MAVLink Drones
|
A tree model for QObject* items, usable from both C++ and QML. More...
#include <QmlObjectTreeModel.h>
Inheritance diagram for QmlObjectTreeModel:
Collaboration diagram for QmlObjectTreeModel:Public Member Functions | |
| QmlObjectTreeModel (QObject *parent=nullptr) | |
| ~QmlObjectTreeModel () override | |
| int | count () const override |
| void | setDirty (bool dirty) override |
| void | clear () override |
| QModelIndex | index (int row, int column, const QModelIndex &parent=QModelIndex()) const override |
| QModelIndex | parent (const QModelIndex &child) const override |
| int | rowCount (const QModelIndex &parent=QModelIndex()) const override |
| int | columnCount (const QModelIndex &parent=QModelIndex()) const override |
| bool | hasChildren (const QModelIndex &parent=QModelIndex()) const override |
| QVariant | data (const QModelIndex &index, int role=Qt::DisplayRole) const override |
| bool | setData (const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override |
| bool | insertRows (int row, int count, const QModelIndex &parent=QModelIndex()) override |
| bool | removeRows (int row, int count, const QModelIndex &parent=QModelIndex()) override |
| QHash< int, QByteArray > | roleNames () const override |
| Q_INVOKABLE QObject * | getObject (const QModelIndex &index) const |
Returns the QObject* stored at index, or nullptr if invalid. | |
| Q_INVOKABLE QModelIndex | appendItem (QObject *object, const QModelIndex &parentIndex=QModelIndex()) |
Appends object as the last child of parentIndex (root if invalid). Returns the new item's index. | |
| Q_INVOKABLE QModelIndex | appendItem (QObject *object, const QModelIndex &parentIndex, const QString &nodeType) |
| Same as above but also sets a nodeType tag on the created tree node. | |
| Q_INVOKABLE QModelIndex | insertItem (int row, QObject *object, const QModelIndex &parentIndex=QModelIndex()) |
Inserts object at row under parentIndex. Returns the new item's index. | |
| Q_INVOKABLE QModelIndex | insertItem (int row, QObject *object, const QModelIndex &parentIndex, const QString &nodeType) |
| Same as above but also sets a nodeType tag on the created tree node. | |
| Q_INVOKABLE QObject * | removeItem (const QModelIndex &index) |
| Q_INVOKABLE int | childCount (const QModelIndex &parentIndex=QModelIndex()) const |
Number of direct children under parentIndex. | |
| Q_INVOKABLE QModelIndex | childIndex (int row, const QModelIndex &parentIndex=QModelIndex()) const |
Returns the QModelIndex for the child at row under parentIndex. | |
| Q_INVOKABLE QModelIndex | indexForObject (QObject *object) const |
Searches the entire tree for object and returns its QModelIndex (invalid if not found) | |
| Q_INVOKABLE QModelIndex | parentIndex (const QModelIndex &index) const |
| Convenience wrapper around parent() | |
| Q_INVOKABLE int | depth (const QModelIndex &index) const |
Returns the depth of index (0 = root-level item, -1 = invalid index) | |
| void | appendRootItem (QObject *object) |
| void | appendChild (const QModelIndex &parentIndex, QObject *object) |
| QObject * | removeAt (const QModelIndex &parentIndex, int row) |
| void | removeChildren (const QModelIndex &parentIndex) |
| Removes all children of parentIndex without removing the parent itself. | |
| void | clearAndDeleteContents () |
| Clears the tree and calls deleteLater on every QObject. | |
| bool | contains (QObject *object) const |
Public Member Functions inherited from ObjectItemModelBase | |
| ObjectItemModelBase (QObject *parent=nullptr) | |
| ~ObjectItemModelBase () override | |
| bool | dirty () const |
| void | beginResetModel () |
| Depth-counted beginResetModel — only the outermost call has effect. | |
| void | endResetModel () |
| Depth-counted endResetModel — only the outermost call has effect. | |
| virtual bool | isEmpty () const |
Static Public Attributes | |
| static constexpr int | NodeTypeRole = Qt::UserRole + 2 |
| static constexpr int | SeparatorRole = Qt::UserRole + 3 |
Additional Inherited Members | |
Signals inherited from ObjectItemModelBase | |
| void | countChanged (int count) |
| void | dirtyChanged (bool dirty) |
Protected Slots inherited from ObjectItemModelBase | |
| void | _childDirtyChanged (bool dirty) |
Protected Member Functions inherited from ObjectItemModelBase | |
| QHash< int, QByteArray > | roleNames () const override |
| void | _signalCountChangedIfNotNested () |
Protected Attributes inherited from ObjectItemModelBase | |
| bool | _dirty = false |
| uint | _resetModelNestingCount = 0 |
Static Protected Attributes inherited from ObjectItemModelBase | |
| static constexpr int | ObjectRole = Qt::UserRole |
| static constexpr int | TextRole = Qt::UserRole + 1 |
A tree model for QObject* items, usable from both C++ and QML.
Works like QmlObjectListModel but supports hierarchical parent/child relationships. Compatible with Qt 6 TreeView.
Top-level items are children of an invisible root node. The root is represented by an invalid QModelIndex (the default).
Definition at line 24 of file QmlObjectTreeModel.h.
|
explicit |
Definition at line 60 of file QmlObjectTreeModel.cc.
|
override |
Definition at line 65 of file QmlObjectTreeModel.cc.
| void QmlObjectTreeModel::appendChild | ( | const QModelIndex & | parentIndex, |
| QObject * | object | ||
| ) |
Definition at line 377 of file QmlObjectTreeModel.cc.
References appendItem(), and parentIndex().
| QModelIndex QmlObjectTreeModel::appendItem | ( | QObject * | object, |
| const QModelIndex & | parentIndex, | ||
| const QString & | nodeType | ||
| ) |
Same as above but also sets a nodeType tag on the created tree node.
Definition at line 288 of file QmlObjectTreeModel.cc.
References index(), insertItem(), and parentIndex().
| QModelIndex QmlObjectTreeModel::appendItem | ( | QObject * | object, |
| const QModelIndex & | parentIndex = QModelIndex() |
||
| ) |
Appends object as the last child of parentIndex (root if invalid). Returns the new item's index.
Definition at line 232 of file QmlObjectTreeModel.cc.
References index(), insertItem(), and parentIndex().
Referenced by appendChild(), and appendRootItem().
| void QmlObjectTreeModel::appendRootItem | ( | QObject * | object | ) |
Definition at line 372 of file QmlObjectTreeModel.cc.
References appendItem().
|
inline |
Number of direct children under parentIndex.
Definition at line 73 of file QmlObjectTreeModel.h.
References parentIndex(), and rowCount().
Referenced by removeChildren().
|
inline |
Returns the QModelIndex for the child at row under parentIndex.
Definition at line 76 of file QmlObjectTreeModel.h.
References index(), and parentIndex().
|
overridevirtual |
Implements ObjectItemModelBase.
Definition at line 428 of file QmlObjectTreeModel.cc.
References ObjectItemModelBase::beginResetModel(), and ObjectItemModelBase::endResetModel().
| void QmlObjectTreeModel::clearAndDeleteContents | ( | ) |
Clears the tree and calls deleteLater on every QObject.
Definition at line 441 of file QmlObjectTreeModel.cc.
References ObjectItemModelBase::beginResetModel(), and ObjectItemModelBase::endResetModel().
|
override |
Definition at line 110 of file QmlObjectTreeModel.cc.
| bool QmlObjectTreeModel::contains | ( | QObject * | object | ) | const |
Definition at line 454 of file QmlObjectTreeModel.cc.
|
overridevirtual |
Implements ObjectItemModelBase.
Definition at line 205 of file QmlObjectTreeModel.cc.
|
override |
Definition at line 122 of file QmlObjectTreeModel.cc.
References index(), NodeTypeRole, ObjectItemModelBase::ObjectRole, SeparatorRole, and ObjectItemModelBase::TextRole.
| int QmlObjectTreeModel::depth | ( | const QModelIndex & | index | ) | const |
Returns the depth of index (0 = root-level item, -1 = invalid index)
Definition at line 353 of file QmlObjectTreeModel.cc.
References index().
| QObject * QmlObjectTreeModel::getObject | ( | const QModelIndex & | index | ) | const |
Returns the QObject* stored at index, or nullptr if invalid.
Definition at line 222 of file QmlObjectTreeModel.cc.
References index().
|
override |
Definition at line 116 of file QmlObjectTreeModel.cc.
References parent().
|
override |
Definition at line 76 of file QmlObjectTreeModel.cc.
References index(), and parent().
Referenced by appendItem(), appendItem(), childIndex(), columnCount(), data(), depth(), getObject(), index(), indexForObject(), insertItem(), insertItem(), insertRows(), parent(), parentIndex(), removeAt(), removeChildren(), removeItem(), removeRows(), roleNames(), setData(), and setDirty().
| QModelIndex QmlObjectTreeModel::indexForObject | ( | QObject * | object | ) | const |
Searches the entire tree for object and returns its QModelIndex (invalid if not found)
Definition at line 343 of file QmlObjectTreeModel.cc.
References index().
| QModelIndex QmlObjectTreeModel::insertItem | ( | int | row, |
| QObject * | object, | ||
| const QModelIndex & | parentIndex, | ||
| const QString & | nodeType | ||
| ) |
Same as above but also sets a nodeType tag on the created tree node.
Definition at line 248 of file QmlObjectTreeModel.cc.
References ObjectItemModelBase::_resetModelNestingCount, ObjectItemModelBase::_signalCountChangedIfNotNested(), index(), parentIndex(), and setDirty().
| QModelIndex QmlObjectTreeModel::insertItem | ( | int | row, |
| QObject * | object, | ||
| const QModelIndex & | parentIndex = QModelIndex() |
||
| ) |
Inserts object at row under parentIndex. Returns the new item's index.
Definition at line 243 of file QmlObjectTreeModel.cc.
References index(), insertItem(), and parentIndex().
Referenced by appendItem(), appendItem(), and insertItem().
|
override |
Definition at line 181 of file QmlObjectTreeModel.cc.
References index().
|
override |
Definition at line 90 of file QmlObjectTreeModel.cc.
References index().
Referenced by columnCount(), hasChildren(), index(), parentIndex(), and rowCount().
|
inline |
Convenience wrapper around parent()
Definition at line 82 of file QmlObjectTreeModel.h.
References index(), and parent().
Referenced by appendChild(), appendItem(), appendItem(), childCount(), childIndex(), insertItem(), insertItem(), removeAt(), and removeChildren().
| QObject * QmlObjectTreeModel::removeAt | ( | const QModelIndex & | parentIndex, |
| int | row | ||
| ) |
Definition at line 382 of file QmlObjectTreeModel.cc.
References index(), parentIndex(), and removeItem().
| void QmlObjectTreeModel::removeChildren | ( | const QModelIndex & | parentIndex | ) |
Removes all children of parentIndex without removing the parent itself.
Definition at line 387 of file QmlObjectTreeModel.cc.
References ObjectItemModelBase::_resetModelNestingCount, ObjectItemModelBase::_signalCountChangedIfNotNested(), childCount(), index(), and parentIndex().
| QObject * QmlObjectTreeModel::removeItem | ( | const QModelIndex & | index | ) |
Removes the item (and its entire subtree) at index. Returns the removed QObject* (caller takes ownership). Child QObjects are NOT deleted; only the internal tree nodes are freed.
Definition at line 298 of file QmlObjectTreeModel.cc.
References ObjectItemModelBase::_resetModelNestingCount, ObjectItemModelBase::_signalCountChangedIfNotNested(), index(), and setDirty().
Referenced by removeAt().
|
override |
Definition at line 187 of file QmlObjectTreeModel.cc.
References index().
|
override |
Definition at line 193 of file QmlObjectTreeModel.cc.
References index(), NodeTypeRole, ObjectItemModelBase::roleNames(), and SeparatorRole.
|
override |
Definition at line 104 of file QmlObjectTreeModel.cc.
References parent().
Referenced by childCount().
|
override |
Definition at line 155 of file QmlObjectTreeModel.cc.
References index(), and ObjectItemModelBase::ObjectRole.
Implements ObjectItemModelBase.
Definition at line 210 of file QmlObjectTreeModel.cc.
References ObjectItemModelBase::_dirty, ObjectItemModelBase::dirty(), ObjectItemModelBase::dirtyChanged(), and index().
Referenced by insertItem(), and removeItem().
Definition at line 95 of file QmlObjectTreeModel.h.
Referenced by data(), and roleNames().
Definition at line 96 of file QmlObjectTreeModel.h.
Referenced by data(), and roleNames().