1 | // Copyright (C) 2016 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 QQMLPROPERTYINDEX_P_H |
5 | #define QQMLPROPERTYINDEX_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 <private/qglobal_p.h> |
19 | |
20 | QT_BEGIN_NAMESPACE |
21 | |
22 | class QQmlPropertyIndex |
23 | { |
24 | qint32 index; |
25 | |
26 | public: |
27 | QQmlPropertyIndex() |
28 | { index = -1; } |
29 | |
30 | static QQmlPropertyIndex fromEncoded(qint32 encodedIndex) |
31 | { |
32 | QQmlPropertyIndex idx; |
33 | idx.index = encodedIndex; |
34 | return idx; |
35 | } |
36 | |
37 | explicit QQmlPropertyIndex(int coreIndex) |
38 | { index = encode(coreIndex, valueTypeIndex: -1); } |
39 | |
40 | explicit QQmlPropertyIndex(int coreIndex, int valueTypeIndex) |
41 | : index(encode(coreIndex, valueTypeIndex)) |
42 | {} |
43 | |
44 | bool isValid() const |
45 | { return index != -1; } |
46 | |
47 | int coreIndex() const |
48 | { |
49 | if (index == -1) |
50 | return -1; |
51 | return index & 0xffff; |
52 | } |
53 | |
54 | int valueTypeIndex() const |
55 | { |
56 | if (index == -1) |
57 | return -1; |
58 | return (index >> 16) - 1; |
59 | } |
60 | |
61 | bool hasValueTypeIndex() const |
62 | { |
63 | if (index == -1) |
64 | return false; |
65 | return index >> 16; |
66 | } |
67 | |
68 | qint32 toEncoded() const |
69 | { return index; } |
70 | |
71 | int intValue() const |
72 | { return index; } |
73 | |
74 | bool operator==(const QQmlPropertyIndex &other) const |
75 | { return index == other.index; } |
76 | |
77 | bool operator!=(const QQmlPropertyIndex &other) const |
78 | { return !operator==(other); } |
79 | |
80 | private: |
81 | static qint32 encode(int coreIndex, int valueTypeIndex) |
82 | { |
83 | Q_ASSERT(coreIndex >= -1); |
84 | Q_ASSERT(coreIndex <= 0xffff); |
85 | Q_ASSERT(valueTypeIndex >= -1); |
86 | Q_ASSERT(valueTypeIndex < 0xffff); |
87 | |
88 | if (coreIndex == -1) |
89 | return -1; |
90 | else |
91 | return coreIndex | ((valueTypeIndex + 1) << 16); |
92 | } |
93 | }; |
94 | |
95 | QT_END_NAMESPACE |
96 | |
97 | #endif // QQMLPROPERTYINDEX_P_H |
98 | |