1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
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.
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.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
42 #ifndef QDECLARATIVEPROPERTYCACHE_P_H
43 #define QDECLARATIVEPROPERTYCACHE_P_H
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.
56 #include "private/qdeclarativerefcount_p.h"
57 #include "private/qdeclarativecleanup_p.h"
58 #include "private/qdeclarativenotifier_p.h"
60 #include <QtCore/qvector.h>
62 #include <QtScript/private/qscriptdeclarativeclass_p.h>
65 class QDeclarativeEngine;
67 class Q_AUTOTEST_EXPORT QDeclarativePropertyCache : public QDeclarativeRefCount, public QDeclarativeCleanup
70 QDeclarativePropertyCache(QDeclarativeEngine *);
71 QDeclarativePropertyCache(QDeclarativeEngine *, const QMetaObject *);
72 virtual ~QDeclarativePropertyCache();
77 inline bool operator==(const Data &);
82 // Can apply to all properties, except IsFunction
83 IsConstant = 0x00000001,
84 IsWritable = 0x00000002,
85 IsResettable = 0x00000004,
89 // These are mutualy exclusive
90 IsFunction = 0x00000020,
91 IsQObjectDerived = 0x00000040,
92 IsEnumType = 0x00000080,
94 IsQmlBinding = 0x00000200,
95 IsQScriptValue = 0x00000400,
97 // Apply only to IsFunctions
98 IsVMEFunction = 0x00000800,
99 HasArguments = 0x00001000,
100 IsSignal = 0x00002000,
101 IsVMESignal = 0x00004000
103 Q_DECLARE_FLAGS(Flags, Flag)
105 bool isValid() const { return coreIndex != -1; }
111 int notifyIndex; // When !IsFunction
112 int relatedIndex; // When IsFunction
114 uint overrideIndexIsProperty : 1;
115 int overrideIndex : 31;
117 int metaObjectOffset;
118 QVector<int> paramTypes;
119 static Flags flagsForProperty(const QMetaProperty &, QDeclarativeEngine *engine = 0);
120 int enumType(const QMetaObject *meta, const QString &strname);
121 void load(const QMetaProperty &, QDeclarativeEngine *engine = 0);
122 void load(const QMetaMethod &);
123 QString name(QObject *);
124 QString name(const QMetaObject *);
127 struct ValueTypeData {
128 inline ValueTypeData();
129 inline bool operator==(const ValueTypeData &);
130 Data::Flags flags; // flags of the access property on the value type proxy object
131 int valueTypeCoreIdx; // The prop index of the access property on the value type proxy object
132 int valueTypePropType; // The QVariant::Type of access property on the value type proxy object
135 void update(QDeclarativeEngine *, const QMetaObject *);
137 QDeclarativePropertyCache *copy() const;
138 void append(QDeclarativeEngine *, const QMetaObject *, Data::Flag propertyFlags = Data::NoFlags,
139 Data::Flag methodFlags = Data::NoFlags, Data::Flag signalFlags = Data::NoFlags);
140 void append(QDeclarativeEngine *, const QMetaObject *, int revision, Data::Flag propertyFlags = Data::NoFlags,
141 Data::Flag methodFlags = Data::NoFlags, Data::Flag signalFlags = Data::NoFlags);
143 static Data create(const QMetaObject *, const QString &);
145 inline Data *property(const QScriptDeclarativeClass::Identifier &id) const;
146 Data *property(const QString &) const;
147 Data *property(int) const;
148 Data *method(int) const;
149 QStringList propertyNames() const;
151 inline Data *overrideData(Data *) const;
152 inline bool isAllowedInRevision(Data *) const;
154 inline QDeclarativeEngine *qmlEngine() const;
155 static Data *property(QDeclarativeEngine *, QObject *, const QScriptDeclarativeClass::Identifier &, Data &);
156 static Data *property(QDeclarativeEngine *, QObject *, const QString &, Data &);
159 virtual void clear();
162 friend class QDeclarativeEnginePrivate;
164 struct RData : public Data, public QDeclarativeRefCount {
165 QScriptDeclarativeClass::PersistentIdentifier identifier;
168 typedef QVector<RData *> IndexCache;
169 typedef QHash<QString, RData *> StringCache;
170 typedef QHash<QScriptDeclarativeClass::Identifier, RData *> IdentifierCache;
171 typedef QVector<int> AllowedRevisionCache;
173 void updateRecur(QDeclarativeEngine *, const QMetaObject *);
175 QDeclarativeEngine *engine;
176 IndexCache indexCache;
177 IndexCache methodIndexCache;
178 StringCache stringCache;
179 IdentifierCache identifierCache;
180 AllowedRevisionCache allowedRevisionCache;
182 Q_DECLARE_OPERATORS_FOR_FLAGS(QDeclarativePropertyCache::Data::Flags);
184 QDeclarativePropertyCache::Data::Data()
185 : flags(0), propType(0), coreIndex(-1), notifyIndex(-1), overrideIndexIsProperty(false), overrideIndex(-1),
186 revision(0), metaObjectOffset(-1)
190 bool QDeclarativePropertyCache::Data::operator==(const QDeclarativePropertyCache::Data &other)
192 return flags == other.flags &&
193 propType == other.propType &&
194 coreIndex == other.coreIndex &&
195 notifyIndex == other.notifyIndex &&
196 revision == other.revision;
199 QDeclarativePropertyCache::Data *
200 QDeclarativePropertyCache::overrideData(Data *data) const
202 if (data->overrideIndex < 0)
205 if (data->overrideIndexIsProperty)
206 return indexCache.at(data->overrideIndex);
208 return methodIndexCache.at(data->overrideIndex);
211 QDeclarativePropertyCache::Data *
212 QDeclarativePropertyCache::property(const QScriptDeclarativeClass::Identifier &id) const
214 return identifierCache.value(id);
217 QDeclarativePropertyCache::ValueTypeData::ValueTypeData()
218 : flags(QDeclarativePropertyCache::Data::NoFlags), valueTypeCoreIdx(-1), valueTypePropType(0)
222 bool QDeclarativePropertyCache::ValueTypeData::operator==(const ValueTypeData &o)
224 return flags == o.flags &&
225 valueTypeCoreIdx == o.valueTypeCoreIdx &&
226 valueTypePropType == o.valueTypePropType;
229 bool QDeclarativePropertyCache::isAllowedInRevision(Data *data) const
231 return (data->metaObjectOffset == -1 && data->revision == 0) ||
232 (allowedRevisionCache[data->metaObjectOffset] >= data->revision);
235 QDeclarativeEngine *QDeclarativePropertyCache::qmlEngine() const
242 #endif // QDECLARATIVEPROPERTYCACHE_P_H