| 1 | // Copyright (C) 2021 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 QQMLMODELINDEXVALUETYPE_P_H |
| 5 | #define QQMLMODELINDEXVALUETYPE_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 <QtCore/qabstractitemmodel.h> |
| 19 | #include <QtCore/qitemselectionmodel.h> |
| 20 | #include <QtQml/qqml.h> |
| 21 | #include <QtCore/private/qglobal_p.h> |
| 22 | |
| 23 | QT_BEGIN_NAMESPACE |
| 24 | |
| 25 | struct QQmlModelIndexValueType |
| 26 | { |
| 27 | QModelIndex v; |
| 28 | |
| 29 | Q_PROPERTY(int row READ row CONSTANT FINAL) |
| 30 | Q_PROPERTY(int column READ column CONSTANT FINAL) |
| 31 | Q_PROPERTY(QModelIndex parent READ parent FINAL) |
| 32 | Q_PROPERTY(bool valid READ isValid CONSTANT FINAL) |
| 33 | Q_PROPERTY(QAbstractItemModel *model READ model CONSTANT FINAL) |
| 34 | Q_PROPERTY(quint64 internalId READ internalId CONSTANT FINAL) |
| 35 | Q_GADGET |
| 36 | QML_ANONYMOUS |
| 37 | QML_EXTENDED(QQmlModelIndexValueType) |
| 38 | QML_FOREIGN(QModelIndex) |
| 39 | QML_ADDED_IN_VERSION(2, 0) |
| 40 | |
| 41 | public: |
| 42 | Q_INVOKABLE QString toString() const |
| 43 | { return QLatin1String("QModelIndex" ) + propertiesString(idx: v); } |
| 44 | |
| 45 | Q_REVISION(6, 7) Q_INVOKABLE QVariant data(int role = Qt::DisplayRole) const |
| 46 | { return v.data(arole: role); } |
| 47 | |
| 48 | inline int row() const noexcept { return v.row(); } |
| 49 | inline int column() const noexcept { return v.column(); } |
| 50 | inline QModelIndex parent() const { return v.parent(); } |
| 51 | inline bool isValid() const noexcept { return v.isValid(); } |
| 52 | inline QAbstractItemModel *model() const noexcept |
| 53 | { return const_cast<QAbstractItemModel *>(v.model()); } |
| 54 | quint64 internalId() const { return v.internalId(); } |
| 55 | |
| 56 | static QString propertiesString(const QModelIndex &idx); |
| 57 | |
| 58 | static QPersistentModelIndex toPersistentModelIndex(const QModelIndex &index) |
| 59 | { return QPersistentModelIndex(index); } |
| 60 | |
| 61 | operator QModelIndex() const { return v; } |
| 62 | }; |
| 63 | |
| 64 | struct QQmlPersistentModelIndexValueType |
| 65 | { |
| 66 | QPersistentModelIndex v; |
| 67 | |
| 68 | Q_PROPERTY(int row READ row FINAL) |
| 69 | Q_PROPERTY(int column READ column FINAL) |
| 70 | Q_PROPERTY(QModelIndex parent READ parent FINAL) |
| 71 | Q_PROPERTY(bool valid READ isValid FINAL) |
| 72 | Q_PROPERTY(QAbstractItemModel *model READ model FINAL) |
| 73 | Q_PROPERTY(quint64 internalId READ internalId FINAL) |
| 74 | Q_GADGET |
| 75 | QML_ANONYMOUS |
| 76 | QML_EXTENDED(QQmlPersistentModelIndexValueType) |
| 77 | QML_FOREIGN(QPersistentModelIndex) |
| 78 | QML_ADDED_IN_VERSION(2, 0) |
| 79 | |
| 80 | public: |
| 81 | Q_INVOKABLE QString toString() const |
| 82 | { return QLatin1String("QPersistentModelIndex" ) + QQmlModelIndexValueType::propertiesString(idx: v); } |
| 83 | |
| 84 | Q_REVISION(6, 7) Q_INVOKABLE QVariant data(int role = Qt::DisplayRole) const |
| 85 | { return v.data(role); } |
| 86 | |
| 87 | inline int row() const { return v.row(); } |
| 88 | inline int column() const { return v.column(); } |
| 89 | inline QModelIndex parent() const { return v.parent(); } |
| 90 | inline bool isValid() const { return v.isValid(); } |
| 91 | inline QAbstractItemModel *model() const { return const_cast<QAbstractItemModel *>(v.model()); } |
| 92 | inline quint64 internalId() const { return v.internalId(); } |
| 93 | |
| 94 | operator QPersistentModelIndex() const { return v; } |
| 95 | }; |
| 96 | |
| 97 | struct QQmlItemSelectionRangeValueType |
| 98 | { |
| 99 | QItemSelectionRange v; |
| 100 | |
| 101 | Q_PROPERTY(int top READ top FINAL) |
| 102 | Q_PROPERTY(int left READ left FINAL) |
| 103 | Q_PROPERTY(int bottom READ bottom FINAL) |
| 104 | Q_PROPERTY(int right READ right FINAL) |
| 105 | Q_PROPERTY(int width READ width FINAL) |
| 106 | Q_PROPERTY(int height READ height FINAL) |
| 107 | Q_PROPERTY(QPersistentModelIndex topLeft READ topLeft FINAL) |
| 108 | Q_PROPERTY(QPersistentModelIndex bottomRight READ bottomRight FINAL) |
| 109 | Q_PROPERTY(QModelIndex parent READ parent FINAL) |
| 110 | Q_PROPERTY(bool valid READ isValid FINAL) |
| 111 | Q_PROPERTY(bool empty READ isEmpty FINAL) |
| 112 | Q_PROPERTY(QAbstractItemModel *model READ model FINAL) |
| 113 | Q_GADGET |
| 114 | QML_ANONYMOUS |
| 115 | QML_EXTENDED(QQmlItemSelectionRangeValueType) |
| 116 | QML_FOREIGN(QItemSelectionRange) |
| 117 | QML_ADDED_IN_VERSION(2, 0) |
| 118 | |
| 119 | public: |
| 120 | Q_INVOKABLE QString toString() const; |
| 121 | Q_INVOKABLE inline bool contains(const QModelIndex &index) const |
| 122 | { return v.contains(index); } |
| 123 | Q_INVOKABLE inline bool contains(int row, int column, const QModelIndex &parentIndex) const |
| 124 | { return v.contains(row, column, parentIndex); } |
| 125 | Q_INVOKABLE inline bool intersects(const QItemSelectionRange &other) const |
| 126 | { return v.intersects(other); } |
| 127 | Q_INVOKABLE QItemSelectionRange intersected(const QItemSelectionRange &other) const |
| 128 | { return v.intersected(other); } |
| 129 | |
| 130 | inline int top() const { return v.top(); } |
| 131 | inline int left() const { return v.left(); } |
| 132 | inline int bottom() const { return v.bottom(); } |
| 133 | inline int right() const { return v.right(); } |
| 134 | inline int width() const { return v.width(); } |
| 135 | inline int height() const { return v.height(); } |
| 136 | inline QPersistentModelIndex &topLeft() const { return const_cast<QPersistentModelIndex &>(v.topLeft()); } |
| 137 | inline QPersistentModelIndex &bottomRight() const { return const_cast<QPersistentModelIndex &>(v.bottomRight()); } |
| 138 | inline QModelIndex parent() const { return v.parent(); } |
| 139 | inline QAbstractItemModel *model() const { return const_cast<QAbstractItemModel *>(v.model()); } |
| 140 | inline bool isValid() const { return v.isValid(); } |
| 141 | inline bool isEmpty() const { return v.isEmpty(); } |
| 142 | |
| 143 | operator QItemSelectionRange() const { return v; } |
| 144 | }; |
| 145 | |
| 146 | struct QModelIndexListForeign |
| 147 | { |
| 148 | Q_GADGET |
| 149 | QML_ANONYMOUS |
| 150 | QML_SEQUENTIAL_CONTAINER(QModelIndex) |
| 151 | QML_FOREIGN(QModelIndexList) |
| 152 | QML_ADDED_IN_VERSION(2, 0) |
| 153 | }; |
| 154 | |
| 155 | struct QModelIndexStdVectorForeign |
| 156 | { |
| 157 | Q_GADGET |
| 158 | QML_ANONYMOUS |
| 159 | QML_SEQUENTIAL_CONTAINER(QModelIndex) |
| 160 | QML_FOREIGN(std::vector<QModelIndex>) |
| 161 | QML_ADDED_IN_VERSION(2, 0) |
| 162 | }; |
| 163 | |
| 164 | struct QItemSelectionForeign |
| 165 | { |
| 166 | Q_GADGET |
| 167 | QML_ANONYMOUS |
| 168 | QML_SEQUENTIAL_CONTAINER(QItemSelectionRange) |
| 169 | QML_FOREIGN(QItemSelection) |
| 170 | QML_ADDED_IN_VERSION(2, 0) |
| 171 | }; |
| 172 | |
| 173 | #undef QLISTVALUETYPE_INVOKABLE_API |
| 174 | |
| 175 | QT_END_NAMESPACE |
| 176 | |
| 177 | #endif // QQMLMODELINDEXVALUETYPE_P_H |
| 178 | |
| 179 | |