Commit 7ab575a9 authored by Marco Bubke's avatar Marco Bubke

QmlDesigner: Refactor custom notifications

The custom notification code leads to hard readable code.
parent ad905869
......@@ -458,68 +458,68 @@ void FormEditorView::instancesCompleted(const QVector<ModelNode> &completedNodeL
currentTool()->instancesCompleted(itemNodeList);
}
void FormEditorView::customNotification(const AbstractView *view, const QString &identifier, const QList<ModelNode> &nodeList, const QList<QVariant> &data)
void FormEditorView::instanceInformationsChange(const QVector<ModelNode> &nodeList)
{
if (identifier == "__start rewriter transaction__") {
m_transactionCounter++;
if (m_transactionCounter == 1
&& selectedModelNodes().count() == 1)
m_formEditorWidget->setFeedbackNode(QmlItemNode(selectedModelNodes().first()));
}
if (identifier == "__end rewriter transaction__") {
m_transactionCounter--;
if (m_transactionCounter == 0)
m_formEditorWidget->setFeedbackNode(QmlItemNode());
}
if (identifier == "__instance information changed__") {
QList<FormEditorItem*> itemNodeList;
QList<FormEditorItem*> itemNodeList;
foreach (const ModelNode &node, nodeList) {
QmlItemNode qmlItemNode(node);
if (qmlItemNode.isValid() && scene()->hasItemForQmlItemNode(qmlItemNode)) {
scene()->synchronizeTransformation(qmlItemNode);
if (qmlItemNode.isRootModelNode())
widget()->setRootItemRect(qmlItemNode.instanceBoundingRect());
foreach (const ModelNode &node, nodeList) {
QmlItemNode qmlItemNode(node);
if (qmlItemNode.isValid() && scene()->hasItemForQmlItemNode(qmlItemNode)) {
scene()->synchronizeTransformation(qmlItemNode);
if (qmlItemNode.isRootModelNode())
widget()->setRootItemRect(qmlItemNode.instanceBoundingRect());
itemNodeList.append(scene()->itemForQmlItemNode(qmlItemNode));
}
itemNodeList.append(scene()->itemForQmlItemNode(qmlItemNode));
}
m_currentTool->formEditorItemsChanged(itemNodeList);
}
if (identifier == "__instance render pixmap changed__") {
QList<FormEditorItem*> itemNodeList;
m_currentTool->formEditorItemsChanged(itemNodeList);
}
foreach (const ModelNode &node, nodeList) {
QmlItemNode qmlItemNode(node);
if (qmlItemNode.isValid() && scene()->hasItemForQmlItemNode(qmlItemNode)) {
scene()->itemForQmlItemNode(qmlItemNode)->update();
}
void FormEditorView::instancesRenderImageChanged(const QVector<ModelNode> &nodeList)
{
foreach (const ModelNode &node, nodeList) {
QmlItemNode qmlItemNode(node);
if (qmlItemNode.isValid() && scene()->hasItemForQmlItemNode(qmlItemNode)) {
scene()->itemForQmlItemNode(qmlItemNode)->update();
}
}
}
if (identifier == "__instance children changed__") {
QList<FormEditorItem*> itemNodeList;
void FormEditorView::instancesPreviewImageChanged(const QVector<ModelNode> &/*nodeList*/)
{
foreach (const ModelNode &node, nodeList) {
QmlItemNode qmlItemNode(node);
if (qmlItemNode.isValid() && scene()->hasItemForQmlItemNode(qmlItemNode)) {
scene()->synchronizeParent(qmlItemNode);
itemNodeList.append(scene()->itemForQmlItemNode(qmlItemNode));
}
}
}
m_currentTool->formEditorItemsChanged(itemNodeList);
void FormEditorView::instancesChildrenChanged(const QVector<ModelNode> &nodeList)
{
QList<FormEditorItem*> itemNodeList;
foreach (const ModelNode &node, nodeList) {
QmlItemNode qmlItemNode(node);
if (qmlItemNode.isValid() && scene()->hasItemForQmlItemNode(qmlItemNode)) {
scene()->synchronizeParent(qmlItemNode);
itemNodeList.append(scene()->itemForQmlItemNode(qmlItemNode));
}
}
QmlModelView::customNotification(view, identifier, nodeList, data);
m_currentTool->formEditorItemsChanged(itemNodeList);
}
void FormEditorView::rewriterBeginTransaction()
{
m_transactionCounter++;
if (m_transactionCounter == 1
&& selectedModelNodes().count() == 1)
m_formEditorWidget->setFeedbackNode(QmlItemNode(selectedModelNodes().first()));
}
void FormEditorView::rewriterEndTransaction()
{
m_transactionCounter--;
if (m_transactionCounter == 0)
m_formEditorWidget->setFeedbackNode(QmlItemNode());
}
double FormEditorView::margins() const
{
......
......@@ -106,9 +106,15 @@ public:
void nodeSlidedToIndex(const NodeListProperty &listProperty, int newIndex, int oldIndex);
void auxiliaryDataChanged(const ModelNode &node, const QString &name, const QVariant &data);
void customNotification(const AbstractView *view, const QString &identifier, const QList<ModelNode> &nodeList, const QList<QVariant> &data);
void instancesCompleted(const QVector<ModelNode> &completedNodeList);
void instanceInformationsChange(const QVector<ModelNode> &nodeList);
void instancesRenderImageChanged(const QVector<ModelNode> &nodeList);
void instancesPreviewImageChanged(const QVector<ModelNode> &nodeList);
void instancesChildrenChanged(const QVector<ModelNode> &nodeList);
void rewriterBeginTransaction();
void rewriterEndTransaction();
double margins() const;
double spacing() const;
......
......@@ -166,7 +166,13 @@ void ComponentView::rootNodeTypeChanged(const QString &/*type*/, int /*majorVers
void ComponentView::scriptFunctionsChanged(const ModelNode &/*node*/, const QStringList &/*scriptFunctionList*/) {}
void ComponentView::instancePropertyChange(const QList<QPair<ModelNode, QString> > &/*propertyList*/) {}
void ComponentView::instancesCompleted(const QVector<ModelNode> &/*completedNodeList*/) {}
void ComponentView::instanceInformationsChange(const QVector<ModelNode> &/*nodeList*/) {}
void ComponentView::instancesRenderImageChanged(const QVector<ModelNode> &/*nodeList*/) {}
void ComponentView::instancesPreviewImageChanged(const QVector<ModelNode> &/*nodeList*/) {}
void ComponentView::instancesChildrenChanged(const QVector<ModelNode> &/*nodeList*/) {}
void ComponentView::rewriterBeginTransaction() {}
void ComponentView::rewriterEndTransaction() {}
void ComponentView::selectedNodesChanged(const QList<ModelNode> &/*selectedNodeList*/,
const QList<ModelNode> &/*lastSelectedNodeList*/) {}
......
......@@ -74,6 +74,13 @@ public:
void scriptFunctionsChanged(const ModelNode &node, const QStringList &scriptFunctionList);
void instancePropertyChange(const QList<QPair<ModelNode, QString> > &propertyList);
void instancesCompleted(const QVector<ModelNode> &completedNodeList);
void instanceInformationsChange(const QVector<ModelNode> &nodeList);
void instancesRenderImageChanged(const QVector<ModelNode> &nodeList);
void instancesPreviewImageChanged(const QVector<ModelNode> &nodeList);
void instancesChildrenChanged(const QVector<ModelNode> &nodeList);
void rewriterBeginTransaction();
void rewriterEndTransaction();
void selectedNodesChanged(const QList<ModelNode> &selectedNodeList,
const QList<ModelNode> &lastSelectedNodeList);
......
......@@ -73,6 +73,37 @@ void DesignDocumentControllerView::instancesCompleted(const QVector<ModelNode> &
{
}
void DesignDocumentControllerView::instanceInformationsChange(const QVector<ModelNode> &/*nodeList*/)
{
}
void DesignDocumentControllerView::instancesRenderImageChanged(const QVector<ModelNode> &/*nodeList*/)
{
}
void DesignDocumentControllerView::instancesPreviewImageChanged(const QVector<ModelNode> &/*nodeList*/)
{
}
void DesignDocumentControllerView::instancesChildrenChanged(const QVector<ModelNode> &/*nodeList*/)
{
}
void DesignDocumentControllerView::rewriterBeginTransaction()
{
}
void DesignDocumentControllerView::rewriterEndTransaction()
{
}
static QStringList arrayToStringList(const QByteArray &byteArray)
{
......
......@@ -65,6 +65,13 @@ public:
virtual void scriptFunctionsChanged(const ModelNode &node, const QStringList &scriptFunctionList);
void instancePropertyChange(const QList<QPair<ModelNode, QString> > &propertyList);
void instancesCompleted(const QVector<ModelNode> &completedNodeList);
void instanceInformationsChange(const QVector<ModelNode> &nodeList);
void instancesRenderImageChanged(const QVector<ModelNode> &nodeList);
void instancesPreviewImageChanged(const QVector<ModelNode> &nodeList);
void instancesChildrenChanged(const QVector<ModelNode> &nodeList);
void rewriterBeginTransaction();
void rewriterEndTransaction();
ModelNode insertModel(const ModelNode &modelNode)
{ return m_modelMerger.insertModel(modelNode); }
......
......@@ -128,6 +128,31 @@ void ItemLibraryView::instancesCompleted(const QVector<ModelNode> &)
}
void ItemLibraryView::instanceInformationsChange(const QVector<ModelNode> &/*nodeList*/)
{
}
void ItemLibraryView::instancesRenderImageChanged(const QVector<ModelNode> &/*nodeList*/)
{
}
void ItemLibraryView::instancesPreviewImageChanged(const QVector<ModelNode> &/*nodeList*/)
{
}
void ItemLibraryView::instancesChildrenChanged(const QVector<ModelNode> &/*nodeList*/)
{
}
void ItemLibraryView::rewriterBeginTransaction()
{
}
void ItemLibraryView::rewriterEndTransaction()
{
}
void ItemLibraryView::updateImports()
{
m_widget->updateModel();
......
......@@ -82,6 +82,13 @@ public:
void scriptFunctionsChanged(const ModelNode &node, const QStringList &scriptFunctionList);
void instancePropertyChange(const QList<QPair<ModelNode, QString> > &propertyList);
void instancesCompleted(const QVector<ModelNode> &completedNodeList);
void instanceInformationsChange(const QVector<ModelNode> &nodeList);
void instancesRenderImageChanged(const QVector<ModelNode> &nodeList);
void instancesPreviewImageChanged(const QVector<ModelNode> &nodeList);
void instancesChildrenChanged(const QVector<ModelNode> &nodeList);
void rewriterBeginTransaction();
void rewriterEndTransaction();
protected:
void updateImports();
......
......@@ -217,6 +217,31 @@ void NavigatorView::instancesCompleted(const QVector<ModelNode> &/*completedNode
{
}
void NavigatorView::instanceInformationsChange(const QVector<ModelNode> &/*nodeList*/)
{
}
void NavigatorView::instancesRenderImageChanged(const QVector<ModelNode> &/*nodeList*/)
{
}
void NavigatorView::instancesPreviewImageChanged(const QVector<ModelNode> &/*nodeList*/)
{
}
void NavigatorView::instancesChildrenChanged(const QVector<ModelNode> &/*nodeList*/)
{
}
void NavigatorView::rewriterBeginTransaction()
{
}
void NavigatorView::rewriterEndTransaction()
{
}
void NavigatorView::nodeOrderChanged(const NodeListProperty &listProperty, const ModelNode &node, int oldIndex)
{
if (m_treeModel->isInTree(node))
......
......@@ -90,6 +90,13 @@ public:
void scriptFunctionsChanged(const ModelNode &node, const QStringList &scriptFunctionList);
void instancePropertyChange(const QList<QPair<ModelNode, QString> > &propertyList);
void instancesCompleted(const QVector<ModelNode> &completedNodeList);
void instanceInformationsChange(const QVector<ModelNode> &nodeList);
void instancesRenderImageChanged(const QVector<ModelNode> &nodeList);
void instancesPreviewImageChanged(const QVector<ModelNode> &nodeList);
void instancesChildrenChanged(const QVector<ModelNode> &nodeList);
void rewriterBeginTransaction();
void rewriterEndTransaction();
private slots:
// void handleChangedItem(QStandardItem * item);
......
......@@ -325,32 +325,25 @@ void StatesEditorView::otherPropertyChanged(const QmlObjectNode &qmlObjectNode,
QmlModelView::otherPropertyChanged(qmlObjectNode, propertyName);
}
void StatesEditorView::customNotification(const AbstractView * view, const QString & identifier, const QList<ModelNode> & nodeList, const QList<QVariant> &imageList)
void StatesEditorView::instancesPreviewImageChanged(const QVector<ModelNode> &nodeList)
{
if (identifier == "__instance preview image changed__") {
int minimumIndex = 10000;
int maximumIndex = -1;
foreach(const ModelNode &node, nodeList) {
if (node.isRootNode()) {
minimumIndex = qMin(minimumIndex, 0);
maximumIndex = qMax(maximumIndex, 0);
} else {
int index = rootStateGroup().allStates().indexOf(QmlModelState(node)) + 1;
if (index > 0) {
minimumIndex = qMin(minimumIndex, index);
maximumIndex = qMax(maximumIndex, index);
}
int minimumIndex = 10000;
int maximumIndex = -1;
foreach(const ModelNode &node, nodeList) {
if (node.isRootNode()) {
minimumIndex = qMin(minimumIndex, 0);
maximumIndex = qMax(maximumIndex, 0);
} else {
int index = rootStateGroup().allStates().indexOf(QmlModelState(node)) + 1;
if (index > 0) {
minimumIndex = qMin(minimumIndex, index);
maximumIndex = qMax(maximumIndex, index);
}
}
if (maximumIndex >= 0)
m_statesEditorModel->updateState(minimumIndex, maximumIndex);
} else {
QmlModelView::customNotification(view, identifier, nodeList, imageList);
}
if (maximumIndex >= 0)
m_statesEditorModel->updateState(minimumIndex, maximumIndex);
}
void StatesEditorView::scriptFunctionsChanged(const ModelNode &node, const QStringList &scriptFunctionList)
......
......@@ -72,12 +72,13 @@ public:
void parentChanged(const QmlObjectNode &qmlObjectNode);
void otherPropertyChanged(const QmlObjectNode &qmlObjectNode, const QString &propertyName);
void customNotification(const AbstractView *view, const QString &identifier, const QList<ModelNode> &nodeList, const QList<QVariant> &data);
void scriptFunctionsChanged(const ModelNode &node, const QStringList &scriptFunctionList);
void nodeIdChanged(const ModelNode &node, const QString &newId, const QString &oldId);
void bindingPropertiesChanged(const QList<BindingProperty> &propertyList, PropertyChangeFlags propertyChange);
void selectedNodesChanged(const QList<ModelNode> &selectedNodeList, const QList<ModelNode> &lastSelectedNodeList);
void instancesPreviewImageChanged(const QVector<ModelNode> &nodeList);
StatesEditorWidget *widget();
public slots:
......
......@@ -112,6 +112,12 @@ public:
void emitInstancePropertyChange(const QList<QPair<ModelNode, QString> > &propertyList);
void emitInstancesCompleted(const QVector<ModelNode> &nodeList);
void emitInstanceInformationsChange(const QVector<ModelNode> &nodeList);
void emitInstancesRenderImageChanged(const QVector<ModelNode> &nodeList);
void emitInstancesPreviewImageChanged(const QVector<ModelNode> &nodeList);
void emitInstancesChildrenChanged(const QVector<ModelNode> &nodeList);
void emitRewriterBeginTransaction();
void emitRewriterEndTransaction();
virtual void modelAttached(Model *model);
virtual void modelAboutToBeDetached(Model *model);
......@@ -130,7 +136,13 @@ public:
virtual void instancePropertyChange(const QList<QPair<ModelNode, QString> > &propertyList) = 0;
virtual void instancesCompleted(const QVector<ModelNode> &completedNodeList) = 0;
virtual void instanceInformationsChange(const QVector<ModelNode> &nodeList) = 0;
virtual void instancesRenderImageChanged(const QVector<ModelNode> &nodeList) = 0;
virtual void instancesPreviewImageChanged(const QVector<ModelNode> &nodeList) = 0;
virtual void instancesChildrenChanged(const QVector<ModelNode> &nodeList) = 0;
virtual void rewriterBeginTransaction() = 0;
virtual void rewriterEndTransaction() = 0;
virtual void selectedNodesChanged(const QList<ModelNode> &selectedNodeList,
const QList<ModelNode> &lastSelectedNodeList) = 0;
......
......@@ -105,6 +105,13 @@ public:
void instancesCompleted(const QVector<ModelNode> &completedNodeList);
void importAdded(const Import &import);
void importRemoved(const Import &import);
void instanceInformationsChange(const QVector<ModelNode> &nodeList);
void instancesRenderImageChanged(const QVector<ModelNode> &nodeList);
void instancesPreviewImageChanged(const QVector<ModelNode> &nodeList);
void instancesChildrenChanged(const QVector<ModelNode> &nodeList);
void rewriterBeginTransaction();
void rewriterEndTransaction();
QList<NodeInstance> instances() const;
NodeInstance instanceForNode(const ModelNode &node) const ;
......
......@@ -96,6 +96,13 @@ public:
void instancePropertyChange(const QList<QPair<ModelNode, QString> > &propertyList);
void instancesCompleted(const QVector<ModelNode> &completedNodeList);
void instanceInformationsChange(const QVector<ModelNode> &nodeList);
void instancesRenderImageChanged(const QVector<ModelNode> &nodeList);
void instancesPreviewImageChanged(const QVector<ModelNode> &nodeList);
void instancesChildrenChanged(const QVector<ModelNode> &nodeList);
void rewriterBeginTransaction();
void rewriterEndTransaction();
void nodeCreated(const ModelNode &createdNode);
void nodeRemoved(const ModelNode &removedNode, const NodeAbstractProperty &parentProperty, PropertyChangeFlags propertyChange);
......
......@@ -140,6 +140,13 @@ public:
void instancePropertyChange(const QList<QPair<ModelNode, QString> > &propertyList);
void instancesCompleted(const QVector<ModelNode> &completedNodeList);
void instanceInformationsChange(const QVector<ModelNode> &nodeList);
void instancesRenderImageChanged(const QVector<ModelNode> &nodeList);
void instancesPreviewImageChanged(const QVector<ModelNode> &nodeList);
void instancesChildrenChanged(const QVector<ModelNode> &nodeList);
void rewriterBeginTransaction();
void rewriterEndTransaction();
void importAdded(const Import &import);
void importRemoved(const Import &import);
......
......@@ -443,6 +443,37 @@ void NodeInstanceView::importRemoved(const Import &/*import*/)
restartProcess();
}
void NodeInstanceView::instanceInformationsChange(const QVector<ModelNode> &/*nodeList*/)
{
}
void NodeInstanceView::instancesRenderImageChanged(const QVector<ModelNode> &/*nodeList*/)
{
}
void NodeInstanceView::instancesPreviewImageChanged(const QVector<ModelNode> &/*nodeList*/)
{
}
void NodeInstanceView::instancesChildrenChanged(const QVector<ModelNode> &/*nodeList*/)
{
}
void NodeInstanceView::rewriterBeginTransaction()
{
}
void NodeInstanceView::rewriterEndTransaction()
{
}
//\}
......@@ -931,7 +962,7 @@ void NodeInstanceView::pixmapChanged(const PixmapChangedCommand &command)
}
if (!renderImageChangeSet.isEmpty())
emitCustomNotification("__instance render pixmap changed__", renderImageChangeSet.toList());
emitInstancesRenderImageChanged(renderImageChangeSet.toList().toVector());
}
void NodeInstanceView::informationChanged(const InformationChangedCommand &command)
......@@ -953,7 +984,7 @@ void NodeInstanceView::informationChanged(const InformationChangedCommand &comma
}
if (!informationChangedVector.isEmpty())
emitCustomNotification("__instance information changed__", informationChangedVector.toList());
emitInstanceInformationsChange(informationChangedVector.toList().toVector());
}
QImage NodeInstanceView::statePreviewImage(const ModelNode &stateNode) const
......@@ -969,21 +1000,21 @@ void NodeInstanceView::statePreviewImagesChanged(const StatePreviewImageChangedC
if (!model())
return;
QList<ModelNode> previewImageChangeList;
QVector<ModelNode> previewImageChangeVector;
foreach (const ImageContainer &container, command.previews()) {
if (container.instanceId() == 0) {
m_baseStatePreviewImage = container.image();
previewImageChangeList.append(rootModelNode());
previewImageChangeVector.append(rootModelNode());
} else if (hasInstanceForId(container.instanceId())) {
ModelNode node = modelNodeForInternalId(container.instanceId());
m_statePreviewImage.insert(node, container.image());
previewImageChangeList.append(node);
previewImageChangeVector.append(node);
}
}
if (!previewImageChangeList.isEmpty())
emitCustomNotification("__instance preview image changed__", previewImageChangeList);
if (!previewImageChangeVector.isEmpty())
emitInstancesPreviewImageChanged(previewImageChangeVector);
}
void NodeInstanceView::componentCompleted(const ComponentCompletedCommand &command)
......@@ -1008,18 +1039,18 @@ void NodeInstanceView::childrenChanged(const ChildrenChangedCommand &command)
if (!model())
return;
QList<ModelNode> childNodeList;
QVector<ModelNode> childNodeVector;
foreach(qint32 instanceId, command.childrenInstances()) {
if (hasInstanceForId(instanceId)) {
NodeInstance instance = instanceForId(instanceId);
instance.setParentId(command.parentInstanceId());
childNodeList.append(instance.modelNode());
childNodeVector.append(instance.modelNode());
}
}
if (!childNodeList.isEmpty())
emitCustomNotification("__instance children changed__", childNodeList);
if (!childNodeVector.isEmpty())
emitInstancesChildrenChanged(childNodeVector);
}
}
......@@ -403,6 +403,42 @@ void AbstractView::emitInstancesCompleted(const QVector<ModelNode> &nodeVector)
model()->m_d->notifyInstancesCompleted(nodeVector);
}
void AbstractView::emitInstanceInformationsChange(const QVector<ModelNode> &nodeVector)
{
if (model() && nodeInstanceView() == this)
model()->m_d->notifyInstancesInformationsChange(nodeVector);
}
void AbstractView::emitInstancesRenderImageChanged(const QVector<ModelNode> &nodeVector)
{
if (model() && nodeInstanceView() == this)
model()->m_d->notifyInstancesRenderImageChanged(nodeVector);
}
void AbstractView::emitInstancesPreviewImageChanged(const QVector<ModelNode> &nodeVector)
{
if (model() && nodeInstanceView() == this)
model()->m_d->notifyInstancesPreviewImageChanged(nodeVector);
}
void AbstractView::emitInstancesChildrenChanged(const QVector<ModelNode> &nodeVector)
{
if (model() && nodeInstanceView() == this)
model()->m_d->notifyInstancesChildrenChanged(nodeVector);
}
void AbstractView::emitRewriterBeginTransaction()
{
if (model())
model()->m_d->notifyRewriterBeginTransaction();
}
void AbstractView::emitRewriterEndTransaction()
{