diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-07-07 03:28:56 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-07-07 03:28:56 (GMT) |
commit | f0062920559dd44f5f463ea4c3fa2657fceb81fb (patch) | |
tree | 58fd70afedd518c45d9e76847c889b805b07eb7f /src/declarative/qml/qmlcomponent.cpp | |
parent | 5972bfc6adaa32e4b21eb31a224346f143cbc530 (diff) | |
download | Qt-f0062920559dd44f5f463ea4c3fa2657fceb81fb.zip Qt-f0062920559dd44f5f463ea4c3fa2657fceb81fb.tar.gz Qt-f0062920559dd44f5f463ea4c3fa2657fceb81fb.tar.bz2 |
Improve QmlComponent API
Having to use QUrl::fromLocalFile() is crummy. Add appropriate overloads the QmlComponent, and resolve relative paths against a "base url" set on the QmlEngine.
Diffstat (limited to 'src/declarative/qml/qmlcomponent.cpp')
-rw-r--r-- | src/declarative/qml/qmlcomponent.cpp | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/src/declarative/qml/qmlcomponent.cpp b/src/declarative/qml/qmlcomponent.cpp index d6b38c9..3474487 100644 --- a/src/declarative/qml/qmlcomponent.cpp +++ b/src/declarative/qml/qmlcomponent.cpp @@ -270,10 +270,25 @@ QmlComponent::QmlComponent(QmlEngine *engine, const QUrl &url, QObject *parent) } /*! + Create a QmlComponent from the given \a url and give it the specified + \a parent and \a engine. + + \sa loadUrl() +*/ +QmlComponent::QmlComponent(QmlEngine *engine, const QString &url, + QObject *parent) +: QObject(*(new QmlComponentPrivate), parent) +{ + Q_D(QmlComponent); + d->engine = engine; + loadUrl(QUrl(url)); +} + +/*! Create a QmlComponent from the given QML \a data and give it the - specified \a parent and \a engine. If \a url is provided, it is used to set - the component name, and to provide a base path for items resolved - by this component. + specified \a parent and \a engine. \a url is used to provide a base path + for items resolved by this component, and may be an empty url if the + component contains no items to resolve. \sa setData() */ @@ -339,10 +354,13 @@ void QmlComponent::loadUrl(const QUrl &url) d->clear(); - d->url = url; + if (url.isRelative()) + d->url = d->engine->baseUrl().resolved(url); + else + d->url = url; QmlCompositeTypeData *data = - d->engine->d_func()->typeManager.get(url); + d->engine->d_func()->typeManager.get(d->url); if (data->status == QmlCompositeTypeData::Waiting) { |