| 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 QQMLTREEROW_P_H |
| 5 | #define QQMLTREEROW_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 | |
| 18 | #include <QtQmlModels/private/qtqmlmodelsglobal_p.h> |
| 19 | |
| 20 | #include <QtCore/qmap.h> |
| 21 | #include <QtCore/qvariant.h> |
| 22 | |
| 23 | #include <memory> |
| 24 | #include <vector> |
| 25 | |
| 26 | QT_REQUIRE_CONFIG(qml_tree_model); |
| 27 | |
| 28 | QT_BEGIN_NAMESPACE |
| 29 | |
| 30 | class QQmlTreeRow |
| 31 | { |
| 32 | public: |
| 33 | explicit QQmlTreeRow(QQmlTreeRow *parentItem = nullptr); |
| 34 | explicit QQmlTreeRow(const QVariant &data, QQmlTreeRow *parentItem = nullptr); |
| 35 | explicit QQmlTreeRow(const QVariantMap &data, QQmlTreeRow *parentItem = nullptr); |
| 36 | |
| 37 | QQmlTreeRow *parent() const { return m_parent; } |
| 38 | void setParent(QQmlTreeRow *parent) { m_parent = parent; } |
| 39 | |
| 40 | const QQmlTreeRow *getRow(int i) const { return m_children[i].get(); } |
| 41 | void addChild(QQmlTreeRow *child); |
| 42 | size_t rowCount() const { return m_children.size(); } |
| 43 | int subTreeSize() const; |
| 44 | |
| 45 | QVariantMap data() const { return dataMap; } |
| 46 | QVariant data(const QString &key) const { return dataMap[key]; } |
| 47 | const std::vector<std::unique_ptr<QQmlTreeRow>>& children() const { return m_children; } |
| 48 | void removeChild(std::vector<std::unique_ptr<QQmlTreeRow>>::const_iterator &child); |
| 49 | void removeChildAt(int i); |
| 50 | void setData(const QVariant &data); |
| 51 | void setData(const QVariantMap &data); |
| 52 | void setField(const QString &key, const QVariant &value); |
| 53 | QVariant toVariant() const; |
| 54 | private: |
| 55 | void unpackVariantMap(const QVariantMap &dataMap); |
| 56 | |
| 57 | QQmlTreeRow *m_parent; |
| 58 | std::vector<std::unique_ptr<QQmlTreeRow>> m_children; |
| 59 | QVariantMap dataMap; |
| 60 | }; |
| 61 | |
| 62 | QT_END_NAMESPACE |
| 63 | |
| 64 | #endif // QQMLTREEROW_P_H |
| 65 |
