36 int count()
const override;
37 void setDirty(
bool dirty)
override;
38 void clear()
override;
41 QModelIndex index(
int row,
int column,
const QModelIndex& parent = QModelIndex())
const override;
42 QModelIndex parent(
const QModelIndex& child)
const override;
43 int rowCount(
const QModelIndex& parent = QModelIndex())
const override;
44 int columnCount(
const QModelIndex& parent = QModelIndex())
const override;
45 bool hasChildren(
const QModelIndex& parent = QModelIndex())
const override;
46 QVariant data(
const QModelIndex& index,
int role = Qt::DisplayRole)
const override;
47 bool setData(
const QModelIndex& index,
const QVariant& value,
int role = Qt::EditRole)
override;
48 bool insertRows(
int row,
int count,
const QModelIndex& parent = QModelIndex())
override;
49 bool removeRows(
int row,
int count,
const QModelIndex& parent = QModelIndex())
override;
50 QHash<int, QByteArray> roleNames()
const override;
55 Q_INVOKABLE QObject* getObject(
const QModelIndex& index)
const;
58 Q_INVOKABLE QModelIndex appendItem(QObject*
object,
const QModelIndex& parentIndex = QModelIndex());
61 Q_INVOKABLE QModelIndex appendItem(QObject*
object,
const QModelIndex& parentIndex,
const QString& nodeType);
64 Q_INVOKABLE QModelIndex insertItem(
int row, QObject*
object,
const QModelIndex& parentIndex = QModelIndex());
67 Q_INVOKABLE QModelIndex insertItem(
int row, QObject*
object,
const QModelIndex& parentIndex,
const QString& nodeType);
71 Q_INVOKABLE QObject* removeItem(
const QModelIndex& index);
74 Q_INVOKABLE
int childCount(
const QModelIndex& parentIndex = QModelIndex())
const {
return rowCount(parentIndex); }
77 Q_INVOKABLE QModelIndex
childIndex(
int row,
const QModelIndex& parentIndex = QModelIndex())
const {
return index(row, 0, parentIndex); }
80 Q_INVOKABLE QModelIndex indexForObject(QObject*
object)
const;
83 Q_INVOKABLE QModelIndex
parentIndex(
const QModelIndex& index)
const {
return parent(index); }
86 Q_INVOKABLE
int depth(
const QModelIndex& index)
const;
89 void appendRootItem(QObject*
object);
90 void appendChild(
const QModelIndex& parentIndex, QObject*
object);
91 QObject* removeAt(
const QModelIndex& parentIndex,
int row);
92 void removeChildren(
const QModelIndex& parentIndex);
93 void clearAndDeleteContents();
94 bool contains(QObject*
object)
const;
96 static constexpr int NodeTypeRole = Qt::UserRole + 2;
100 QObject*
object =
nullptr;
101 TreeNode* parentNode =
nullptr;
102 QList<TreeNode*> children;
109 TreeNode* _nodeFromIndex(
const QModelIndex& index)
const;
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);
114 void _deleteSubtree(TreeNode* node,
bool deleteObjects);
115 void _connectDirtyChanged(QObject*
object);
116 void _disconnectDirtyChanged(QObject*
object);