From 7d67d5c24ce3e707c1bb9bc6f181765cccc4090d Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Fri, 8 May 2009 14:36:51 +0200 Subject: Expose import statements in QmlDomDocument Reviewed-by: erikv Reviewed-by: Roberto Raggi --- src/declarative/canvas/qsimplecanvas.h | 12 ++++++------ src/declarative/qml/qmldom.cpp | 17 +++++++++++++++-- src/declarative/qml/qmldom.h | 3 ++- src/declarative/qml/qmldom_p.h | 3 +++ src/declarative/qml/qmlscriptparser.cpp | 15 +++++++++++++++ src/declarative/qml/qmlscriptparser_p.h | 18 +++++++++++++----- 6 files changed, 54 insertions(+), 14 deletions(-) diff --git a/src/declarative/canvas/qsimplecanvas.h b/src/declarative/canvas/qsimplecanvas.h index 20dab28..d57ada4 100644 --- a/src/declarative/canvas/qsimplecanvas.h +++ b/src/declarative/canvas/qsimplecanvas.h @@ -48,12 +48,12 @@ #include #endif -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include QT_BEGIN_HEADER diff --git a/src/declarative/qml/qmldom.cpp b/src/declarative/qml/qmldom.cpp index a31be81..4e754a3 100644 --- a/src/declarative/qml/qmldom.cpp +++ b/src/declarative/qml/qmldom.cpp @@ -143,7 +143,15 @@ int QmlDomDocument::version() const } /*! - Loads a QmlDomDocument from \a data. \a data should be valid QML XML + Return the URIs listed by "import " in the qml. +*/ +QList QmlDomDocument::imports() const +{ + return d->imports; +} + +/*! + Loads a QmlDomDocument from \a data. \a data should be valid QML data. On success, true is returned. If the \a data is malformed, false is returned and QmlDomDocument::loadError() contains an error description. @@ -153,11 +161,12 @@ bool QmlDomDocument::load(QmlEngine *engine, const QByteArray &data, const QUrl { Q_UNUSED(engine); d->errors.clear(); + d->imports.clear(); QmlCompiledComponent component; QmlCompiler compiler; - QmlCompositeTypeData *td = ((QmlEnginePrivate *)QmlEnginePrivate::get(engine))->typeManager.getImmediate(data, url);; + QmlCompositeTypeData *td = ((QmlEnginePrivate *)QmlEnginePrivate::get(engine))->typeManager.getImmediate(data, url); if(td->status == QmlCompositeTypeData::Error) { d->errors = td->errors; @@ -179,6 +188,10 @@ bool QmlDomDocument::load(QmlEngine *engine, const QByteArray &data, const QUrl return false; } + for (int i = 0; i < td->data.imports().size(); ++i) { + d->imports += QUrl(td->data.imports().at(i).uri); + } + if (td->data.tree()) { td->data.tree()->dump(); d->root = td->data.tree(); diff --git a/src/declarative/qml/qmldom.h b/src/declarative/qml/qmldom.h index f90fb08..8b503fa 100644 --- a/src/declarative/qml/qmldom.h +++ b/src/declarative/qml/qmldom.h @@ -71,7 +71,8 @@ public: QmlDomDocument &operator=(const QmlDomDocument &); int version() const; - + QList imports() const; + QList errors() const; bool load(QmlEngine *, const QByteArray &, const QUrl & = QUrl()); QByteArray save() const; diff --git a/src/declarative/qml/qmldom_p.h b/src/declarative/qml/qmldom_p.h index 4c3ca44..74edd47 100644 --- a/src/declarative/qml/qmldom_p.h +++ b/src/declarative/qml/qmldom_p.h @@ -42,6 +42,8 @@ #ifndef QMLDOM_P_H #define QMLDOM_P_H +#include + QT_BEGIN_HEADER QT_BEGIN_NAMESPACE @@ -58,6 +60,7 @@ public: ~QmlDomDocumentPrivate(); QList errors; + QList imports; QmlParser::Object *root; }; diff --git a/src/declarative/qml/qmlscriptparser.cpp b/src/declarative/qml/qmlscriptparser.cpp index 4385601..8506933 100644 --- a/src/declarative/qml/qmlscriptparser.cpp +++ b/src/declarative/qml/qmlscriptparser.cpp @@ -362,6 +362,16 @@ bool ProcessAST::visit(AST::UiImport *node) { QString fileName = node->fileName->asString(); _parser->addNamespacePath(fileName); + + AST::SourceLocation startLoc = node->importToken; + AST::SourceLocation endLoc = node->semicolonToken; + + QmlScriptParser::Import import; + import.location = location(startLoc, endLoc); + import.uri = fileName; + + _parser->_imports << import; + return false; } @@ -686,6 +696,11 @@ Object *QmlScriptParser::tree() const return root; } +QList QmlScriptParser::imports() const +{ + return _imports; +} + QList QmlScriptParser::errors() const { return _errors; diff --git a/src/declarative/qml/qmlscriptparser_p.h b/src/declarative/qml/qmlscriptparser_p.h index 4155bba..8a5466f 100644 --- a/src/declarative/qml/qmlscriptparser_p.h +++ b/src/declarative/qml/qmlscriptparser_p.h @@ -4,22 +4,28 @@ #include #include #include -#include +#include "qmlparser_p.h" + QT_BEGIN_HEADER QT_BEGIN_NAMESPACE QT_MODULE(Declarative) -namespace QmlParser { - class Object; -} - class QByteArray; class QmlScriptParser { public: + class Import + { + public: + Import() {} + + QString uri; + QmlParser::LocationSpan location; + }; + QmlScriptParser(); ~QmlScriptParser(); @@ -29,6 +35,7 @@ public: QStringList types() const; QmlParser::Object *tree() const; + QList imports() const; void clear(); @@ -48,6 +55,7 @@ public: QMap _nameSpacePaths; QmlParser::Object *root; + QList _imports; QStringList _typeNames; QString _scriptFile; }; -- cgit v0.12