QmlDesigner.NodeInstances: Fix restore bindings for reset

Task-number: QTCREATORBUG-5415

Change-Id: I1cbc8dda5eb1512db52a2767837b53eb136dc387
Reviewed-on: http://codereview.qt.nokia.com/1664
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Thomas Hartmann <Thomas.Hartmann@nokia.com>
This commit is contained in:
Marco Bubke
2011-07-14 15:15:57 +02:00
parent 7ec3a259f4
commit 8a5fffb945
9 changed files with 41 additions and 14 deletions

View File

@@ -51,7 +51,7 @@ BehaviorNodeInstance::Pointer BehaviorNodeInstance::create(QObject *object)
Pointer instance(new BehaviorNodeInstance(behavior)); Pointer instance(new BehaviorNodeInstance(behavior));
instance->populateResetValueHash(); instance->populateResetHashes();
behavior->setEnabled(false); behavior->setEnabled(false);

View File

@@ -60,7 +60,7 @@ ComponentNodeInstance::Pointer ComponentNodeInstance::create(QObject *object)
Pointer instance(new ComponentNodeInstance(component)); Pointer instance(new ComponentNodeInstance(component));
instance->populateResetValueHash(); instance->populateResetHashes();
return instance; return instance;
} }

View File

@@ -390,6 +390,9 @@ void ObjectNodeInstance::setPropertyVariant(const QString &name, const QVariant
nodeInstanceServer()->removeFilePropertyFromFileSystemWatcher(object(), name, path); nodeInstanceServer()->removeFilePropertyFromFileSystemWatcher(object(), name, path);
} }
if (hasValidResetBinding(name)) {
QDeclarativePropertyPrivate::setBinding(property, 0, QDeclarativePropertyPrivate::BypassInterceptor | QDeclarativePropertyPrivate::DontRemoveBinding);
}
bool isWritten = property.write(value); bool isWritten = property.write(value);
@@ -417,7 +420,7 @@ void ObjectNodeInstance::setPropertyBinding(const QString &name, const QString &
binding->setTarget(property); binding->setTarget(property);
binding->setNotifyOnValueChanged(true); binding->setNotifyOnValueChanged(true);
QDeclarativeAbstractBinding *oldBinding = QDeclarativePropertyPrivate::setBinding(property, binding); QDeclarativeAbstractBinding *oldBinding = QDeclarativePropertyPrivate::setBinding(property, binding);
if (oldBinding) if (oldBinding && !hasValidResetBinding(name))
oldBinding->destroy(); oldBinding->destroy();
binding->update(); binding->update();
if (binding->hasError()) if (binding->hasError())
@@ -512,12 +515,17 @@ void ObjectNodeInstance::doResetProperty(const QString &propertyName)
QDeclarativeAbstractBinding *binding = QDeclarativePropertyPrivate::binding(property); QDeclarativeAbstractBinding *binding = QDeclarativePropertyPrivate::binding(property);
if (binding) { if (binding && !(hasValidResetBinding(propertyName) && resetBinding(propertyName) == binding)) {
binding->setEnabled(false, 0); binding->setEnabled(false, 0);
binding->destroy(); 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(); property.reset();
} else if (property.propertyTypeCategory() == QDeclarativeProperty::List) { } else if (property.propertyTypeCategory() == QDeclarativeProperty::List) {
QDeclarativeListReference list = qvariant_cast<QDeclarativeListReference>(property.read()); QDeclarativeListReference list = qvariant_cast<QDeclarativeListReference>(property.read());
@@ -639,7 +647,7 @@ ObjectNodeInstance::Pointer ObjectNodeInstance::create(QObject *object)
{ {
Pointer instance(new ObjectNodeInstance(object)); Pointer instance(new ObjectNodeInstance(object));
instance->populateResetValueHash(); instance->populateResetHashes();
return instance; return instance;
} }
@@ -959,17 +967,32 @@ QStringList propertyNameForWritableProperties(QObject *object, const QString &ba
return propertyNameList; return propertyNameList;
} }
void ObjectNodeInstance::populateResetValueHash() void ObjectNodeInstance::populateResetHashes()
{ {
QStringList propertyNameList = propertyNameForWritableProperties(object()); QStringList propertyNameList = propertyNameForWritableProperties(object());
foreach(const QString &propertyName, propertyNameList) { foreach(const QString &propertyName, propertyNameList) {
QDeclarativeProperty property(object(), propertyName, QDeclarativeEngine::contextForObject(object())); 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()); 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 QVariant ObjectNodeInstance::resetValue(const QString &propertyName) const
{ {
return m_resetValueHash.value(propertyName); return m_resetValueHash.value(propertyName);

View File

@@ -49,6 +49,7 @@ class QDeclarativeEngine;
class QDeclarativeProperty; class QDeclarativeProperty;
class QDeclarativeContext; class QDeclarativeContext;
class QDeclarativeBinding; class QDeclarativeBinding;
class QDeclarativeAbstractBinding;
QT_END_NAMESPACE QT_END_NAMESPACE
namespace QmlDesigner { namespace QmlDesigner {
@@ -151,7 +152,9 @@ public:
virtual void activateState(); virtual void activateState();
virtual void deactivateState(); 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; QVariant resetValue(const QString &propertyName) const;
void setResetValue(const QString &propertyName, const QVariant &value); void setResetValue(const QString &propertyName, const QVariant &value);
@@ -190,6 +193,7 @@ protected:
private: private:
QHash<QString, QVariant> m_resetValueHash; QHash<QString, QVariant> m_resetValueHash;
QHash<QString, QWeakPointer<QDeclarativeAbstractBinding> > m_resetBindingHash;
QHash<QString, ServerNodeInstance> m_modelAbstractPropertyHash; QHash<QString, ServerNodeInstance> m_modelAbstractPropertyHash;
mutable QHash<QString, bool> m_hasBindingHash; mutable QHash<QString, bool> m_hasBindingHash;
qint32 m_instanceId; qint32 m_instanceId;

View File

@@ -59,7 +59,7 @@ QmlPropertyChangesNodeInstance::Pointer QmlPropertyChangesNodeInstance::create(Q
Pointer instance(new QmlPropertyChangesNodeInstance(propertyChange)); Pointer instance(new QmlPropertyChangesNodeInstance(propertyChange));
instance->populateResetValueHash(); instance->populateResetHashes();
return instance; return instance;
} }

View File

@@ -60,7 +60,7 @@ QmlStateNodeInstance::Pointer
Pointer instance(new QmlStateNodeInstance(stateObject)); Pointer instance(new QmlStateNodeInstance(stateObject));
instance->populateResetValueHash(); instance->populateResetHashes();
return instance; return instance;
} }

View File

@@ -49,7 +49,7 @@ QmlTransitionNodeInstance::Pointer QmlTransitionNodeInstance::create(QObject *ob
Pointer instance(new QmlTransitionNodeInstance(transition)); Pointer instance(new QmlTransitionNodeInstance(transition));
instance->populateResetValueHash(); instance->populateResetHashes();
transition->setToState("invalidState"); transition->setToState("invalidState");
transition->setFromState("invalidState"); transition->setFromState("invalidState");

View File

@@ -80,7 +80,7 @@ PositionerNodeInstance::Pointer PositionerNodeInstance::create(QObject *object)
static_cast<QDeclarativeParserStatus*>(positioner)->classBegin(); static_cast<QDeclarativeParserStatus*>(positioner)->classBegin();
instance->populateResetValueHash(); instance->populateResetHashes();
return instance; return instance;
} }

View File

@@ -92,7 +92,7 @@ QmlGraphicsItemNodeInstance::Pointer QmlGraphicsItemNodeInstance::create(QObject
static_cast<QDeclarativeParserStatus*>(qmlGraphicsItem)->classBegin(); static_cast<QDeclarativeParserStatus*>(qmlGraphicsItem)->classBegin();
instance->populateResetValueHash(); instance->populateResetHashes();
return instance; return instance;
} }