diff options
author | Alan Alpert <alan.alpert@nokia.com> | 2009-10-29 03:52:36 (GMT) |
---|---|---|
committer | Alan Alpert <alan.alpert@nokia.com> | 2009-10-29 04:06:09 (GMT) |
commit | 220eea1b5a978cf62e27878e7d9b2e1f4d10e91e (patch) | |
tree | 0cdb8ba932cedd3b2f0f1b45b92c4c095a36862c /src/declarative/qml/qmlcomponent.cpp | |
parent | bfbded95056d43a65b2c9ef1fa90bfd40adc6472 (diff) | |
download | Qt-220eea1b5a978cf62e27878e7d9b2e1f4d10e91e.zip Qt-220eea1b5a978cf62e27878e7d9b2e1f4d10e91e.tar.gz Qt-220eea1b5a978cf62e27878e7d9b2e1f4d10e91e.tar.bz2 |
Merge QmlComponentJS into QmlComponent
createComponent() and Component{} are now the same, and so Component{}s
can now be passed around for use in script.
Also this commit fixes the minor bug QT-2386
Diffstat (limited to 'src/declarative/qml/qmlcomponent.cpp')
-rw-r--r-- | src/declarative/qml/qmlcomponent.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/declarative/qml/qmlcomponent.cpp b/src/declarative/qml/qmlcomponent.cpp index 6181f41..72ead87 100644 --- a/src/declarative/qml/qmlcomponent.cpp +++ b/src/declarative/qml/qmlcomponent.cpp @@ -409,6 +409,9 @@ valid for components created directly from QML. */ QmlContext *QmlComponent::creationContext() const { + Q_D(const QmlComponent); + if(d->creationContext) + return d->creationContext; QmlDeclarativeData *ddata = QmlDeclarativeData::get(this); if (ddata) return ddata->context; @@ -417,6 +420,17 @@ QmlContext *QmlComponent::creationContext() const } /*! + \internal + Sets the QmlContext the component was created in. This is only + desirable for components created in QML script. +*/ +void QmlComponent::setCreationContext(QmlContext* c) +{ + Q_D(QmlComponent); + d->creationContext = c; +} + +/*! Load the QmlComponent from the provided \a url. */ void QmlComponent::loadUrl(const QUrl &url) @@ -462,6 +476,24 @@ QList<QmlError> QmlComponent::errors() const } /*! + \internal + errorsString is only meant as a way to get the errors in script +*/ +QString QmlComponent::errorsString() const +{ + Q_D(const QmlComponent); + QString ret; + if(!isError()) + return ret; + foreach(const QmlError &e, d->errors) { + ret += e.url().toString() + QLatin1String(":") + + QString::number(e.line()) + QLatin1String(" ") + + e.description() + QLatin1String("\n"); + } + return ret; +} + +/*! Return the component URL. This is the URL passed to either the constructor, or the loadUrl() or setData() methods. */ @@ -481,6 +513,22 @@ QmlComponent::QmlComponent(QmlComponentPrivate &dd, QObject *parent) /*! + \internal + A version of create which returns a scriptObject, for use in script +*/ +QScriptValue QmlComponent::createObject() +{ + Q_D(QmlComponent); + QmlContext* ctxt = creationContext(); + if(!ctxt){ + qWarning() << QLatin1String("createObject can only be used in QML"); + return QScriptValue(); + } + QObject* ret = create(ctxt); + return QmlEnginePrivate::qmlScriptObject(ret, d->engine); +} + +/*! Create an object instance from this component. Returns 0 if creation failed. \a context specifies the context within which to create the object instance. |