Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qqmlpropertyindex_p.h
Go to the documentation of this file.
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// Qt-Security score:significant
4
5#ifndef QQMLPROPERTYINDEX_P_H
6#define QQMLPROPERTYINDEX_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <private/qglobal_p.h>
20
21QT_BEGIN_NAMESPACE
22
23class QQmlPropertyIndex
24{
25 qint32 index;
26
27public:
28 QQmlPropertyIndex()
29 { index = -1; }
30
31 static QQmlPropertyIndex fromEncoded(qint32 encodedIndex)
32 {
33 QQmlPropertyIndex idx;
34 idx.index = encodedIndex;
35 return idx;
36 }
37
38 explicit QQmlPropertyIndex(int coreIndex)
39 { index = encode(coreIndex, -1); }
40
41 explicit QQmlPropertyIndex(int coreIndex, int valueTypeIndex)
42 : index(encode(coreIndex, valueTypeIndex))
43 {}
44
45 bool isValid() const
46 { return index != -1; }
47
48 int coreIndex() const
49 {
50 if (index == -1)
51 return -1;
52 return index & 0xffff;
53 }
54
55 int valueTypeIndex() const
56 {
57 if (index == -1)
58 return -1;
59 return (index >> 16) - 1;
60 }
61
62 bool hasValueTypeIndex() const
63 {
64 if (index == -1)
65 return false;
66 return index >> 16;
67 }
68
69 qint32 toEncoded() const
70 { return index; }
71
72 int intValue() const
73 { return index; }
74
75 bool operator==(const QQmlPropertyIndex &other) const
76 { return index == other.index; }
77
78 bool operator!=(const QQmlPropertyIndex &other) const
79 { return !operator==(other); }
80
81private:
82 static qint32 encode(int coreIndex, int valueTypeIndex)
83 {
84 Q_ASSERT(coreIndex >= -1);
85 Q_ASSERT(coreIndex <= 0xffff);
86 Q_ASSERT(valueTypeIndex >= -1);
87 Q_ASSERT(valueTypeIndex < 0xffff);
88
89 if (coreIndex == -1)
90 return -1;
91 else
92 return coreIndex | ((valueTypeIndex + 1) << 16);
93 }
94};
95
96QT_END_NAMESPACE
97
98#endif // QQMLPROPERTYINDEX_P_H