diff options
author | Martin Jones <martin.jones@nokia.com> | 2009-10-14 04:38:29 (GMT) |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2009-10-14 04:38:29 (GMT) |
commit | 9410f4b0e9aa3ce310c65f24c60576ce7317f88d (patch) | |
tree | 01a1f00025083124657e722e82776ff627b75507 /src/declarative/qml | |
parent | 1db61e89cb96022a6f5bffdc698f1f4dd4400b68 (diff) | |
parent | 513cc4be0bec4a5fb303062ecbecf87708dc0e9b (diff) | |
download | Qt-9410f4b0e9aa3ce310c65f24c60576ce7317f88d.zip Qt-9410f4b0e9aa3ce310c65f24c60576ce7317f88d.tar.gz Qt-9410f4b0e9aa3ce310c65f24c60576ce7317f88d.tar.bz2 |
Merge branch 'kinetic-declarativeui' of scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'src/declarative/qml')
-rw-r--r-- | src/declarative/qml/qmlcomponent.cpp | 65 | ||||
-rw-r--r-- | src/declarative/qml/qmlcomponent.h | 3 | ||||
-rw-r--r-- | src/declarative/qml/qmlcomponent_p.h | 21 | ||||
-rw-r--r-- | src/declarative/qml/qmlcompositetypemanager.cpp | 18 | ||||
-rw-r--r-- | src/declarative/qml/qmlengine.cpp | 17 | ||||
-rw-r--r-- | src/declarative/qml/qmlengine_p.h | 2 |
6 files changed, 117 insertions, 9 deletions
diff --git a/src/declarative/qml/qmlcomponent.cpp b/src/declarative/qml/qmlcomponent.cpp index 9a761b2..dc71989 100644 --- a/src/declarative/qml/qmlcomponent.cpp +++ b/src/declarative/qml/qmlcomponent.cpp @@ -95,6 +95,27 @@ Item { Loader { sourceComponent: RedSquare; x: 20 } } \endqml + + \section1 Attached Properties + + \e onCompleted + + Emitted after component "startup" has completed. This can be used to + execute script code at startup, once the full QML environment has been + established. + + The \c {Component::onCompleted} attached property can be applied to + any element. The order of running the \c onCompleted scripts is + undefined. + + \qml + Rectangle { + Component.onCompleted: print("Completed Running!") + Rectangle { + Component.onCompleted: print("Nested Completed Running!") + } + } + \endqml */ QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Component,QmlComponent); @@ -532,6 +553,11 @@ QmlComponentPrivate::beginCreate(QmlContext *context, const QBitField &bindings) bindValues = ep->bindValues; parserStatus = ep->parserStatus; + componentAttacheds = ep->componentAttacheds; + if (componentAttacheds) + componentAttacheds->prev = &componentAttacheds; + + ep->componentAttacheds = 0; ep->bindValues.clear(); ep->parserStatus.clear(); completePending = true; @@ -593,10 +619,49 @@ void QmlComponentPrivate::completeCreate() QmlEnginePrivate::clear(ps); } + while (componentAttacheds) { + QmlComponentAttached *a = componentAttacheds; + if (a->next) a->next->prev = &componentAttacheds; + componentAttacheds = a->next; + a->prev = 0; a->next = 0; + emit a->completed(); + } + bindValues.clear(); parserStatus.clear(); completePending = false; } } +QmlComponentAttached::QmlComponentAttached(QObject *parent) +: QObject(parent), prev(0), next(0) +{ +} + +QmlComponentAttached::~QmlComponentAttached() +{ + if (prev) *prev = next; + if (next) next->prev = prev; + prev = 0; + next = 0; +} + +QmlComponentAttached *QmlComponent::qmlAttachedProperties(QObject *obj) +{ + QmlComponentAttached *a = new QmlComponentAttached(obj); + + QmlEngine *engine = qmlEngine(obj); + if (!engine || !QmlEnginePrivate::get(engine)->rootComponent) + return a; + + QmlEnginePrivate *p = QmlEnginePrivate::get(engine); + + a->next = p->componentAttacheds; + a->prev = &p->componentAttacheds; + if (a->next) a->next->prev = &a->next; + p->componentAttacheds = a; + + return a; +} + QT_END_NAMESPACE diff --git a/src/declarative/qml/qmlcomponent.h b/src/declarative/qml/qmlcomponent.h index c6924e3..dcf9347 100644 --- a/src/declarative/qml/qmlcomponent.h +++ b/src/declarative/qml/qmlcomponent.h @@ -59,6 +59,7 @@ class QmlCompiledData; class QByteArray; class QmlComponentPrivate; class QmlEngine; +class QmlComponentAttached; class Q_DECLARATIVE_EXPORT QmlComponent : public QObject { Q_OBJECT @@ -95,6 +96,8 @@ public: void loadUrl(const QUrl &url); void setData(const QByteArray &, const QUrl &baseUrl); + static QmlComponentAttached *qmlAttachedProperties(QObject *); + Q_SIGNALS: void statusChanged(QmlComponent::Status); void progressChanged(qreal); diff --git a/src/declarative/qml/qmlcomponent_p.h b/src/declarative/qml/qmlcomponent_p.h index 2d0c77f..7eedfbd 100644 --- a/src/declarative/qml/qmlcomponent_p.h +++ b/src/declarative/qml/qmlcomponent_p.h @@ -70,12 +70,13 @@ class QmlComponent; class QmlEngine; class QmlCompiledData; +class QmlComponentAttached; class QmlComponentPrivate : public QObjectPrivate { Q_DECLARE_PUBLIC(QmlComponent) public: - QmlComponentPrivate() : typeData(0), progress(0.), start(-1), count(-1), cc(0), completePending(false), engine(0) {} + QmlComponentPrivate() : typeData(0), progress(0.), start(-1), count(-1), cc(0), completePending(false), componentAttacheds(0), engine(0) {} QObject *create(QmlContext *context, const QBitField &); @@ -98,6 +99,7 @@ public: QList<QmlEnginePrivate::SimpleList<QmlAbstractBinding> > bindValues; QList<QmlEnginePrivate::SimpleList<QmlParserStatus> > parserStatus; + QmlComponentAttached *componentAttacheds; bool completePending; @@ -110,6 +112,23 @@ public: } }; +class QmlComponentAttached : public QObject +{ + Q_OBJECT +public: + QmlComponentAttached(QObject *parent = 0); + ~QmlComponentAttached(); + + QmlComponentAttached **prev; + QmlComponentAttached *next; + +signals: + void completed(); + +private: + friend class QmlComponentPrivate; +}; + QT_END_NAMESPACE #endif // QMLCOMPONENT_P_H diff --git a/src/declarative/qml/qmlcompositetypemanager.cpp b/src/declarative/qml/qmlcompositetypemanager.cpp index 13bd02c..3c76344 100644 --- a/src/declarative/qml/qmlcompositetypemanager.cpp +++ b/src/declarative/qml/qmlcompositetypemanager.cpp @@ -262,13 +262,22 @@ void QmlCompositeTypeManager::resourceReplyFinished() reply->deleteLater(); } +static QString toLocalFileOrQrc(const QUrl& url) +{ + QString r = url.toLocalFile(); + if (r.isEmpty() && url.scheme() == QLatin1String("qrc")) + r = QLatin1Char(':') + url.path(); + return r; +} + void QmlCompositeTypeManager::loadResource(QmlCompositeTypeResource *resource) { QUrl url(resource->url); - if (url.scheme() == QLatin1String("file")) { + QString lf = toLocalFileOrQrc(url); + if (!lf.isEmpty()) { - QFile file(url.toLocalFile()); + QFile file(lf); if (file.open(QFile::ReadOnly)) { resource->data = file.readAll(); resource->status = QmlCompositeTypeResource::Complete; @@ -290,9 +299,10 @@ void QmlCompositeTypeManager::loadSource(QmlCompositeTypeData *unit) { QUrl url(unit->imports.baseUrl()); - if (url.scheme() == QLatin1String("file")) { + QString lf = toLocalFileOrQrc(url); + if (!lf.isEmpty()) { - QFile file(url.toLocalFile()); + QFile file(lf); if (file.open(QFile::ReadOnly)) { QByteArray data = file.readAll(); setData(unit, data, url); diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index ef0f975..d5f64c2 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -125,8 +125,8 @@ static QString userLocalDataPath(const QString& app) QmlEnginePrivate::QmlEnginePrivate(QmlEngine *e) : rootContext(0), currentExpression(0), isDebugging(false), contextClass(0), objectClass(0), valueTypeClass(0), globalClass(0), - nodeListClass(0), namedNodeMapClass(0), sqlQueryClass(0), scriptEngine(this), rootComponent(0), - networkAccessManager(0), typeManager(e), uniqueId(1) + nodeListClass(0), namedNodeMapClass(0), sqlQueryClass(0), scriptEngine(this), + componentAttacheds(0), rootComponent(0), networkAccessManager(0), typeManager(e), uniqueId(1) { QScriptValue qtObject = scriptEngine.newQMetaObject(StaticQtMetaObject::get()); @@ -955,6 +955,15 @@ QVariant QmlScriptClass::toVariant(QmlEngine *engine, const QScriptValue &val) return QVariant(); } +// XXX this beyonds in QUrl::toLocalFile() +static QString toLocalFileOrQrc(const QUrl& url) +{ + QString r = url.toLocalFile(); + if (r.isEmpty() && url.scheme() == QLatin1String("qrc")) + r = QLatin1Char(':') + url.path(); + return r; +} + ///////////////////////////////////////////////////////////// struct QmlEnginePrivate::ImportedNamespace { QStringList urls; @@ -985,7 +994,7 @@ struct QmlEnginePrivate::ImportedNamespace { QUrl url = QUrl(urls.at(i) + QLatin1String("/") + QString::fromUtf8(type) + QLatin1String(".qml")); if (vmaj || vmin) { // Check version file - XXX cache these in QmlEngine! - QFile qmldir(QUrl(urls.at(i)+QLatin1String("/qmldir")).toLocalFile()); + QFile qmldir(toLocalFileOrQrc(QUrl(urls.at(i)+QLatin1String("/qmldir")))); if (qmldir.open(QIODevice::ReadOnly)) { do { QByteArray lineba = qmldir.readLine(); @@ -1016,7 +1025,7 @@ struct QmlEnginePrivate::ImportedNamespace { } } else { // XXX search non-files too! (eg. zip files, see QT-524) - QFileInfo f(url.toLocalFile()); + QFileInfo f(toLocalFileOrQrc(url)); if (f.exists()) { if (url_return) *url_return = url; diff --git a/src/declarative/qml/qmlengine_p.h b/src/declarative/qml/qmlengine_p.h index 7978023..4c90a80 100644 --- a/src/declarative/qml/qmlengine_p.h +++ b/src/declarative/qml/qmlengine_p.h @@ -95,6 +95,7 @@ class QmlAbstractBinding; class QScriptDeclarativeClass; class QmlTypeNameScriptClass; class QmlTypeNameCache; +class QmlComponentAttached; class QmlEnginePrivate : public QObjectPrivate { @@ -174,6 +175,7 @@ public: QList<SimpleList<QmlAbstractBinding> > bindValues; QList<SimpleList<QmlParserStatus> > parserStatus; + QmlComponentAttached *componentAttacheds; QmlComponent *rootComponent; mutable QNetworkAccessManager *networkAccessManager; |