Commit 14a5d575 authored by Marco Bubke's avatar Marco Bubke
Browse files

QmlDesigner: Add notifier for state change

parent 7c6a13b3
...@@ -173,7 +173,7 @@ void ComponentView::instancesChildrenChanged(const QVector<ModelNode> &/*nodeLis ...@@ -173,7 +173,7 @@ void ComponentView::instancesChildrenChanged(const QVector<ModelNode> &/*nodeLis
void ComponentView::rewriterBeginTransaction() {} void ComponentView::rewriterBeginTransaction() {}
void ComponentView::rewriterEndTransaction() {} void ComponentView::rewriterEndTransaction() {}
void ComponentView::actualStateChanged(const ModelNode &/*node*/) {}
void ComponentView::selectedNodesChanged(const QList<ModelNode> &/*selectedNodeList*/, void ComponentView::selectedNodesChanged(const QList<ModelNode> &/*selectedNodeList*/,
const QList<ModelNode> &/*lastSelectedNodeList*/) {} const QList<ModelNode> &/*lastSelectedNodeList*/) {}
......
...@@ -82,6 +82,8 @@ public: ...@@ -82,6 +82,8 @@ public:
void rewriterBeginTransaction(); void rewriterBeginTransaction();
void rewriterEndTransaction(); void rewriterEndTransaction();
void actualStateChanged(const ModelNode &node);
void selectedNodesChanged(const QList<ModelNode> &selectedNodeList, void selectedNodesChanged(const QList<ModelNode> &selectedNodeList,
const QList<ModelNode> &lastSelectedNodeList); const QList<ModelNode> &lastSelectedNodeList);
......
...@@ -101,9 +101,11 @@ void DesignDocumentControllerView::rewriterBeginTransaction() ...@@ -101,9 +101,11 @@ void DesignDocumentControllerView::rewriterBeginTransaction()
void DesignDocumentControllerView::rewriterEndTransaction() void DesignDocumentControllerView::rewriterEndTransaction()
{ {
} }
void DesignDocumentControllerView::actualStateChanged(const ModelNode &/*node*/)
{
}
static QStringList arrayToStringList(const QByteArray &byteArray) static QStringList arrayToStringList(const QByteArray &byteArray)
{ {
......
...@@ -73,6 +73,8 @@ public: ...@@ -73,6 +73,8 @@ public:
void rewriterBeginTransaction(); void rewriterBeginTransaction();
void rewriterEndTransaction(); void rewriterEndTransaction();
void actualStateChanged(const ModelNode &node);
ModelNode insertModel(const ModelNode &modelNode) ModelNode insertModel(const ModelNode &modelNode)
{ return m_modelMerger.insertModel(modelNode); } { return m_modelMerger.insertModel(modelNode); }
void replaceModel(const ModelNode &modelNode) void replaceModel(const ModelNode &modelNode)
......
...@@ -153,6 +153,10 @@ void ItemLibraryView::rewriterEndTransaction() ...@@ -153,6 +153,10 @@ void ItemLibraryView::rewriterEndTransaction()
{ {
} }
void ItemLibraryView::actualStateChanged(const ModelNode &/*node*/)
{
}
void ItemLibraryView::updateImports() void ItemLibraryView::updateImports()
{ {
m_widget->updateModel(); m_widget->updateModel();
......
...@@ -90,6 +90,8 @@ public: ...@@ -90,6 +90,8 @@ public:
void rewriterBeginTransaction(); void rewriterBeginTransaction();
void rewriterEndTransaction(); void rewriterEndTransaction();
void actualStateChanged(const ModelNode &node);
protected: protected:
void updateImports(); void updateImports();
......
...@@ -245,6 +245,10 @@ void NavigatorView::rewriterEndTransaction() ...@@ -245,6 +245,10 @@ void NavigatorView::rewriterEndTransaction()
{ {
} }
void NavigatorView::actualStateChanged(const ModelNode &/*node*/)
{
}
void NavigatorView::nodeOrderChanged(const NodeListProperty &listProperty, const ModelNode &node, int oldIndex) void NavigatorView::nodeOrderChanged(const NodeListProperty &listProperty, const ModelNode &node, int oldIndex)
{ {
if (m_treeModel->isInTree(node)) if (m_treeModel->isInTree(node))
......
...@@ -98,6 +98,8 @@ public: ...@@ -98,6 +98,8 @@ public:
void rewriterBeginTransaction(); void rewriterBeginTransaction();
void rewriterEndTransaction(); void rewriterEndTransaction();
void actualStateChanged(const ModelNode &node);
private slots: private slots:
// void handleChangedItem(QStandardItem * item); // void handleChangedItem(QStandardItem * item);
void changeSelection(const QItemSelection &selected, const QItemSelection &deselected); void changeSelection(const QItemSelection &selected, const QItemSelection &deselected);
......
...@@ -118,6 +118,7 @@ public: ...@@ -118,6 +118,7 @@ public:
void emitInstancesChildrenChanged(const QVector<ModelNode> &nodeList); void emitInstancesChildrenChanged(const QVector<ModelNode> &nodeList);
void emitRewriterBeginTransaction(); void emitRewriterBeginTransaction();
void emitRewriterEndTransaction(); void emitRewriterEndTransaction();
void emitActualStateChanged(const ModelNode &node);
virtual void modelAttached(Model *model); virtual void modelAttached(Model *model);
virtual void modelAboutToBeDetached(Model *model); virtual void modelAboutToBeDetached(Model *model);
...@@ -144,6 +145,8 @@ public: ...@@ -144,6 +145,8 @@ public:
virtual void rewriterBeginTransaction() = 0; virtual void rewriterBeginTransaction() = 0;
virtual void rewriterEndTransaction() = 0; virtual void rewriterEndTransaction() = 0;
virtual void actualStateChanged(const ModelNode &node) = 0; // base state is a invalid model node
virtual void selectedNodesChanged(const QList<ModelNode> &selectedNodeList, virtual void selectedNodesChanged(const QList<ModelNode> &selectedNodeList,
const QList<ModelNode> &lastSelectedNodeList) = 0; const QList<ModelNode> &lastSelectedNodeList) = 0;
......
...@@ -113,6 +113,8 @@ public: ...@@ -113,6 +113,8 @@ public:
void rewriterBeginTransaction(); void rewriterBeginTransaction();
void rewriterEndTransaction(); void rewriterEndTransaction();
void actualStateChanged(const ModelNode &node);
QList<NodeInstance> instances() const; QList<NodeInstance> instances() const;
NodeInstance instanceForNode(const ModelNode &node) const ; NodeInstance instanceForNode(const ModelNode &node) const ;
bool hasInstanceForNode(const ModelNode &node) const; bool hasInstanceForNode(const ModelNode &node) const;
......
...@@ -87,8 +87,6 @@ public: ...@@ -87,8 +87,6 @@ public:
QmlObjectNode fxObjectNodeForId(const QString &id); QmlObjectNode fxObjectNodeForId(const QString &id);
void customNotification(const AbstractView *view, const QString &identifier, const QList<ModelNode> &nodeList, const QList<QVariant> &data);
void modelAttached(Model *model); void modelAttached(Model *model);
void modelAboutToBeDetached(Model *model); void modelAboutToBeDetached(Model *model);
...@@ -104,6 +102,8 @@ public: ...@@ -104,6 +102,8 @@ public:
void rewriterBeginTransaction(); void rewriterBeginTransaction();
void rewriterEndTransaction(); void rewriterEndTransaction();
void actualStateChanged(const ModelNode &node);
void nodeCreated(const ModelNode &createdNode); void nodeCreated(const ModelNode &createdNode);
void nodeRemoved(const ModelNode &removedNode, const NodeAbstractProperty &parentProperty, PropertyChangeFlags propertyChange); void nodeRemoved(const ModelNode &removedNode, const NodeAbstractProperty &parentProperty, PropertyChangeFlags propertyChange);
void nodeAboutToBeReparented(const ModelNode &node, const NodeAbstractProperty &newPropertyParent, const NodeAbstractProperty &oldPropertyParent, AbstractView::PropertyChangeFlags propertyChange); void nodeAboutToBeReparented(const ModelNode &node, const NodeAbstractProperty &newPropertyParent, const NodeAbstractProperty &oldPropertyParent, AbstractView::PropertyChangeFlags propertyChange);
...@@ -129,7 +129,6 @@ protected: ...@@ -129,7 +129,6 @@ protected:
virtual void stateChanged(const QmlModelState &newQmlModelState, const QmlModelState &oldQmlModelState); virtual void stateChanged(const QmlModelState &newQmlModelState, const QmlModelState &oldQmlModelState);
void activateState(const QmlModelState &state); void activateState(const QmlModelState &state);
void changeToState(const ModelNode &node, const QString &stateName);
private: private:
QmlModelState m_state; QmlModelState m_state;
......
...@@ -148,6 +148,8 @@ public: ...@@ -148,6 +148,8 @@ public:
void rewriterBeginTransaction(); void rewriterBeginTransaction();
void rewriterEndTransaction(); void rewriterEndTransaction();
void actualStateChanged(const ModelNode &node);
void importAdded(const Import &import); void importAdded(const Import &import);
void importRemoved(const Import &import); void importRemoved(const Import &import);
......
...@@ -474,6 +474,11 @@ void NodeInstanceView::rewriterEndTransaction() ...@@ -474,6 +474,11 @@ void NodeInstanceView::rewriterEndTransaction()
} }
void NodeInstanceView::actualStateChanged(const ModelNode &/*node*/)
{
}
//\} //\}
......
...@@ -439,6 +439,12 @@ void AbstractView::emitRewriterEndTransaction() ...@@ -439,6 +439,12 @@ void AbstractView::emitRewriterEndTransaction()
model()->m_d->notifyRewriterEndTransaction(); model()->m_d->notifyRewriterEndTransaction();
} }
void AbstractView::emitActualStateChanged(const ModelNode &node)
{
if (model())
model()->m_d->notifyActualStateChanged(node);
}
void AbstractView::changeRootNodeType(const QString &type, int majorVersion, int minorVersion) void AbstractView::changeRootNodeType(const QString &type, int majorVersion, int minorVersion)
{ {
Internal::WriteLocker locker(m_model.data()); Internal::WriteLocker locker(m_model.data());
......
...@@ -567,6 +567,33 @@ void ModelPrivate::notifyInstancesChildrenChanged(const QVector<ModelNode> &node ...@@ -567,6 +567,33 @@ void ModelPrivate::notifyInstancesChildrenChanged(const QVector<ModelNode> &node
} }
} }
void ModelPrivate::notifyActualStateChanged(const ModelNode &node)
{
bool resetModel = false;
QString description;
try {
if (rewriterView())
rewriterView()->actualStateChanged(ModelNode(node.internalNode(), model(), rewriterView()));
} catch (RewritingException &e) {
description = e.description();
resetModel = true;
}
foreach (const QWeakPointer<AbstractView> &view, m_viewList) {
Q_ASSERT(view != 0);
view->actualStateChanged(ModelNode(node.internalNode(), model(), view.data()));
}
if (nodeInstanceView()) {
nodeInstanceView()->actualStateChanged(ModelNode(node.internalNode(), model(), nodeInstanceView()));
}
if (resetModel) {
resetModelByRewriter(description);
}
}
void ModelPrivate::notifyRewriterBeginTransaction() void ModelPrivate::notifyRewriterBeginTransaction()
{ {
bool resetModel = false; bool resetModel = false;
......
...@@ -153,6 +153,7 @@ public: ...@@ -153,6 +153,7 @@ public:
void notifyInstancesRenderImageChanged(const QVector<ModelNode> &nodeList); void notifyInstancesRenderImageChanged(const QVector<ModelNode> &nodeList);
void notifyInstancesPreviewImageChanged(const QVector<ModelNode> &nodeList); void notifyInstancesPreviewImageChanged(const QVector<ModelNode> &nodeList);
void notifyInstancesChildrenChanged(const QVector<ModelNode> &nodeList); void notifyInstancesChildrenChanged(const QVector<ModelNode> &nodeList);
void notifyActualStateChanged(const ModelNode &node);
void notifyRewriterBeginTransaction(); void notifyRewriterBeginTransaction();
void notifyRewriterEndTransaction(); void notifyRewriterEndTransaction();
......
...@@ -57,7 +57,7 @@ void QmlModelView::setCurrentState(const QmlModelState &state) ...@@ -57,7 +57,7 @@ void QmlModelView::setCurrentState(const QmlModelState &state)
if (!state.isValid()) if (!state.isValid())
return; return;
emitCustomNotification("__state changed__", QList<ModelNode>() << state.modelNode()); emitActualStateChanged(state.modelNode());
} }
QmlModelState QmlModelView::currentState() const QmlModelState QmlModelView::currentState() const
...@@ -281,24 +281,6 @@ QmlObjectNode QmlModelView::fxObjectNodeForId(const QString &id) ...@@ -281,24 +281,6 @@ QmlObjectNode QmlModelView::fxObjectNodeForId(const QString &id)
return QmlObjectNode(modelNodeForId(id)); return QmlObjectNode(modelNodeForId(id));
} }
void QmlModelView::customNotification(const AbstractView * /* view */, const QString &identifier, const QList<ModelNode> &nodeList, const QList<QVariant> & /* data */)
{
if (identifier == "__state changed__") { // TODO: Is this still needed?
QmlModelState newState(nodeList.first());
QmlModelState oldState = currentState();
if (!newState.isValid())
newState = baseState();
activateState(newState);
m_state = newState;
if (newState != oldState)
stateChanged(newState, oldState);
}
}
NodeInstance QmlModelView::instanceForModelNode(const ModelNode &modelNode) NodeInstance QmlModelView::instanceForModelNode(const ModelNode &modelNode)
{ {
return nodeInstanceView()->instanceForNode(modelNode); return nodeInstanceView()->instanceForNode(modelNode);
...@@ -401,6 +383,23 @@ void QmlModelView::rewriterEndTransaction() ...@@ -401,6 +383,23 @@ void QmlModelView::rewriterEndTransaction()
} }
void QmlModelView::actualStateChanged(const ModelNode &node)
{
QmlModelState newState(node);
QmlModelState oldState = currentState();
if (!newState.isValid())
newState = baseState();
activateState(newState);
m_state = newState;
if (newState != oldState)
stateChanged(newState, oldState);
}
void QmlModelView::nodeInstancePropertyChanged(const ModelNode &node, const QString &propertyName) void QmlModelView::nodeInstancePropertyChanged(const ModelNode &node, const QString &propertyName)
{ {
QmlObjectNode qmlObjectNode(node); QmlObjectNode qmlObjectNode(node);
...@@ -438,25 +437,6 @@ void QmlModelView::activateState(const QmlModelState &state) ...@@ -438,25 +437,6 @@ void QmlModelView::activateState(const QmlModelState &state)
} }
} }
void QmlModelView::changeToState(const ModelNode &node, const QString &stateName)
{
QmlItemNode itemNode(node);
QmlModelState newState;
if (stateName.isEmpty())
newState = baseState();
else
newState = itemNode.states().state(stateName);
QmlModelState oldState = m_state;
if (newState.isValid() && oldState != newState) {
m_state = newState;
stateChanged(newState, oldState);
}
}
void QmlModelView::transformChanged(const QmlObjectNode &/*qmlObjectNode*/, const QString &/*propertyName*/) void QmlModelView::transformChanged(const QmlObjectNode &/*qmlObjectNode*/, const QString &/*propertyName*/)
{ {
} }
......
...@@ -415,6 +415,10 @@ void RewriterView::rewriterEndTransaction() ...@@ -415,6 +415,10 @@ void RewriterView::rewriterEndTransaction()
} }
} }
void RewriterView::actualStateChanged(const ModelNode &/*node*/)
{
}
void RewriterView::selectedNodesChanged(const QList<ModelNode> & /* selectedNodeList, */, const QList<ModelNode> & /*lastSelectedNodeList */) void RewriterView::selectedNodesChanged(const QList<ModelNode> & /* selectedNodeList, */, const QList<ModelNode> & /*lastSelectedNodeList */)
{ {
} }
......
...@@ -267,5 +267,9 @@ void ViewLogger::rewriterEndTransaction() ...@@ -267,5 +267,9 @@ void ViewLogger::rewriterEndTransaction()
m_output << time() << indent("rewriterEndTransaction:") << endl; m_output << time() << indent("rewriterEndTransaction:") << endl;
} }
void ViewLogger::actualStateChanged(const ModelNode &node)
{
m_output << time() << indent("actualStateChanged:") << node << endl;
}
} // namespace Internal } // namespace Internal
} // namespace QmlDesigner } // namespace QmlDesigner
...@@ -86,6 +86,8 @@ public: ...@@ -86,6 +86,8 @@ public:
void rewriterBeginTransaction(); void rewriterBeginTransaction();
void rewriterEndTransaction(); void rewriterEndTransaction();
void actualStateChanged(const ModelNode &node);
protected: protected:
QString time() const; QString time() const;
......
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