Commit 14d1edd5 authored by Marco Bubke's avatar Marco Bubke

Cleanup QmlStateNodeInstance

parent e8d4b898
......@@ -131,6 +131,10 @@ public:
int penWidth() const;
void activateState();
void deactivateState();
void refreshState();
private: // functions
NodeInstance(const QSharedPointer<Internal::ObjectNodeInstance> &abstractInstance);
......
......@@ -594,4 +594,18 @@ QObject *NodeInstance::internalObject() const
return m_nodeInstance->object();
}
void NodeInstance::activateState()
{
m_nodeInstance->activateState();
}
void NodeInstance::deactivateState()
{
m_nodeInstance->deactivateState();
}
void NodeInstance::refreshState()
{
m_nodeInstance->refreshState();
}
}
......@@ -592,6 +592,18 @@ void ObjectNodeInstance::paintUpdate()
{
}
void ObjectNodeInstance::activateState()
{
}
void ObjectNodeInstance::deactivateState()
{
}
void ObjectNodeInstance::refreshState()
{
}
QStringList propertyNameForWritableProperties(QObject *object, const QString &baseName = QString())
{
QStringList propertyNameList;
......
......@@ -150,6 +150,10 @@ public:
virtual void updateAnchors();
virtual void paintUpdate();
virtual void activateState();
virtual void deactivateState();
virtual void refreshState();
void populateResetValueHash();
QVariant resetValue(const QString &propertyName) const;
......
......@@ -196,7 +196,7 @@ void QmlPropertyChangesNodeInstance::updateStateInstance() const
|| !qmlStateInstance.modelNode().isValid())
return;
qmlStateInstance.setPropertyVariant(PROPERTY_STATEACTIONSCHANGED, true);
qmlStateInstance.refreshState();
}
} // namespace Internal
......
......@@ -33,9 +33,6 @@
namespace QmlDesigner {
namespace Internal {
const char * const ACTIVATESTATEPROPERTY = "__activateState";
const char * const STATEACTIONSCHANGED = "__stateActionsChanged";
/**
\class QmlStateNodeInstance
......@@ -65,52 +62,22 @@ QmlStateNodeInstance::Pointer
return instance;
}
void QmlStateNodeInstance::setPropertyVariant(const QString &name, const QVariant &value)
void QmlStateNodeInstance::activateState()
{
if (name == ACTIVATESTATEPROPERTY) {
Q_ASSERT(value.type() == QVariant::Bool);
bool shouldActivate = value.toBool();
if (shouldActivate != isStateActive()) {
if (shouldActivate) {
// QmlState *currentState = stateGroup()->findState(stateGroup()->state());
// stateObject()->apply(stateGroup(), 0, currentState);
// TODO: Will this activate transitions????
stateGroup()->setState(property("name").toString());
} else {
resetProperty(name);
}
}
} else if (name == PROPERTY_STATEACTIONSCHANGED) {
if (isStateActive()) {
stateGroup()->setState(QString());
stateGroup()->setState(property("name").toString());
}
} else {
ObjectNodeInstance::setPropertyVariant(name, value);
}
if (!isStateActive())
stateGroup()->setState(property("name").toString());
}
QVariant QmlStateNodeInstance::property(const QString &name) const
void QmlStateNodeInstance::deactivateState()
{
if (name == ACTIVATESTATEPROPERTY) {
return isStateActive();
} else {
return ObjectNodeInstance::property(name);
}
if (isStateActive())
stateGroup()->setState(QString());
}
void QmlStateNodeInstance::resetProperty(const QString &name)
void QmlStateNodeInstance::refreshState()
{
if (name == ACTIVATESTATEPROPERTY) {
if (isStateActive()) {
// TODO: Will this activate transitions????
stateGroup()->setState(QString());
}
} else {
ObjectNodeInstance::resetProperty(name);
}
deactivateState();
activateState();
}
QmlState *QmlStateNodeInstance::stateObject() const
......
......@@ -37,8 +37,6 @@ namespace QmlDesigner {
namespace Internal {
const char * const PROPERTY_STATEACTIONSCHANGED = "__stateActionsChanged";
class QmlStateNodeInstance : public ObjectNodeInstance
{
public:
......@@ -47,9 +45,9 @@ public:
static Pointer create(const NodeMetaInfo &metaInfo, QmlContext *context, QObject *objectToBeWrapped);
virtual void setPropertyVariant(const QString &name, const QVariant &value);
virtual QVariant property(const QString &name) const;
virtual void resetProperty(const QString &name);
void activateState();
void deactivateState();
void refreshState();
protected:
QmlStateNodeInstance(QmlState *object);
......
......@@ -307,14 +307,14 @@ void QmlModelView::stateChanged(const QmlModelState &newQmlModelState, const Qm
NodeInstance newStateInstance = instanceForModelNode(newQmlModelState.modelNode());
Q_ASSERT(newStateInstance.isValid());
if (!newQmlModelState.isBaseState())
newStateInstance.setPropertyVariant("__activateState", true);
newStateInstance.activateState();
}
if (oldQmlModelState.isValid()) {
NodeInstance oldStateInstance = instanceForModelNode(oldQmlModelState.modelNode());
Q_ASSERT(oldStateInstance.isValid());
if (!oldQmlModelState.isBaseState())
oldStateInstance.setPropertyVariant("__activateState", false);
oldStateInstance.deactivateState();
}
}
......
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