Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qqmltreemodel_p.h
Go to the documentation of this file.
1// Copyright (C) 2025 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QQMLTREEMODEL_P_H
5#define QQMLTREEMODEL_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
19
20#include <QtCore/qabstractitemmodel.h>
21#include <QtCore/qvariant.h>
22
23#include <memory>
24#include <vector>
25
27
28class tst_QQmlTreeModel;
29
30QT_BEGIN_NAMESPACE
31
32class QQmlTreeRow;
33
34class Q_LABSQMLMODELS_EXPORT QQmlTreeModel : public QQmlAbstractColumnModel
35{
36 Q_OBJECT
37 Q_PROPERTY(QVariant rows READ rows WRITE setRows NOTIFY rowsChanged FINAL)
38 QML_NAMED_ELEMENT(TreeModel)
39 QML_ADDED_IN_VERSION(6, 10)
40
41public:
42 Q_DISABLE_COPY_MOVE(QQmlTreeModel)
43
44 explicit QQmlTreeModel(QObject *parent = nullptr);
45 ~QQmlTreeModel() override;
46
47 QVariant rows() const;
48 void setRows(const QVariant &rows);
49
50 Q_INVOKABLE void appendRow(QModelIndex parent, const QVariant &row);
51 Q_INVOKABLE void appendRow(const QVariant &row);
52 Q_INVOKABLE void clear();
53 Q_INVOKABLE QVariant getRow(const QModelIndex &index) const;
54 Q_INVOKABLE void insertRow(int rowIndex, QModelIndex parent, const QVariant &row);
55 Q_INVOKABLE void insertRow(int rowIndex, const QVariant &row);
56 bool moveRows(const QModelIndex &fromIndex, int fromRowIndex, int rows,
57 const QModelIndex &toIndex, int toRowIndex) override;
58 Q_INVOKABLE void removeRow(QModelIndex index);
59 Q_INVOKABLE void setRow(QModelIndex index, const QVariant &rowData);
60
61 Q_INVOKABLE QModelIndex index(const std::vector<int> &rowIndex, int column);
62
63 //AbstractItemModel interface
64 QModelIndex index(int row, int column, const QModelIndex &parent = {}) const override;
65 int rowCount(const QModelIndex &parent = {}) const override;
66 int columnCount(const QModelIndex &parent = {}) const override;
67 QModelIndex parent(const QModelIndex &index) const override;
68
69protected:
70 QVariant firstRow() const override;
71 void setInitialRows() override;
72
73private:
74 QQmlTreeRow *getPointerToTreeRow(QModelIndex &index, const std::vector<int> &rowIndex) const;
75
76 int treeSize() const;
77 friend class ::tst_QQmlTreeModel;
78
79 void setRowsPrivate(const QVariantList &rowsAsVariantList);
80 QVariant dataPrivate(const QModelIndex &index, const QString &roleName) const override;
81 void setDataPrivate(const QModelIndex &index, const QString &roleName, QVariant value) override;
82
83 bool validateNewRow(QLatin1StringView functionName, const QVariant &row,
84 NewRowOperationFlag = OtherOperation) const override;
85
86 void doInsert(const QModelIndex &index, int rowIndex, const QVariant &row);
87
88 std::vector<std::unique_ptr<QQmlTreeRow>> mRows;
89
90 QVariantList mInitialRows;
91};
92
93QT_END_NAMESPACE
94
95#endif // QQMLTREEMODEL_P_H
Combined button and popup list for selecting options.
QT_REQUIRE_CONFIG(qml_tree_model)