1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation (qt-info@nokia.com)
|
---|
6 | **
|
---|
7 | ** This file is part of the QtDeclarative module of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Lesser General Public License Usage
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
18 | ** General Public License version 2.1 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
20 | ** packaging of this file. Please review the following information to
|
---|
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
23 | **
|
---|
24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at qt-info@nokia.com.
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #ifndef QDECLARATIVEPROPERTYCACHE_P_H
|
---|
43 | #define QDECLARATIVEPROPERTYCACHE_P_H
|
---|
44 |
|
---|
45 | //
|
---|
46 | // W A R N I N G
|
---|
47 | // -------------
|
---|
48 | //
|
---|
49 | // This file is not part of the Qt API. It exists purely as an
|
---|
50 | // implementation detail. This header file may change from version to
|
---|
51 | // version without notice, or even be removed.
|
---|
52 | //
|
---|
53 | // We mean it.
|
---|
54 | //
|
---|
55 |
|
---|
56 | #include "private/qdeclarativerefcount_p.h"
|
---|
57 | #include "private/qdeclarativecleanup_p.h"
|
---|
58 | #include "private/qdeclarativenotifier_p.h"
|
---|
59 |
|
---|
60 | #include <QtCore/qvector.h>
|
---|
61 |
|
---|
62 | #include <QtScript/private/qscriptdeclarativeclass_p.h>
|
---|
63 | QT_BEGIN_NAMESPACE
|
---|
64 |
|
---|
65 | class QDeclarativeEngine;
|
---|
66 | class QMetaProperty;
|
---|
67 |
|
---|
68 | class Q_AUTOTEST_EXPORT QDeclarativePropertyCache : public QDeclarativeRefCount, public QDeclarativeCleanup
|
---|
69 | {
|
---|
70 | public:
|
---|
71 | QDeclarativePropertyCache(QDeclarativeEngine *);
|
---|
72 | QDeclarativePropertyCache(QDeclarativeEngine *, const QMetaObject *);
|
---|
73 | virtual ~QDeclarativePropertyCache();
|
---|
74 |
|
---|
75 | struct Data {
|
---|
76 | inline Data();
|
---|
77 | inline bool operator==(const Data &);
|
---|
78 |
|
---|
79 | enum Flag {
|
---|
80 | NoFlags = 0x00000000,
|
---|
81 |
|
---|
82 | // Can apply to all properties, except IsFunction
|
---|
83 | IsConstant = 0x00000001,
|
---|
84 | IsWritable = 0x00000002,
|
---|
85 | IsResettable = 0x00000004,
|
---|
86 | IsAlias = 0x00000008,
|
---|
87 |
|
---|
88 | // These are mutualy exclusive
|
---|
89 | IsFunction = 0x00000010,
|
---|
90 | IsQObjectDerived = 0x00000020,
|
---|
91 | IsEnumType = 0x00000040,
|
---|
92 | IsQList = 0x00000080,
|
---|
93 | IsQmlBinding = 0x00000100,
|
---|
94 | IsQScriptValue = 0x00000200,
|
---|
95 |
|
---|
96 | // Apply only to IsFunctions
|
---|
97 | IsVMEFunction = 0x00000400,
|
---|
98 | HasArguments = 0x00000800,
|
---|
99 | IsSignal = 0x00001000,
|
---|
100 | IsVMESignal = 0x00002000
|
---|
101 | };
|
---|
102 | Q_DECLARE_FLAGS(Flags, Flag)
|
---|
103 |
|
---|
104 | bool isValid() const { return coreIndex != -1; }
|
---|
105 |
|
---|
106 | Flags flags;
|
---|
107 | int propType;
|
---|
108 | int coreIndex;
|
---|
109 | union {
|
---|
110 | int notifyIndex; // When !IsFunction
|
---|
111 | int relatedIndex; // When IsFunction
|
---|
112 | };
|
---|
113 |
|
---|
114 | static Flags flagsForProperty(const QMetaProperty &, QDeclarativeEngine *engine = 0);
|
---|
115 | void load(const QMetaProperty &, QDeclarativeEngine *engine = 0);
|
---|
116 | void load(const QMetaMethod &);
|
---|
117 | QString name(QObject *);
|
---|
118 | QString name(const QMetaObject *);
|
---|
119 | };
|
---|
120 |
|
---|
121 | struct ValueTypeData {
|
---|
122 | inline ValueTypeData();
|
---|
123 | inline bool operator==(const ValueTypeData &);
|
---|
124 | Data::Flags flags; // flags of the access property on the value type proxy object
|
---|
125 | int valueTypeCoreIdx; // The prop index of the access property on the value type proxy object
|
---|
126 | int valueTypePropType; // The QVariant::Type of access property on the value type proxy object
|
---|
127 | };
|
---|
128 |
|
---|
129 | void update(QDeclarativeEngine *, const QMetaObject *);
|
---|
130 |
|
---|
131 | QDeclarativePropertyCache *copy() const;
|
---|
132 | void append(QDeclarativeEngine *, const QMetaObject *, Data::Flag propertyFlags = Data::NoFlags,
|
---|
133 | Data::Flag methodFlags = Data::NoFlags, Data::Flag signalFlags = Data::NoFlags);
|
---|
134 |
|
---|
135 | static QDeclarativePropertyCache *create(QDeclarativeEngine *, const QMetaObject *);
|
---|
136 | static Data create(const QMetaObject *, const QString &);
|
---|
137 |
|
---|
138 | inline Data *property(const QScriptDeclarativeClass::Identifier &id) const;
|
---|
139 | Data *property(const QString &) const;
|
---|
140 | Data *property(int) const;
|
---|
141 | Data *method(int) const;
|
---|
142 | QStringList propertyNames() const;
|
---|
143 |
|
---|
144 | inline QDeclarativeEngine *qmlEngine() const;
|
---|
145 | static Data *property(QDeclarativeEngine *, QObject *, const QScriptDeclarativeClass::Identifier &, Data &);
|
---|
146 | static Data *property(QDeclarativeEngine *, QObject *, const QString &, Data &);
|
---|
147 | protected:
|
---|
148 | virtual void clear();
|
---|
149 |
|
---|
150 | private:
|
---|
151 | struct RData : public Data, public QDeclarativeRefCount {
|
---|
152 | QScriptDeclarativeClass::PersistentIdentifier identifier;
|
---|
153 | };
|
---|
154 |
|
---|
155 | typedef QVector<RData *> IndexCache;
|
---|
156 | typedef QHash<QString, RData *> StringCache;
|
---|
157 | typedef QHash<QScriptDeclarativeClass::Identifier, RData *> IdentifierCache;
|
---|
158 |
|
---|
159 | void updateRecur(QDeclarativeEngine *, const QMetaObject *);
|
---|
160 |
|
---|
161 | QDeclarativeEngine *engine;
|
---|
162 | IndexCache indexCache;
|
---|
163 | IndexCache methodIndexCache;
|
---|
164 | StringCache stringCache;
|
---|
165 | IdentifierCache identifierCache;
|
---|
166 | };
|
---|
167 | Q_DECLARE_OPERATORS_FOR_FLAGS(QDeclarativePropertyCache::Data::Flags);
|
---|
168 |
|
---|
169 | QDeclarativePropertyCache::Data::Data()
|
---|
170 | : flags(0), propType(0), coreIndex(-1), notifyIndex(-1)
|
---|
171 | {
|
---|
172 | }
|
---|
173 |
|
---|
174 | bool QDeclarativePropertyCache::Data::operator==(const QDeclarativePropertyCache::Data &other)
|
---|
175 | {
|
---|
176 | return flags == other.flags &&
|
---|
177 | propType == other.propType &&
|
---|
178 | coreIndex == other.coreIndex &&
|
---|
179 | notifyIndex == other.notifyIndex;
|
---|
180 | }
|
---|
181 |
|
---|
182 | QDeclarativePropertyCache::Data *
|
---|
183 | QDeclarativePropertyCache::property(const QScriptDeclarativeClass::Identifier &id) const
|
---|
184 | {
|
---|
185 | return identifierCache.value(id);
|
---|
186 | }
|
---|
187 |
|
---|
188 | QDeclarativePropertyCache::ValueTypeData::ValueTypeData()
|
---|
189 | : flags(QDeclarativePropertyCache::Data::NoFlags), valueTypeCoreIdx(-1), valueTypePropType(0)
|
---|
190 | {
|
---|
191 | }
|
---|
192 |
|
---|
193 | bool QDeclarativePropertyCache::ValueTypeData::operator==(const ValueTypeData &o)
|
---|
194 | {
|
---|
195 | return flags == o.flags &&
|
---|
196 | valueTypeCoreIdx == o.valueTypeCoreIdx &&
|
---|
197 | valueTypePropType == o.valueTypePropType;
|
---|
198 | }
|
---|
199 |
|
---|
200 | QDeclarativeEngine *QDeclarativePropertyCache::qmlEngine() const
|
---|
201 | {
|
---|
202 | return engine;
|
---|
203 | }
|
---|
204 |
|
---|
205 | QT_END_NAMESPACE
|
---|
206 |
|
---|
207 | #endif // QDECLARATIVEPROPERTYCACHE_P_H
|
---|