Commit 01eece3d authored by Marco Bubke's avatar Marco Bubke

QmlDesigner: Fix state switching

Task-number: QTCREATORBUG-4062

Change-Id: I2a04c5a04ef40390772fe46f587bc60c02a4bab1
Reviewed-on: http://codereview.qt.nokia.com/1605Reviewed-by: default avatarQt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: default avatarThomas Hartmann <Thomas.Hartmann@nokia.com>
parent 086e3ad3
......@@ -187,5 +187,13 @@ void Qt4RenderNodeInstanceServer::completeComponent(const CompleteComponentComma
nodeInstanceClient()->pixmapChanged(createPixmapChangedCommand(instanceList));
}
void Qt4RenderNodeInstanceServer::changeState(const ChangeStateCommand &command)
{
Qt4NodeInstanceServer::changeState(command);
foreach (QGraphicsItem *item, declarativeView()->items()) {
item->update();
QGraphicsItemPrivate::get(item)->notifyBoundingRectChanged = 1;
}
}
} // namespace QmlDesigner
......@@ -46,6 +46,7 @@ public:
void createScene(const CreateSceneCommand &command);
void clearScene(const ClearSceneCommand &command);
void completeComponent(const CompleteComponentCommand &command);
void changeState(const ChangeStateCommand &command);
protected:
void collectItemChangesAndSendChangeCommands();
......
......@@ -122,7 +122,6 @@ public:
void emitRewriterBeginTransaction();
void emitRewriterEndTransaction();
void emitInstanceToken(const QString &token, int number, const QVector<ModelNode> &nodeVector);
void emitActualStateChanged(const ModelNode &node);
void sendTokenToInstances(const QString &token, int number, const QVector<ModelNode> &nodeVector);
......@@ -178,6 +177,9 @@ public:
NodeInstanceView *nodeInstanceView() const;
RewriterView *rewriterView() const;
void setAcutalStateNode(const ModelNode &node);
ModelNode actualStateNode() const;
void resetView();
protected:
......
......@@ -130,8 +130,6 @@ public:
NodeInstance activeStateInstance() const;
void activateState(const NodeInstance &instance);
void activateBaseState();
void valuesChanged(const ValuesChangedCommand &command);
void pixmapChanged(const PixmapChangedCommand &command);
......@@ -151,6 +149,9 @@ signals:
void qmlPuppetCrashed();
private: // functions
void activateState(const NodeInstance &instance);
void activateBaseState();
NodeInstance rootNodeInstance() const;
NodeInstance loadNode(const ModelNode &node);
......
......@@ -77,8 +77,6 @@ protected:
void addChangeSetIfNotExists(const ModelNode &node);
static QmlModelState createBaseState(const QmlModelView *view);
private:
bool m_isBaseState;
};
} //QmlDesigner
......
......@@ -172,6 +172,13 @@ void NodeInstanceView::modelAttached(Model *model)
if (!isSkippedRootNode(rootModelNode()))
nodeInstanceServer()->createScene(createCreateSceneCommand());
ModelNode stateNode = actualStateNode();
if (stateNode.isValid() && stateNode.metaInfo().isSubclassOf("QtQuick.State", 1, 0)) {
NodeInstance newStateInstance = instanceForNode(stateNode);
activateState(newStateInstance);
}
}
void NodeInstanceView::modelAboutToBeDetached(Model * model)
......@@ -210,6 +217,12 @@ void NodeInstanceView::restartProcess()
if (!isSkippedRootNode(rootModelNode()))
nodeInstanceServer()->createScene(createCreateSceneCommand());
ModelNode stateNode = actualStateNode();
if (stateNode.isValid() && stateNode.metaInfo().isSubclassOf("QtQuick.State", 1, 0)) {
NodeInstance newStateInstance = instanceForNode(stateNode);
activateState(newStateInstance);
}
}
}
......@@ -539,8 +552,15 @@ void NodeInstanceView::rewriterEndTransaction()
}
void NodeInstanceView::actualStateChanged(const ModelNode &/*node*/)
void NodeInstanceView::actualStateChanged(const ModelNode &node)
{
NodeInstance newStateInstance = instanceForNode(node);
if (newStateInstance.isValid() && node.metaInfo().isSubclassOf("QtQuick.State", 1, 0)) {
nodeInstanceView()->activateState(newStateInstance);
} else {
nodeInstanceView()->activateBaseState();
}
}
......@@ -693,16 +713,11 @@ NodeInstance NodeInstanceView::loadNode(const ModelNode &node)
void NodeInstanceView::activateState(const NodeInstance &instance)
{
nodeInstanceServer()->changeState(ChangeStateCommand(instance.instanceId()));
// activateBaseState();
// NodeInstance stateInstance(instance);
// stateInstance.activateState();
}
void NodeInstanceView::activateBaseState()
{
nodeInstanceServer()->changeState(ChangeStateCommand(-1));
// if (activeStateInstance().isValid())
// activeStateInstance().deactivateState();
}
void NodeInstanceView::removeRecursiveChildRelationship(const ModelNode &removedNode)
......@@ -1103,8 +1118,10 @@ QImage NodeInstanceView::statePreviewImage(const ModelNode &stateNode) const
void NodeInstanceView::setPathToQt(const QString &pathToQt)
{
m_pathToQt = pathToQt;
restartProcess();
if (m_pathToQt != pathToQt) {
m_pathToQt = pathToQt;
restartProcess();
}
}
void NodeInstanceView::statePreviewImagesChanged(const StatePreviewImageChangedCommand &command)
......
......@@ -447,8 +447,9 @@ void AbstractView::emitRewriterEndTransaction()
model()->m_d->notifyRewriterEndTransaction();
}
void AbstractView::emitActualStateChanged(const ModelNode &node)
void AbstractView::setAcutalStateNode(const ModelNode &node)
{
Internal::WriteLocker locker(m_model.data());
if (model())
model()->m_d->notifyActualStateChanged(node);
}
......@@ -460,4 +461,9 @@ void AbstractView::changeRootNodeType(const QString &type, int majorVersion, int
m_model.data()->m_d->changeRootNodeType(type, majorVersion, minorVersion);
}
ModelNode AbstractView::actualStateNode() const
{
return ModelNode(m_model.data()->m_d->actualStateNode(), m_model.data(), const_cast<AbstractView*>(this));
}
} // namespace QmlDesigner
......@@ -605,6 +605,8 @@ void ModelPrivate::notifyActualStateChanged(const ModelNode &node)
bool resetModel = false;
QString description;
m_acutalStateNode = node.internalNode();
try {
if (rewriterView())
rewriterView()->actualStateChanged(ModelNode(node.internalNode(), model(), rewriterView()));
......@@ -1638,6 +1640,11 @@ bool ModelPrivate::isWriteLocked() const
return m_writeLock;
}
InternalNode::Pointer ModelPrivate::actualStateNode() const
{
return m_acutalStateNode;
}
WriteLocker::WriteLocker(ModelPrivate *model)
: m_model(model)
......
......@@ -218,6 +218,8 @@ public:
void setNodeInstanceView(NodeInstanceView *nodeInstanceView);
NodeInstanceView *nodeInstanceView() const;
InternalNodePointer actualStateNode() const;
private: //functions
void removePropertyWithoutNotification(const InternalPropertyPointer &property);
void removeAllSubNodes(const InternalNodePointer &node);
......@@ -237,6 +239,8 @@ private:
QHash<QString,InternalNodePointer> m_idNodeHash;
QHash<qint32, InternalNodePointer> m_internalIdNodeHash;
QSet<InternalNodePointer> m_nodeSet;
InternalNodePointer m_acutalStateNode;
InternalNodePointer m_rootInternalNode;
......
......@@ -63,12 +63,12 @@ void QmlModelView::setCurrentState(const QmlModelState &state)
if (!state.isValid())
return;
emitActualStateChanged(state.modelNode());
setAcutalStateNode(state.modelNode());
}
QmlModelState QmlModelView::currentState() const
{
return m_state;
return QmlModelState(actualStateNode());
}
QmlModelState QmlModelView::baseState() const
......@@ -334,14 +334,10 @@ bool QmlModelView::hasInstanceForModelNode(const ModelNode &modelNode)
void QmlModelView::modelAttached(Model *model)
{
AbstractView::modelAttached(model);
m_state = QmlModelState();
m_state = baseState();
Q_ASSERT(m_state.isBaseState());
}
void QmlModelView::modelAboutToBeDetached(Model *model)
{
m_state = QmlModelState();
AbstractView::modelAboutToBeDetached(model);
}
......@@ -452,10 +448,6 @@ void QmlModelView::actualStateChanged(const ModelNode &node)
if (!newState.isValid())
newState = baseState();
activateState(newState);
m_state = newState;
if (newState != oldState)
stateChanged(newState, oldState);
......@@ -476,28 +468,6 @@ void QmlModelView::nodeInstancePropertyChanged(const ModelNode &node, const QStr
otherPropertyChanged(qmlObjectNode, propertyName);
}
void QmlModelView::activateState(const QmlModelState &state)
{
if (!state.isValid())
return;
if (m_state == state)
return;
m_state = state; //This is hacky. m_state should be controlled by the instances
//### todo: If the state thumbnail code gets refactored.
// this is not necessary anymore.
NodeInstance newStateInstance = instanceForModelNode(state.modelNode());
if (state.isBaseState()) {
nodeInstanceView()->activateBaseState();
} else {
nodeInstanceView()->activateState(newStateInstance);
}
}
void QmlModelView::transformChanged(const QmlObjectNode &/*qmlObjectNode*/, const QString &/*propertyName*/)
{
}
......
......@@ -42,14 +42,12 @@
namespace QmlDesigner {
QmlModelState::QmlModelState()
: QmlModelNodeFacade(),
m_isBaseState(false)
: QmlModelNodeFacade()
{
}
QmlModelState::QmlModelState(const ModelNode &modelNode)
: QmlModelNodeFacade(modelNode),
m_isBaseState(false)
: QmlModelNodeFacade(modelNode)
{
}
......@@ -268,7 +266,7 @@ void QmlModelState::destroy()
bool QmlModelState::isBaseState() const
{
return m_isBaseState && modelNode().isRootNode();
return !modelNode().isValid() || modelNode().isRootNode();
}
QmlModelState QmlModelState::duplicate(const QString &name) const
......@@ -308,7 +306,7 @@ QmlModelStateGroup QmlModelState::stateGroup() const
QmlModelState QmlModelState::createBaseState(const QmlModelView *view)
{
QmlModelState fxState(view->rootModelNode());
fxState.m_isBaseState = true;
return fxState;
}
......
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