aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmlmodels/qqmlmodelindexvaluetype_p.h
blob: 35ebacc0515c288bc6ed30be63b123a537c6d676 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
// Copyright (C) 2021 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#ifndef QQMLMODELINDEXVALUETYPE_P_H
#define QQMLMODELINDEXVALUETYPE_P_H

//
//  W A R N I N G
//  -------------
//
// This file is not part of the Qt API.  It exists purely as an
// implementation detail.  This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//

#include <QtCore/qabstractitemmodel.h>
#include <QtCore/qitemselectionmodel.h>
#include <QtQml/qqml.h>
#include <QtCore/private/qglobal_p.h>

QT_BEGIN_NAMESPACE

struct QQmlModelIndexValueType
{
    QModelIndex v;

    Q_PROPERTY(int row READ row CONSTANT FINAL)
    Q_PROPERTY(int column READ column CONSTANT FINAL)
    Q_PROPERTY(QModelIndex parent READ parent FINAL)
    Q_PROPERTY(bool valid READ isValid CONSTANT FINAL)
    Q_PROPERTY(QAbstractItemModel *model READ model CONSTANT FINAL)
    Q_PROPERTY(quint64 internalId READ internalId CONSTANT FINAL)
    Q_GADGET
    QML_ANONYMOUS
    QML_EXTENDED(QQmlModelIndexValueType)
    QML_FOREIGN(QModelIndex)
    QML_ADDED_IN_VERSION(2, 0)

public:
    Q_INVOKABLE QString toString() const
    { return QLatin1String("QModelIndex") + propertiesString(v); }

    Q_REVISION(6, 7) Q_INVOKABLE QVariant data(int role = Qt::DisplayRole) const
    { return v.data(role); }

    inline int row() const noexcept { return v.row(); }
    inline int column() const noexcept { return v.column(); }
    inline QModelIndex parent() const { return v.parent(); }
    inline bool isValid() const noexcept { return v.isValid(); }
    inline QAbstractItemModel *model() const noexcept
    { return const_cast<QAbstractItemModel *>(v.model()); }
    quint64 internalId() const { return v.internalId(); }

    static QString propertiesString(const QModelIndex &idx);

    static QPersistentModelIndex toPersistentModelIndex(const QModelIndex &index)
    { return QPersistentModelIndex(index); }

    operator QModelIndex() const { return v; }
};

struct QQmlPersistentModelIndexValueType
{
    QPersistentModelIndex v;

    Q_PROPERTY(int row READ row FINAL)
    Q_PROPERTY(int column READ column FINAL)
    Q_PROPERTY(QModelIndex parent READ parent FINAL)
    Q_PROPERTY(bool valid READ isValid FINAL)
    Q_PROPERTY(QAbstractItemModel *model READ model FINAL)
    Q_PROPERTY(quint64 internalId READ internalId FINAL)
    Q_GADGET
    QML_ANONYMOUS
    QML_EXTENDED(QQmlPersistentModelIndexValueType)
    QML_FOREIGN(QPersistentModelIndex)
    QML_ADDED_IN_VERSION(2, 0)

public:
    Q_INVOKABLE QString toString() const
    { return QLatin1String("QPersistentModelIndex") + QQmlModelIndexValueType::propertiesString(v); }

    Q_REVISION(6, 7) Q_INVOKABLE QVariant data(int role = Qt::DisplayRole) const
    { return v.data(role); }

    inline int row() const { return v.row(); }
    inline int column() const { return v.column(); }
    inline QModelIndex parent() const { return v.parent(); }
    inline bool isValid() const { return v.isValid(); }
    inline QAbstractItemModel *model() const { return const_cast<QAbstractItemModel *>(v.model()); }
    inline quint64 internalId() const { return v.internalId(); }

    operator QPersistentModelIndex() const { return v; }
};

struct QQmlItemSelectionRangeValueType
{
    QItemSelectionRange v;

    Q_PROPERTY(int top READ top FINAL)
    Q_PROPERTY(int left READ left FINAL)
    Q_PROPERTY(int bottom READ bottom FINAL)
    Q_PROPERTY(int right READ right FINAL)
    Q_PROPERTY(int width READ width FINAL)
    Q_PROPERTY(int height READ height FINAL)
    Q_PROPERTY(QPersistentModelIndex topLeft READ topLeft FINAL)
    Q_PROPERTY(QPersistentModelIndex bottomRight READ bottomRight FINAL)
    Q_PROPERTY(QModelIndex parent READ parent FINAL)
    Q_PROPERTY(bool valid READ isValid FINAL)
    Q_PROPERTY(bool empty READ isEmpty FINAL)
    Q_PROPERTY(QAbstractItemModel *model READ model FINAL)
    Q_GADGET
    QML_ANONYMOUS
    QML_EXTENDED(QQmlItemSelectionRangeValueType)
    QML_FOREIGN(QItemSelectionRange)
    QML_ADDED_IN_VERSION(2, 0)

public:
    Q_INVOKABLE QString toString() const;
    Q_INVOKABLE inline bool contains(const QModelIndex &index) const
    { return v.contains(index); }
    Q_INVOKABLE inline bool contains(int row, int column, const QModelIndex &parentIndex) const
    { return v.contains(row, column, parentIndex); }
    Q_INVOKABLE inline bool intersects(const QItemSelectionRange &other) const
    { return v.intersects(other); }
    Q_INVOKABLE QItemSelectionRange intersected(const QItemSelectionRange &other) const
    { return v.intersected(other); }

    inline int top() const { return v.top(); }
    inline int left() const { return v.left(); }
    inline int bottom() const { return v.bottom(); }
    inline int right() const { return v.right(); }
    inline int width() const { return v.width(); }
    inline int height() const { return v.height(); }
    inline QPersistentModelIndex &topLeft() const { return const_cast<QPersistentModelIndex &>(v.topLeft()); }
    inline QPersistentModelIndex &bottomRight() const { return const_cast<QPersistentModelIndex &>(v.bottomRight()); }
    inline QModelIndex parent() const { return v.parent(); }
    inline QAbstractItemModel *model() const { return const_cast<QAbstractItemModel *>(v.model()); }
    inline bool isValid() const { return v.isValid(); }
    inline bool isEmpty() const { return v.isEmpty(); }

    operator QItemSelectionRange() const { return v; }
};

struct QModelIndexListForeign
{
    Q_GADGET
    QML_ANONYMOUS
    QML_SEQUENTIAL_CONTAINER(QModelIndex)
    QML_FOREIGN(QModelIndexList)
    QML_ADDED_IN_VERSION(2, 0)
};

struct QModelIndexStdVectorForeign
{
    Q_GADGET
    QML_ANONYMOUS
    QML_SEQUENTIAL_CONTAINER(QModelIndex)
    QML_FOREIGN(std::vector<QModelIndex>)
    QML_ADDED_IN_VERSION(2, 0)
};

struct QItemSelectionForeign
{
    Q_GADGET
    QML_ANONYMOUS
    QML_SEQUENTIAL_CONTAINER(QItemSelectionRange)
    QML_FOREIGN(QItemSelection)
    QML_ADDED_IN_VERSION(2, 0)
};

#undef QLISTVALUETYPE_INVOKABLE_API

QT_END_NAMESPACE

#endif // QQMLMODELINDEXVALUETYPE_P_H