summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWarwick Allison <warwick.allison@nokia.com>2010-04-30 05:32:43 (GMT)
committerWarwick Allison <warwick.allison@nokia.com>2010-04-30 05:32:43 (GMT)
commit85db980578cb9f1b95be160a4386d9822c6ec6d0 (patch)
tree94db73d854dd559a355207f21aa49c903bcce28a
parent77cddec6ea642b073d1d9c017c865e740c0c60bc (diff)
downloadQt-85db980578cb9f1b95be160a4386d9822c6ec6d0.zip
Qt-85db980578cb9f1b95be160a4386d9822c6ec6d0.tar.gz
Qt-85db980578cb9f1b95be160a4386d9822c6ec6d0.tar.bz2
Make QDeclarativeParserStatus method pure virtual to encourage right code.
Fix all code to be right, except multimedia. Currently, it's not *required* that types work without componentComplete, so not vital.
-rw-r--r--src/declarative/qml/qdeclarativeparserstatus.cpp10
-rw-r--r--src/declarative/qml/qdeclarativeparserstatus.h4
-rw-r--r--src/declarative/qml/qdeclarativeworkerscript.cpp29
-rw-r--r--src/declarative/qml/qdeclarativeworkerscript_p.h3
-rw-r--r--src/declarative/util/qdeclarativebind.cpp8
-rw-r--r--src/declarative/util/qdeclarativebind_p.h1
-rw-r--r--src/declarative/util/qdeclarativeconnections.cpp8
-rw-r--r--src/declarative/util/qdeclarativeconnections_p.h1
-rw-r--r--src/imports/multimedia/qdeclarativeaudio.cpp7
-rw-r--r--src/imports/multimedia/qdeclarativeaudio_p.h1
-rw-r--r--tests/auto/declarative/qdeclarativelanguage/testtypes.h4
-rw-r--r--tests/auto/declarative/qdeclarativemetatype/tst_qdeclarativemetatype.cpp3
-rw-r--r--tools/qml/qdeclarativefolderlistmodel.cpp4
-rw-r--r--tools/qml/qdeclarativefolderlistmodel.h1
14 files changed, 64 insertions, 20 deletions
diff --git a/src/declarative/qml/qdeclarativeparserstatus.cpp b/src/declarative/qml/qdeclarativeparserstatus.cpp
index 978bfb4..4c4e429 100644
--- a/src/declarative/qml/qdeclarativeparserstatus.cpp
+++ b/src/declarative/qml/qdeclarativeparserstatus.cpp
@@ -91,19 +91,17 @@ QDeclarativeParserStatus::~QDeclarativeParserStatus()
}
/*!
+ \fn void QDeclarativeParserStatus::classBegin()
+
Invoked after class creation, but before any properties have been set.
*/
-void QDeclarativeParserStatus::classBegin()
-{
-}
/*!
+ \fn void QDeclarativeParserStatus::componentComplete()
+
Invoked after the root component that caused this instantiation has
completed construction. At this point all static values and binding values
have been assigned to the class.
*/
-void QDeclarativeParserStatus::componentComplete()
-{
-}
QT_END_NAMESPACE
diff --git a/src/declarative/qml/qdeclarativeparserstatus.h b/src/declarative/qml/qdeclarativeparserstatus.h
index 34528c1..60d423e 100644
--- a/src/declarative/qml/qdeclarativeparserstatus.h
+++ b/src/declarative/qml/qdeclarativeparserstatus.h
@@ -56,8 +56,8 @@ public:
QDeclarativeParserStatus();
virtual ~QDeclarativeParserStatus();
- virtual void classBegin();
- virtual void componentComplete();
+ virtual void classBegin()=0;
+ virtual void componentComplete()=0;
private:
friend class QDeclarativeVME;
diff --git a/src/declarative/qml/qdeclarativeworkerscript.cpp b/src/declarative/qml/qdeclarativeworkerscript.cpp
index 138d979..c55998f 100644
--- a/src/declarative/qml/qdeclarativeworkerscript.cpp
+++ b/src/declarative/qml/qdeclarativeworkerscript.cpp
@@ -538,7 +538,7 @@ void QDeclarativeWorkerScriptEngine::run()
by the \tt onMessage() handler of \tt myWorker.
*/
QDeclarativeWorkerScript::QDeclarativeWorkerScript(QObject *parent)
-: QObject(parent), m_engine(0), m_scriptId(-1)
+: QObject(parent), m_engine(0), m_scriptId(-1), m_componentComplete(true)
{
}
@@ -565,7 +565,7 @@ void QDeclarativeWorkerScript::setSource(const QUrl &source)
m_source = source;
- if (m_engine)
+ if (engine())
m_engine->executeUrl(m_scriptId, m_source);
emit sourceChanged();
@@ -580,7 +580,7 @@ void QDeclarativeWorkerScript::setSource(const QUrl &source)
*/
void QDeclarativeWorkerScript::sendMessage(const QScriptValue &message)
{
- if (!m_engine) {
+ if (!engine()) {
qWarning("QDeclarativeWorkerScript: Attempt to send message before WorkerScript establishment");
return;
}
@@ -588,13 +588,19 @@ void QDeclarativeWorkerScript::sendMessage(const QScriptValue &message)
m_engine->sendMessage(m_scriptId, QDeclarativeWorkerScriptEnginePrivate::scriptValueToVariant(message));
}
-void QDeclarativeWorkerScript::componentComplete()
+void QDeclarativeWorkerScript::classBegin()
{
- if (!m_engine) {
+ m_componentComplete = false;
+}
+
+QDeclarativeWorkerScriptEngine *QDeclarativeWorkerScript::engine()
+{
+ if (m_engine) return m_engine;
+ if (m_componentComplete) {
QDeclarativeEngine *engine = qmlEngine(this);
if (!engine) {
- qWarning("QDeclarativeWorkerScript: componentComplete() called without qmlEngine() set");
- return;
+ qWarning("QDeclarativeWorkerScript: engine() called without qmlEngine() set");
+ return 0;
}
m_engine = QDeclarativeEnginePrivate::get(engine)->getWorkerScriptEngine();
@@ -602,7 +608,16 @@ void QDeclarativeWorkerScript::componentComplete()
if (m_source.isValid())
m_engine->executeUrl(m_scriptId, m_source);
+
+ return m_engine;
}
+ return 0;
+}
+
+void QDeclarativeWorkerScript::componentComplete()
+{
+ m_componentComplete = true;
+ engine(); // Get it started now.
}
/*!
diff --git a/src/declarative/qml/qdeclarativeworkerscript_p.h b/src/declarative/qml/qdeclarativeworkerscript_p.h
index 6cce799..80ef5f3 100644
--- a/src/declarative/qml/qdeclarativeworkerscript_p.h
+++ b/src/declarative/qml/qdeclarativeworkerscript_p.h
@@ -108,13 +108,16 @@ signals:
void message(const QScriptValue &messageObject);
protected:
+ virtual void classBegin();
virtual void componentComplete();
virtual bool event(QEvent *);
private:
+ QDeclarativeWorkerScriptEngine *engine();
QDeclarativeWorkerScriptEngine *m_engine;
int m_scriptId;
QUrl m_source;
+ bool m_componentComplete;
};
QT_END_NAMESPACE
diff --git a/src/declarative/util/qdeclarativebind.cpp b/src/declarative/util/qdeclarativebind.cpp
index 5516628..1f528e8 100644
--- a/src/declarative/util/qdeclarativebind.cpp
+++ b/src/declarative/util/qdeclarativebind.cpp
@@ -60,7 +60,7 @@ QT_BEGIN_NAMESPACE
class QDeclarativeBindPrivate : public QObjectPrivate
{
public:
- QDeclarativeBindPrivate() : when(true), componentComplete(false), obj(0) {}
+ QDeclarativeBindPrivate() : when(true), componentComplete(true), obj(0) {}
bool when : 1;
bool componentComplete : 1;
@@ -198,6 +198,12 @@ void QDeclarativeBind::setValue(const QVariant &v)
eval();
}
+void QDeclarativeBind::classBegin()
+{
+ Q_D(QDeclarativeBind);
+ d->componentComplete = false;
+}
+
void QDeclarativeBind::componentComplete()
{
Q_D(QDeclarativeBind);
diff --git a/src/declarative/util/qdeclarativebind_p.h b/src/declarative/util/qdeclarativebind_p.h
index f756e80..f89c2eb 100644
--- a/src/declarative/util/qdeclarativebind_p.h
+++ b/src/declarative/util/qdeclarativebind_p.h
@@ -80,6 +80,7 @@ public:
void setValue(const QVariant &);
protected:
+ virtual void classBegin();
virtual void componentComplete();
private:
diff --git a/src/declarative/util/qdeclarativeconnections.cpp b/src/declarative/util/qdeclarativeconnections.cpp
index 5dd825e..ffa160f 100644
--- a/src/declarative/util/qdeclarativeconnections.cpp
+++ b/src/declarative/util/qdeclarativeconnections.cpp
@@ -57,7 +57,7 @@ QT_BEGIN_NAMESPACE
class QDeclarativeConnectionsPrivate : public QObjectPrivate
{
public:
- QDeclarativeConnectionsPrivate() : target(0), targetSet(false), ignoreUnknownSignals(false), componentcomplete(false) {}
+ QDeclarativeConnectionsPrivate() : target(0), targetSet(false), ignoreUnknownSignals(false), componentcomplete(true) {}
QList<QDeclarativeBoundSignal*> boundsignals;
QObject *target;
@@ -271,6 +271,12 @@ void QDeclarativeConnections::connectSignals()
}
}
+void QDeclarativeConnections::classBegin()
+{
+ Q_D(QDeclarativeConnections);
+ d->componentcomplete=false;
+}
+
void QDeclarativeConnections::componentComplete()
{
Q_D(QDeclarativeConnections);
diff --git a/src/declarative/util/qdeclarativeconnections_p.h b/src/declarative/util/qdeclarativeconnections_p.h
index b51899e..a914166 100644
--- a/src/declarative/util/qdeclarativeconnections_p.h
+++ b/src/declarative/util/qdeclarativeconnections_p.h
@@ -82,6 +82,7 @@ Q_SIGNALS:
private:
void connectSignals();
+ void classBegin();
void componentComplete();
};
diff --git a/src/imports/multimedia/qdeclarativeaudio.cpp b/src/imports/multimedia/qdeclarativeaudio.cpp
index 896f9b7..3c35bc1 100644
--- a/src/imports/multimedia/qdeclarativeaudio.cpp
+++ b/src/imports/multimedia/qdeclarativeaudio.cpp
@@ -316,9 +316,14 @@ QDeclarativeAudio::Error QDeclarativeAudio::error() const
return Error(m_error);
}
+void QDeclarativeAudio::classBegin()
+{
+}
+
void QDeclarativeAudio::componentComplete()
{
- setObject(this);
+ if (m_playerControl == 0)
+ setObject(this);
}
diff --git a/src/imports/multimedia/qdeclarativeaudio_p.h b/src/imports/multimedia/qdeclarativeaudio_p.h
index 24276ea..e960b9d 100644
--- a/src/imports/multimedia/qdeclarativeaudio_p.h
+++ b/src/imports/multimedia/qdeclarativeaudio_p.h
@@ -115,6 +115,7 @@ public:
Status status() const;
Error error() const;
+ void classBegin();
void componentComplete();
public Q_SLOTS:
diff --git a/tests/auto/declarative/qdeclarativelanguage/testtypes.h b/tests/auto/declarative/qdeclarativelanguage/testtypes.h
index 89f99c8..acbe219 100644
--- a/tests/auto/declarative/qdeclarativelanguage/testtypes.h
+++ b/tests/auto/declarative/qdeclarativelanguage/testtypes.h
@@ -99,7 +99,7 @@ private:
int m_value2;
};
-class MyQmlObject : public QObject, public MyInterface, public QDeclarativeParserStatus
+class MyQmlObject : public QObject, public MyInterface
{
Q_OBJECT
Q_PROPERTY(int value READ value WRITE setValue FINAL)
@@ -113,7 +113,7 @@ class MyQmlObject : public QObject, public MyInterface, public QDeclarativeParse
Q_PROPERTY(MyQmlObject *qmlobjectProperty READ qmlobject WRITE setQmlobject)
Q_PROPERTY(int propertyWithNotify READ propertyWithNotify WRITE setPropertyWithNotify NOTIFY oddlyNamedNotifySignal)
- Q_INTERFACES(MyInterface QDeclarativeParserStatus)
+ Q_INTERFACES(MyInterface)
public:
MyQmlObject() : m_value(-1), m_interface(0), m_qmlobject(0) { qRegisterMetaType<MyCustomVariantType>("MyCustomVariantType"); }
diff --git a/tests/auto/declarative/qdeclarativemetatype/tst_qdeclarativemetatype.cpp b/tests/auto/declarative/qdeclarativemetatype/tst_qdeclarativemetatype.cpp
index 36efe13..76e86c9 100644
--- a/tests/auto/declarative/qdeclarativemetatype/tst_qdeclarativemetatype.cpp
+++ b/tests/auto/declarative/qdeclarativemetatype/tst_qdeclarativemetatype.cpp
@@ -88,7 +88,10 @@ QML_DECLARE_TYPE(TestType);
class ParserStatusTestType : public QObject, public QDeclarativeParserStatus
{
Q_OBJECT
+ void classBegin(){}
+ void componentComplete(){}
Q_CLASSINFO("DefaultProperty", "foo") // Missing default property
+ Q_INTERFACES(QDeclarativeParserStatus)
};
QML_DECLARE_TYPE(ParserStatusTestType);
diff --git a/tools/qml/qdeclarativefolderlistmodel.cpp b/tools/qml/qdeclarativefolderlistmodel.cpp
index 2ac71ad..7ac25d6 100644
--- a/tools/qml/qdeclarativefolderlistmodel.cpp
+++ b/tools/qml/qdeclarativefolderlistmodel.cpp
@@ -256,6 +256,10 @@ void QDeclarativeFolderListModel::setNameFilters(const QStringList &filters)
d->model.setNameFilters(d->nameFilters);
}
+void QDeclarativeFolderListModel::classBegin()
+{
+}
+
void QDeclarativeFolderListModel::componentComplete()
{
if (!d->folder.isValid() || !QDir().exists(d->folder.toLocalFile()))
diff --git a/tools/qml/qdeclarativefolderlistmodel.h b/tools/qml/qdeclarativefolderlistmodel.h
index 57b7fe5..1ecc784 100644
--- a/tools/qml/qdeclarativefolderlistmodel.h
+++ b/tools/qml/qdeclarativefolderlistmodel.h
@@ -87,6 +87,7 @@ public:
QStringList nameFilters() const;
void setNameFilters(const QStringList &filters);
+ virtual void classBegin();
virtual void componentComplete();
Q_INVOKABLE bool isFolder(int index) const;