diff options
author | Kai Koehne <kai.koehne@nokia.com> | 2009-05-08 12:36:51 (GMT) |
---|---|---|
committer | Kai Koehne <kai.koehne@nokia.com> | 2009-05-08 12:47:34 (GMT) |
commit | 7d67d5c24ce3e707c1bb9bc6f181765cccc4090d (patch) | |
tree | a289b9637975c91d74e5df1e85a5d896fe7b90f2 /src | |
parent | 79900981848fc4ba812243db83a7456d72ddda15 (diff) | |
download | Qt-7d67d5c24ce3e707c1bb9bc6f181765cccc4090d.zip Qt-7d67d5c24ce3e707c1bb9bc6f181765cccc4090d.tar.gz Qt-7d67d5c24ce3e707c1bb9bc6f181765cccc4090d.tar.bz2 |
Expose import statements in QmlDomDocument
Reviewed-by: erikv
Reviewed-by: Roberto Raggi
Diffstat (limited to 'src')
-rw-r--r-- | src/declarative/canvas/qsimplecanvas.h | 12 | ||||
-rw-r--r-- | src/declarative/qml/qmldom.cpp | 17 | ||||
-rw-r--r-- | src/declarative/qml/qmldom.h | 3 | ||||
-rw-r--r-- | src/declarative/qml/qmldom_p.h | 3 | ||||
-rw-r--r-- | src/declarative/qml/qmlscriptparser.cpp | 15 | ||||
-rw-r--r-- | 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 <QtGui/qmatrix4x4.h> #endif -#include <QTransform> -#include <QPainter> -#include <QDebug> -#include <QWidget> -#include <QImage> -#include <QKeyEvent> +#include <QtGui/QTransform> +#include <QtGui/QPainter> +#include <QtCore/QDebug> +#include <QtGui/QWidget> +#include <QtGui/QImage> +#include <QtGui/QKeyEvent> 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 <dir>" in the qml. +*/ +QList<QUrl> 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<QUrl> imports() const; + QList<QmlError> 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 <QtCore/QtGlobal> + QT_BEGIN_HEADER QT_BEGIN_NAMESPACE @@ -58,6 +60,7 @@ public: ~QmlDomDocumentPrivate(); QList<QmlError> errors; + QList<QUrl> 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::Import> QmlScriptParser::imports() const +{ + return _imports; +} + QList<QmlError> 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 <QtCore/QList> #include <QtCore/QUrl> #include <QtDeclarative/qmlerror.h> -#include <qml.h> +#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<Import> imports() const; void clear(); @@ -48,6 +55,7 @@ public: QMap<QString,QString> _nameSpacePaths; QmlParser::Object *root; + QList<Import> _imports; QStringList _typeNames; QString _scriptFile; }; |