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 | inline int row() const noexcept { return v.row(); } |
46 | inline int column() const noexcept { return v.column(); } |
47 | inline QModelIndex parent() const { return v.parent(); } |
48 | inline bool isValid() const noexcept { return v.isValid(); } |
49 | inline QAbstractItemModel *model() const noexcept |
50 | { return const_cast<QAbstractItemModel *>(v.model()); } |
51 | quint64 internalId() const { return v.internalId(); } |
52 | |
53 | static QString propertiesString(const QModelIndex &idx); |
54 | |
55 | static QPersistentModelIndex toPersistentModelIndex(const QModelIndex &index) |
56 | { return QPersistentModelIndex(index); } |
57 | |
58 | operator QModelIndex() const { return v; } |
59 | }; |
60 | |
61 | struct QQmlPersistentModelIndexValueType |
62 | { |
63 | QPersistentModelIndex v; |
64 | |
65 | Q_PROPERTY(int row READ row FINAL) |
66 | Q_PROPERTY(int column READ column FINAL) |
67 | Q_PROPERTY(QModelIndex parent READ parent FINAL) |
68 | Q_PROPERTY(bool valid READ isValid FINAL) |
69 | Q_PROPERTY(QAbstractItemModel *model READ model FINAL) |
70 | Q_PROPERTY(quint64 internalId READ internalId FINAL) |
71 | Q_GADGET |
72 | QML_ANONYMOUS |
73 | QML_EXTENDED(QQmlPersistentModelIndexValueType) |
74 | QML_FOREIGN(QPersistentModelIndex) |
75 | QML_ADDED_IN_VERSION(2, 0) |
76 | |
77 | public: |
78 | Q_INVOKABLE QString toString() const |
79 | { return QLatin1String("QPersistentModelIndex" ) + QQmlModelIndexValueType::propertiesString(idx: v); } |
80 | |
81 | inline int row() const { return v.row(); } |
82 | inline int column() const { return v.column(); } |
83 | inline QModelIndex parent() const { return v.parent(); } |
84 | inline bool isValid() const { return v.isValid(); } |
85 | inline QAbstractItemModel *model() const { return const_cast<QAbstractItemModel *>(v.model()); } |
86 | inline quint64 internalId() const { return v.internalId(); } |
87 | |
88 | operator QPersistentModelIndex() const { return v; } |
89 | }; |
90 | |
91 | struct QQmlItemSelectionRangeValueType |
92 | { |
93 | QItemSelectionRange v; |
94 | |
95 | Q_PROPERTY(int top READ top FINAL) |
96 | Q_PROPERTY(int left READ left FINAL) |
97 | Q_PROPERTY(int bottom READ bottom FINAL) |
98 | Q_PROPERTY(int right READ right FINAL) |
99 | Q_PROPERTY(int width READ width FINAL) |
100 | Q_PROPERTY(int height READ height FINAL) |
101 | Q_PROPERTY(QPersistentModelIndex topLeft READ topLeft FINAL) |
102 | Q_PROPERTY(QPersistentModelIndex bottomRight READ bottomRight FINAL) |
103 | Q_PROPERTY(QModelIndex parent READ parent FINAL) |
104 | Q_PROPERTY(bool valid READ isValid FINAL) |
105 | Q_PROPERTY(bool empty READ isEmpty FINAL) |
106 | Q_PROPERTY(QAbstractItemModel *model READ model FINAL) |
107 | Q_GADGET |
108 | QML_ANONYMOUS |
109 | QML_EXTENDED(QQmlItemSelectionRangeValueType) |
110 | QML_FOREIGN(QItemSelectionRange) |
111 | QML_ADDED_IN_VERSION(2, 0) |
112 | |
113 | public: |
114 | Q_INVOKABLE QString toString() const; |
115 | Q_INVOKABLE inline bool contains(const QModelIndex &index) const |
116 | { return v.contains(index); } |
117 | Q_INVOKABLE inline bool contains(int row, int column, const QModelIndex &parentIndex) const |
118 | { return v.contains(row, column, parentIndex); } |
119 | Q_INVOKABLE inline bool intersects(const QItemSelectionRange &other) const |
120 | { return v.intersects(other); } |
121 | Q_INVOKABLE QItemSelectionRange intersected(const QItemSelectionRange &other) const |
122 | { return v.intersected(other); } |
123 | |
124 | inline int top() const { return v.top(); } |
125 | inline int left() const { return v.left(); } |
126 | inline int bottom() const { return v.bottom(); } |
127 | inline int right() const { return v.right(); } |
128 | inline int width() const { return v.width(); } |
129 | inline int height() const { return v.height(); } |
130 | inline QPersistentModelIndex &topLeft() const { return const_cast<QPersistentModelIndex &>(v.topLeft()); } |
131 | inline QPersistentModelIndex &bottomRight() const { return const_cast<QPersistentModelIndex &>(v.bottomRight()); } |
132 | inline QModelIndex parent() const { return v.parent(); } |
133 | inline QAbstractItemModel *model() const { return const_cast<QAbstractItemModel *>(v.model()); } |
134 | inline bool isValid() const { return v.isValid(); } |
135 | inline bool isEmpty() const { return v.isEmpty(); } |
136 | |
137 | operator QItemSelectionRange() const { return v; } |
138 | }; |
139 | |
140 | struct QModelIndexListForeign |
141 | { |
142 | Q_GADGET |
143 | QML_ANONYMOUS |
144 | QML_SEQUENTIAL_CONTAINER(QModelIndex) |
145 | QML_FOREIGN(QModelIndexList) |
146 | QML_ADDED_IN_VERSION(2, 0) |
147 | }; |
148 | |
149 | struct QModelIndexStdVectorForeign |
150 | { |
151 | Q_GADGET |
152 | QML_ANONYMOUS |
153 | QML_SEQUENTIAL_CONTAINER(QModelIndex) |
154 | QML_FOREIGN(std::vector<QModelIndex>) |
155 | QML_ADDED_IN_VERSION(2, 0) |
156 | }; |
157 | |
158 | struct QItemSelectionForeign |
159 | { |
160 | Q_GADGET |
161 | QML_ANONYMOUS |
162 | QML_SEQUENTIAL_CONTAINER(QItemSelectionRange) |
163 | QML_FOREIGN(QItemSelection) |
164 | QML_ADDED_IN_VERSION(2, 0) |
165 | }; |
166 | |
167 | #undef QLISTVALUETYPE_INVOKABLE_API |
168 | |
169 | QT_END_NAMESPACE |
170 | |
171 | #endif // QQMLMODELINDEXVALUETYPE_P_H |
172 | |
173 | |