diff --git a/src/plugins/qmldesigner/designercore/instances/nodeinstance.cpp b/src/plugins/qmldesigner/designercore/instances/nodeinstance.cpp index e0cba857fe7f743a33114349dcec2080441c830a..09a4ee7bc3fbd95e548dbdfff7a5c9945fc8ecb4 100644 --- a/src/plugins/qmldesigner/designercore/instances/nodeinstance.cpp +++ b/src/plugins/qmldesigner/designercore/instances/nodeinstance.cpp @@ -632,7 +632,7 @@ bool NodeInstance::resetStateProperty(const NodeInstance &target, const QString */ void NodeInstance::registerDeclarativeTypes() { - qmlRegisterType<QmlDesigner::Internal::QmlPropertyChangesObject>(); +// qmlRegisterType<QmlDesigner::Internal::QmlPropertyChangesObject>(); } #ifdef QTCREATOR_TEST diff --git a/src/plugins/qmldesigner/designercore/instances/nodeinstanceview.cpp b/src/plugins/qmldesigner/designercore/instances/nodeinstanceview.cpp index 443c189d0c996d4f8d6fb28c675e8b6e5b7f45e1..728d5867a9a7da4224bc4c699aa1928350676554 100644 --- a/src/plugins/qmldesigner/designercore/instances/nodeinstanceview.cpp +++ b/src/plugins/qmldesigner/designercore/instances/nodeinstanceview.cpp @@ -186,7 +186,7 @@ void NodeInstanceView::resetInstanceProperty(const AbstractProperty &property) NodeInstance instance = instanceForNode(property.parentModelNode()); Q_ASSERT(instance.isValid()); const QString name = property.name(); - if (activeStateInstance().isValid()) { + if (activeStateInstance().isValid() && !property.parentModelNode().metaInfo().isSubclassOf("PropertyChange", 4, 7)) { bool statePropertyWasReseted = activeStateInstance().resetStateProperty(instance, name, instance.resetVariant(name)); if (!statePropertyWasReseted) instance.resetProperty(name); @@ -204,7 +204,7 @@ void NodeInstanceView::setInstancePropertyBinding(const BindingProperty &propert const QString expression = property.expression(); - if (activeStateInstance().isValid()) { + if (activeStateInstance().isValid() && !property.parentModelNode().metaInfo().isSubclassOf("PropertyChange", 4, 7)) { bool stateBindingWasUpdated = activeStateInstance().updateStateBinding(instance, name, expression); if (!stateBindingWasUpdated) { if (property.isDynamic()) @@ -240,7 +240,7 @@ void NodeInstanceView::setInstancePropertyVariant(const VariantProperty &propert const QVariant value = property.value(); - if (activeStateInstance().isValid()) { + if (activeStateInstance().isValid() && !property.parentModelNode().metaInfo().isSubclassOf("PropertyChange", 4, 7)) { bool stateValueWasUpdated = activeStateInstance().updateStateVariant(instance, name, value); if (!stateValueWasUpdated) { if (property.isDynamic()) diff --git a/src/plugins/qmldesigner/designercore/instances/qmlpropertychangesnodeinstance.cpp b/src/plugins/qmldesigner/designercore/instances/qmlpropertychangesnodeinstance.cpp index 6b301754c777ffec6a87fcfd9fe42be54dc73d2d..a427a09c961fe85cfe4b6fe0925665aa322b0137 100644 --- a/src/plugins/qmldesigner/designercore/instances/qmlpropertychangesnodeinstance.cpp +++ b/src/plugins/qmldesigner/designercore/instances/qmlpropertychangesnodeinstance.cpp @@ -37,141 +37,141 @@ #include <QMutableListIterator> #include <private/qdeclarativestate_p_p.h> -#include <private/qdeclarativestategroup_p.h> +#include <private/qdeclarativepropertychanges_p.h> #include <private/qdeclarativeproperty_p.h> namespace QmlDesigner { namespace Internal { -QmlPropertyChangesObject::QmlPropertyChangesObject() : - QDeclarativeStateOperation(), - m_restoreEntryValues(true), - m_isExplicit(false) -{ -} - -QDeclarativeStateOperation::ActionList QmlPropertyChangesObject::actions() -{ - QMutableListIterator<QDeclarativeAction> actionIterator(m_qmlActionList); - - while (actionIterator.hasNext()) { - QDeclarativeAction &action = actionIterator.next(); - action.fromBinding = QDeclarativePropertyPrivate::binding(action.property); - action.fromValue = action.property.read(); - if (m_expressionHash.contains(action.specifiedProperty)) { - if(m_expressionHash[action.specifiedProperty].second.isNull()) { - if (targetObject()) { - QDeclarativeBinding *binding = new QDeclarativeBinding(m_expressionHash[action.specifiedProperty].first, targetObject(), QDeclarativeEngine::contextForObject(targetObject()), this); - binding->setTarget(action.property); - binding->setNotifyOnValueChanged(true); - action.toBinding = binding; - action.toValue = binding->evaluate(); - m_expressionHash.insert(action.specifiedProperty, ExpressionPair(m_expressionHash[action.specifiedProperty].first, binding)); - } else { - action.toBinding = 0; - } - } else { - action.toBinding = m_expressionHash[action.specifiedProperty].second.data(); - action.toValue = m_expressionHash[action.specifiedProperty].second->evaluate(); - } - } else { - action.toBinding = 0; - } - } - - return m_qmlActionList; -} - -QObject *QmlPropertyChangesObject::targetObject() const -{ - return m_targetObject.data(); -} - -void QmlPropertyChangesObject::setTargetObject(QObject *object) -{ - if (m_targetObject.data() == object) - return; - - QMutableListIterator<QDeclarativeAction> actionIterator(m_qmlActionList); - while (actionIterator.hasNext()) { - QDeclarativeAction &qmlAction = actionIterator.next(); - if (m_expressionHash.contains(qmlAction.specifiedProperty) && m_expressionHash[qmlAction.specifiedProperty].second) { - if (isActive()) { - QDeclarativePropertyPrivate::setBinding(qmlAction.property, 0, QDeclarativePropertyPrivate::DontRemoveBinding| QDeclarativePropertyPrivate::BypassInterceptor); - qmlAction.property.write(qmlAction.fromValue); - m_expressionHash[qmlAction.specifiedProperty].second.data()->destroy(); - } - - - qmlAction.toBinding = 0; - } - - if (isActive() && targetObject()) { - updateRevertValueAndBinding(qmlAction.specifiedProperty); - } - } - - m_targetObject = object; - - actionIterator.toFront(); - while (actionIterator.hasNext()) { - QDeclarativeAction &qmlAction = actionIterator.next(); - qmlAction.specifiedObject = object; - qmlAction.property = createMetaProperty(qmlAction.specifiedProperty); - qmlAction.fromValue = qmlAction.property.read(); - qmlAction.fromBinding = QDeclarativePropertyPrivate::binding(qmlAction.property); - - if (m_expressionHash.contains(qmlAction.specifiedProperty) && targetObject()) { - QDeclarativeBinding *binding = new QDeclarativeBinding(m_expressionHash[qmlAction.specifiedProperty].first ,targetObject(), QDeclarativeEngine::contextForObject(targetObject())); - binding->setTarget(qmlAction.property); - binding->setNotifyOnValueChanged(true); - qmlAction.toBinding = binding; - m_expressionHash.insert(qmlAction.specifiedProperty, ExpressionPair(m_expressionHash[qmlAction.specifiedProperty].first, binding)); - if (isActive()) { - QDeclarativePropertyPrivate::setBinding(qmlAction.property, qmlAction.toBinding, QDeclarativePropertyPrivate::DontRemoveBinding| QDeclarativePropertyPrivate::BypassInterceptor); - } - } - - if (isActive() && targetObject()) { - updateRevertValueAndBinding(qmlAction.specifiedProperty); - } - } -} - -bool QmlPropertyChangesObject::restoreEntryValues() const -{ - return m_restoreEntryValues; -} - -void QmlPropertyChangesObject::setRestoreEntryValues(bool restore) -{ - m_restoreEntryValues = restore; -} - -bool QmlPropertyChangesObject::isExplicit() const -{ - return m_isExplicit; -} - -void QmlPropertyChangesObject::setIsExplicit(bool isExplicit) -{ - m_isExplicit = isExplicit; -} - -QDeclarativeProperty QmlPropertyChangesObject::createMetaProperty(const QString &property) -{ - QDeclarativeProperty prop(m_targetObject.data(), property, QDeclarativeEngine::contextForObject(m_targetObject.data())); - if (!prop.isValid()) { - qWarning() << "Cannot assign to non-existent property" << property; - return QDeclarativeProperty(); - } else if (!prop.isWritable()) { - qWarning() << "Cannot assign to read-only property" << property; - return QDeclarativeProperty(); - } - return prop; -} - -QmlPropertyChangesNodeInstance::QmlPropertyChangesNodeInstance(QmlPropertyChangesObject *propertyChangesObject) : +//QmlPropertyChangesObject::QmlPropertyChangesObject() : +// QDeclarativeStateOperation(), +// m_restoreEntryValues(true), +// m_isExplicit(false) +//{ +//} + +//QDeclarativeStateOperation::ActionList QmlPropertyChangesObject::actions() +//{ +// QMutableListIterator<QDeclarativeAction> actionIterator(m_qmlActionList); + +// while (actionIterator.hasNext()) { +// QDeclarativeAction &action = actionIterator.next(); +// action.fromBinding = QDeclarativePropertyPrivate::binding(action.property); +// action.fromValue = action.property.read(); +// if (m_expressionHash.contains(action.specifiedProperty)) { +// if(m_expressionHash[action.specifiedProperty].second.isNull()) { +// if (targetObject()) { +// QDeclarativeBinding *binding = new QDeclarativeBinding(m_expressionHash[action.specifiedProperty].first, targetObject(), QDeclarativeEngine::contextForObject(targetObject()), this); +// binding->setTarget(action.property); +// binding->setNotifyOnValueChanged(true); +// action.toBinding = binding; +// action.toValue = binding->evaluate(); +// m_expressionHash.insert(action.specifiedProperty, ExpressionPair(m_expressionHash[action.specifiedProperty].first, binding)); +// } else { +// action.toBinding = 0; +// } +// } else { +// action.toBinding = m_expressionHash[action.specifiedProperty].second.data(); +// action.toValue = m_expressionHash[action.specifiedProperty].second->evaluate(); +// } +// } else { +// action.toBinding = 0; +// } +// } + +// return m_qmlActionList; +//} + +//QObject *QmlPropertyChangesObject::targetObject() const +//{ +// return m_targetObject.data(); +//} + +//void QmlPropertyChangesObject::setTargetObject(QObject *object) +//{ +// if (m_targetObject.data() == object) +// return; + +// QMutableListIterator<QDeclarativeAction> actionIterator(m_qmlActionList); +// while (actionIterator.hasNext()) { +// QDeclarativeAction &qmlAction = actionIterator.next(); +// if (m_expressionHash.contains(qmlAction.specifiedProperty) && m_expressionHash[qmlAction.specifiedProperty].second) { +// if (isActive()) { +// QDeclarativePropertyPrivate::setBinding(qmlAction.property, 0, QDeclarativePropertyPrivate::DontRemoveBinding| QDeclarativePropertyPrivate::BypassInterceptor); +// qmlAction.property.write(qmlAction.fromValue); +// m_expressionHash[qmlAction.specifiedProperty].second.data()->destroy(); +// } + + +// qmlAction.toBinding = 0; +// } + +// if (isActive() && targetObject()) { +// updateRevertValueAndBinding(qmlAction.specifiedProperty); +// } +// } + +// m_targetObject = object; + +// actionIterator.toFront(); +// while (actionIterator.hasNext()) { +// QDeclarativeAction &qmlAction = actionIterator.next(); +// qmlAction.specifiedObject = object; +// qmlAction.property = createMetaProperty(qmlAction.specifiedProperty); +// qmlAction.fromValue = qmlAction.property.read(); +// qmlAction.fromBinding = QDeclarativePropertyPrivate::binding(qmlAction.property); + +// if (m_expressionHash.contains(qmlAction.specifiedProperty) && targetObject()) { +// QDeclarativeBinding *binding = new QDeclarativeBinding(m_expressionHash[qmlAction.specifiedProperty].first ,targetObject(), QDeclarativeEngine::contextForObject(targetObject())); +// binding->setTarget(qmlAction.property); +// binding->setNotifyOnValueChanged(true); +// qmlAction.toBinding = binding; +// m_expressionHash.insert(qmlAction.specifiedProperty, ExpressionPair(m_expressionHash[qmlAction.specifiedProperty].first, binding)); +// if (isActive()) { +// QDeclarativePropertyPrivate::setBinding(qmlAction.property, qmlAction.toBinding, QDeclarativePropertyPrivate::DontRemoveBinding| QDeclarativePropertyPrivate::BypassInterceptor); +// } +// } + +// if (isActive() && targetObject()) { +// updateRevertValueAndBinding(qmlAction.specifiedProperty); +// } +// } +//} + +//bool QmlPropertyChangesObject::restoreEntryValues() const +//{ +// return m_restoreEntryValues; +//} + +//void QmlPropertyChangesObject::setRestoreEntryValues(bool restore) +//{ +// m_restoreEntryValues = restore; +//} + +//bool QmlPropertyChangesObject::isExplicit() const +//{ +// return m_isExplicit; +//} + +//void QmlPropertyChangesObject::setIsExplicit(bool isExplicit) +//{ +// m_isExplicit = isExplicit; +//} + +//QDeclarativeProperty QmlPropertyChangesObject::createMetaProperty(const QString &property) +//{ +// QDeclarativeProperty prop(m_targetObject.data(), property, QDeclarativeEngine::contextForObject(m_targetObject.data())); +// if (!prop.isValid()) { +// qWarning() << "Cannot assign to non-existent property" << property; +// return QDeclarativeProperty(); +// } else if (!prop.isWritable()) { +// qWarning() << "Cannot assign to read-only property" << property; +// return QDeclarativeProperty(); +// } +// return prop; +//} + +QmlPropertyChangesNodeInstance::QmlPropertyChangesNodeInstance(QDeclarativePropertyChanges *propertyChangesObject) : ObjectNodeInstance(propertyChangesObject) { } @@ -183,7 +183,7 @@ QmlPropertyChangesNodeInstance::Pointer { Q_ASSERT(!objectToBeWrapped); - QmlPropertyChangesObject *object = new QmlPropertyChangesObject; + QDeclarativePropertyChanges *object = new QDeclarativePropertyChanges; QDeclarativeEngine::setContextForObject(object, context); Pointer instance(new QmlPropertyChangesNodeInstance(object)); return instance; @@ -191,15 +191,14 @@ QmlPropertyChangesNodeInstance::Pointer void QmlPropertyChangesNodeInstance::setPropertyVariant(const QString &name, const QVariant &value) { - QMetaObject metaObject = QmlPropertyChangesObject::staticMetaObject; + QMetaObject metaObject = QDeclarativePropertyChanges::staticMetaObject; if (metaObject.indexOfProperty(name.toLatin1()) > 0) { // 'restoreEntryValues', 'explicit' ObjectNodeInstance::setPropertyVariant(name, value); } else { - changesObject()->setVariantValue(name, value); - QObject *targetObject = changesObject()->targetObject(); + changesObject()->changeValue(name.toLatin1(), value); + QObject *targetObject = changesObject()->object(); if (targetObject && nodeInstanceView()->activeStateInstance().isWrappingThisObject(changesObject()->state())) { - changesObject()->updateRevertValueAndBinding(name); NodeInstance targetInstance = nodeInstanceView()->instanceForObject(targetObject); targetInstance.setPropertyVariant(name, value); } @@ -208,451 +207,434 @@ void QmlPropertyChangesNodeInstance::setPropertyVariant(const QString &name, con void QmlPropertyChangesNodeInstance::setPropertyBinding(const QString &name, const QString &expression) { - QMetaObject metaObject = QmlPropertyChangesObject::staticMetaObject; + QMetaObject metaObject = QDeclarativePropertyChanges::staticMetaObject; if (metaObject.indexOfProperty(name.toLatin1()) > 0) { // 'restoreEntryValues', 'explicit' ObjectNodeInstance::setPropertyBinding(name, expression); } else { - changesObject()->setExpression(name, expression); + changesObject()->changeExpression(name.toLatin1(), expression); } } QVariant QmlPropertyChangesNodeInstance::property(const QString &name) const { - if (changesObject()->hasVariantValue(name)) - return changesObject()->variantValue(name); - if (changesObject()->hasExpression(name)) - return QVariant(changesObject()->expression(name)); - - return QVariant(); + return changesObject()->property(name.toLatin1()); } void QmlPropertyChangesNodeInstance::resetProperty(const QString &name) { - changesObject()->resetProperty(name); + changesObject()->removeProperty(name.toLatin1()); } void QmlPropertyChangesNodeInstance::reparent(const NodeInstance &oldParentInstance, const QString &oldParentProperty, const NodeInstance &newParentInstance, const QString &newParentProperty) { - if (oldParentProperty == "changes") { - if (changesObject()) { - changesObject()->removeFromStateRevertList(); - } - } - ObjectNodeInstance::reparent(oldParentInstance, oldParentProperty, newParentInstance, newParentProperty); - - if (newParentProperty == "changes") { - if (changesObject()) { - changesObject()->addToStateRevertList(); - } - } -} - -QDeclarativeState *QmlPropertyChangesObject::state() const -{ - if (!parent()) - return 0; - - Q_ASSERT(qobject_cast<QDeclarativeState*>(parent())); - return static_cast<QDeclarativeState*>(parent()); -} - -QDeclarativeStateGroup *QmlPropertyChangesObject::stateGroup() const -{ - if (!state()) - return 0; - - return state()->stateGroup(); -} - -QDeclarativeStatePrivate *QmlPropertyChangesObject::statePrivate() const -{ - if (!parent() || QObjectPrivate::get(parent())->wasDeleted) - return 0; - - Q_ASSERT(qobject_cast<QDeclarativeState*>(parent())); - return static_cast<QDeclarativeStatePrivate*>(QObjectPrivate::get(parent())); -} - -QmlPropertyChangesObject *QmlPropertyChangesNodeInstance::changesObject() const -{ - Q_ASSERT(qobject_cast<QmlPropertyChangesObject*>(object())); - return static_cast<QmlPropertyChangesObject*>(object()); } +//QDeclarativeState *QmlPropertyChangesObject::state() const +//{ +// if (!parent()) +// return 0; + +// Q_ASSERT(qobject_cast<QDeclarativeState*>(parent())); +// return static_cast<QDeclarativeState*>(parent()); +//} + +//QDeclarativeStateGroup *QmlPropertyChangesObject::stateGroup() const +//{ +// if (!state()) +// return 0; + +// return state()->stateGroup(); +//} + +//QDeclarativeStatePrivate *QmlPropertyChangesObject::statePrivate() const +//{ +// if (!parent() || QObjectPrivate::get(parent())->wasDeleted) +// return 0; + +// Q_ASSERT(qobject_cast<QDeclarativeState*>(parent())); +// return static_cast<QDeclarativeStatePrivate*>(QObjectPrivate::get(parent())); +//} + +QDeclarativePropertyChanges *QmlPropertyChangesNodeInstance::changesObject() const +{ + Q_ASSERT(qobject_cast<QDeclarativePropertyChanges*>(object())); + return static_cast<QDeclarativePropertyChanges*>(object()); +} + + +//QDeclarativeAction QmlPropertyChangesObject::createQDeclarativeAction(const QString &propertyName) +//{ +// QDeclarativeProperty qmlMetaProperty = createMetaProperty(propertyName); + +// QDeclarativeAction qmlAction; +// qmlAction.restore = true; +// qmlAction.property = qmlMetaProperty; +// qmlAction.fromValue = qmlMetaProperty.read(); +// qmlAction.fromBinding = QDeclarativePropertyPrivate::binding(qmlMetaProperty); +// qmlAction.specifiedObject = m_targetObject.data(); +// qmlAction.specifiedProperty = propertyName; +// qmlAction.event = 0; + +// return qmlAction; +//} + +//bool QmlPropertyChangesObject::hasActionForProperty(const QString &propertyName) const +//{ +// for(ActionList::iterator actionIterator = m_qmlActionList.begin(); +// actionIterator != m_qmlActionList.end(); +// ++actionIterator) { +// QDeclarativeAction &qmlAction = *actionIterator; +// if (qmlAction.specifiedProperty == propertyName) { +// return true; +// } +// } + +// return false; +//} + +//QDeclarativeAction &QmlPropertyChangesObject::qmlActionForProperty(const QString &propertyName) const +//{ +// for(ActionList::iterator actionIterator = m_qmlActionList.begin(); +// actionIterator != m_qmlActionList.end(); +// ++actionIterator) { +// QDeclarativeAction &qmlAction = *actionIterator; +// if (qmlAction.specifiedProperty == propertyName) +// return qmlAction; +// } + +// Q_ASSERT(false); + +// return m_qmlActionList[0]; +//} + +//void QmlPropertyChangesObject::removeActionForProperty(const QString &propertyName) +//{ +// QMutableListIterator<QDeclarativeAction> actionIterator(m_qmlActionList); +// while (actionIterator.hasNext()) { +// QDeclarativeAction &qmlAction = actionIterator.next(); +// if (qmlAction.specifiedProperty == propertyName) +// actionIterator.remove(); +// } + +// if (statePrivate()) { +// QMutableListIterator<QDeclarativeSimpleAction> simpleActionIterator(statePrivate()->revertList); +// while (simpleActionIterator.hasNext()) { +// QDeclarativeSimpleAction &qmlSimpleAction = simpleActionIterator.next(); +// if (qmlSimpleAction.specifiedProperty == propertyName && qmlSimpleAction.specifiedObject == targetObject()) { +// simpleActionIterator.remove(); +// } +// } +// } +//} + +//bool QmlPropertyChangesObject::isActive() const +//{ +// if (state() && stateGroup()) +// return state()->name() == stateGroup()->state(); + +// return false; +//} +//QmlPropertyChangesObject::~QmlPropertyChangesObject() +//{ +// removeFromStateRevertList(); +//} + +//void QmlPropertyChangesObject::removeFromStateRevertList() +//{ +// if (statePrivate()) { +// QMutableListIterator<QDeclarativeSimpleAction> simpleActionIterator(statePrivate()->revertList); +// while(simpleActionIterator.hasNext()) { +// QDeclarativeSimpleAction &simpleAction = simpleActionIterator.next(); +// if (simpleAction.specifiedObject == targetObject()) { +// if (simpleAction.property.isValid()) { +// if (simpleAction.binding) { +// QDeclarativePropertyPrivate::setBinding(simpleAction.property, simpleAction.binding); +// } else if (simpleAction.value.isValid()) { +// QDeclarativePropertyPrivate::setBinding(simpleAction.property, 0); +// simpleAction.property.write(simpleAction.value); +// } +// } +// simpleActionIterator.remove(); +// } +// } +// } +//} + +//void QmlPropertyChangesObject::addToStateRevertList() +//{ +// if (isActive() && statePrivate()) { +// QListIterator<QDeclarativeAction> actionIterator(m_qmlActionList); +// while (actionIterator.hasNext()) { +// const QDeclarativeAction &qmlAction = actionIterator.next(); +// QDeclarativeSimpleAction simpleAction(qmlAction); +// simpleAction.binding = qmlAction.fromBinding; +// simpleAction.value = qmlAction.fromValue; +// statePrivate()->revertList.append(simpleAction); +// if (qmlAction.toBinding) +// QDeclarativePropertyPrivate::setBinding(qmlAction.property, qmlAction.toBinding); +// else +// qmlAction.property.write(qmlAction.toValue); +// } +// } +//} + +//void QmlPropertyChangesObject::updateRevertValueAndBinding(const QString &name) +//{ +// if (isActive() && statePrivate()) { +// typedef QList<QDeclarativeSimpleAction> SimpleActionList; +// if (!statePrivate()->revertList.isEmpty()) { +// for(SimpleActionList::iterator actionIterator = statePrivate()->revertList.begin(); +// actionIterator != statePrivate()->revertList.end(); +// ++actionIterator) { +// //simple action defines values and bindings to revert current state +// QDeclarativeSimpleAction &simpleAction = *actionIterator; +// if (simpleAction.specifiedObject == targetObject() +// && simpleAction.specifiedProperty == name) { +// const QDeclarativeAction &qmlAction = qmlActionForProperty(name); +// simpleAction.value = qmlAction.fromValue; +// simpleAction.binding = qmlAction.fromBinding; +// simpleAction.specifiedObject = qmlAction.specifiedObject; +// simpleAction.specifiedProperty = qmlAction.specifiedProperty; +// simpleAction.property = qmlAction.property; +// return; //return since we just had to update exisisting simple action +// } +// } +// } + +// //simple action does not exist, yet + +// const QDeclarativeAction &qmlAction = qmlActionForProperty(name); +// QDeclarativeSimpleAction simpleAction(qmlAction); +// simpleAction.binding = qmlAction.fromBinding; +// simpleAction.value = qmlAction.fromValue; +// statePrivate()->revertList.append(simpleAction); +// } +//} + +//void QmlPropertyChangesObject::setVariantValue(const QString &name, const QVariant & value) +//{ +// if (!hasActionForProperty(name)) { +// m_qmlActionList.append(createQDeclarativeAction(name)); +// } + +// QDeclarativeAction &qmlAction = qmlActionForProperty(name); +// if (qmlAction.fromBinding) +// qmlAction.fromBinding->setEnabled(false, QDeclarativePropertyPrivate::BypassInterceptor | QDeclarativePropertyPrivate::DontRemoveBinding); + +// qmlAction.toValue = value; +//} + +//void QmlPropertyChangesObject::setExpression(const QString &name, const QString &expression) +//{ +// if (!hasActionForProperty(name)) { +// m_qmlActionList.append(createQDeclarativeAction(name)); +// } + +// QDeclarativeContext *context = QDeclarativeEngine::contextForObject(targetObject()); +// QDeclarativeBinding *binding = 0; +// QDeclarativeProperty metaProperty(targetObject(), name, context); + +// QDeclarativeAction &qmlAction = qmlActionForProperty(name); +// if (m_expressionHash.contains(name) && m_expressionHash[name].second) { +// if (QDeclarativePropertyPrivate::binding(metaProperty) == m_expressionHash[name].second.data()) +// QDeclarativePropertyPrivate::setBinding(metaProperty, 0, QDeclarativePropertyPrivate::BypassInterceptor | QDeclarativePropertyPrivate::DontRemoveBinding); +// m_expressionHash.take(name).second->destroy(); +// qmlAction.toBinding = 0; +// } + + +// if (metaProperty.isValid() && metaProperty.isProperty()) { +// binding = new QDeclarativeBinding(expression, targetObject(), context, this); +// binding->setTarget(metaProperty); +// binding->setNotifyOnValueChanged(true); +// qmlAction.toBinding = binding; +// m_expressionHash.insert(name, ExpressionPair(expression, binding)); +// } else { +// m_expressionHash.insert(name, ExpressionPair(expression, static_cast<QDeclarativeBinding*>(0))); +// } + +// updateRevertValueAndBinding(name); +// if (isActive() && binding) +// QDeclarativePropertyPrivate::setBinding(metaProperty, binding, QDeclarativePropertyPrivate::BypassInterceptor | QDeclarativePropertyPrivate::DontRemoveBinding); +//} + +//void QmlPropertyChangesObject::removeVariantValue(const QString &name) +//{ +// if (hasActionForProperty(name)) { +// QDeclarativeAction &qmlAction = qmlActionForProperty(name); +// if (hasExpression(name)) { +// qmlAction.toValue = QVariant(); +// updateRevertValueAndBinding(name); +// } else { +// if (qmlAction.fromBinding) +// QDeclarativePropertyPrivate::setBinding(qmlAction.property, qmlAction.fromBinding); +// else +// qmlAction.property.write(qmlAction.fromValue); +// removeActionForProperty(name); +// } +// } +//} + +//void QmlPropertyChangesObject::removeExpression(const QString &name) +//{ +// if (hasActionForProperty(name)) { +// QDeclarativeAction &qmlAction = qmlActionForProperty(name); +// if (hasVariantValue(name)) { +// ExpressionPair expr = m_expressionHash.take(name); +// if (expr.second) +// expr.second.data()->destroy(); +// qmlAction.toBinding = 0; +// updateRevertValueAndBinding(name); +// qmlAction.property.write(qmlAction.toValue); +// } else { +// if (qmlAction.fromBinding) +// QDeclarativePropertyPrivate::setBinding(qmlAction.property, qmlAction.fromBinding); +// else +// qmlAction.property.write(qmlAction.fromValue); +// removeActionForProperty(name); +// } +// } +//} + +//void QmlPropertyChangesObject::resetProperty(const QString &name) +//{ +// if (statePrivate()) { +// QMutableListIterator<QDeclarativeSimpleAction> simpleActionIterator(statePrivate()->revertList); +// while (simpleActionIterator.hasNext()) { +// QDeclarativeSimpleAction &qmlSimpleAction = simpleActionIterator.next(); +// if (qmlSimpleAction.specifiedProperty == name && qmlSimpleAction.specifiedObject == targetObject()) { +// if (qmlSimpleAction.binding) { +// qDebug() << qmlSimpleAction.binding->expression(); +// QDeclarativePropertyPrivate::setBinding(qmlSimpleAction.property, qmlSimpleAction.binding); +// } else { +// QDeclarativePropertyPrivate::setBinding(qmlSimpleAction.property, 0); +// qmlSimpleAction.property.write(qmlSimpleAction.value); +// } +// } +// } +// } + +// if (m_expressionHash.contains(name)) { +// if (m_expressionHash[name].second) { +// QDeclarativeProperty metaProperty(targetObject(), name, QDeclarativeEngine::contextForObject(targetObject())); +// if (metaProperty.isValid() && QDeclarativePropertyPrivate::binding(metaProperty) == m_expressionHash[name].second.data()) +// QDeclarativePropertyPrivate::setBinding(metaProperty, 0, QDeclarativePropertyPrivate::BypassInterceptor | QDeclarativePropertyPrivate::DontRemoveBinding); +// m_expressionHash[name].second.data()->destroy(); +// } +// m_expressionHash.remove(name); +// } + +// if (hasActionForProperty(name)) { +// removeActionForProperty(name); +// } + + +//} + +//QVariant QmlPropertyChangesObject::variantValue(const QString &name) const +//{ +// if (hasActionForProperty(name)) { +// QDeclarativeAction &qmlAction = qmlActionForProperty(name); +// return qmlAction.toValue; +// } + +// return QVariant(); +//} + +//QString QmlPropertyChangesObject::expression(const QString &name) const +//{ +// if (hasActionForProperty(name)) { +// QDeclarativeAction &qmlAction = qmlActionForProperty(name); +// if (qmlAction.toBinding) +// return qmlAction.toBinding->expression(); +// } + +// return QString(); +//} + +//bool QmlPropertyChangesObject::hasVariantValue(const QString &name) const +//{ +// if (hasActionForProperty(name)) +// return qmlActionForProperty(name).toValue.isValid(); + +// return false; +//} + +//bool QmlPropertyChangesObject::hasExpression(const QString &name) const +//{ +// return m_expressionHash.contains(name); +//} + +//bool QmlPropertyChangesObject::updateStateVariant(const QString &name, const QVariant &value) +//{ +// if (hasActionForProperty(name)) { +// QDeclarativeAction &qmlAction = qmlActionForProperty(name); +// if (qmlAction.fromValue.isValid()) { +// qmlAction.fromValue = value; +// updateRevertValueAndBinding(name); + +// return true; +// } +// } + +// return false; +//} + +//bool QmlPropertyChangesObject::updateStateBinding(const QString &name, const QString &expression) +//{ +// if (hasActionForProperty(name)) { +// QDeclarativeContext *context = QDeclarativeEngine::contextForObject(targetObject()); +// QDeclarativeProperty metaProperty(targetObject(), name, context); +// QDeclarativeAction &qmlAction = qmlActionForProperty(name); + +// if (qmlAction.fromBinding) { +// if (QDeclarativePropertyPrivate::binding(qmlAction.property) == qmlAction.fromBinding) +// QDeclarativePropertyPrivate::setBinding(qmlAction.property, 0); +// qmlAction.fromBinding->destroy(); + +// } + +// QDeclarativeBinding *binding = new QDeclarativeBinding(expression, targetObject(), context, this); +// binding->setTarget(metaProperty); +// binding->setNotifyOnValueChanged(true); +// qmlAction.fromBinding = binding; + +// if (m_expressionHash.contains(name)) +// QDeclarativePropertyPrivate::setBinding(qmlAction.property, binding); + +// updateRevertValueAndBinding(name); + +// return true; +// } + +// return false; +//} + +//bool QmlPropertyChangesObject::resetStateProperty(const QString &name, const QVariant &resetValue) +//{ +// if (hasActionForProperty(name)) { +// QDeclarativeContext *context = QDeclarativeEngine::contextForObject(targetObject()); +// QDeclarativeProperty metaProperty(targetObject(), name, context); +// QDeclarativeAction &qmlAction = qmlActionForProperty(name); +// if (m_expressionHash.contains(name) && m_expressionHash[name].second) { +// m_expressionHash[name].second.data()->destroy(); +// qmlAction.toBinding = 0; +// } + +// qmlAction.fromValue = resetValue; -QDeclarativeAction QmlPropertyChangesObject::createQDeclarativeAction(const QString &propertyName) -{ - QDeclarativeProperty qmlMetaProperty = createMetaProperty(propertyName); - - QDeclarativeAction qmlAction; - qmlAction.restore = true; - qmlAction.property = qmlMetaProperty; - qmlAction.fromValue = qmlMetaProperty.read(); - qmlAction.fromBinding = QDeclarativePropertyPrivate::binding(qmlMetaProperty); - qmlAction.specifiedObject = m_targetObject.data(); - qmlAction.specifiedProperty = propertyName; - qmlAction.event = 0; - - return qmlAction; -} - -bool QmlPropertyChangesObject::hasActionForProperty(const QString &propertyName) const -{ - for(ActionList::iterator actionIterator = m_qmlActionList.begin(); - actionIterator != m_qmlActionList.end(); - ++actionIterator) { - QDeclarativeAction &qmlAction = *actionIterator; - if (qmlAction.specifiedProperty == propertyName) { - return true; - } - } - - return false; -} - -QDeclarativeAction &QmlPropertyChangesObject::qmlActionForProperty(const QString &propertyName) const -{ - for(ActionList::iterator actionIterator = m_qmlActionList.begin(); - actionIterator != m_qmlActionList.end(); - ++actionIterator) { - QDeclarativeAction &qmlAction = *actionIterator; - if (qmlAction.specifiedProperty == propertyName) - return qmlAction; - } - - Q_ASSERT(false); +// updateRevertValueAndBinding(name); + +// removeActionForProperty(name); - return m_qmlActionList[0]; -} - -void QmlPropertyChangesObject::removeActionForProperty(const QString &propertyName) -{ - QMutableListIterator<QDeclarativeAction> actionIterator(m_qmlActionList); - while (actionIterator.hasNext()) { - QDeclarativeAction &qmlAction = actionIterator.next(); - if (qmlAction.specifiedProperty == propertyName) - actionIterator.remove(); - } - - if (statePrivate()) { - QMutableListIterator<QDeclarativeSimpleAction> simpleActionIterator(statePrivate()->revertList); - while (simpleActionIterator.hasNext()) { - QDeclarativeSimpleAction &qmlSimpleAction = simpleActionIterator.next(); - if (qmlSimpleAction.specifiedProperty == propertyName && qmlSimpleAction.specifiedObject == targetObject()) { - simpleActionIterator.remove(); - } - } - } -} - -bool QmlPropertyChangesObject::isActive() const -{ - if (state() && stateGroup()) - return state()->name() == stateGroup()->state(); - - return false; -} -QmlPropertyChangesObject::~QmlPropertyChangesObject() -{ - removeFromStateRevertList(); -} - -void QmlPropertyChangesObject::removeFromStateRevertList() -{ - if (statePrivate()) { - QMutableListIterator<QDeclarativeSimpleAction> simpleActionIterator(statePrivate()->revertList); - while(simpleActionIterator.hasNext()) { - QDeclarativeSimpleAction &simpleAction = simpleActionIterator.next(); - if (simpleAction.specifiedObject == targetObject()) { - if (simpleAction.property.isValid()) { - if (simpleAction.binding) { - QDeclarativePropertyPrivate::setBinding(simpleAction.property, simpleAction.binding); - } else if (simpleAction.value.isValid()) { - QDeclarativePropertyPrivate::setBinding(simpleAction.property, 0); - simpleAction.property.write(simpleAction.value); - } - } - simpleActionIterator.remove(); - } - } - } -} - -void QmlPropertyChangesObject::addToStateRevertList() -{ - if (isActive() && statePrivate()) { - QListIterator<QDeclarativeAction> actionIterator(m_qmlActionList); - while (actionIterator.hasNext()) { - const QDeclarativeAction &qmlAction = actionIterator.next(); - QDeclarativeSimpleAction simpleAction(qmlAction); - simpleAction.binding = qmlAction.fromBinding; - simpleAction.value = qmlAction.fromValue; - statePrivate()->revertList.append(simpleAction); - if (qmlAction.toBinding) - QDeclarativePropertyPrivate::setBinding(qmlAction.property, qmlAction.toBinding); - else - qmlAction.property.write(qmlAction.toValue); - } - } -} - -void QmlPropertyChangesObject::updateRevertValueAndBinding(const QString &name) -{ - if (isActive() && statePrivate()) { - typedef QList<QDeclarativeSimpleAction> SimpleActionList; - if (!statePrivate()->revertList.isEmpty()) { - for(SimpleActionList::iterator actionIterator = statePrivate()->revertList.begin(); - actionIterator != statePrivate()->revertList.end(); - ++actionIterator) { - //simple action defines values and bindings to revert current state - QDeclarativeSimpleAction &simpleAction = *actionIterator; - if (simpleAction.specifiedObject == targetObject() - && simpleAction.specifiedProperty == name) { - const QDeclarativeAction &qmlAction = qmlActionForProperty(name); - simpleAction.value = qmlAction.fromValue; - simpleAction.binding = qmlAction.fromBinding; - simpleAction.specifiedObject = qmlAction.specifiedObject; - simpleAction.specifiedProperty = qmlAction.specifiedProperty; - simpleAction.property = qmlAction.property; - return; //return since we just had to update exisisting simple action - } - } - } - - //simple action does not exist, yet - - const QDeclarativeAction &qmlAction = qmlActionForProperty(name); - QDeclarativeSimpleAction simpleAction(qmlAction); - simpleAction.binding = qmlAction.fromBinding; - simpleAction.value = qmlAction.fromValue; - statePrivate()->revertList.append(simpleAction); - } -} - -void QmlPropertyChangesObject::setVariantValue(const QString &name, const QVariant & value) -{ - if (!hasActionForProperty(name)) { - m_qmlActionList.append(createQDeclarativeAction(name)); - } - - QDeclarativeAction &qmlAction = qmlActionForProperty(name); - if (qmlAction.fromBinding) - qmlAction.fromBinding->setEnabled(false, QDeclarativePropertyPrivate::BypassInterceptor | QDeclarativePropertyPrivate::DontRemoveBinding); - - qmlAction.toValue = value; -} - -void QmlPropertyChangesObject::setExpression(const QString &name, const QString &expression) -{ - if (!hasActionForProperty(name)) { - m_qmlActionList.append(createQDeclarativeAction(name)); - } - - QDeclarativeContext *context = QDeclarativeEngine::contextForObject(targetObject()); - QDeclarativeBinding *binding = 0; - QDeclarativeProperty metaProperty(targetObject(), name, context); - - QDeclarativeAction &qmlAction = qmlActionForProperty(name); - if (m_expressionHash.contains(name) && m_expressionHash[name].second) { - if (QDeclarativePropertyPrivate::binding(metaProperty) == m_expressionHash[name].second.data()) - QDeclarativePropertyPrivate::setBinding(metaProperty, 0, QDeclarativePropertyPrivate::BypassInterceptor | QDeclarativePropertyPrivate::DontRemoveBinding); - m_expressionHash.take(name).second->destroy(); - qmlAction.toBinding = 0; - } - - - if (metaProperty.isValid() && metaProperty.isProperty()) { - binding = new QDeclarativeBinding(expression, targetObject(), context, this); - binding->setTarget(metaProperty); - binding->setNotifyOnValueChanged(true); - qmlAction.toBinding = binding; - m_expressionHash.insert(name, ExpressionPair(expression, binding)); - } else { - m_expressionHash.insert(name, ExpressionPair(expression, static_cast<QDeclarativeBinding*>(0))); - } - - updateRevertValueAndBinding(name); - if (isActive() && binding) - QDeclarativePropertyPrivate::setBinding(metaProperty, binding, QDeclarativePropertyPrivate::BypassInterceptor | QDeclarativePropertyPrivate::DontRemoveBinding); -} - -void QmlPropertyChangesObject::removeVariantValue(const QString &name) -{ - if (hasActionForProperty(name)) { - QDeclarativeAction &qmlAction = qmlActionForProperty(name); - if (hasExpression(name)) { - qmlAction.toValue = QVariant(); - updateRevertValueAndBinding(name); - } else { - if (qmlAction.fromBinding) - QDeclarativePropertyPrivate::setBinding(qmlAction.property, qmlAction.fromBinding); - else - qmlAction.property.write(qmlAction.fromValue); - removeActionForProperty(name); - } - } -} - -void QmlPropertyChangesObject::removeExpression(const QString &name) -{ - if (hasActionForProperty(name)) { - QDeclarativeAction &qmlAction = qmlActionForProperty(name); - if (hasVariantValue(name)) { - ExpressionPair expr = m_expressionHash.take(name); - if (expr.second) - expr.second.data()->destroy(); - qmlAction.toBinding = 0; - updateRevertValueAndBinding(name); - qmlAction.property.write(qmlAction.toValue); - } else { - if (qmlAction.fromBinding) - QDeclarativePropertyPrivate::setBinding(qmlAction.property, qmlAction.fromBinding); - else - qmlAction.property.write(qmlAction.fromValue); - removeActionForProperty(name); - } - } -} - -void QmlPropertyChangesObject::resetProperty(const QString &name) -{ - if (statePrivate()) { - QMutableListIterator<QDeclarativeSimpleAction> simpleActionIterator(statePrivate()->revertList); - while (simpleActionIterator.hasNext()) { - QDeclarativeSimpleAction &qmlSimpleAction = simpleActionIterator.next(); - if (qmlSimpleAction.specifiedProperty == name && qmlSimpleAction.specifiedObject == targetObject()) { - if (qmlSimpleAction.binding) { - qDebug() << qmlSimpleAction.binding->expression(); - QDeclarativePropertyPrivate::setBinding(qmlSimpleAction.property, qmlSimpleAction.binding); - } else { - QDeclarativePropertyPrivate::setBinding(qmlSimpleAction.property, 0); - qmlSimpleAction.property.write(qmlSimpleAction.value); - } - } - } - } - - if (m_expressionHash.contains(name)) { - if (m_expressionHash[name].second) { - QDeclarativeProperty metaProperty(targetObject(), name, QDeclarativeEngine::contextForObject(targetObject())); - if (metaProperty.isValid() && QDeclarativePropertyPrivate::binding(metaProperty) == m_expressionHash[name].second.data()) - QDeclarativePropertyPrivate::setBinding(metaProperty, 0, QDeclarativePropertyPrivate::BypassInterceptor | QDeclarativePropertyPrivate::DontRemoveBinding); - m_expressionHash[name].second.data()->destroy(); - } - m_expressionHash.remove(name); - } - - if (hasActionForProperty(name)) { - removeActionForProperty(name); - } - - -} - -QVariant QmlPropertyChangesObject::variantValue(const QString &name) const -{ - if (hasActionForProperty(name)) { - QDeclarativeAction &qmlAction = qmlActionForProperty(name); - return qmlAction.toValue; - } - - return QVariant(); -} - -QString QmlPropertyChangesObject::expression(const QString &name) const -{ - if (hasActionForProperty(name)) { - QDeclarativeAction &qmlAction = qmlActionForProperty(name); - if (qmlAction.toBinding) - return qmlAction.toBinding->expression(); - } - - return QString(); -} - -bool QmlPropertyChangesObject::hasVariantValue(const QString &name) const -{ - if (hasActionForProperty(name)) - return qmlActionForProperty(name).toValue.isValid(); - - return false; -} - -bool QmlPropertyChangesObject::hasExpression(const QString &name) const -{ - return m_expressionHash.contains(name); -} - -bool QmlPropertyChangesObject::updateStateVariant(const QString &name, const QVariant &value) -{ - if (hasActionForProperty(name)) { - QDeclarativeAction &qmlAction = qmlActionForProperty(name); - if (qmlAction.fromValue.isValid()) { - qmlAction.fromValue = value; - updateRevertValueAndBinding(name); - - return true; - } - } - - return false; -} - -bool QmlPropertyChangesObject::updateStateBinding(const QString &name, const QString &expression) -{ - if (hasActionForProperty(name)) { - QDeclarativeContext *context = QDeclarativeEngine::contextForObject(targetObject()); - QDeclarativeProperty metaProperty(targetObject(), name, context); - QDeclarativeAction &qmlAction = qmlActionForProperty(name); - - if (qmlAction.fromBinding) { - if (QDeclarativePropertyPrivate::binding(qmlAction.property) == qmlAction.fromBinding) - QDeclarativePropertyPrivate::setBinding(qmlAction.property, 0); - qmlAction.fromBinding->destroy(); - - } - - QDeclarativeBinding *binding = new QDeclarativeBinding(expression, targetObject(), context, this); - binding->setTarget(metaProperty); - binding->setNotifyOnValueChanged(true); - qmlAction.fromBinding = binding; - - if (m_expressionHash.contains(name)) - QDeclarativePropertyPrivate::setBinding(qmlAction.property, binding); - - updateRevertValueAndBinding(name); - - return true; - } - - return false; -} - -bool QmlPropertyChangesObject::resetStateProperty(const QString &name, const QVariant &resetValue) -{ - if (hasActionForProperty(name)) { - QDeclarativeContext *context = QDeclarativeEngine::contextForObject(targetObject()); - QDeclarativeProperty metaProperty(targetObject(), name, context); - QDeclarativeAction &qmlAction = qmlActionForProperty(name); - if (m_expressionHash.contains(name) && m_expressionHash[name].second) { - m_expressionHash[name].second.data()->destroy(); - qmlAction.toBinding = 0; - } - - qmlAction.fromValue = resetValue; - - updateRevertValueAndBinding(name); - - removeActionForProperty(name); - - return true; - } - - return false; -} +// return true; +// } + +// return false; +//} } // namespace Internal } // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/designercore/instances/qmlpropertychangesnodeinstance.h b/src/plugins/qmldesigner/designercore/instances/qmlpropertychangesnodeinstance.h index 2a3b7926479059b324d9068adf9189c90b459bd0..dfd28a9fc6699e7df09cef1674d06f09e88d0ecb 100644 --- a/src/plugins/qmldesigner/designercore/instances/qmlpropertychangesnodeinstance.h +++ b/src/plugins/qmldesigner/designercore/instances/qmlpropertychangesnodeinstance.h @@ -32,6 +32,7 @@ #include "objectnodeinstance.h" #include <private/qdeclarativestateoperations_p.h> +#include <private/qdeclarativepropertychanges_p.h> #include <QPair> #include <QWeakPointer> @@ -48,74 +49,74 @@ class QmlPropertyChangesNodeInstance; // Original QmlPropertyChanges class requires a custom parser // work around this by writing a replacement class -class QmlPropertyChangesObject : public QDeclarativeStateOperation -{ - Q_OBJECT - Q_PROPERTY(QObject *target READ targetObject WRITE setTargetObject) - Q_PROPERTY(bool restoreEntryValues READ restoreEntryValues WRITE setRestoreEntryValues) - Q_PROPERTY(bool explicit READ isExplicit WRITE setIsExplicit) +//class QmlPropertyChangesObject : public QDeclarativeStateOperation +//{ +// Q_OBJECT +// Q_PROPERTY(QObject *target READ targetObject WRITE setTargetObject) +// Q_PROPERTY(bool restoreEntryValues READ restoreEntryValues WRITE setRestoreEntryValues) +// Q_PROPERTY(bool explicit READ isExplicit WRITE setIsExplicit) - typedef QPair<QString, QWeakPointer<QDeclarativeBinding> > ExpressionPair; -public: - ~QmlPropertyChangesObject(); - QObject *targetObject() const; - void setTargetObject(QObject *object); +// typedef QPair<QString, QWeakPointer<QDeclarativeBinding> > ExpressionPair; +//public: +// ~QmlPropertyChangesObject(); +// QObject *targetObject() const; +// void setTargetObject(QObject *object); - bool restoreEntryValues() const; - void setRestoreEntryValues(bool restore); +// bool restoreEntryValues() const; +// void setRestoreEntryValues(bool restore); - bool isExplicit() const; - void setIsExplicit(bool isExplicit); +// bool isExplicit() const; +// void setIsExplicit(bool isExplicit); - virtual ActionList actions(); +// virtual ActionList actions(); - void setVariantValue(const QString &name, const QVariant & value); - void setExpression(const QString &name, const QString &expression); - void removeVariantValue(const QString &name); - void removeExpression(const QString &name); +// void setVariantValue(const QString &name, const QVariant & value); +// void setExpression(const QString &name, const QString &expression); +// void removeVariantValue(const QString &name); +// void removeExpression(const QString &name); - void resetProperty(const QString &name); +// void resetProperty(const QString &name); - QVariant variantValue(const QString &name) const; - QString expression(const QString &name) const; +// QVariant variantValue(const QString &name) const; +// QString expression(const QString &name) const; - bool hasVariantValue(const QString &name) const; - bool hasExpression(const QString &name) const; +// bool hasVariantValue(const QString &name) const; +// bool hasExpression(const QString &name) const; - QmlPropertyChangesObject(); +// QmlPropertyChangesObject(); - bool updateStateVariant(const QString &propertyName, const QVariant &value); - bool updateStateBinding(const QString &propertyName, const QString &expression); - bool resetStateProperty(const QString &propertyName, const QVariant &resetValue); +// bool updateStateVariant(const QString &propertyName, const QVariant &value); +// bool updateStateBinding(const QString &propertyName, const QString &expression); +// bool resetStateProperty(const QString &propertyName, const QVariant &resetValue); - QDeclarativeState *state() const; - void updateRevertValueAndBinding(const QString &name); +// QDeclarativeState *state() const; +// void updateRevertValueAndBinding(const QString &name); - void removeFromStateRevertList(); - void addToStateRevertList(); +// void removeFromStateRevertList(); +// void addToStateRevertList(); -private: // functions - bool isActive() const; +//private: // functions +// bool isActive() const; - QDeclarativeStatePrivate *statePrivate() const; +// QDeclarativeStatePrivate *statePrivate() const; - QDeclarativeStateGroup *stateGroup() const; - QDeclarativeProperty createMetaProperty(const QString &property); +// QDeclarativeStateGroup *stateGroup() const; +// QDeclarativeProperty createMetaProperty(const QString &property); - QDeclarativeAction &qmlActionForProperty(const QString &propertyName) const; - bool hasActionForProperty(const QString &propertyName) const; - void removeActionForProperty(const QString &propertyName); +// QDeclarativeAction &qmlActionForProperty(const QString &propertyName) const; +// bool hasActionForProperty(const QString &propertyName) const; +// void removeActionForProperty(const QString &propertyName); - QDeclarativeAction createQDeclarativeAction(const QString &propertyName); +// QDeclarativeAction createQDeclarativeAction(const QString &propertyName); -private: // variables - QWeakPointer<QObject> m_targetObject; - bool m_restoreEntryValues; - bool m_isExplicit; +//private: // variables +// QWeakPointer<QObject> m_targetObject; +// bool m_restoreEntryValues; +// bool m_isExplicit; - mutable ActionList m_qmlActionList; - QHash<QString, ExpressionPair> m_expressionHash; -}; +// mutable ActionList m_qmlActionList; +// QHash<QString, ExpressionPair> m_expressionHash; +//}; class QmlPropertyChangesNodeInstance : public ObjectNodeInstance { @@ -133,13 +134,13 @@ public: void reparent(const NodeInstance &oldParentInstance, const QString &oldParentProperty, const NodeInstance &newParentInstance, const QString &newParentProperty); protected: - QmlPropertyChangesNodeInstance(QmlPropertyChangesObject *object); - QmlPropertyChangesObject *changesObject() const; + QmlPropertyChangesNodeInstance(QDeclarativePropertyChanges *object); + QDeclarativePropertyChanges *changesObject() const; }; } // namespace Internal } // namespace QmlDesigner -QML_DECLARE_TYPE(QmlDesigner::Internal::QmlPropertyChangesObject) +//QML_DECLARE_TYPE(QmlDesigner::Internal::QmlPropertyChangesObject) #endif // QMLPROPERTYCHANGESNODEINSTANCE_H diff --git a/src/plugins/qmldesigner/designercore/instances/qmlstatenodeinstance.cpp b/src/plugins/qmldesigner/designercore/instances/qmlstatenodeinstance.cpp index bf7103c467dd744d90daad67f18e69f9fb4d4fad..2abb34501b7a4a8c553d09a9a19fa750ab83768c 100644 --- a/src/plugins/qmldesigner/designercore/instances/qmlstatenodeinstance.cpp +++ b/src/plugins/qmldesigner/designercore/instances/qmlstatenodeinstance.cpp @@ -127,42 +127,17 @@ void QmlStateNodeInstance::setPropertyBinding(const QString &name, const QString bool QmlStateNodeInstance::updateStateVariant(const NodeInstance &target, const QString &propertyName, const QVariant &value) { - // iterate over propertychange object and update values - QDeclarativeListReference listReference(stateObject(), "changes"); - for (int i = 0; i < listReference.count(); i++) { - //We also have parent and anchor changes - QmlPropertyChangesObject *changeObject = qobject_cast<QmlPropertyChangesObject*>(listReference.at(i)); - if (changeObject && target.isWrappingThisObject(changeObject->targetObject())) - return changeObject->updateStateVariant(propertyName, value); - } - - return false; + return stateObject()->changeValueInRevertList(target.internalObject(), propertyName.toLatin1(), value); } bool QmlStateNodeInstance::updateStateBinding(const NodeInstance &target, const QString &propertyName, const QString &expression) { - // iterate over propertychange object and update binding - QDeclarativeListReference listReference(stateObject(), "changes"); - for (int i = 0; i < listReference.count(); i++) { - QmlPropertyChangesObject *changeObject = qobject_cast<QmlPropertyChangesObject*>(listReference.at(i)); - if (changeObject && target.isWrappingThisObject(changeObject->targetObject())) - return changeObject->updateStateBinding(propertyName, expression); - } - - return false; + return stateObject()->changeValueInRevertList(target.internalObject(), propertyName.toLatin1(), expression); } bool QmlStateNodeInstance::resetStateProperty(const NodeInstance &target, const QString &propertyName, const QVariant &resetValue) { - // iterate over propertychange object and reset propertry - QDeclarativeListReference listReference(stateObject(), "changes"); - for (int i = 0; i < listReference.count(); i++) { - QmlPropertyChangesObject *changeObject = qobject_cast<QmlPropertyChangesObject*>(listReference.at(i)); - if (changeObject && target.isWrappingThisObject(changeObject->targetObject())) - return changeObject->resetStateProperty(propertyName, resetValue); - } - - return false; + return stateObject()->removeEntryInRevertList(target.internalObject(), propertyName.toLatin1()); } } // namespace Internal