QmlDesigner: Fix state switching

Task-number: QTCREATORBUG-4062

Change-Id: I2a04c5a04ef40390772fe46f587bc60c02a4bab1
Reviewed-on: http://codereview.qt.nokia.com/1605
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Thomas Hartmann <Thomas.Hartmann@nokia.com>
This commit is contained in:
Marco Bubke
2011-07-13 17:53:14 +02:00
parent 086e3ad373
commit 01eece3d84
11 changed files with 64 additions and 52 deletions

View File

@@ -187,5 +187,13 @@ void Qt4RenderNodeInstanceServer::completeComponent(const CompleteComponentComma
nodeInstanceClient()->pixmapChanged(createPixmapChangedCommand(instanceList)); 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 } // namespace QmlDesigner

View File

@@ -46,6 +46,7 @@ public:
void createScene(const CreateSceneCommand &command); void createScene(const CreateSceneCommand &command);
void clearScene(const ClearSceneCommand &command); void clearScene(const ClearSceneCommand &command);
void completeComponent(const CompleteComponentCommand &command); void completeComponent(const CompleteComponentCommand &command);
void changeState(const ChangeStateCommand &command);
protected: protected:
void collectItemChangesAndSendChangeCommands(); void collectItemChangesAndSendChangeCommands();

View File

@@ -122,7 +122,6 @@ public:
void emitRewriterBeginTransaction(); void emitRewriterBeginTransaction();
void emitRewriterEndTransaction(); void emitRewriterEndTransaction();
void emitInstanceToken(const QString &token, int number, const QVector<ModelNode> &nodeVector); 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); void sendTokenToInstances(const QString &token, int number, const QVector<ModelNode> &nodeVector);
@@ -178,6 +177,9 @@ public:
NodeInstanceView *nodeInstanceView() const; NodeInstanceView *nodeInstanceView() const;
RewriterView *rewriterView() const; RewriterView *rewriterView() const;
void setAcutalStateNode(const ModelNode &node);
ModelNode actualStateNode() const;
void resetView(); void resetView();
protected: protected:

View File

@@ -130,8 +130,6 @@ public:
NodeInstance activeStateInstance() const; NodeInstance activeStateInstance() const;
void activateState(const NodeInstance &instance);
void activateBaseState();
void valuesChanged(const ValuesChangedCommand &command); void valuesChanged(const ValuesChangedCommand &command);
void pixmapChanged(const PixmapChangedCommand &command); void pixmapChanged(const PixmapChangedCommand &command);
@@ -151,6 +149,9 @@ signals:
void qmlPuppetCrashed(); void qmlPuppetCrashed();
private: // functions private: // functions
void activateState(const NodeInstance &instance);
void activateBaseState();
NodeInstance rootNodeInstance() const; NodeInstance rootNodeInstance() const;
NodeInstance loadNode(const ModelNode &node); NodeInstance loadNode(const ModelNode &node);

View File

@@ -77,8 +77,6 @@ protected:
void addChangeSetIfNotExists(const ModelNode &node); void addChangeSetIfNotExists(const ModelNode &node);
static QmlModelState createBaseState(const QmlModelView *view); static QmlModelState createBaseState(const QmlModelView *view);
private:
bool m_isBaseState;
}; };
} //QmlDesigner } //QmlDesigner

View File

@@ -172,6 +172,13 @@ void NodeInstanceView::modelAttached(Model *model)
if (!isSkippedRootNode(rootModelNode())) if (!isSkippedRootNode(rootModelNode()))
nodeInstanceServer()->createScene(createCreateSceneCommand()); 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) void NodeInstanceView::modelAboutToBeDetached(Model * model)
@@ -210,6 +217,12 @@ void NodeInstanceView::restartProcess()
if (!isSkippedRootNode(rootModelNode())) if (!isSkippedRootNode(rootModelNode()))
nodeInstanceServer()->createScene(createCreateSceneCommand()); 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) void NodeInstanceView::activateState(const NodeInstance &instance)
{ {
nodeInstanceServer()->changeState(ChangeStateCommand(instance.instanceId())); nodeInstanceServer()->changeState(ChangeStateCommand(instance.instanceId()));
// activateBaseState();
// NodeInstance stateInstance(instance);
// stateInstance.activateState();
} }
void NodeInstanceView::activateBaseState() void NodeInstanceView::activateBaseState()
{ {
nodeInstanceServer()->changeState(ChangeStateCommand(-1)); nodeInstanceServer()->changeState(ChangeStateCommand(-1));
// if (activeStateInstance().isValid())
// activeStateInstance().deactivateState();
} }
void NodeInstanceView::removeRecursiveChildRelationship(const ModelNode &removedNode) void NodeInstanceView::removeRecursiveChildRelationship(const ModelNode &removedNode)
@@ -1103,8 +1118,10 @@ QImage NodeInstanceView::statePreviewImage(const ModelNode &stateNode) const
void NodeInstanceView::setPathToQt(const QString &pathToQt) void NodeInstanceView::setPathToQt(const QString &pathToQt)
{ {
m_pathToQt = pathToQt; if (m_pathToQt != pathToQt) {
restartProcess(); m_pathToQt = pathToQt;
restartProcess();
}
} }
void NodeInstanceView::statePreviewImagesChanged(const StatePreviewImageChangedCommand &command) void NodeInstanceView::statePreviewImagesChanged(const StatePreviewImageChangedCommand &command)

View File

@@ -447,8 +447,9 @@ void AbstractView::emitRewriterEndTransaction()
model()->m_d->notifyRewriterEndTransaction(); model()->m_d->notifyRewriterEndTransaction();
} }
void AbstractView::emitActualStateChanged(const ModelNode &node) void AbstractView::setAcutalStateNode(const ModelNode &node)
{ {
Internal::WriteLocker locker(m_model.data());
if (model()) if (model())
model()->m_d->notifyActualStateChanged(node); 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); 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 } // namespace QmlDesigner

View File

@@ -605,6 +605,8 @@ void ModelPrivate::notifyActualStateChanged(const ModelNode &node)
bool resetModel = false; bool resetModel = false;
QString description; QString description;
m_acutalStateNode = node.internalNode();
try { try {
if (rewriterView()) if (rewriterView())
rewriterView()->actualStateChanged(ModelNode(node.internalNode(), model(), rewriterView())); rewriterView()->actualStateChanged(ModelNode(node.internalNode(), model(), rewriterView()));
@@ -1638,6 +1640,11 @@ bool ModelPrivate::isWriteLocked() const
return m_writeLock; return m_writeLock;
} }
InternalNode::Pointer ModelPrivate::actualStateNode() const
{
return m_acutalStateNode;
}
WriteLocker::WriteLocker(ModelPrivate *model) WriteLocker::WriteLocker(ModelPrivate *model)
: m_model(model) : m_model(model)

View File

@@ -218,6 +218,8 @@ public:
void setNodeInstanceView(NodeInstanceView *nodeInstanceView); void setNodeInstanceView(NodeInstanceView *nodeInstanceView);
NodeInstanceView *nodeInstanceView() const; NodeInstanceView *nodeInstanceView() const;
InternalNodePointer actualStateNode() const;
private: //functions private: //functions
void removePropertyWithoutNotification(const InternalPropertyPointer &property); void removePropertyWithoutNotification(const InternalPropertyPointer &property);
void removeAllSubNodes(const InternalNodePointer &node); void removeAllSubNodes(const InternalNodePointer &node);
@@ -237,6 +239,8 @@ private:
QHash<QString,InternalNodePointer> m_idNodeHash; QHash<QString,InternalNodePointer> m_idNodeHash;
QHash<qint32, InternalNodePointer> m_internalIdNodeHash; QHash<qint32, InternalNodePointer> m_internalIdNodeHash;
QSet<InternalNodePointer> m_nodeSet; QSet<InternalNodePointer> m_nodeSet;
InternalNodePointer m_acutalStateNode;
InternalNodePointer m_rootInternalNode; InternalNodePointer m_rootInternalNode;

View File

@@ -63,12 +63,12 @@ void QmlModelView::setCurrentState(const QmlModelState &state)
if (!state.isValid()) if (!state.isValid())
return; return;
emitActualStateChanged(state.modelNode()); setAcutalStateNode(state.modelNode());
} }
QmlModelState QmlModelView::currentState() const QmlModelState QmlModelView::currentState() const
{ {
return m_state; return QmlModelState(actualStateNode());
} }
QmlModelState QmlModelView::baseState() const QmlModelState QmlModelView::baseState() const
@@ -334,14 +334,10 @@ bool QmlModelView::hasInstanceForModelNode(const ModelNode &modelNode)
void QmlModelView::modelAttached(Model *model) void QmlModelView::modelAttached(Model *model)
{ {
AbstractView::modelAttached(model); AbstractView::modelAttached(model);
m_state = QmlModelState();
m_state = baseState();
Q_ASSERT(m_state.isBaseState());
} }
void QmlModelView::modelAboutToBeDetached(Model *model) void QmlModelView::modelAboutToBeDetached(Model *model)
{ {
m_state = QmlModelState();
AbstractView::modelAboutToBeDetached(model); AbstractView::modelAboutToBeDetached(model);
} }
@@ -452,10 +448,6 @@ void QmlModelView::actualStateChanged(const ModelNode &node)
if (!newState.isValid()) if (!newState.isValid())
newState = baseState(); newState = baseState();
activateState(newState);
m_state = newState;
if (newState != oldState) if (newState != oldState)
stateChanged(newState, oldState); stateChanged(newState, oldState);
@@ -476,28 +468,6 @@ void QmlModelView::nodeInstancePropertyChanged(const ModelNode &node, const QStr
otherPropertyChanged(qmlObjectNode, propertyName); 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*/) void QmlModelView::transformChanged(const QmlObjectNode &/*qmlObjectNode*/, const QString &/*propertyName*/)
{ {
} }

View File

@@ -42,14 +42,12 @@
namespace QmlDesigner { namespace QmlDesigner {
QmlModelState::QmlModelState() QmlModelState::QmlModelState()
: QmlModelNodeFacade(), : QmlModelNodeFacade()
m_isBaseState(false)
{ {
} }
QmlModelState::QmlModelState(const ModelNode &modelNode) QmlModelState::QmlModelState(const ModelNode &modelNode)
: QmlModelNodeFacade(modelNode), : QmlModelNodeFacade(modelNode)
m_isBaseState(false)
{ {
} }
@@ -268,7 +266,7 @@ void QmlModelState::destroy()
bool QmlModelState::isBaseState() const bool QmlModelState::isBaseState() const
{ {
return m_isBaseState && modelNode().isRootNode(); return !modelNode().isValid() || modelNode().isRootNode();
} }
QmlModelState QmlModelState::duplicate(const QString &name) const QmlModelState QmlModelState::duplicate(const QString &name) const
@@ -308,7 +306,7 @@ QmlModelStateGroup QmlModelState::stateGroup() const
QmlModelState QmlModelState::createBaseState(const QmlModelView *view) QmlModelState QmlModelState::createBaseState(const QmlModelView *view)
{ {
QmlModelState fxState(view->rootModelNode()); QmlModelState fxState(view->rootModelNode());
fxState.m_isBaseState = true;
return fxState; return fxState;
} }