Commit 3b62aeaf authored by Thomas Hartmann's avatar Thomas Hartmann
Browse files

QmlDesigner: fixing states

parent 0fe36330
......@@ -120,6 +120,8 @@ public:
QVariant defaultValue(const QString &name) const;
QString instanceType(const QString &name) const;
bool hasBindingForProperty(const QString &name) const;
bool isValid() const;
void makeInvalid();
bool hasContent() const;
......
......@@ -67,6 +67,7 @@ public:
bool hasProperty(const QString &name) const;
bool hasBindingProperty(const QString &name) const;
bool instanceHasBinding(const QString &name) const;
bool propertyAffectedByCurrentState(const QString &name) const;
QVariant modelValue(const QString &name) const;
QString expression(const QString &name) const;
......
......@@ -418,6 +418,11 @@ QVariant NodeInstance::property(const QString &name) const
return m_nodeInstance->property(name);
}
bool NodeInstance::hasBindingForProperty(const QString &name) const
{
return m_nodeInstance->hasBindingForProperty(name);
}
/*!
\brief Returns the property default value of the property of this NodeInstance.
\returns QVariant default value which is the reset value to
......
......@@ -548,6 +548,13 @@ void ObjectNodeInstance::refreshProperty(const QString &name)
property.write(oldValue);
}
bool ObjectNodeInstance::hasBindingForProperty(const QString &name) const
{
QDeclarativeProperty property(object(), name, context());
return QDeclarativePropertyPrivate::binding(property);
}
void ObjectNodeInstance::doResetProperty(const QString &propertyName)
{
m_modelAbstractPropertyHash.remove(propertyName);
......
......@@ -163,6 +163,8 @@ public:
virtual bool hasContent() const;
bool hasBindingForProperty(const QString &name) const;
QDeclarativeContext *context() const;
virtual bool updateStateVariant(const NodeInstance &target, const QString &propertyName, const QVariant &value);
......
......@@ -229,7 +229,11 @@ void QmlPropertyChangesNodeInstance::resetProperty(const QString &name)
void QmlPropertyChangesNodeInstance::reparent(const NodeInstance &oldParentInstance, const QString &oldParentProperty, const NodeInstance &newParentInstance, const QString &newParentProperty)
{
changesObject()->detachFromState();
ObjectNodeInstance::reparent(oldParentInstance, oldParentProperty, newParentInstance, newParentProperty);
changesObject()->attachToState();
}
//QDeclarativeState *QmlPropertyChangesObject::state() const
......
......@@ -100,9 +100,7 @@ QDeclarativeStateGroup *QmlStateNodeInstance::stateGroup() const
bool QmlStateNodeInstance::isStateActive() const
{
Q_ASSERT(stateObject());
Q_ASSERT(stateGroup());
return (stateGroup()->state() == property("name"));
return stateObject() && stateGroup() && stateGroup()->state() == property("name");
}
void QmlStateNodeInstance::setPropertyVariant(const QString &name, const QVariant &value)
......@@ -137,7 +135,7 @@ bool QmlStateNodeInstance::updateStateBinding(const NodeInstance &target, const
bool QmlStateNodeInstance::resetStateProperty(const NodeInstance &target, const QString &propertyName, const QVariant &resetValue)
{
return stateObject()->removeEntryInRevertList(target.internalObject(), propertyName.toLatin1());
return stateObject()->removeEntryFromRevertList(target.internalObject(), propertyName.toLatin1());
}
} // namespace Internal
......
......@@ -47,7 +47,7 @@ void QmlObjectNode::setVariantProperty(const QString &name, const QVariant &valu
throw new InvalidModelNodeException(__LINE__, __FUNCTION__, __FILE__);
if (isInBaseState()) {
modelNode().variantProperty(name) = value; //basestate
modelNode().variantProperty(name).setValue(value); //basestate
} else {
modelNode().validId();
......@@ -95,7 +95,7 @@ instanciated instance of this object.
*/
QVariant QmlObjectNode::instanceValue(const QString &name) const
{
return instanceValue(modelNode(), name);
return nodeInstance().property(name);
}
......@@ -392,6 +392,15 @@ QString QmlObjectNode::instanceType(const QString &name) const
return nodeInstance().instanceType(name);
}
bool QmlObjectNode::instanceHasBinding(const QString &name) const
{
QmlModelView *modelView = qobject_cast<QmlModelView*>(modelNode().view());
if (!modelView)
throw new InvalidModelNodeException(__LINE__, __FUNCTION__, __FILE__);
return nodeInstance().hasBindingForProperty(name);
}
NodeInstance QmlObjectNode::nodeInstance() const
{
return qmlModelView()->nodeInstanceView()->instanceForNode(modelNode());
......
......@@ -4794,6 +4794,7 @@ void tst_TestCore::testInstancesBindingsInStatesStress()
}
QmlItemNode(node3).setBindingProperty("width", "parent.x + 30");
QVERIFY(QmlItemNode(node3).instanceHasBinding("width"));
QCOMPARE(QmlItemNode(node3).instanceValue("width").toInt(), 130);
view->setCurrentState(view->baseState());
......
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