Qt 4.8
qdeclarativetypeloader_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 QDECLARATIVETYPELOADER_P_H
43 #define QDECLARATIVETYPELOADER_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 <QtCore/qobject.h>
57 #include <QtNetwork/qnetworkreply.h>
58 #include <QtDeclarative/qdeclarativeerror.h>
59 #include <QtDeclarative/qdeclarativeengine.h>
60 #include <private/qdeclarativescriptparser_p.h>
61 #include <private/qdeclarativedirparser_p.h>
62 #include <private/qdeclarativeimport_p.h>
63 
65 
73 
75 {
76 public:
77  enum Status {
78  Null, // Prior to QDeclarativeDataLoader::load()
79  Loading, // Prior to data being received and dataReceived() being called
80  WaitingForDependencies, // While there are outstanding addDependency()s
81  Complete, // Finished
82  Error // Error
83  };
84 
85  enum Type {
88  QmldirFile
89  };
90 
91  QDeclarativeDataBlob(const QUrl &, Type);
92  virtual ~QDeclarativeDataBlob();
93 
94  Type type() const;
95 
96  Status status() const;
97  bool isNull() const;
98  bool isLoading() const;
99  bool isWaiting() const;
100  bool isComplete() const;
101  bool isError() const;
102  bool isCompleteOrError() const;
103 
104  qreal progress() const;
105 
106  QUrl url() const;
107  QUrl finalUrl() const;
108 
109  QList<QDeclarativeError> errors() const;
110 
111  void setError(const QDeclarativeError &);
112  void setError(const QList<QDeclarativeError> &errors);
113 
114  void addDependency(QDeclarativeDataBlob *);
115 
116 protected:
117  virtual void dataReceived(const QByteArray &) = 0;
118 
119  virtual void done();
120  virtual void networkError(QNetworkReply::NetworkError);
121 
122  virtual void dependencyError(QDeclarativeDataBlob *);
123  virtual void dependencyComplete(QDeclarativeDataBlob *);
124  virtual void allDependenciesDone();
125 
126  virtual void downloadProgressChanged(qreal);
127 
128 private:
130  void tryDone();
131  void cancelAllWaitingFor();
132  void notifyAllWaitingOnMe();
133  void notifyComplete(QDeclarativeDataBlob *);
134 
138 
141 
142  // List of QDeclarativeDataBlob's that are waiting for me to complete.
144 
145  // List of QDeclarativeDataBlob's that I am waiting for to complete.
147 
148  // Manager that is currently fetching data for me
151  bool m_inCallback:1;
152  bool m_isDone:1;
153 
155 };
156 
158 {
159  Q_OBJECT
160 public:
163 
164  void load(QDeclarativeDataBlob *);
165  void loadWithStaticData(QDeclarativeDataBlob *, const QByteArray &);
166 
167  QDeclarativeEngine *engine() const;
168 
169 private slots:
170  void networkReplyFinished();
171  void networkReplyProgress(qint64,qint64);
172 
173 private:
174  void setData(QDeclarativeDataBlob *, const QByteArray &);
175  void networkReplyFinished(QNetworkReply *);
176  void networkReplyProgress(QNetworkReply *, qint64, qint64);
177 
180  NetworkReplies m_networkReplies;
181 };
182 
183 
185 {
186  Q_OBJECT
187 public:
190 
191  enum Option {
193  PreserveParser
194  };
195  Q_DECLARE_FLAGS(Options, Option)
196 
197  QDeclarativeTypeData *get(const QUrl &url);
198  QDeclarativeTypeData *get(const QByteArray &, const QUrl &url, Options = None);
199  void clearCache();
200 
201  QDeclarativeScriptData *getScript(const QUrl &);
202  QDeclarativeQmldirData *getQmldir(const QUrl &);
203 
204  QString absoluteFilePath(const QString &path);
205  const QDeclarativeDirParser *qmlDirParser(const QString &absoluteFilePath);
206 
207 private:
214 
215  TypeCache m_typeCache;
216  ScriptCache m_scriptCache;
217  QmldirCache m_qmldirCache;
218  ImportDirCache m_importDirCache;
219  ImportQmlDirCache m_importQmlDirCache;
220 };
221 
222 Q_DECLARE_OPERATORS_FOR_FLAGS(QDeclarativeTypeLoader::Options)
223 
225 {
226 public:
228  {
229  TypeReference() : type(0), majorVersion(0), minorVersion(0), typeData(0) {}
230 
236  };
237 
239  {
241 
245  };
246 
247  QDeclarativeTypeData(const QUrl &, QDeclarativeTypeLoader::Options, QDeclarativeTypeLoader *);
249 
250  QDeclarativeTypeLoader *typeLoader() const;
251 
252  const QDeclarativeImports &imports() const;
253  const QDeclarativeScriptParser &parser() const;
254 
255  const QList<TypeReference> &resolvedTypes() const;
256  const QList<ScriptReference> &resolvedScripts() const;
257 
258  QDeclarativeCompiledData *compiledData() const;
259 
260  // Used by QDeclarativeComponent to get notifications
265  };
266  void registerCallback(TypeDataCallback *);
267  void unregisterCallback(TypeDataCallback *);
268 
269 protected:
270  virtual void done();
271  virtual void dataReceived(const QByteArray &);
272  virtual void allDependenciesDone();
273  virtual void downloadProgressChanged(qreal);
274 
275 private:
276  void resolveTypes();
277  void compile();
278 
279  QDeclarativeTypeLoader::Options m_options;
280 
281  QDeclarativeQmldirData *qmldirForUrl(const QUrl &);
282 
285 
288 
291 
293 
295 
297 };
298 
300 {
301 public:
302  QDeclarativeScriptData(const QUrl &);
303 
304  QDeclarativeParser::Object::ScriptBlock::Pragmas pragmas() const;
305  QString scriptSource() const;
306 
307 protected:
308  virtual void dataReceived(const QByteArray &);
309 
310 private:
311  QDeclarativeParser::Object::ScriptBlock::Pragmas m_pragmas;
313 };
314 
316 {
317 public:
318  QDeclarativeQmldirData(const QUrl &);
319 
320  const QDeclarativeDirComponents &dirComponents() const;
321 
322 protected:
323  virtual void dataReceived(const QByteArray &);
324 
325 private:
327 
328 };
329 
331 
332 #endif // QDECLARATIVETYPELOADER_P_H
The QDeclarativeDataBlob encapsulates a data request that can be issued to a QDeclarativeDataLoader.
QHash< QUrl, QDeclarativeTypeData * > TypeCache
QHash< QUrl, QDeclarativeQmldirData * > QmldirCache
Error
Definition: qaudio.h:58
int type
Definition: qmetatype.cpp:239
double qreal
Definition: qglobal.h:1193
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
Status
This enum describes the status of the data blob.
QDeclarativeDataLoader * m_manager
QList< QDeclarativeError > m_errors
QDeclarativeParser::Object::ScriptBlock::Pragmas m_pragmas
#define Q_DECLARE_FLAGS(Flags, Enum)
The Q_DECLARE_FLAGS() macro expands to.
Definition: qglobal.h:2348
QHash< QString, StringSet * > ImportDirCache
The QNetworkReply class contains the data and headers for a request sent with QNetworkAccessManager.
Definition: qnetworkreply.h:65
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QDeclarativeCompiledData * m_compiledData
NetworkError
Indicates all possible error conditions found during the processing of the request.
Definition: qnetworkreply.h:70
static LibLoadStatus status
Definition: qlocale_icu.cpp:69
QList< TypeDataCallback * > m_callbacks
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
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
QList< QDeclarativeDataBlob * > m_waitingOnMe
The QDeclarativeDataLoader class abstracts loading files and their dependencies over the network...
Option
This enum defines the options that control the way type data is handled.
The QDeclarativeImports class encapsulates one QML document&#39;s import statements.
Type
This enum describes the type of the data blob.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QDeclarativeImports m_imports
#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
The Q_DECLARE_OPERATORS_FOR_FLAGS() macro declares global operator|() functions for Flags...
Definition: qglobal.h:2355
virtual void typeDataReady(QDeclarativeTypeData *)
static bool setData(const QByteArray &data, STGMEDIUM *pmedium)
Definition: qmime_win.cpp:141
virtual void typeDataProgress(QDeclarativeTypeData *, qreal)
QList< QDeclarativeDataBlob * > m_waitingFor
The QDeclarativeError class encapsulates a QML error.
__int64 qint64
Definition: qglobal.h:942
QDeclarativeDirComponents m_components
QHash< QUrl, QDeclarativeScriptData * > ScriptCache
Q_CORE_EXPORT int QT_FASTCALL script(uint ucs4)
#define Q_OBJECT
Definition: qobjectdefs.h:157
#define None
#define load(x)
QDeclarativeTypeLoader::Options m_options
The QDeclarativeEngine class provides an environment for instantiating QML components.
QHash< QString, QDeclarativeDirParser * > ImportQmlDirCache
QHash< QNetworkReply *, QDeclarativeDataBlob * > NetworkReplies
#define Q_AUTOTEST_EXPORT
Definition: qglobal.h:1510
QDeclarativeScriptParser scriptParser
QList< QDeclarativeQmldirData * > m_qmldirs
QList< TypeReference > m_types
QDeclarativeTypeLoader * m_typeLoader
#define slots
Definition: qobjectdefs.h:68
#define class
QList< ScriptReference > m_scripts
ImportQmlDirCache m_importQmlDirCache
static bool isNull(const QVariant::Private *d)
Definition: qvariant.cpp:300