From a7809d4f5ef0710f602f8caba927d988e5af5736 Mon Sep 17 00:00:00 2001 From: Marco Benelli Date: Thu, 23 Feb 2017 14:11:11 +0100 Subject: [PATCH] SCXML Editor: fix behavior of else and elseif tags SCXML specify that the tag contains elements separated by tags and . The SCXML Editor used to nest instruction inside the and tags. This patch implement the correct behavior, so each new inserted element is appended inside the wrapping . Note that the new elements are always inserted as last child of . Task-number: QTCREATORBUG-17674 Change-Id: I327941bbbd8b0cc04b0c26553257ccb2a24c8306 Reviewed-by: Erik Verbruggen --- src/plugins/scxmleditor/common/structure.cpp | 5 ++++- src/plugins/scxmleditor/plugin_interface/sceneutils.cpp | 9 +++++++++ src/plugins/scxmleditor/plugin_interface/sceneutils.h | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/plugins/scxmleditor/common/structure.cpp b/src/plugins/scxmleditor/common/structure.cpp index 147bf9ff6d7..93e5c63fa5f 100644 --- a/src/plugins/scxmleditor/common/structure.cpp +++ b/src/plugins/scxmleditor/common/structure.cpp @@ -329,7 +329,10 @@ void Structure::showMenu(const QModelIndex &index, const QPoint &globalPos) m_currentDocument->undoStack()->endMacro(); } else if (actionType == TagUtils::AddChild) { tag->document()->undoStack()->beginMacro(tr("Add child")); - ScxmlTag *childTag = SceneUtils::addChild(tag, data, m_scene); + ScxmlTag *childTag = (tag->tagType() == TagType::Else + || tag->tagType() == TagType::ElseIf) + ? SceneUtils::addSibling(tag, data, m_scene) + : SceneUtils::addChild(tag, data, m_scene); if (childTag && childTag->tagType() <= MetadataItem) m_structureView->edit(m_structureView->currentIndex()); tag->document()->undoStack()->endMacro(); diff --git a/src/plugins/scxmleditor/plugin_interface/sceneutils.cpp b/src/plugins/scxmleditor/plugin_interface/sceneutils.cpp index 187f471dacf..ccf8bbb15bc 100644 --- a/src/plugins/scxmleditor/plugin_interface/sceneutils.cpp +++ b/src/plugins/scxmleditor/plugin_interface/sceneutils.cpp @@ -414,6 +414,15 @@ ScxmlTag *addChild(ScxmlTag *tag, const QVariantMap &data, GraphicsScene *scene) return nullptr; } +ScxmlTag *addSibling(ScxmlTag *tag, const QVariantMap &data, GraphicsScene *scene) +{ + TagType newTagType = (TagType)data.value(Constants::C_SCXMLTAG_TAGTYPE, 0).toInt(); + if (newTagType >= UnknownTag) { + return addNewTag(tag->parentTag(), newTagType, scene); + } + return nullptr; +} + } // namespace SceneUtils } // namespace PluginInterface } // namespace ScxmlEditor diff --git a/src/plugins/scxmleditor/plugin_interface/sceneutils.h b/src/plugins/scxmleditor/plugin_interface/sceneutils.h index baa4394ecf5..2b13f46a347 100644 --- a/src/plugins/scxmleditor/plugin_interface/sceneutils.h +++ b/src/plugins/scxmleditor/plugin_interface/sceneutils.h @@ -47,6 +47,7 @@ class ScxmlTag; namespace SceneUtils { ScxmlTag *addChild(ScxmlTag *tag, const QVariantMap &data, GraphicsScene *scene); +ScxmlTag *addSibling(ScxmlTag *tag, const QVariantMap &data, GraphicsScene *scene); ScxmlTag *addNewTag(ScxmlTag *parent, TagType type, GraphicsScene *scene); ConnectableItem *createItem(ItemType type, const QPointF &pos = QPointF()); ConnectableItem *createItemByTagType(TagType type, const QPointF &pos = QPointF());