forked from qt-creator/qt-creator
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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user