diff options
author | Michael Brasser <michael.brasser@nokia.com> | 2009-10-23 02:45:47 (GMT) |
---|---|---|
committer | Michael Brasser <michael.brasser@nokia.com> | 2009-10-23 02:48:53 (GMT) |
commit | 3386479da9526f0ae8978cd9e0afdd0559049ef9 (patch) | |
tree | 4a76e50347e64527621e96b7ceb4bfe25e0eeb24 /src/declarative | |
parent | 4890660acfc55db4e4e79375d562e729935092bd (diff) | |
download | Qt-3386479da9526f0ae8978cd9e0afdd0559049ef9.zip Qt-3386479da9526f0ae8978cd9e0afdd0559049ef9.tar.gz Qt-3386479da9526f0ae8978cd9e0afdd0559049ef9.tar.bz2 |
Update ScriptAction and StateChangeScript to use QmlScriptString.
Now you can assign the script you want to run to the property directly,
rather than assigning a string.
Task-number: QT-734
Diffstat (limited to 'src/declarative')
-rw-r--r-- | src/declarative/QmlChanges.txt | 1 | ||||
-rw-r--r-- | src/declarative/util/qmlanimation.cpp | 22 | ||||
-rw-r--r-- | src/declarative/util/qmlanimation.h | 10 | ||||
-rw-r--r-- | src/declarative/util/qmlanimation_p.h | 8 | ||||
-rw-r--r-- | src/declarative/util/qmlstateoperations.cpp | 13 | ||||
-rw-r--r-- | src/declarative/util/qmlstateoperations.h | 7 |
6 files changed, 31 insertions, 30 deletions
diff --git a/src/declarative/QmlChanges.txt b/src/declarative/QmlChanges.txt index 6a6c394..465ee9e 100644 --- a/src/declarative/QmlChanges.txt +++ b/src/declarative/QmlChanges.txt @@ -105,3 +105,4 @@ Script: now an intrinsic type in the language - bad: Item { resources: Script { ... } } Script: delay-loaded of the QML file until their source has been loaded (this only effects QML files loaded across the network.) Scope: declared properties shadow a property of the same name (was previously the reverse) +ScriptAction and StateChangeScript: the script property now takes script rather than a string containing script (script: doSomething() rather than script: "doSomething()") diff --git a/src/declarative/util/qmlanimation.cpp b/src/declarative/util/qmlanimation.cpp index c5a7f38..98453ed 100644 --- a/src/declarative/util/qmlanimation.cpp +++ b/src/declarative/util/qmlanimation.cpp @@ -790,22 +790,19 @@ void QmlScriptActionPrivate::init() } /*! - \qmlproperty QString ScriptAction::script + \qmlproperty script ScriptAction::script This property holds the script to run. */ -QString QmlScriptAction::script() const +QmlScriptString QmlScriptAction::script() const { Q_D(const QmlScriptAction); return d->script; } -void QmlScriptAction::setScript(const QString &script) +void QmlScriptAction::setScript(const QmlScriptString &script) { Q_D(QmlScriptAction); - if (script == d->script) - return; d->script = script; - emit scriptChanged(script); } /*! @@ -818,7 +815,7 @@ void QmlScriptAction::setScript(const QString &script) QString QmlScriptAction::stateChangeScriptName() const { Q_D(const QmlScriptAction); - return d->script; + return d->name; } void QmlScriptAction::setStateChangeScriptName(const QString &name) @@ -829,11 +826,11 @@ void QmlScriptAction::setStateChangeScriptName(const QString &name) void QmlScriptActionPrivate::execute() { - Q_Q(QmlScriptAction); - QString scriptStr = runScriptScript.isEmpty() ? script : runScriptScript; + QmlScriptString scriptStr = hasRunScriptScript ? script : runScriptScript; - if (!scriptStr.isEmpty()) { - QmlExpression expr(qmlContext(q), scriptStr, q); + const QString &str = scriptStr.script(); + if (!str.isEmpty()) { + QmlExpression expr(scriptStr.context(), str, scriptStr.scopeObject()); expr.setTrackChange(false); expr.value(); } @@ -847,7 +844,7 @@ void QmlScriptAction::transition(QmlStateActions &actions, Q_UNUSED(modified); Q_UNUSED(direction); - d->runScriptScript.clear(); + d->hasRunScriptScript = false; for (int ii = 0; ii < actions.count(); ++ii) { Action &action = actions[ii]; @@ -855,6 +852,7 @@ void QmlScriptAction::transition(QmlStateActions &actions, && static_cast<QmlStateChangeScript*>(action.event)->name() == d->name) { //### how should we handle reverse direction? d->runScriptScript = static_cast<QmlStateChangeScript*>(action.event)->script(); + d->hasRunScriptScript = true; action.actionDone = true; break; //assumes names are unique } diff --git a/src/declarative/util/qmlanimation.h b/src/declarative/util/qmlanimation.h index 508b2b5..7898980 100644 --- a/src/declarative/util/qmlanimation.h +++ b/src/declarative/util/qmlanimation.h @@ -49,6 +49,7 @@ #include <QtDeclarative/qmlpropertyvaluesource.h> #include <QtDeclarative/qmlstate.h> #include <QtDeclarative/qml.h> +#include <QtDeclarative/qmlscriptstring.h> QT_BEGIN_HEADER @@ -161,22 +162,19 @@ class QmlScriptAction : public QmlAbstractAnimation Q_OBJECT Q_DECLARE_PRIVATE(QmlScriptAction) - Q_PROPERTY(QString script READ script WRITE setScript NOTIFY scriptChanged) + Q_PROPERTY(QmlScriptString script READ script WRITE setScript) Q_PROPERTY(QString stateChangeScriptName READ stateChangeScriptName WRITE setStateChangeScriptName) public: QmlScriptAction(QObject *parent=0); virtual ~QmlScriptAction(); - QString script() const; - void setScript(const QString &); + QmlScriptString script() const; + void setScript(const QmlScriptString &); QString stateChangeScriptName() const; void setStateChangeScriptName(const QString &); -Q_SIGNALS: - void scriptChanged(const QString &); - protected: virtual void transition(QmlStateActions &actions, QmlMetaProperties &modified, diff --git a/src/declarative/util/qmlanimation_p.h b/src/declarative/util/qmlanimation_p.h index 22c4e2d..1f52fcd 100644 --- a/src/declarative/util/qmlanimation_p.h +++ b/src/declarative/util/qmlanimation_p.h @@ -170,6 +170,7 @@ private: template<class T, void (T::*method)(int)> class QTickAnimationProxy : public QAbstractAnimation { + //Q_OBJECT //doesn't work with templating public: QTickAnimationProxy(T *p, QObject *parent = 0) : QAbstractAnimation(parent), m_p(p) {} virtual int duration() const { return -1; } @@ -227,13 +228,14 @@ class QmlScriptActionPrivate : public QmlAbstractAnimationPrivate Q_DECLARE_PUBLIC(QmlScriptAction) public: QmlScriptActionPrivate() - : QmlAbstractAnimationPrivate(), proxy(this), rsa(0) {} + : QmlAbstractAnimationPrivate(), hasRunScriptScript(false), proxy(this), rsa(0) {} void init(); - QString script; + QmlScriptString script; QString name; - QString runScriptScript; + QmlScriptString runScriptScript; + bool hasRunScriptScript; void execute(); diff --git a/src/declarative/util/qmlstateoperations.cpp b/src/declarative/util/qmlstateoperations.cpp index 053cdc3..4d469f9 100644 --- a/src/declarative/util/qmlstateoperations.cpp +++ b/src/declarative/util/qmlstateoperations.cpp @@ -285,7 +285,7 @@ class QmlStateChangeScriptPrivate : public QObjectPrivate public: QmlStateChangeScriptPrivate() {} - QString script; + QmlScriptString script; QString name; }; @@ -304,16 +304,16 @@ QmlStateChangeScript::~QmlStateChangeScript() } /*! - \qmlproperty string StateChangeScript::script + \qmlproperty script StateChangeScript::script This property holds the script to run when the state is current. */ -QString QmlStateChangeScript::script() const +QmlScriptString QmlStateChangeScript::script() const { Q_D(const QmlStateChangeScript); return d->script; } -void QmlStateChangeScript::setScript(const QString &s) +void QmlStateChangeScript::setScript(const QmlScriptString &s) { Q_D(QmlStateChangeScript); d->script = s; @@ -334,8 +334,9 @@ void QmlStateChangeScript::setName(const QString &n) void QmlStateChangeScript::execute() { Q_D(QmlStateChangeScript); - if (!d->script.isEmpty()) { - QmlExpression expr(qmlContext(this), d->script, this); + const QString &script = d->script.script(); + if (!script.isEmpty()) { + QmlExpression expr(d->script.context(), script, d->script.scopeObject()); expr.setTrackChange(false); expr.value(); } diff --git a/src/declarative/util/qmlstateoperations.h b/src/declarative/util/qmlstateoperations.h index d8132fd..237e3e8 100644 --- a/src/declarative/util/qmlstateoperations.h +++ b/src/declarative/util/qmlstateoperations.h @@ -45,6 +45,7 @@ #include <QtDeclarative/qmlstate.h> #include <QtDeclarative/qfxitem.h> #include <QtDeclarative/qfxanchors.h> +#include <QtDeclarative/qmlscriptstring.h> QT_BEGIN_HEADER @@ -86,7 +87,7 @@ class Q_DECLARATIVE_EXPORT QmlStateChangeScript : public QmlStateOperation, publ Q_OBJECT Q_DECLARE_PRIVATE(QmlStateChangeScript) - Q_PROPERTY(QString script READ script WRITE setScript) + Q_PROPERTY(QmlScriptString script READ script WRITE setScript) Q_PROPERTY(QString name READ name WRITE setName) public: @@ -95,8 +96,8 @@ public: virtual ActionList actions(); - QString script() const; - void setScript(const QString &); + QmlScriptString script() const; + void setScript(const QmlScriptString &); QString name() const; void setName(const QString &); |