Commit 8a5fffb9 authored by Marco Bubke's avatar Marco Bubke
Browse files

QmlDesigner.NodeInstances: Fix restore bindings for reset

Task-number: QTCREATORBUG-5415

Change-Id: I1cbc8dda5eb1512db52a2767837b53eb136dc387
Reviewed-on: http://codereview.qt.nokia.com/1664

Reviewed-by: default avatarQt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: default avatarThomas Hartmann <Thomas.Hartmann@nokia.com>
parent 7ec3a259
......@@ -51,7 +51,7 @@ BehaviorNodeInstance::Pointer BehaviorNodeInstance::create(QObject *object)
Pointer instance(new BehaviorNodeInstance(behavior));
instance->populateResetValueHash();
instance->populateResetHashes();
behavior->setEnabled(false);
......
......@@ -60,7 +60,7 @@ ComponentNodeInstance::Pointer ComponentNodeInstance::create(QObject *object)
Pointer instance(new ComponentNodeInstance(component));
instance->populateResetValueHash();
instance->populateResetHashes();
return instance;
}
......
......@@ -390,6 +390,9 @@ void ObjectNodeInstance::setPropertyVariant(const QString &name, const QVariant
nodeInstanceServer()->removeFilePropertyFromFileSystemWatcher(object(), name, path);
}
if (hasValidResetBinding(name)) {
QDeclarativePropertyPrivate::setBinding(property, 0, QDeclarativePropertyPrivate::BypassInterceptor | QDeclarativePropertyPrivate::DontRemoveBinding);
}
bool isWritten = property.write(value);
......@@ -417,7 +420,7 @@ void ObjectNodeInstance::setPropertyBinding(const QString &name, const QString &
binding->setTarget(property);
binding->setNotifyOnValueChanged(true);
QDeclarativeAbstractBinding *oldBinding = QDeclarativePropertyPrivate::setBinding(property, binding);
if (oldBinding)
if (oldBinding && !hasValidResetBinding(name))
oldBinding->destroy();
binding->update();
if (binding->hasError())
......@@ -512,12 +515,17 @@ void ObjectNodeInstance::doResetProperty(const QString &propertyName)
QDeclarativeAbstractBinding *binding = QDeclarativePropertyPrivate::binding(property);
if (binding) {
if (binding && !(hasValidResetBinding(propertyName) && resetBinding(propertyName) == binding)) {
binding->setEnabled(false, 0);
binding->destroy();
}
if (property.isResettable()) {
if (hasValidResetBinding(propertyName)) {
QDeclarativeAbstractBinding *binding = resetBinding(propertyName);
QDeclarativePropertyPrivate::setBinding(property, binding, QDeclarativePropertyPrivate::DontRemoveBinding);
binding->update();
} else if (property.isResettable()) {
property.reset();
} else if (property.propertyTypeCategory() == QDeclarativeProperty::List) {
QDeclarativeListReference list = qvariant_cast<QDeclarativeListReference>(property.read());
......@@ -639,7 +647,7 @@ ObjectNodeInstance::Pointer ObjectNodeInstance::create(QObject *object)
{
Pointer instance(new ObjectNodeInstance(object));
instance->populateResetValueHash();
instance->populateResetHashes();
return instance;
}
......@@ -959,17 +967,32 @@ QStringList propertyNameForWritableProperties(QObject *object, const QString &ba
return propertyNameList;
}
void ObjectNodeInstance::populateResetValueHash()
void ObjectNodeInstance::populateResetHashes()
{
QStringList propertyNameList = propertyNameForWritableProperties(object());
foreach(const QString &propertyName, propertyNameList) {
QDeclarativeProperty property(object(), propertyName, QDeclarativeEngine::contextForObject(object()));
if (property.isWritable())
QDeclarativeAbstractBinding::Pointer binding = QDeclarativeAbstractBinding::getPointer(QDeclarativePropertyPrivate::binding(property));
if (binding) {
m_resetBindingHash.insert(propertyName, binding);
} else if (property.isWritable()) {
m_resetValueHash.insert(propertyName, property.read());
}
}
}
QDeclarativeAbstractBinding *ObjectNodeInstance::resetBinding(const QString &propertyName) const
{
return m_resetBindingHash.value(propertyName).data();
}
bool ObjectNodeInstance::hasValidResetBinding(const QString &propertyName) const
{
return m_resetBindingHash.contains(propertyName) && m_resetBindingHash.value(propertyName).data();
}
QVariant ObjectNodeInstance::resetValue(const QString &propertyName) const
{
return m_resetValueHash.value(propertyName);
......
......@@ -49,6 +49,7 @@ class QDeclarativeEngine;
class QDeclarativeProperty;
class QDeclarativeContext;
class QDeclarativeBinding;
class QDeclarativeAbstractBinding;
QT_END_NAMESPACE
namespace QmlDesigner {
......@@ -151,7 +152,9 @@ public:
virtual void activateState();
virtual void deactivateState();
void populateResetValueHash();
void populateResetHashes();
bool hasValidResetBinding(const QString &propertyName) const;
QDeclarativeAbstractBinding *resetBinding(const QString &propertyName) const;
QVariant resetValue(const QString &propertyName) const;
void setResetValue(const QString &propertyName, const QVariant &value);
......@@ -190,6 +193,7 @@ protected:
private:
QHash<QString, QVariant> m_resetValueHash;
QHash<QString, QWeakPointer<QDeclarativeAbstractBinding> > m_resetBindingHash;
QHash<QString, ServerNodeInstance> m_modelAbstractPropertyHash;
mutable QHash<QString, bool> m_hasBindingHash;
qint32 m_instanceId;
......
......@@ -59,7 +59,7 @@ QmlPropertyChangesNodeInstance::Pointer QmlPropertyChangesNodeInstance::create(Q
Pointer instance(new QmlPropertyChangesNodeInstance(propertyChange));
instance->populateResetValueHash();
instance->populateResetHashes();
return instance;
}
......
......@@ -60,7 +60,7 @@ QmlStateNodeInstance::Pointer
Pointer instance(new QmlStateNodeInstance(stateObject));
instance->populateResetValueHash();
instance->populateResetHashes();
return instance;
}
......
......@@ -49,7 +49,7 @@ QmlTransitionNodeInstance::Pointer QmlTransitionNodeInstance::create(QObject *ob
Pointer instance(new QmlTransitionNodeInstance(transition));
instance->populateResetValueHash();
instance->populateResetHashes();
transition->setToState("invalidState");
transition->setFromState("invalidState");
......
......@@ -80,7 +80,7 @@ PositionerNodeInstance::Pointer PositionerNodeInstance::create(QObject *object)
static_cast<QDeclarativeParserStatus*>(positioner)->classBegin();
instance->populateResetValueHash();
instance->populateResetHashes();
return instance;
}
......
......@@ -92,7 +92,7 @@ QmlGraphicsItemNodeInstance::Pointer QmlGraphicsItemNodeInstance::create(QObject
static_cast<QDeclarativeParserStatus*>(qmlGraphicsItem)->classBegin();
instance->populateResetValueHash();
instance->populateResetHashes();
return instance;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment