Qt 4.8
qdeclarativetypeloader.cpp
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 
43 
44 #include <private/qdeclarativeengine_p.h>
45 #include <private/qdeclarativecompiler_p.h>
46 #include <private/qdeclarativecomponent_p.h>
47 #include <private/qdeclarativeglobal_p.h>
48 #include <private/qdeclarativedebugtrace_p.h>
49 
50 #include <QtDeclarative/qdeclarativecomponent.h>
51 #include <QtCore/qdebug.h>
52 #include <QtCore/qdir.h>
53 #include <QtCore/qdiriterator.h>
54 #include <QtCore/qfile.h>
55 
57 
58 /*
59 Returns the set of QML files in path (qmldir, *.qml, *.js). The caller
60 is responsible for deleting the returned data.
61 */
63 {
65  if (!dir.hasNext())
66  return 0;
67  QSet<QString> *files = new QSet<QString>;
68  while (dir.hasNext()) {
69  dir.next();
70  QString fileName = dir.fileName();
71  if (fileName == QLatin1String("qmldir")
72  || fileName.endsWith(QLatin1String(".qml"))
73  || fileName.endsWith(QLatin1String(".js"))) {
74 #if defined(Q_OS_WIN32) || defined(Q_OS_WINCE) || defined(Q_OS_DARWIN) || defined(Q_OS_SYMBIAN)
75  fileName = fileName.toLower();
76 #endif
77  files->insert(fileName);
78  }
79  }
80  return files;
81 }
82 
83 
135 : m_type(type), m_status(Null), m_progress(0), m_url(url), m_finalUrl(url), m_manager(0),
136  m_redirectCount(0), m_inCallback(false), m_isDone(false)
137 {
138 }
139 
142 {
144 
146 }
147 
152 {
153  return m_type;
154 }
155 
160 {
161  return m_status;
162 }
163 
168 {
169  return m_status == Null;
170 }
171 
176 {
177  return m_status == Loading;
178 }
179 
184 {
186 }
187 
192 {
193  return m_status == Complete;
194 }
195 
200 {
201  return m_status == Error;
202 }
203 
208 {
209  return isComplete() || isError();
210 }
211 
216 {
217  return m_progress;
218 }
219 
227 {
228  return m_url;
229 }
230 
237 {
238  return m_finalUrl;
239 }
240 
245 {
246  return m_errors;
247 }
248 
257 {
259  l << errors;
260  setError(l);
261 }
262 
267 {
268  m_status = Error;
269  m_errors = errors;
270 
272 
273  if (!m_inCallback)
274  tryDone();
275 }
276 
282 {
283  Q_ASSERT(status() != Null);
284 
285  if (!blob ||
286  blob->status() == Error || blob->status() == Complete ||
287  status() == Error || status() == Complete ||
288  m_waitingFor.contains(blob))
289  return;
290 
291  blob->addref();
293  m_waitingFor.append(blob);
294  blob->m_waitingOnMe.append(this);
295 }
296 
315 {
316 }
317 
324 {
325  Q_UNUSED(networkError);
326 
328  error.setUrl(m_finalUrl);
329 
330  const char *errorString = 0;
331  switch (networkError) {
332  default:
333  errorString = "Network error";
334  break;
336  errorString = "Connection refused";
337  break;
339  errorString = "Remote host closed the connection";
340  break;
342  errorString = "Host not found";
343  break;
345  errorString = "Timeout";
346  break;
353  errorString = "Proxy error";
354  break;
356  errorString = "Access denied";
357  break;
359  errorString = "File not found";
360  break;
362  errorString = "Authentication required";
363  break;
364  };
365 
366  error.setDescription(QLatin1String(errorString));
367 
368  setError(error);
369 }
370 
377 {
378  Q_UNUSED(blob);
379 }
380 
387 {
388  Q_UNUSED(blob);
389 }
390 
398 {
399 }
400 
406 {
407  Q_UNUSED(progress);
408 }
409 
411 {
412  if (status() != Loading && m_waitingFor.isEmpty() && !m_isDone) {
413  if (status() != Error)
414  m_status = Complete;
415 
416  m_isDone = true;
417  done();
419  }
420 }
421 
423 {
424  while (m_waitingFor.count()) {
426 
427  Q_ASSERT(blob->m_waitingOnMe.contains(this));
428 
429  blob->m_waitingOnMe.removeOne(this);
430 
431  blob->release();
432  }
433 }
434 
436 {
437  while (m_waitingOnMe.count()) {
439 
440  Q_ASSERT(blob->m_waitingFor.contains(this));
441 
442  blob->notifyComplete(this);
443  }
444 }
445 
447 {
449  Q_ASSERT(blob->status() == Error || blob->status() == Complete);
450 
451  m_inCallback = true;
452 
453  if (blob->status() == Error) {
454  dependencyError(blob);
455  } else if (blob->status() == Complete) {
456  dependencyComplete(blob);
457  }
458 
459  m_waitingFor.removeOne(blob);
460  blob->release();
461 
462  if (!isError() && m_waitingFor.isEmpty())
464 
465  m_inCallback = false;
466 
467  tryDone();
468 }
469 
507 : m_engine(engine)
508 {
509 }
510 
513 {
514  for (NetworkReplies::Iterator iter = m_networkReplies.begin(); iter != m_networkReplies.end(); ++iter)
515  (*iter)->release();
516 }
517 
522 {
524  Q_ASSERT(blob->m_manager == 0);
525 
527 
528  if (blob->m_url.isEmpty()) {
530  error.setDescription(QLatin1String("Invalid null URL"));
531  blob->setError(error);
532  return;
533  }
534 
536 
537  if (!lf.isEmpty()) {
540  error.setUrl(blob->m_url);
541  error.setDescription(QLatin1String("File name case mismatch"));
542  blob->setError(error);
543  return;
544  }
545  QFile file(lf);
546  if (file.open(QFile::ReadOnly)) {
547  QByteArray data = file.readAll();
548 
549  blob->m_progress = 1.;
550  blob->downloadProgressChanged(1.);
551 
552  setData(blob, data);
553  } else {
555  }
556 
557  } else {
558 
559  blob->m_manager = this;
561 
562  m_networkReplies.insert(reply, blob);
563  blob->addref();
564 
565  if (reply->isFinished()) {
566  // Short-circuit synchronous replies.
567  qint64 size = reply->size();
568  networkReplyProgress(reply, size, size);
569  networkReplyFinished(reply);
570  } else {
571  QObject::connect(reply, SIGNAL(downloadProgress(qint64,qint64)),
573  QObject::connect(reply, SIGNAL(finished()),
574  this, SLOT(networkReplyFinished()));
575  }
576  }
577 }
578 
579 #define DATALOADER_MAXIMUM_REDIRECT_RECURSION 16
580 
582 {
583  reply->deleteLater();
584 
586 
587  Q_ASSERT(blob);
588 
589  blob->m_redirectCount++;
590 
593  if (redirect.isValid()) {
594  QUrl url = reply->url().resolved(redirect.toUrl());
595  blob->m_finalUrl = url;
596 
598  QObject::connect(reply, SIGNAL(finished()), this, SLOT(networkReplyFinished()));
599  m_networkReplies.insert(reply, blob);
600  return;
601  }
602  }
603 
604  if (reply->error()) {
605  blob->networkError(reply->error());
606  } else {
607  QByteArray data = reply->readAll();
608  setData(blob, data);
609  }
610 
611  blob->release();
612 }
613 
615 {
616  QNetworkReply *reply = static_cast<QNetworkReply *>(sender());
617  networkReplyFinished(reply);
618 }
619 
621 {
623 
624  Q_ASSERT(blob);
625 
626  if (bytesTotal != 0) {
627  blob->m_progress = bytesReceived / bytesTotal;
628  blob->downloadProgressChanged(blob->m_progress);
629  }
630 }
631 
633 {
634  QNetworkReply *reply = static_cast<QNetworkReply *>(sender());
635  networkReplyProgress(reply, bytesReceived, bytesTotal);
636 }
637 
642 {
644  Q_ASSERT(blob->m_manager == 0);
645 
647 
648  setData(blob, data);
649 }
650 
655 {
656  return m_engine;
657 }
658 
660 {
661  blob->m_inCallback = true;
662 
663  blob->dataReceived(data);
664 
665  if (!blob->isError() && !blob->isWaiting())
666  blob->allDependenciesDone();
667 
668  if (blob->status() != QDeclarativeDataBlob::Error)
670 
671  blob->m_inCallback = false;
672 
673  blob->tryDone();
674 }
675 
680 : QDeclarativeDataLoader(engine)
681 {
682 }
683 
689 {
690  clearCache();
691 }
692 
708 {
709  Q_ASSERT(!url.isRelative() &&
712 
713  QDeclarativeTypeData *typeData = m_typeCache.value(url);
714 
715  if (!typeData) {
716  typeData = new QDeclarativeTypeData(url, None, this);
717  m_typeCache.insert(url, typeData);
719  }
720 
721  typeData->addref();
722  return typeData;
723 }
724 
732 {
733  QDeclarativeTypeData *typeData = new QDeclarativeTypeData(url, options, this);
735  return typeData;
736 }
737 
742 {
743  Q_ASSERT(!url.isRelative() &&
746 
747  QDeclarativeScriptData *scriptData = m_scriptCache.value(url);
748 
749  if (!scriptData) {
750  scriptData = new QDeclarativeScriptData(url);
751  m_scriptCache.insert(url, scriptData);
752  QDeclarativeDataLoader::load(scriptData);
753  }
754 
755  scriptData->addref();
756  return scriptData;
757 }
758 
763 {
764  Q_ASSERT(!url.isRelative() &&
767 
768  QDeclarativeQmldirData *qmldirData = m_qmldirCache.value(url);
769 
770  if (!qmldirData) {
771  qmldirData = new QDeclarativeQmldirData(url);
772  m_qmldirCache.insert(url, qmldirData);
773  QDeclarativeDataLoader::load(qmldirData);
774  }
775 
776  qmldirData->addref();
777  return qmldirData;
778 }
779 
786 {
787  if (path.isEmpty())
788  return QString();
789  if (path.at(0) == QLatin1Char(':')) {
790  // qrc resource
791  QFileInfo fileInfo(path);
792  return fileInfo.isFile() ? fileInfo.absoluteFilePath() : QString();
793  }
794 #if defined(Q_OS_WIN32) || defined(Q_OS_WINCE) || defined(Q_OS_DARWIN) || defined(Q_OS_SYMBIAN)
795  QString lowPath(path.toLower());
796 #else
797  QString lowPath(path);
798 #endif
799  int lastSlash = lowPath.lastIndexOf(QLatin1Char('/'));
800  QString dirPath = lowPath.left(lastSlash);
801 
802  StringSet *fileSet = 0;
804  if (it == m_importDirCache.end()) {
805  StringSet *files = qmlFilesInDirectory(path.left(lastSlash));
806  m_importDirCache.insert(dirPath, files);
807  fileSet = files;
808  } else {
809  fileSet = *it;
810  }
811  if (!fileSet)
812  return QString();
813 
814  QString absoluteFilePath = fileSet->contains(QString(lowPath.constData()+lastSlash+1, lowPath.length()-lastSlash-1)) ? path : QString();
815  if (absoluteFilePath.length() > 2 && absoluteFilePath.at(0) != QLatin1Char('/') && absoluteFilePath.at(1) != QLatin1Char(':'))
816  absoluteFilePath = QFileInfo(absoluteFilePath).absoluteFilePath();
817 
818  return absoluteFilePath;
819 }
820 
825 {
826  QDeclarativeDirParser *qmldirParser;
828  if (it == m_importQmlDirCache.end()) {
829  qmldirParser = new QDeclarativeDirParser;
830  qmldirParser->setFileSource(absoluteFilePath);
831  qmldirParser->setUrl(QUrl::fromLocalFile(absoluteFilePath));
832  qmldirParser->parse();
833  m_importQmlDirCache.insert(absoluteFilePath, qmldirParser);
834  } else {
835  qmldirParser = *it;
836  }
837 
838  return qmldirParser;
839 }
840 
841 /*
842 Clears cached information about loaded files, including any type data, scripts
843 and qmldir information.
844 */
846 {
847  for (TypeCache::Iterator iter = m_typeCache.begin(); iter != m_typeCache.end(); ++iter)
848  (*iter)->release();
849  for (ScriptCache::Iterator iter = m_scriptCache.begin(); iter != m_scriptCache.end(); ++iter)
850  (*iter)->release();
851  for (QmldirCache::Iterator iter = m_qmldirCache.begin(); iter != m_qmldirCache.end(); ++iter)
852  (*iter)->release();
855 
856  m_typeCache.clear();
861 }
862 
863 
864 QDeclarativeTypeData::QDeclarativeTypeData(const QUrl &url, QDeclarativeTypeLoader::Options options,
865  QDeclarativeTypeLoader *manager)
866 : QDeclarativeDataBlob(url, QmlFile), m_options(options), m_imports(manager), m_typesResolved(false),
867  m_compiledData(0), m_typeLoader(manager)
868 {
869 }
870 
872 {
873  for (int ii = 0; ii < m_scripts.count(); ++ii)
874  m_scripts.at(ii).script->release();
875  for (int ii = 0; ii < m_qmldirs.count(); ++ii)
876  m_qmldirs.at(ii)->release();
877  for (int ii = 0; ii < m_types.count(); ++ii)
878  if (m_types.at(ii).typeData) m_types.at(ii).typeData->release();
879  if (m_compiledData)
881 }
882 
884 {
885  return m_typeLoader;
886 }
887 
889 {
890  return m_imports;
891 }
892 
894 {
895  return scriptParser;
896 }
897 
899 {
900  return m_types;
901 }
902 
904 {
905  return m_scripts;
906 }
907 
909 {
910  if (m_compiledData)
912 
913  return m_compiledData;
914 }
915 
917 {
918  Q_ASSERT(!m_callbacks.contains(callback));
919  m_callbacks.append(callback);
920 }
921 
923 {
924  Q_ASSERT(m_callbacks.contains(callback));
925  m_callbacks.removeOne(callback);
926  Q_ASSERT(!m_callbacks.contains(callback));
927 }
928 
930 {
931  addref();
932 
933  // Check all script dependencies for errors
934  for (int ii = 0; !isError() && ii < m_scripts.count(); ++ii) {
935  const ScriptReference &script = m_scripts.at(ii);
936  Q_ASSERT(script.script->isCompleteOrError());
937  if (script.script->isError()) {
940  error.setUrl(finalUrl());
941  error.setLine(script.location.line);
942  error.setColumn(script.location.column);
943  error.setDescription(QDeclarativeTypeLoader::tr("Script %1 unavailable").arg(script.script->url().toString()));
944  errors.prepend(error);
945  setError(errors);
946  }
947  }
948 
949  // Check all type dependencies for errors
950  for (int ii = 0; !isError() && ii < m_types.count(); ++ii) {
951  const TypeReference &type = m_types.at(ii);
952  Q_ASSERT(!type.typeData || type.typeData->isCompleteOrError());
953  if (type.typeData && type.typeData->isError()) {
954  QString typeName = scriptParser.referencedTypes().at(ii)->name;
955 
958  error.setUrl(finalUrl());
959  error.setLine(type.location.line);
960  error.setColumn(type.location.column);
961  error.setDescription(QDeclarativeTypeLoader::tr("Type %1 unavailable").arg(typeName));
962  errors.prepend(error);
963  setError(errors);
964  }
965  }
966 
967  // Compile component
968  if (!isError())
969  compile();
970 
973 
974  // Notify callbacks
975  while (!m_callbacks.isEmpty()) {
976  TypeDataCallback *callback = m_callbacks.takeFirst();
977  callback->typeDataReady(this);
978  }
979 
980  release();
981 }
982 
984 {
985  if (!scriptParser.parse(data, finalUrl())) {
987  return;
988  }
989 
991 
992  foreach (const QDeclarativeScriptParser::Import &import, scriptParser.imports()) {
993  if (import.type == QDeclarativeScriptParser::Import::File && import.qualifier.isEmpty()) {
994  QUrl importUrl = finalUrl().resolved(QUrl(import.uri + QLatin1String("/qmldir")));
996  QDeclarativeQmldirData *data = typeLoader()->getQmldir(importUrl);
997  addDependency(data);
998  m_qmldirs << data;
999  }
1000  } else if (import.type == QDeclarativeScriptParser::Import::Script) {
1001  QUrl scriptUrl = finalUrl().resolved(QUrl(import.uri));
1002  QDeclarativeScriptData *data = typeLoader()->getScript(scriptUrl);
1003  addDependency(data);
1004 
1005  ScriptReference ref;
1006  ref.location = import.location.start;
1007  ref.qualifier = import.qualifier;
1008  ref.script = data;
1009  m_scripts << ref;
1010 
1011  }
1012  }
1013 
1014  if (!finalUrl().scheme().isEmpty()) {
1015  QUrl importUrl = finalUrl().resolved(QUrl(QLatin1String("qmldir")));
1017  QDeclarativeQmldirData *data = typeLoader()->getQmldir(importUrl);
1018  addDependency(data);
1019  m_qmldirs << data;
1020  }
1021  }
1022 }
1023 
1025 {
1026  if (!m_typesResolved) {
1027  resolveTypes();
1028  m_typesResolved = true;
1029  }
1030 }
1031 
1033 {
1034  for (int ii = 0; ii < m_callbacks.count(); ++ii) {
1036  callback->typeDataProgress(this, p);
1037  }
1038 }
1039 
1041 {
1042  Q_ASSERT(m_compiledData == 0);
1044 
1049 
1050  QDeclarativeCompiler compiler;
1051  if (!compiler.compile(typeLoader()->engine(), this, m_compiledData)) {
1052  setError(compiler.errors());
1054  m_compiledData = 0;
1055  }
1057 }
1058 
1060 {
1062  QDeclarativeImportDatabase *importDatabase = &ep->importDatabase;
1063 
1064  foreach (const QDeclarativeScriptParser::Import &import, scriptParser.imports()) {
1065  QDeclarativeDirComponents qmldircomponentsnetwork;
1067  continue;
1068 
1069  if (import.type == QDeclarativeScriptParser::Import::File && import.qualifier.isEmpty()) {
1070  QUrl qmldirUrl = finalUrl().resolved(QUrl(import.uri + QLatin1String("/qmldir")));
1071  if (QDeclarativeQmldirData *qmldir = qmldirForUrl(qmldirUrl))
1072  qmldircomponentsnetwork = qmldir->dirComponents();
1073  }
1074 
1075  int vmaj = -1;
1076  int vmin = -1;
1077 
1078  if (!import.version.isEmpty()) {
1079  int dot = import.version.indexOf(QLatin1Char('.'));
1080  if (dot < 0) {
1081  vmaj = import.version.toInt();
1082  vmin = 0;
1083  } else {
1084  vmaj = import.version.left(dot).toInt();
1085  vmin = import.version.mid(dot+1).toInt();
1086  }
1087  }
1088 
1090  if (!m_imports.addImport(importDatabase, import.uri, import.qualifier,
1091  vmaj, vmin, import.type, qmldircomponentsnetwork, &errorString)) {
1093  error.setUrl(m_imports.baseUrl());
1094  error.setDescription(errorString);
1095  error.setLine(import.location.start.line);
1096  error.setColumn(import.location.start.column);
1097 
1098  setError(error);
1099  return;
1100  }
1101  }
1102 
1103  bool implicitImportLoaded = false;
1105  QByteArray typeName = parserRef->name.toUtf8();
1106 
1107  TypeReference ref;
1108 
1109  QUrl url;
1110  int majorVersion;
1111  int minorVersion;
1112  QDeclarativeImportedNamespace *typeNamespace = 0;
1114 
1115  if (!m_imports.resolveType(typeName, &ref.type, &url, &majorVersion, &minorVersion,
1116  &typeNamespace, &errorString) || typeNamespace) {
1117  // Known to not be a type:
1118  // - known to be a namespace (Namespace {})
1119  // - type with unknown namespace (UnknownNamespace.SomeType {})
1120  bool typeFound = false;
1121 
1122  if (!typeNamespace && !implicitImportLoaded) {
1123  implicitImportLoaded = true;
1124  // For local urls, add an implicit import "." as most overridden lookup.
1125  // This will also trigger the loading of the qmldir and the import of any native
1126  // types from available plugins.
1127  // This is only done if the type is not otherwise found, side effects of plugin loading may be avoided
1128  // ### This should be an acceptable variation because A) It's only side effects (and img providers) B) You shouldn't be doing that in "." anyways!
1129  if (QDeclarativeQmldirData *qmldir = qmldirForUrl(finalUrl().resolved(QUrl(QLatin1String("./qmldir"))))) {
1130  m_imports.addImport(importDatabase, QLatin1String("."),
1132  qmldir->dirComponents(), 0);
1133  } else {
1134  m_imports.addImport(importDatabase, QLatin1String("."),
1137  }
1138  if (m_imports.resolveType(typeName, &ref.type, &url, &majorVersion, &minorVersion,
1139  &typeNamespace, &errorString) || typeNamespace) {
1140  typeFound = true;
1141  }
1142  }
1143 
1144  if (!typeFound) {
1146  error.setUrl(m_imports.baseUrl());
1147  QString userTypeName = parserRef->name;
1148  userTypeName.replace(QLatin1Char('/'),QLatin1Char('.'));
1149  if (typeNamespace)
1150  error.setDescription(QDeclarativeTypeLoader::tr("Namespace %1 cannot be used as a type").arg(userTypeName));
1151  else
1152  error.setDescription(QDeclarativeTypeLoader::tr("%1 %2").arg(userTypeName).arg(errorString));
1153 
1154  if (!parserRef->refObjects.isEmpty()) {
1155  QDeclarativeParser::Object *obj = parserRef->refObjects.first();
1156  error.setLine(obj->location.start.line);
1157  error.setColumn(obj->location.start.column);
1158  }
1159 
1160  setError(error);
1161  return;
1162  }
1163  }
1164 
1165  if (ref.type) {
1166  ref.majorVersion = majorVersion;
1167  ref.minorVersion = minorVersion;
1168  foreach (QDeclarativeParser::Object *obj, parserRef->refObjects) {
1169  // store namespace for DOM
1170  obj->majorVersion = majorVersion;
1171  obj->minorVersion = minorVersion;
1172  }
1173  } else {
1174  ref.typeData = typeLoader()->get(url);
1175  addDependency(ref.typeData);
1176  }
1177 
1178  if (parserRef->refObjects.count())
1179  ref.location = parserRef->refObjects.first()->location.start;
1180 
1181  m_types << ref;
1182  }
1183 }
1184 
1186 {
1187  for (int ii = 0; ii < m_qmldirs.count(); ++ii) {
1188  if (m_qmldirs.at(ii)->url() == url)
1189  return m_qmldirs.at(ii);
1190  }
1191  return 0;
1192 }
1193 
1195 : QDeclarativeDataBlob(url, JavaScriptFile), m_pragmas(QDeclarativeParser::Object::ScriptBlock::None)
1196 {
1197 }
1198 
1199 QDeclarativeParser::Object::ScriptBlock::Pragmas QDeclarativeScriptData::pragmas() const
1200 {
1201  return m_pragmas;
1202 }
1203 
1205 {
1206  return m_source;
1207 }
1208 
1210 {
1211  m_source = QString::fromUtf8(data);
1213 }
1214 
1217 {
1218 }
1219 
1221 {
1222  return m_components;
1223 }
1224 
1226 {
1227  QDeclarativeDirParser parser;
1228  parser.setSource(QString::fromUtf8(data));
1229  parser.parse();
1230  m_components = parser.components();
1231 }
1232 
1234 
const QDeclarativeImports & imports() const
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
static QString urlToLocalFileOrQrc(const QUrl &url)
The QDeclarativeDataBlob encapsulates a data request that can be issued to a QDeclarativeDataLoader.
virtual void downloadProgressChanged(qreal)
Called when the download progress of this blob changes.
QDeclarativeTypeLoader * typeLoader() const
bool isError() const
Returns true if the status is Error.
static void callback(AuServer *, AuEventHandlerRec *, AuEvent *e, AuPointer p)
Definition: qsound_x11.cpp:170
QDeclarativeQmldirData * getQmldir(const QUrl &)
Returns a QDeclarativeQmldirData for url.
virtual qint64 size() const
For open random-access devices, this function returns the size of the device.
Definition: qiodevice.cpp:642
NetworkError error() const
Returns the error that was found during the processing of this request.
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.
bool hasNext() const
Returns true if there is at least one more entry in the directory; otherwise, false is returned...
void clear()
Removes all items from the hash.
Definition: qhash.h:574
void setDescription(const QString &)
Sets the error description.
QDeclarativeDataLoader * m_manager
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
QUrl finalUrl() const
Returns the final url of the data.
QList< QDeclarativeError > m_errors
QDeclarativeParser::Object::ScriptBlock::Pragmas m_pragmas
QString toString(FormattingOptions options=None) const
Returns the human-displayable string representation of the URL.
Definition: qurl.cpp:5896
virtual void done()
Invoked once data has either been received or a network error occurred, and all dependencies are comp...
#define it(className, varName)
bool open(OpenMode flags)
Opens the file using OpenMode mode, returning true if successful; otherwise false.
Definition: qfile.cpp:1064
virtual void dependencyComplete(QDeclarativeDataBlob *)
Called if blob, which was previously waited for, has completed.
QVariant attribute(QNetworkRequest::Attribute code) const
Returns the attribute associated with the code code.
bool addImport(QDeclarativeImportDatabase *, const QString &uri, const QString &prefix, int vmaj, int vmin, QDeclarativeScriptParser::Import::Type importType, const QDeclarativeDirComponents &qmldircomponentsnetwork, QString *errorString)
Adds information to imports such that subsequent calls to resolveType() will resolve types qualified ...
const QDeclarativeDirComponents & dirComponents() const
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
Definition: qstring.cpp:4074
QList< TypeReference * > referencedTypes() const
#define error(msg)
QString & replace(int i, int len, QChar after)
Definition: qstring.cpp:2005
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
bool isEmpty() const
Returns true if the URL has no data; otherwise returns false.
Definition: qurl.cpp:4317
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
QDeclarativeCompiledData * compiledData() const
void addDependency(QDeclarativeDataBlob *)
Wait for blob to become complete or to error.
#define SLOT(a)
Definition: qobjectdefs.h:226
QDeclarativeCompiledData * m_compiledData
void setColumn(int)
Sets the error column number.
NetworkError
Indicates all possible error conditions found during the processing of the request.
Definition: qnetworkreply.h:70
QDeclarativeDataLoader(QDeclarativeEngine *)
Create a new QDeclarativeDataLoader for engine.
QList< TypeDataCallback * > m_callbacks
QString absoluteFilePath() const
Returns an absolute path including the file name.
Definition: qfileinfo.cpp:534
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
bool isCompleteOrError() const
Returns true if the status is Complete or Error.
QList< QDeclarativeError > errors() const
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
bool resolveType(const QByteArray &type, QDeclarativeType **type_return, QUrl *url_return, int *version_major, int *version_minor, QDeclarativeImportedNamespace **ns_return, QString *errorString=0) const
The given (namespace qualified) type is resolved to either.
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
static bool isRelativePath(const QString &path)
Returns true if path is relative; returns false if it is absolute.
Definition: qdir.cpp:2210
QList< QDeclarativeDirParser::Component > QDeclarativeDirComponents
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
The QDirIterator class provides an iterator for directory entrylists.
Definition: qdiriterator.h:54
The QString class provides a Unicode character string.
Definition: qstring.h:83
T take(const Key &key)
Removes the item with the key from the hash and returns the value associated with it...
Definition: qhash.h:807
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
static QDeclarativeEnginePrivate * get(QDeclarativeEngine *e)
static QDeclarativeParser::Object::ScriptBlock::Pragmas extractPragmas(QString &)
bool isLoading() const
Returns true if the status is Loading.
bool isRelative() const
Returns true if the URL is relative; otherwise returns false.
Definition: qurl.cpp:5880
virtual void allDependenciesDone()
Called when all blobs waited for have completed.
QList< QDeclarativeDataBlob * > m_waitingOnMe
The QDeclarativeDataLoader class abstracts loading files and their dependencies over the network...
void networkReplyProgress(qint64, qint64)
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
QDeclarativeEngine * engine() const
Return the QDeclarativeEngine associated with this loader.
void setData(QDeclarativeDataBlob *, const QByteArray &)
The QDeclarativeImports class encapsulates one QML document&#39;s import statements.
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
const QList< TypeReference > & resolvedTypes() const
QObject * sender() const
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; othe...
Definition: qobject.cpp:2327
qreal progress() const
Returns the data download progress from 0 to 1.
Type
This enum describes the type of the data blob.
Q_GUI_EXPORT QString errorString(EGLint code=eglGetError())
Definition: qegl.cpp:743
bool removeOne(const T &t)
Removes the first occurrence of value in the list and returns true on success; otherwise returns fals...
Definition: qlist.h:796
#define SIGNAL(a)
Definition: qobjectdefs.h:227
QDeclarativeTypeLoader(QDeclarativeEngine *)
Constructs a new type loader that uses the given engine.
bool QDeclarative_isFileCaseCorrect(const QString &fileName)
Returns true if the case of fileName is equivalent to the file case of fileName on disk...
QString fileName() const
Returns the file name for the current directory entry, without the path prepended.
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
void loadWithStaticData(QDeclarativeDataBlob *, const QByteArray &)
Load the provided blob with data.
QUrl baseUrl() const
Returns the base URL to be used for all relative file imports added.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QList< Component > components() const
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
Definition: qlist.h:880
QDeclarativeImports m_imports
static bool isEmpty(const char *str)
virtual void typeDataReady(QDeclarativeTypeData *)
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
const char * typeName
Definition: qmetatype.cpp:239
bool contains(const T &value) const
Definition: qset.h:91
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QList< QDeclarativeParser::Object * > refObjects
virtual void typeDataProgress(QDeclarativeTypeData *, qreal)
void prepend(const T &t)
Inserts value at the beginning of the list.
Definition: qlist.h:541
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QList< QDeclarativeDataBlob * > m_waitingFor
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
Definition: qstring.cpp:4302
const_iterator insert(const T &value)
Definition: qset.h:179
static const char * data(const QByteArray &arr)
void unregisterCallback(TypeDataCallback *)
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
virtual void allDependenciesDone()
Called when all blobs waited for have completed.
const QDeclarativeDirParser * qmlDirParser(const QString &absoluteFilePath)
Return a QDeclarativeDirParser for absoluteFilePath.
void setFileSource(const QString &filePath)
The QDeclarativeError class encapsulates a QML error.
__int64 qint64
Definition: qglobal.h:942
QDeclarativeDirComponents m_components
QDeclarativeImportDatabase importDatabase
Type type() const
Returns the type provided to the constructor.
QNetworkReply * get(const QNetworkRequest &request)
Posts a request to obtain the contents of the target request and returns a new QNetworkReply object o...
QUrl toUrl() const
Returns the variant as a QUrl if the variant has type() Url ; otherwise returns an invalid QUrl...
Definition: qvariant.cpp:2528
bool isNull() const
Returns true if the status is Null.
Q_CORE_EXPORT int QT_FASTCALL script(uint ucs4)
#define None
Status status() const
Returns the blob&#39;s status.
#define DATALOADER_MAXIMUM_REDIRECT_RECURSION
static void endRange(RangeType)
QDeclarativeQmldirData * qmldirForUrl(const QUrl &)
static void startRange(RangeType)
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
void setLine(int)
Sets the error line number.
bool isWaiting() const
Returns true if the status is WaitingForDependencies.
QDeclarativeParser::Object::ScriptBlock::Pragmas pragmas() const
virtual void downloadProgressChanged(qreal)
Called when the download progress of this blob changes.
QString next()
Advances the iterator to the next entry, and returns the file path of this new entry.
virtual void done()
Invoked once data has either been received or a network error occurred, and all dependencies are comp...
The QFile class provides an interface for reading from and writing to files.
Definition: qfile.h:65
bool isComplete() const
Returns true if the status is Complete.
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:467
void setUrl(const QUrl &)
Sets the url for the file that caused this error.
QList< QDeclarativeError > errors() const
Return the errors on this blob.
QDeclarativeTypeLoader::Options m_options
The QDeclarativeEngine class provides an environment for instantiating QML components.
bool isFinished() const
Returns true when the reply has finished or was aborted.
virtual void dataReceived(const QByteArray &)
Invoked when data for the blob is received.
QUrl url() const
Returns the blob url passed to the constructor.
static QTestResult::TestLocation location
Definition: qtestresult.cpp:63
bool parse(const QByteArray &data, const QUrl &url=QUrl())
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389
QList< QDeclarativeError > errors() const
Return the list of errors from the last call to compile(), or an empty list if there were no errors...
The QHash::iterator class provides an STL-style non-const iterator for QHash and QMultiHash.
Definition: qhash.h:330
void load(QDeclarativeDataBlob *)
Load the provided blob from the network or filesystem.
QDeclarativeTypeData(const QUrl &, QDeclarativeTypeLoader::Options, QDeclarativeTypeLoader *)
void setError(const QDeclarativeError &)
Mark this blob as having errors.
QDeclarativeScriptParser scriptParser
iterator begin()
Returns an STL-style iterator pointing to the first item in the hash.
Definition: qhash.h:464
QFactoryLoader * l
bool isFile() const
Returns true if this object points to a file or to a symbolic link to a file.
Definition: qfileinfo.cpp:971
virtual void dataReceived(const QByteArray &)
Invoked when data for the blob is received.
static void rangeData(RangeType, const QString &)
QByteArray readAll()
Reads all available data from the device, and returns it as a QByteArray.
Definition: qiodevice.cpp:1025
The QNetworkRequest class holds a request to be sent with QNetworkAccessManager.
static QSet< QString > * qmlFilesInDirectory(const QString &path)
virtual void dependencyError(QDeclarativeDataBlob *)
Called if blob, which was previously waited for, has an error.
QDeclarativeTypeData * get(const QUrl &url)
Returns a QDeclarativeTypeData for the specified url.
void setBaseUrl(const QUrl &url)
Sets the base URL to be used for all relative file imports added.
T takeLast()
Removes the last item in the list and returns it.
Definition: qlist.h:492
QList< QDeclarativeQmldirData * > m_qmldirs
static QUrl fromLocalFile(const QString &localfile)
Returns a QUrl representation of localFile, interpreted as a local file.
Definition: qurl.cpp:6374
QList< TypeReference > m_types
QString absoluteFilePath(const QString &path)
Returns the absolute filename of path via a directory cache for files named "qmldir", "*.qml", "*.js" Returns a empty string if the path does not exist.
QDeclarativeScriptData * getScript(const QUrl &)
Returns a QDeclarativeScriptData for url.
bool compile(QDeclarativeEngine *, QDeclarativeTypeData *, QDeclarativeCompiledData *)
Compile unit, and store the output in out.
const QList< ScriptReference > & resolvedScripts() const
iterator find(const Key &key)
Returns an iterator pointing to the item with the key in the hash.
Definition: qhash.h:865
void setSource(const QString &source)
const QDeclarativeScriptParser & parser() const
QUrl url() const
Returns the URL of the content downloaded or uploaded.
QDeclarativeTypeLoader * m_typeLoader
void setUrl(const QUrl &url)
QNetworkAccessManager * networkAccessManager() const
Returns a common QNetworkAccessManager which can be used by any QML element instantiated by this engi...
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
Definition: qstring.cpp:3796
QUrl resolved(const QUrl &relative) const
Returns the result of the merge of this URL with relative.
Definition: qurl.cpp:5819
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485
void registerCallback(TypeDataCallback *)
static qreal dot(const QPointF &a, const QPointF &b)
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
static QString fileName(const QString &fileUrl)
Q_OUTOFLINE_TEMPLATE void qDeleteAll(ForwardIterator begin, ForwardIterator end)
Definition: qalgorithms.h:319
QDeclarativeDataBlob(const QUrl &, Type)
Create a new QDeclarativeDataBlob for url and of the provided type.
QList< ScriptReference > m_scripts
~QDeclarativeTypeLoader()
Destroys the type loader, first clearing the cache of any information about loaded files...
void deleteLater()
Schedules this object for deletion.
Definition: qobject.cpp:2145
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
virtual void dataReceived(const QByteArray &)=0
Invoked when data for the blob is received.
virtual void dataReceived(const QByteArray &)
Invoked when data for the blob is received.
void notifyComplete(QDeclarativeDataBlob *)
ImportQmlDirCache m_importQmlDirCache
virtual void networkError(QNetworkReply::NetworkError)
Invoked if there is a network error while fetching this blob.
The QDeclarativeImportDatabase class manages the QML imports for a QDeclarativeEngine.