1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtQml module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QQMLMODELINDEXVALUETYPE_P_H
41#define QQMLMODELINDEXVALUETYPE_P_H
42
43//
44// W A R N I N G
45// -------------
46//
47// This file is not part of the Qt API. It exists purely as an
48// implementation detail. This header file may change from version to
49// version without notice, or even be removed.
50//
51// We mean it.
52//
53
54#include <QtCore/qabstractitemmodel.h>
55#include <QtCore/qitemselectionmodel.h>
56
57QT_BEGIN_NAMESPACE
58
59struct QQmlModelIndexValueType
60{
61 QModelIndex v;
62
63 Q_PROPERTY(int row READ row CONSTANT FINAL)
64 Q_PROPERTY(int column READ column CONSTANT FINAL)
65 Q_PROPERTY(QModelIndex parent READ parent FINAL)
66 Q_PROPERTY(bool valid READ isValid CONSTANT FINAL)
67 Q_PROPERTY(QAbstractItemModel *model READ model CONSTANT FINAL)
68 Q_PROPERTY(quint64 internalId READ internalId CONSTANT FINAL)
69 Q_GADGET
70
71public:
72 Q_INVOKABLE QString toString() const
73 { return QLatin1String("QModelIndex") + propertiesString(idx: v); }
74
75 inline int row() const Q_DECL_NOTHROW { return v.row(); }
76 inline int column() const Q_DECL_NOTHROW { return v.column(); }
77 inline QModelIndex parent() const { return v.parent(); }
78 inline bool isValid() const Q_DECL_NOTHROW { return v.isValid(); }
79 inline QAbstractItemModel *model() const Q_DECL_NOTHROW
80 { return const_cast<QAbstractItemModel *>(v.model()); }
81 quint64 internalId() const { return v.internalId(); }
82
83 static QString propertiesString(const QModelIndex &idx);
84
85 static QPersistentModelIndex toPersistentModelIndex(const QModelIndex &index)
86 { return QPersistentModelIndex(index); }
87};
88
89struct QQmlPersistentModelIndexValueType
90{
91 QPersistentModelIndex v;
92
93 Q_PROPERTY(int row READ row FINAL)
94 Q_PROPERTY(int column READ column FINAL)
95 Q_PROPERTY(QModelIndex parent READ parent FINAL)
96 Q_PROPERTY(bool valid READ isValid FINAL)
97 Q_PROPERTY(QAbstractItemModel *model READ model FINAL)
98 Q_PROPERTY(quint64 internalId READ internalId FINAL)
99 Q_GADGET
100
101public:
102 Q_INVOKABLE QString toString() const
103 { return QLatin1String("QPersistentModelIndex") + QQmlModelIndexValueType::propertiesString(idx: v); }
104
105 inline int row() const { return v.row(); }
106 inline int column() const { return v.column(); }
107 inline QModelIndex parent() const { return v.parent(); }
108 inline bool isValid() const { return v.isValid(); }
109 inline QAbstractItemModel *model() const { return const_cast<QAbstractItemModel *>(v.model()); }
110 inline quint64 internalId() const { return v.internalId(); }
111
112 static const QModelIndex &toModelIndex(const QPersistentModelIndex &index)
113 { return index; }
114};
115
116struct QQmlItemSelectionRangeValueType
117{
118 QItemSelectionRange v;
119
120 Q_PROPERTY(int top READ top FINAL)
121 Q_PROPERTY(int left READ left FINAL)
122 Q_PROPERTY(int bottom READ bottom FINAL)
123 Q_PROPERTY(int right READ right FINAL)
124 Q_PROPERTY(int width READ width FINAL)
125 Q_PROPERTY(int height READ height FINAL)
126 Q_PROPERTY(QPersistentModelIndex topLeft READ topLeft FINAL)
127 Q_PROPERTY(QPersistentModelIndex bottomRight READ bottomRight FINAL)
128 Q_PROPERTY(QModelIndex parent READ parent FINAL)
129 Q_PROPERTY(bool valid READ isValid FINAL)
130 Q_PROPERTY(bool empty READ isEmpty FINAL)
131 Q_PROPERTY(QAbstractItemModel *model READ model FINAL)
132 Q_GADGET
133
134public:
135 Q_INVOKABLE QString toString() const;
136 Q_INVOKABLE inline bool contains(const QModelIndex &index) const
137 { return v.contains(index); }
138 Q_INVOKABLE inline bool contains(int row, int column, const QModelIndex &parentIndex) const
139 { return v.contains(row, column, parentIndex); }
140 Q_INVOKABLE inline bool intersects(const QItemSelectionRange &other) const
141 { return v.intersects(other); }
142 Q_INVOKABLE QItemSelectionRange intersected(const QItemSelectionRange &other) const
143 { return v.intersected(other); }
144
145 inline int top() const { return v.top(); }
146 inline int left() const { return v.left(); }
147 inline int bottom() const { return v.bottom(); }
148 inline int right() const { return v.right(); }
149 inline int width() const { return v.width(); }
150 inline int height() const { return v.height(); }
151 inline QPersistentModelIndex &topLeft() const { return const_cast<QPersistentModelIndex &>(v.topLeft()); }
152 inline QPersistentModelIndex &bottomRight() const { return const_cast<QPersistentModelIndex &>(v.bottomRight()); }
153 inline QModelIndex parent() const { return v.parent(); }
154 inline QAbstractItemModel *model() const { return const_cast<QAbstractItemModel *>(v.model()); }
155 inline bool isValid() const { return v.isValid(); }
156 inline bool isEmpty() const { return v.isEmpty(); }
157};
158
159#undef QLISTVALUETYPE_INVOKABLE_API
160
161QT_END_NAMESPACE
162
163#endif // QQMLMODELINDEXVALUETYPE_P_H
164
165

source code of qtdeclarative/src/qml/types/qqmlmodelindexvaluetype_p.h