diff options
author | Kai Koehne <kai.koehne@nokia.com> | 2009-07-15 01:09:31 (GMT) |
---|---|---|
committer | Kai Koehne <kai.koehne@nokia.com> | 2009-07-15 02:02:32 (GMT) |
commit | 68e47e91af6edca3c714cc3258b65dd88c0ee1e4 (patch) | |
tree | 914ff8bba8e702673a40e55411a47b74522e8016 /src/declarative/qml | |
parent | fa0159762ce65c99907dbcb68d1c10e1a126468f (diff) | |
download | Qt-68e47e91af6edca3c714cc3258b65dd88c0ee1e4.zip Qt-68e47e91af6edca3c714cc3258b65dd88c0ee1e4.tar.gz Qt-68e47e91af6edca3c714cc3258b65dd88c0ee1e4.tar.bz2 |
Expose qml import statements in QmlDom
Diffstat (limited to 'src/declarative/qml')
-rw-r--r-- | src/declarative/qml/qmldom.cpp | 98 | ||||
-rw-r--r-- | src/declarative/qml/qmldom.h | 25 | ||||
-rw-r--r-- | src/declarative/qml/qmldom_p.h | 17 |
3 files changed, 134 insertions, 6 deletions
diff --git a/src/declarative/qml/qmldom.cpp b/src/declarative/qml/qmldom.cpp index 648eb36..e293a93 100644 --- a/src/declarative/qml/qmldom.cpp +++ b/src/declarative/qml/qmldom.cpp @@ -145,9 +145,9 @@ int QmlDomDocument::version() const } /*! - Return the URIs listed by "import <dir>" in the qml. + Returns all import statements in qml. */ -QList<QUrl> QmlDomDocument::imports() const +QList<QmlDomImport> QmlDomDocument::imports() const { return d->imports; } @@ -191,7 +191,13 @@ bool QmlDomDocument::load(QmlEngine *engine, const QByteArray &data, const QUrl } for (int i = 0; i < td->data.imports().size(); ++i) { - d->imports += QUrl(td->data.imports().at(i).uri); + QmlScriptParser::Import parserImport = td->data.imports().at(i); + QmlDomImport domImport; + domImport.d->type = static_cast<QmlDomImportPrivate::Type>(parserImport.type); + domImport.d->uri = parserImport.uri; + domImport.d->qualifier = parserImport.qualifier; + domImport.d->version = parserImport.version; + d->imports += domImport; } if (td->data.tree()) { @@ -207,7 +213,6 @@ bool QmlDomDocument::load(QmlEngine *engine, const QByteArray &data, const QUrl return true; } - /*! Returns the last load errors. The load errors will be reset after a successful call to load(). @@ -1767,4 +1772,89 @@ void QmlDomComponent::setComponentRoot(const QmlDomObject &root) qWarning("QmlDomComponent::setComponentRoot(const QmlDomObject &): Not implemented"); } + +QmlDomImportPrivate::QmlDomImportPrivate() +: type(File) +{ +} + +QmlDomImportPrivate::QmlDomImportPrivate(const QmlDomImportPrivate &other) +: QSharedData(other) +{ +} + +QmlDomImportPrivate::~QmlDomImportPrivate() +{ +} + +/*! + \class QmlDomImport + \internal + \brief The QmlDomImport class represents an import statement. +*/ + +/*! + Construct an empty QmlDomImport. +*/ +QmlDomImport::QmlDomImport() +: d(new QmlDomImportPrivate) +{ +} + +/*! + Create a copy of \a other QmlDomImport. +*/ +QmlDomImport::QmlDomImport(const QmlDomImport &other) +: d(other.d) +{ +} + +/*! + Destroy the QmlDomImport. +*/ +QmlDomImport::~QmlDomImport() +{ +} + +/*! + Assign \a other to this QmlDomImport. +*/ +QmlDomImport &QmlDomImport::operator=(const QmlDomImport &other) +{ + d = other.d; + return *this; +} + +/*! + Returns the type of the import. + */ +QmlDomImport::Type QmlDomImport::type() const +{ + return static_cast<QmlDomImport::Type>(d->type); +} + +/*! + Returns the URI of the import (e.g. 'subdir' or 'com.nokia.Qt') + */ +QString QmlDomImport::uri() const +{ + return d->uri; +} + +/*! + Returns the version specified by the import. An empty string if no version was specified. + */ +QString QmlDomImport::version() const +{ + return d->version; +} + +/*! + Returns the (optional) qualifier string (the token following the 'as' keyword) of the import. + */ +QString QmlDomImport::qualifier() const +{ + return d->qualifier; +} + QT_END_NAMESPACE diff --git a/src/declarative/qml/qmldom.h b/src/declarative/qml/qmldom.h index ef9fe25..456202a 100644 --- a/src/declarative/qml/qmldom.h +++ b/src/declarative/qml/qmldom.h @@ -59,9 +59,11 @@ class QmlDomList; class QmlDomValue; class QmlEngine; class QmlDomComponent; +class QmlDomImport; class QIODevice; class QmlDomDocumentPrivate; + class Q_DECLARATIVE_EXPORT QmlDomDocument { public: @@ -71,7 +73,7 @@ public: QmlDomDocument &operator=(const QmlDomDocument &); int version() const; - QList<QUrl> imports() const; + QList<QmlDomImport> imports() const; QList<QmlError> errors() const; bool load(QmlEngine *, const QByteArray &, const QUrl & = QUrl()); @@ -304,6 +306,27 @@ private: QSharedDataPointer<QmlDomValuePrivate> d; }; +class QmlDomImportPrivate; +class Q_DECLARATIVE_EXPORT QmlDomImport +{ +public: + enum Type { Library, File }; + + QmlDomImport(); + QmlDomImport(const QmlDomImport &); + ~QmlDomImport(); + QmlDomImport &operator=(const QmlDomImport &); + + Type type() const; + QString uri() const; + QString version() const; + QString qualifier() const; + +private: + friend class QmlDomDocument; + QSharedDataPointer<QmlDomImportPrivate> d; +}; + QT_END_NAMESPACE QT_END_HEADER diff --git a/src/declarative/qml/qmldom_p.h b/src/declarative/qml/qmldom_p.h index 5345c44..b15844a 100644 --- a/src/declarative/qml/qmldom_p.h +++ b/src/declarative/qml/qmldom_p.h @@ -66,7 +66,7 @@ public: ~QmlDomDocumentPrivate(); QList<QmlError> errors; - QList<QUrl> imports; + QList<QmlDomImport> imports; QmlParser::Object *root; QList<int> automaticSemicolonOffsets; }; @@ -129,6 +129,21 @@ public: QmlParser::Value *value; }; +class QmlDomImportPrivate : public QSharedData +{ +public: + QmlDomImportPrivate(); + QmlDomImportPrivate(const QmlDomImportPrivate &); + ~QmlDomImportPrivate(); + + enum Type { Library, File }; + + Type type; + QString uri; + QString version; + QString qualifier; +}; + QT_END_NAMESPACE #endif // QMLDOM_P_H |