Qt 4.8
qdeclarativepropertycache_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
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>
64 
65 class QDeclarativeEngine;
66 class QMetaProperty;
67 
69 {
70 public:
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  };
103 
104  bool isValid() const { return coreIndex != -1; }
105 
107  int propType;
109  union {
110  int notifyIndex; // When !IsFunction
111  int relatedIndex; // When IsFunction
112  };
114  signed int overrideIndex : 31;
115  int revision;
117 
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 *);
123  };
124 
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
131  };
132 
133  void update(QDeclarativeEngine *, const QMetaObject *);
134 
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);
140 
141  static Data create(const QMetaObject *, const QString &);
142 
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;
148 
149  inline Data *overrideData(Data *) const;
150  inline bool isAllowedInRevision(Data *) const;
151 
152  inline QDeclarativeEngine *qmlEngine() const;
154  static Data *property(QDeclarativeEngine *, QObject *, const QString &, Data &);
155 
156 protected:
157  virtual void clear();
158 
159 private:
161 
162  struct RData : public Data, public QDeclarativeRefCount {
164  };
165 
170 
171  void updateRecur(QDeclarativeEngine *, const QMetaObject *);
172 
174  IndexCache indexCache;
175  IndexCache methodIndexCache;
176  StringCache stringCache;
177  IdentifierCache identifierCache;
178  AllowedRevisionCache allowedRevisionCache;
179 };
181 
183 : flags(0), propType(0), coreIndex(-1), notifyIndex(-1), overrideIndexIsProperty(false), overrideIndex(-1),
184  revision(0), metaObjectOffset(-1)
185 {
186 }
187 
189 {
190  return flags == other.flags &&
191  propType == other.propType &&
192  coreIndex == other.coreIndex &&
193  notifyIndex == other.notifyIndex &&
194  revision == other.revision;
195 }
196 
199 {
200  if (data->overrideIndex < 0)
201  return 0;
202 
203  if (data->overrideIndexIsProperty)
204  return indexCache.at(data->overrideIndex);
205  else
206  return methodIndexCache.at(data->overrideIndex);
207 }
208 
211 {
212  return identifierCache.value(id);
213 }
214 
216 : flags(QDeclarativePropertyCache::Data::NoFlags), valueTypeCoreIdx(-1), valueTypePropType(0)
217 {
218 }
219 
221 {
222  return flags == o.flags &&
225 }
226 
228 {
229  return (data->metaObjectOffset == -1 && data->revision == 0) ||
231 }
232 
234 {
235  return engine;
236 }
237 
239 
240 #endif // QDECLARATIVEPROPERTYCACHE_P_H
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
#define Q_DECLARE_FLAGS(Flags, Enum)
The Q_DECLARE_FLAGS() macro expands to.
Definition: qglobal.h:2348
static Expression::Ptr create(Expression *const expr, const YYLTYPE &sourceLocator, const ParserContext *const parseInfo)
static void clear(QVariant::Private *d)
Definition: qvariant.cpp:197
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
QHash< QScriptDeclarativeClass::Identifier, RData * > IdentifierCache
QHash< QString, RData * > StringCache
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
const char * name
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
Data * property(const QScriptDeclarativeClass::Identifier &id) const
static const char * data(const QByteArray &arr)
unsigned int uint
Definition: qglobal.h:996
Q_DECLARE_OPERATORS_FOR_FLAGS(QDeclarativePropertyCache::Data::Flags)
QDeclarativeEngine * qmlEngine() const
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
Q_DECLARATIVE_EXPORT QDeclarativeEngine * qmlEngine(const QObject *)
#define load(x)
The QDeclarativeEngine class provides an environment for instantiating QML components.
const char * property
Definition: qwizard.cpp:138
#define Q_AUTOTEST_EXPORT
Definition: qglobal.h:1510
The QDeclarativeCleanup provides a callback when a QDeclarativeEngine is deleted. ...
The QMetaProperty class provides meta-data about a property.
Definition: qmetaobject.h:176
QScriptDeclarativeClass::PersistentIdentifier identifier
Flags
bool operator==(QBool b1, bool b2)
Definition: qglobal.h:2023
The QMetaMethod class provides meta-data about a member function.
Definition: qmetaobject.h:56