summaryrefslogtreecommitdiffstats
path: root/src/declarative
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2009-10-14 01:32:03 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2009-10-14 01:32:03 (GMT)
commit0a10af2463d73106c2f1268553aa6e60890f6180 (patch)
tree2ad916b6a98f16a4c3692a9e227da782dd3c42ac /src/declarative
parentc8198d40af104b5555a975b3156e9d5ba1981e25 (diff)
downloadQt-0a10af2463d73106c2f1268553aa6e60890f6180.zip
Qt-0a10af2463d73106c2f1268553aa6e60890f6180.tar.gz
Qt-0a10af2463d73106c2f1268553aa6e60890f6180.tar.bz2
Add Component::onCompleted attached property
Diffstat (limited to 'src/declarative')
-rw-r--r--src/declarative/qml/qmlcomponent.cpp65
-rw-r--r--src/declarative/qml/qmlcomponent.h3
-rw-r--r--src/declarative/qml/qmlcomponent_p.h21
-rw-r--r--src/declarative/qml/qmlengine.cpp4
-rw-r--r--src/declarative/qml/qmlengine_p.h2
5 files changed, 92 insertions, 3 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/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp
index ef0f975..7e95428 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());
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;