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 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
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;
68 class Q_AUTOTEST_EXPORT QDeclarativePropertyCache : public QDeclarativeRefCount, public QDeclarativeCleanup
71 QDeclarativePropertyCache(QDeclarativeEngine *);
72 QDeclarativePropertyCache(QDeclarativeEngine *, const QMetaObject *);
73 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,
88 // These are mutualy exclusive
89 IsFunction = 0x00000010,
90 IsQObjectDerived = 0x00000020,
91 IsEnumType = 0x00000040,
93 IsQmlBinding = 0x00000100,
94 IsQScriptValue = 0x00000200,
96 // Apply only to IsFunctions
97 IsVMEFunction = 0x00000400,
98 HasArguments = 0x00000800,
99 IsSignal = 0x00001000,
100 IsVMESignal = 0x00002000
102 Q_DECLARE_FLAGS(Flags, Flag)
104 bool isValid() const { return coreIndex != -1; }
110 int notifyIndex; // When !IsFunction
111 int relatedIndex; // When IsFunction
113 uint overrideIndexIsProperty : 1;
114 int overrideIndex : 31;
116 int metaObjectOffset;
118 static Flags flagsForProperty(const QMetaProperty &, QDeclarativeEngine *engine = 0);
119 void load(const QMetaProperty &, QDeclarativeEngine *engine = 0);
120 void load(const QMetaMethod &);
121 QString name(QObject *);
122 QString name(const QMetaObject *);
125 struct ValueTypeData {
126 inline ValueTypeData();
127 inline bool operator==(const ValueTypeData &);
128 Data::Flags flags; // flags of the access property on the value type proxy object
129 int valueTypeCoreIdx; // The prop index of the access property on the value type proxy object
130 int valueTypePropType; // The QVariant::Type of access property on the value type proxy object
133 void update(QDeclarativeEngine *, const QMetaObject *);
135 QDeclarativePropertyCache *copy() const;
136 void append(QDeclarativeEngine *, const QMetaObject *, Data::Flag propertyFlags = Data::NoFlags,
137 Data::Flag methodFlags = Data::NoFlags, Data::Flag signalFlags = Data::NoFlags);
138 void append(QDeclarativeEngine *, const QMetaObject *, int revision, Data::Flag propertyFlags = Data::NoFlags,
139 Data::Flag methodFlags = Data::NoFlags, Data::Flag signalFlags = Data::NoFlags);
141 static Data create(const QMetaObject *, const QString &);
143 inline Data *property(const QScriptDeclarativeClass::Identifier &id) const;
144 Data *property(const QString &) const;
145 Data *property(int) const;
146 Data *method(int) const;
147 QStringList propertyNames() const;
149 inline Data *overrideData(Data *) const;
150 inline bool isAllowedInRevision(Data *) const;
152 inline QDeclarativeEngine *qmlEngine() const;
153 static Data *property(QDeclarativeEngine *, QObject *, const QScriptDeclarativeClass::Identifier &, Data &);
154 static Data *property(QDeclarativeEngine *, QObject *, const QString &, Data &);
157 virtual void clear();
160 friend class QDeclarativeEnginePrivate;
162 struct RData : public Data, public QDeclarativeRefCount {
163 QScriptDeclarativeClass::PersistentIdentifier identifier;
166 typedef QVector<RData *> IndexCache;
167 typedef QHash<QString, RData *> StringCache;
168 typedef QHash<QScriptDeclarativeClass::Identifier, RData *> IdentifierCache;
169 typedef QVector<int> AllowedRevisionCache;
171 void updateRecur(QDeclarativeEngine *, const QMetaObject *);
173 QDeclarativeEngine *engine;
174 IndexCache indexCache;
175 IndexCache methodIndexCache;
176 StringCache stringCache;
177 IdentifierCache identifierCache;
178 AllowedRevisionCache allowedRevisionCache;
180 Q_DECLARE_OPERATORS_FOR_FLAGS(QDeclarativePropertyCache::Data::Flags);
182 QDeclarativePropertyCache::Data::Data()
183 : flags(0), propType(0), coreIndex(-1), notifyIndex(-1), overrideIndexIsProperty(false), overrideIndex(-1),
184 revision(0), metaObjectOffset(-1)
188 bool QDeclarativePropertyCache::Data::operator==(const QDeclarativePropertyCache::Data &other)
190 return flags == other.flags &&
191 propType == other.propType &&
192 coreIndex == other.coreIndex &&
193 notifyIndex == other.notifyIndex &&
194 revision == other.revision;
197 QDeclarativePropertyCache::Data *
198 QDeclarativePropertyCache::overrideData(Data *data) const
200 if (data->overrideIndex < 0)
203 if (data->overrideIndexIsProperty)
204 return indexCache.at(data->overrideIndex);
206 return methodIndexCache.at(data->overrideIndex);
209 QDeclarativePropertyCache::Data *
210 QDeclarativePropertyCache::property(const QScriptDeclarativeClass::Identifier &id) const
212 return identifierCache.value(id);
215 QDeclarativePropertyCache::ValueTypeData::ValueTypeData()
216 : flags(QDeclarativePropertyCache::Data::NoFlags), valueTypeCoreIdx(-1), valueTypePropType(0)
220 bool QDeclarativePropertyCache::ValueTypeData::operator==(const ValueTypeData &o)
222 return flags == o.flags &&
223 valueTypeCoreIdx == o.valueTypeCoreIdx &&
224 valueTypePropType == o.valueTypePropType;
227 bool QDeclarativePropertyCache::isAllowedInRevision(Data *data) const
229 return (data->metaObjectOffset == -1 && data->revision == 0) ||
230 (allowedRevisionCache[data->metaObjectOffset] >= data->revision);
233 QDeclarativeEngine *QDeclarativePropertyCache::qmlEngine() const
240 #endif // QDECLARATIVEPROPERTYCACHE_P_H