Qt 4.8
qdeclarativeengine_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 QDECLARATIVEENGINE_P_H
43 #define QDECLARATIVEENGINE_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 "qdeclarativeengine.h"
57 
58 #include "private/qdeclarativetypeloader_p.h"
59 #include "private/qdeclarativeimport_p.h"
60 #include "private/qpodvector_p.h"
61 #include "qdeclarative.h"
62 #include "private/qdeclarativevaluetype_p.h"
63 #include "qdeclarativecontext.h"
64 #include "private/qdeclarativecontext_p.h"
65 #include "qdeclarativeexpression.h"
67 #include "private/qdeclarativeproperty_p.h"
68 #include "private/qdeclarativepropertycache_p.h"
69 #include "private/qdeclarativeobjectscriptclass_p.h"
70 #include "private/qdeclarativecontextscriptclass_p.h"
71 #include "private/qdeclarativevaluetypescriptclass_p.h"
72 #include "private/qdeclarativemetatype_p.h"
73 #include "private/qdeclarativedirparser_p.h"
74 
75 #include <QtScript/QScriptClass>
76 #include <QtScript/QScriptValue>
77 #include <QtScript/QScriptString>
78 #include <QtCore/qstring.h>
79 #include <QtCore/qlist.h>
80 #include <QtCore/qpair.h>
81 #include <QtCore/qstack.h>
82 #include <QtCore/qmutex.h>
83 #include <QtScript/qscriptengine.h>
84 
85 #include <private/qobject_p.h>
86 
88 
90 class QDeclarativeEngine;
98 class QNetworkReply;
107 class QDeclarativeCleanup;
111 class QDir;
112 
114 {
115 public:
117  virtual ~QDeclarativeScriptEngine();
118 
119  QUrl resolvedUrl(QScriptContext *context, const QUrl& url); // resolved against p's context, or baseUrl if no p
120  static QScriptValue resolvedUrl(QScriptContext *ctxt, QScriptEngine *engine);
121 
122  static QDeclarativeScriptEngine *get(QScriptEngine* e) { return static_cast<QDeclarativeScriptEngine*>(e); }
123 
125 
126  // User by SQL API
129 
130  // Used by DOM Core 3 API
133 
135 
137 };
138 
140 {
142 public:
145 
146  void init();
147 
149  CapturedProperty(QObject *o, int c, int n)
150  : object(o), coreIndex(c), notifier(0), notifyIndex(n) {}
152  : object(0), coreIndex(-1), notifier(n), notifyIndex(-1) {}
153 
158  };
161 
164 
166 
174  // Global script class
176 
177  // Registered cleanup handlers
179 
180  // Bindings that have had errors during startup
183 
185 
186  QDeclarativeWorkerScriptEngine *getWorkerScriptEngine();
188 
190 
191  template<class T>
192  struct SimpleList {
194  : count(0), values(0) {}
195  SimpleList(int r)
196  : count(0), values(new T*[r]) {}
197 
198  int count;
199  T **values;
200 
201  void append(T *v) {
202  values[count++] = v;
203  }
204 
205  T *at(int idx) const {
206  return values[idx];
207  }
208 
209  void clear() {
210  delete [] values;
211  }
212  };
213 
216 
221 
223  finalizedParserStatus.append(qMakePair(QDeclarativeGuard<QObject>(obj), index));
224  }
225 
227 
228  QNetworkAccessManager *createNetworkAccessManager(QObject *parent) const;
229  QNetworkAccessManager *getNetworkAccessManager() const;
232 
234  QDeclarativeImageProvider::ImageType getImageProviderType(const QUrl &url);
235  QImage getImageFromProvider(const QUrl &url, QSize *size, const QSize& req_size);
236  QPixmap getPixmapFromProvider(const QUrl &url, QSize *size, const QSize& req_size);
237 
238  mutable QMutex mutex;
239 
242 
244 
245  mutable quint32 uniqueId;
247  return uniqueId++;
248  }
249 
251 
254  inline QDeclarativePropertyCache *cache(QObject *obj);
255  inline QDeclarativePropertyCache *cache(const QMetaObject *);
257  QDeclarativePropertyCache *createCache(const QMetaObject *);
259 
260  void registerCompositeType(QDeclarativeCompiledData *);
261 
262  bool isQObject(int);
263  QObject *toQObject(const QVariant &, bool *ok = 0) const;
264  QDeclarativeMetaType::TypeCategory typeCategory(int) const;
265  bool isList(int) const;
266  int listType(int) const;
267  const QMetaObject *rawMetaObjectForType(int) const;
268  const QMetaObject *metaObjectForType(int) const;
271 
273 
274  QScriptValue scriptValueFromVariant(const QVariant &);
275  QVariant scriptValueToVariant(const QScriptValue &, int hint = QVariant::Invalid);
276 
277  void sendQuit();
278  void warning(const QDeclarativeError &);
279  void warning(const QList<QDeclarativeError> &);
280  static void warning(QDeclarativeEngine *, const QDeclarativeError &);
281  static void warning(QDeclarativeEngine *, const QList<QDeclarativeError> &);
282  static void warning(QDeclarativeEnginePrivate *, const QDeclarativeError &);
283  static void warning(QDeclarativeEnginePrivate *, const QList<QDeclarativeError> &);
284 
285  static QScriptValue qmlScriptObject(QObject*, QDeclarativeEngine*);
286 
287  static QScriptValue createComponent(QScriptContext*, QScriptEngine*);
288  static QScriptValue createQmlObject(QScriptContext*, QScriptEngine*);
289  static QScriptValue isQtObject(QScriptContext*, QScriptEngine*);
290  static QScriptValue vector3d(QScriptContext*, QScriptEngine*);
291  static QScriptValue rgba(QScriptContext*, QScriptEngine*);
292  static QScriptValue hsla(QScriptContext*, QScriptEngine*);
293  static QScriptValue point(QScriptContext*, QScriptEngine*);
294  static QScriptValue size(QScriptContext*, QScriptEngine*);
295  static QScriptValue rect(QScriptContext*, QScriptEngine*);
296 
297  static QScriptValue lighter(QScriptContext*, QScriptEngine*);
298  static QScriptValue darker(QScriptContext*, QScriptEngine*);
299  static QScriptValue tint(QScriptContext*, QScriptEngine*);
300 
301  static QScriptValue desktopOpenUrl(QScriptContext*, QScriptEngine*);
302  static QScriptValue fontFamilies(QScriptContext*, QScriptEngine*);
304  static QScriptValue btoa(QScriptContext*, QScriptEngine*);
305  static QScriptValue atob(QScriptContext*, QScriptEngine*);
306  static QScriptValue consoleLog(QScriptContext*, QScriptEngine*);
307  static QScriptValue quit(QScriptContext*, QScriptEngine*);
308 
309 #ifndef QT_NO_DATESTRING
310  static QScriptValue formatDate(QScriptContext*, QScriptEngine*);
311  static QScriptValue formatTime(QScriptContext*, QScriptEngine*);
312  static QScriptValue formatDateTime(QScriptContext*, QScriptEngine*);
313 #endif
314  static QScriptEngine *getScriptEngine(QDeclarativeEngine *e) { if (!e) return 0; return &e->d_func()->scriptEngine; }
315  static QDeclarativeEngine *getEngine(QScriptEngine *e) { return static_cast<QDeclarativeScriptEngine*>(e)->p->q_func(); }
316  static QDeclarativeEnginePrivate *get(QDeclarativeEngine *e) { return e->d_func(); }
317  static QDeclarativeEnginePrivate *get(QDeclarativeContext *c) { return (c && c->engine()) ? QDeclarativeEnginePrivate::get(c->engine()) : 0; }
318  static QDeclarativeEnginePrivate *get(QDeclarativeContextData *c) { return (c && c->engine) ? QDeclarativeEnginePrivate::get(c->engine) : 0; }
319  static QDeclarativeEnginePrivate *get(QScriptEngine *e) { return static_cast<QDeclarativeScriptEngine*>(e)->p; }
320  static QDeclarativeEngine *get(QDeclarativeEnginePrivate *p) { return p->q_func(); }
322  QUrl getUrl(QScriptContext *);
323 
324  static QString urlToLocalFileOrQrc(const QUrl& url);
325 
326  static void defineModule();
327  static void defineModuleCompat();
328 
330 };
331 
341 {
342  if (!obj || QObjectPrivate::get(obj)->metaObject || QObjectPrivate::get(obj)->wasDeleted)
343  return 0;
344 
345  const QMetaObject *mo = obj->metaObject();
346  QDeclarativePropertyCache *rv = propertyCache.value(mo);
347  if (!rv) rv = createCache(mo);
348  return rv;
349 }
350 
361 {
362  Q_ASSERT(metaObject);
363 
364  QDeclarativePropertyCache *rv = propertyCache.value(metaObject);
365  if (!rv) rv = createCache(metaObject);
366  return rv;
367 }
368 
375 {
376  Q_ASSERT(type);
377 
378  if (minorVersion == -1 || !type->containsRevisionedAttributes())
379  return cache(type->metaObject());
380 
381  QDeclarativePropertyCache *rv = typePropertyCache.value(qMakePair(type, minorVersion));
382  if (!rv) rv = createCache(type, minorVersion, error);
383  return rv;
384 }
385 
387 
388 #endif // QDECLARATIVEENGINE_P_H
ImageType
Defines the type of image supported by this image provider.
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
The QDir class provides access to directory structures and their contents.
Definition: qdir.h:58
static QScriptEngine * getScriptEngine(QDeclarativeEngine *e)
The QScriptContext class represents a Qt Script function invocation.
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
QDeclarativeCleanup * cleanup
QDeclarativeTypeNameScriptClass * typeNameClass
QHash< QString, QScriptValue > m_sharedScriptImports
virtual QNetworkAccessManager * networkAccessManager()
QDeclarativeNetworkAccessManagerFactory * networkAccessManagerFactory
int type
Definition: qmetatype.cpp:239
unsigned char c[8]
Definition: qnumeric_p.h:62
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
The QMutex class provides access serialization between threads.
Definition: qmutex.h:60
The QScriptClass class provides an interface for defining custom behavior of (a class of) Qt Script o...
Definition: qscriptclass.h:43
QList< QPair< QDeclarativeGuard< QObject >, int > > finalizedParserStatus
#define error(msg)
static QDeclarativeEngine * getEngine(QScriptEngine *e)
The QNetworkReply class contains the data and headers for a request sent with QNetworkAccessManager.
Definition: qnetworkreply.h:65
QDeclarativePropertyCache * cache(QObject *obj)
Returns a QDeclarativePropertyCache for obj if one is available.
QDeclarativeGlobalScriptClass * globalClass
static void clear(QVariant::Private *d)
Definition: qvariant.cpp:197
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
QDeclarativeTypeLoader typeLoader
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
static QDeclarativeEnginePrivate * get(QDeclarativeEngine *e)
static QObjectPrivate * get(QObject *o)
Definition: qobject_p.h:177
bool containsRevisionedAttributes() const
QDeclarativeContext * rootContext
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
The QScriptEngine class provides an environment for evaluating Qt Script code.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QDeclarativeScriptEngine scriptEngine
static bool init
QDeclarativeWorkerScriptEngine * workerScriptEngine
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
QDeclarativeScriptEngine(QDeclarativeEnginePrivate *priv)
The QDeclarativeError class encapsulates a QML error.
void registerFinalizedParserStatusObject(QObject *obj, int index)
QHash< QPair< QDeclarativeType *, int >, QDeclarativePropertyCache * > typePropertyCache
QDeclarativeImportDatabase importDatabase
QDeclarativeValueTypeScriptClass * valueTypeClass
QHash< int, QDeclarativeCompiledData * > m_compositeTypes
quint16 values[128]
The QNetworkAccessManager class allows the application to send network requests and receive replies...
QList< SimpleList< QDeclarativeAbstractBinding > > bindValues
QDeclarativeContextData * sharedContext
QUrl resolvedUrl(QScriptContext *context, const QUrl &url)
QDeclarativeObjectScriptClass * objectClass
const QMetaObject * metaObject() const
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
The QDeclarativeNetworkAccessManagerFactory class creates QNetworkAccessManager instances for a QML e...
static HIMC getContext(HWND wnd)
The QDeclarativeEngine class provides an environment for instantiating QML components.
QDeclarativeListScriptClass * listClass
QDeclarativeValueTypeFactory valueTypes
QDeclarativeDelayedError * erroredBindings
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
Q_OUTOFLINE_TEMPLATE QPair< T1, T2 > qMakePair(const T1 &x, const T2 &y)
Definition: qpair.h:102
unsigned int quint32
Definition: qglobal.h:938
static const QMetaObjectPrivate * priv(const uint *data)
#define Q_AUTOTEST_EXPORT
Definition: qglobal.h:1510
QDeclarativeComponentAttached * componentAttached
The QDeclarativeContext class defines a context within a QML engine.
quint16 index
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
The QDeclarativeCleanup provides a callback when a QDeclarativeEngine is deleted. ...
QDeclarativeEnginePrivate * p
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
The QDeclarativeExpression class evaluates JavaScript in a QML context.
QHash< const QMetaObject *, QDeclarativePropertyCache * > propertyCache
QHash< QString, QSharedPointer< QDeclarativeImageProvider > > imageProviders
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
QPODVector< CapturedProperty, 16 > capturedProperties
QNetworkAccessManager * networkAccessManager
QList< SimpleList< QDeclarativeParserStatus > > parserStatus
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
The QDeclarativeImportDatabase class manages the QML imports for a QDeclarativeEngine.
QDeclarativeContextScriptClass * contextClass