14#include <QtQmlIntegration/QtQmlIntegration>
35 int count()
const override;
37 void clear()
override;
93 bool contains(QObject*
object)
const;
100 QObject*
object =
nullptr;
101 TreeNode* parentNode =
nullptr;
110 QModelIndex _indexForNode(
const TreeNode* node)
const;
111 TreeNode* _findNode(
const TreeNode*
root,
const QObject*
object)
const;
112 static int _subtreeCount(
const TreeNode* node);
113 void _disconnectSubtree(TreeNode* node);
115 void _connectDirtyChanged(QObject*
object);
116 void _disconnectDirtyChanged(QObject*
object);
Common base for QObject*-based item models (flat lists and trees).
A tree model for QObject* items, usable from both C++ and QML.
void appendChild(const QModelIndex &parentIndex, QObject *object)
void setDirty(bool dirty) override
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Q_INVOKABLE QModelIndex childIndex(int row, const QModelIndex &parentIndex=QModelIndex()) const
Returns the QModelIndex for the child at row under parentIndex.
Q_INVOKABLE int childCount(const QModelIndex &parentIndex=QModelIndex()) const
Number of direct children under parentIndex.
static constexpr int NodeTypeRole
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
int count() const override
void removeChildren(const QModelIndex &parentIndex)
Removes all children of parentIndex without removing the parent itself.
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Q_INVOKABLE QModelIndex parentIndex(const QModelIndex &index) const
Convenience wrapper around parent()
Q_INVOKABLE QObject * removeItem(const QModelIndex &index)
QObject * removeAt(const QModelIndex &parentIndex, int row)
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
void appendRootItem(QObject *object)
bool insertRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
Q_INVOKABLE QModelIndex indexForObject(QObject *object) const
Searches the entire tree for object and returns its QModelIndex (invalid if not found)
void clearAndDeleteContents()
Clears the tree and calls deleteLater on every QObject.
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 int depth(const QModelIndex &index) const
Returns the depth of index (0 = root-level item, -1 = invalid index)
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.
~QmlObjectTreeModel() override
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
bool contains(QObject *object) const
QHash< int, QByteArray > roleNames() const override
bool hasChildren(const QModelIndex &parent=QModelIndex()) const override
Q_INVOKABLE QObject * getObject(const QModelIndex &index) const
Returns the QObject* stored at index, or nullptr if invalid.
static constexpr int SeparatorRole
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
QModelIndex parent(const QModelIndex &child) const override