34 Q_PROPERTY(QAbstractItemModel *model READ model WRITE setModel NOTIFY modelChanged FINAL)
35 Q_PROPERTY(QModelIndex rootIndex READ rootIndex WRITE setRootIndex RESET resetRootIndex NOTIFY rootIndexChanged FINAL)
40 explicit QQmlTreeModelToTableModel(QObject *parent =
nullptr);
42 QAbstractItemModel *model()
const;
43 QModelIndex rootIndex()
const;
44 void setRootIndex(
const QModelIndex &idx);
45 void resetRootIndex();
47 QModelIndex index(
int row,
int column,
const QModelIndex &parent = QModelIndex())
const override;
48 QModelIndex parent(
const QModelIndex &child)
const override;
50 int rowCount(
const QModelIndex &parent = QModelIndex())
const override;
51 int columnCount(
const QModelIndex &parent = QModelIndex())
const override;
54 DepthRole = Qt::UserRole - 5,
61 QHash<
int, QByteArray> roleNames()
const override;
62 QVariant data(
const QModelIndex &,
int role)
const override;
63 bool setData(
const QModelIndex &index,
const QVariant &value,
int role) override;
64 QVariant headerData(
int section, Qt::Orientation orientation,
int role)
const override;
65 Qt::ItemFlags flags(
const QModelIndex &index)
const override;
67 void clearModelData();
69 bool isVisible(
const QModelIndex &index);
70 bool childrenVisible(
const QModelIndex &index);
72 QModelIndex mapToModel(
const QModelIndex &index)
const;
73 QModelIndex mapFromModel(
const QModelIndex &index)
const;
74 QModelIndex mapToModel(
int row)
const;
76 Q_INVOKABLE QItemSelection selectionForRowRange(
const QModelIndex &fromIndex,
const QModelIndex &toIndex)
const;
78 void showModelTopLevelItems(
bool doInsertRows =
true);
79 void showModelChildItems(
const TreeItem &parent,
int start,
int end,
bool doInsertRows =
true,
bool doExpandPendingRows =
true);
81 int itemIndex(
const QModelIndex &index)
const;
82 void expandPendingRows(
bool doInsertRows =
true);
83 int lastChildIndex(
const QModelIndex &index)
const;
84 void removeVisibleRows(
int startIndex,
int endIndex,
bool doRemoveRows =
true);
87 bool testConsistency(
bool dumpOnFail =
false)
const;
89 using QAbstractItemModel::hasChildren;
92 void modelChanged(QAbstractItemModel *model);
93 void rootIndexChanged();
94 void expanded(
const QModelIndex &index);
95 void collapsed(
const QModelIndex &index);
98 void expand(
const QModelIndex &);
99 void collapse(
const QModelIndex &);
100 void setModel(QAbstractItemModel *model);
101 bool isExpanded(
const QModelIndex &)
const;
102 bool isExpanded(
int row)
const;
103 bool hasChildren(
int row)
const;
104 bool hasSiblings(
int row)
const;
105 int depthAtRow(
int row)
const;
106 void expandRow(
int n);
107 void expandRecursively(
int row,
int depth);
108 void collapseRow(
int n);
109 void collapseRecursively(
int row);
112 void modelHasBeenDestroyed();
113 void modelHasBeenReset();
114 void modelDataChanged(
const QModelIndex &topLeft,
const QModelIndex &bottomRight,
const QList<
int> &roles);
115 void modelLayoutAboutToBeChanged(
const QList<QPersistentModelIndex> &parents, QAbstractItemModel::LayoutChangeHint hint);
116 void modelLayoutChanged(
const QList<QPersistentModelIndex> &parents, QAbstractItemModel::LayoutChangeHint hint);
117 void modelRowsAboutToBeInserted(
const QModelIndex & parent,
int start,
int end);
118 void modelRowsAboutToBeMoved(
const QModelIndex & sourceParent,
int sourceStart,
int sourceEnd,
const QModelIndex & destinationParent,
int destinationRow);
119 void modelRowsAboutToBeRemoved(
const QModelIndex & parent,
int start,
int end);
120 void modelRowsInserted(
const QModelIndex & parent,
int start,
int end);
121 void modelRowsMoved(
const QModelIndex & sourceParent,
int sourceStart,
int sourceEnd,
const QModelIndex & destinationParent,
int destinationRow);
122 void modelRowsRemoved(
const QModelIndex & parent,
int start,
int end);
123 void modelColumnsAboutToBeInserted(
const QModelIndex & parent,
int start,
int end);
124 void modelColumnsAboutToBeRemoved(
const QModelIndex & parent,
int start,
int end);
125 void modelColumnsInserted(
const QModelIndex & parent,
int start,
int end);
126 void modelColumnsRemoved(
const QModelIndex & parent,
int start,
int end);
130 QPersistentModelIndex index;
134 explicit TreeItem(
const QModelIndex &idx = QModelIndex(),
int d = 0,
int e =
false)
135 : index(idx), depth(d), expanded(e)
138 inline bool operator== (
const TreeItem &other)
const
140 return this->index == other.index;
144 struct DataChangedParams {
147 QVarLengthArray<
int, 5> roles;
150 struct SignalFreezer {
151 SignalFreezer(QQmlTreeModelToTableModel *parent) : m_parent(parent) {
152 m_parent->enableSignalAggregation();
154 ~SignalFreezer() { m_parent->disableSignalAggregation(); }
157 QQmlTreeModelToTableModel *m_parent;
160 void enableSignalAggregation();
161 void disableSignalAggregation();
162 bool isAggregatingSignals()
const {
return m_signalAggregatorStack > 0; }
163 void queueDataChanged(
int top,
int bottom, std::initializer_list<
int> roles);
164 void emitQueuedSignals();
165 void connectToModel();
167 QPointer<QAbstractItemModel> m_model =
nullptr;
168 QPersistentModelIndex m_rootIndex;
169 QList<TreeItem> m_items;
170 QSet<QPersistentModelIndex> m_expandedItems;
171 QList<TreeItem> m_itemsToExpand;
172 mutable int m_lastItemIndex = 0;
173 bool m_visibleRowsMoved =
false;
174 bool m_modelLayoutChanged =
false;
175 int m_signalAggregatorStack = 0;
176 QList<DataChangedParams> m_queuedDataChanged;
177 std::array<QMetaObject::Connection, 15> m_connections;