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 removeRow(QModelIndex index);
55 Q_INVOKABLE void setRow(QModelIndex index, const QVariant &rowData);
56
57 Q_INVOKABLE QModelIndex index(const std::vector<int> &rowIndex, int column);
58
59 //AbstractItemModel interface
60 QModelIndex index(int row, int column, const QModelIndex &parent = {}) const override;
61 int rowCount(const QModelIndex &parent = {}) const override;
62 int columnCount(const QModelIndex &parent = {}) const override;
63 QModelIndex parent(const QModelIndex &index) const override;
64
65protected:
66 QVariant firstRow() const override;
67 void setInitialRows() override;
68
69private:
70 QQmlTreeRow *getPointerToTreeRow(QModelIndex &index, const std::vector<int> &rowIndex) const;
71
72 int treeSize() const;
73 friend class ::tst_QQmlTreeModel;
74
75 void setRowsPrivate(const QVariantList &rowsAsVariantList);
76 QVariant dataPrivate(const QModelIndex &index, const QString &roleName) const override;
77 void setDataPrivate(const QModelIndex &index, const QString &roleName, QVariant value) override;
78
79 bool validateNewRow(QLatin1StringView functionName, const QVariant &row,
80 NewRowOperationFlag = OtherOperation) const override;
81
82 std::vector<std::unique_ptr<QQmlTreeRow>> mRows;
83
84 QVariantList mInitialRows;
85};
86
87QT_END_NAMESPACE
88
89#endif // QQMLTREEMODEL_P_H
static const QString ROWS_PROPERTY_NAME
QT_REQUIRE_CONFIG(qml_tree_model)