summaryrefslogtreecommitdiffstats
path: root/src/declarative/util/qmlpropertychanges.cpp
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@nokia.com>2009-09-25 02:43:42 (GMT)
committerMichael Brasser <michael.brasser@nokia.com>2009-09-25 02:43:42 (GMT)
commit7e6055d5d14ab0cf68df2d54d80ba22fc74fc51a (patch)
tree500b2a619cd3f33dd614254fa60cfa11ffaf7d0a /src/declarative/util/qmlpropertychanges.cpp
parent6a297d3626c1779047812965a12f32e143e63b7d (diff)
downloadQt-7e6055d5d14ab0cf68df2d54d80ba22fc74fc51a.zip
Qt-7e6055d5d14ab0cf68df2d54d80ba22fc74fc51a.tar.gz
Qt-7e6055d5d14ab0cf68df2d54d80ba22fc74fc51a.tar.bz2
Make replacing a signal handler in a state change use the right context.
Diffstat (limited to 'src/declarative/util/qmlpropertychanges.cpp')
-rw-r--r--src/declarative/util/qmlpropertychanges.cpp66
1 files changed, 60 insertions, 6 deletions
diff --git a/src/declarative/util/qmlpropertychanges.cpp b/src/declarative/util/qmlpropertychanges.cpp
index 1fe1731..46cd32c 100644
--- a/src/declarative/util/qmlpropertychanges.cpp
+++ b/src/declarative/util/qmlpropertychanges.cpp
@@ -80,6 +80,43 @@ QT_BEGIN_NAMESPACE
This property holds the object that the properties to change belong to
*/
+class QmlReplaceSignalHandler : public ActionEvent
+{
+public:
+ QmlReplaceSignalHandler() : expression(0), reverseExpression(0), ownedExpression(0) {}
+ ~QmlReplaceSignalHandler() {
+ delete ownedExpression;
+ }
+
+ virtual QString typeName() const { return QLatin1String("ReplaceSignalHandler"); }
+
+ QmlMetaProperty property;
+ QmlExpression *expression;
+ QmlExpression *reverseExpression;
+ QmlExpression *ownedExpression;
+
+ virtual void execute() {
+ reverseExpression = property.setSignalExpression(expression);
+ ownedExpression = reverseExpression;
+ }
+
+ virtual bool isReversable() { return true; }
+ virtual void reverse() {
+ ownedExpression = property.setSignalExpression(reverseExpression);
+ }
+
+ virtual bool override(ActionEvent*other) {
+ if (other == this)
+ return true;
+ if (other->typeName() != typeName())
+ return false;
+ if (static_cast<QmlReplaceSignalHandler*>(other)->property == property)
+ return true;
+ return false;
+ }
+};
+
+
class QmlPropertyChangesPrivate : public QObjectPrivate
{
Q_DECLARE_PUBLIC(QmlPropertyChanges)
@@ -97,6 +134,7 @@ public:
QList<QPair<QByteArray, QVariant> > properties;
QList<QPair<QByteArray, QmlExpression *> > expressions;
+ QList<QmlReplaceSignalHandler*> signalReplacements;
QmlMetaProperty property(const QByteArray &);
};
@@ -193,13 +231,15 @@ void QmlPropertyChangesPrivate::decode()
if (isScript) {
QmlMetaProperty prop = property(name); //### can we avoid or reuse?
- if (prop.type() != QmlMetaProperty::SignalProperty) { //binding
- QmlExpression *expression = new QmlExpression(qmlContext(q), data.toString(), object);
- expression->setTrackChange(false);
+ QmlExpression *expression = new QmlExpression(qmlContext(q), data.toString(), object);
+ expression->setTrackChange(false);
+ if (prop.type() == QmlMetaProperty::SignalProperty) {
+ QmlReplaceSignalHandler *handler = new QmlReplaceSignalHandler;
+ handler->property = prop;
+ handler->expression = expression;
+ signalReplacements << handler;
+ } else
expressions << qMakePair(name, expression);
- } else {
- properties << qMakePair(name, data); //same as non-script
- }
} else {
properties << qMakePair(name, data);
}
@@ -228,6 +268,9 @@ QmlPropertyChanges::~QmlPropertyChanges()
Q_D(QmlPropertyChanges);
for(int ii = 0; ii < d->expressions.count(); ++ii)
delete d->expressions.at(ii).second;
+ for(int ii = 0; ii < d->signalReplacements.count(); ++ii)
+ delete d->signalReplacements.at(ii);
+
}
QObject *QmlPropertyChanges::object() const
@@ -295,6 +338,17 @@ QmlPropertyChanges::ActionList QmlPropertyChanges::actions()
}
}
+ for (int ii = 0; ii < d->signalReplacements.count(); ++ii) {
+
+ QmlReplaceSignalHandler *handler = signalReplacements.at(ii);
+
+ if (handler->property.isValid()) {
+ Action a;
+ a.event = handler;
+ list << a;
+ }
+ }
+
for (int ii = 0; ii < d->expressions.count(); ++ii) {
QByteArray property = d->expressions.at(ii).first;