SCXML Editor: fix behavior of else and elseif tags

SCXML specify that the <if> tag contains elements separated by tags
<else/> and <elseif/>.
The SCXML Editor used to nest instruction inside the <else/> and
<elseif/> tags.
This patch implement the correct behavior, so each new inserted element
is appended inside the wrapping <if>.  Note that the new elements are
always inserted as last child of <if>.

Task-number: QTCREATORBUG-17674
Change-Id: I327941bbbd8b0cc04b0c26553257ccb2a24c8306
Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
This commit is contained in:
Marco Benelli
2017-02-23 14:11:11 +01:00
parent c84f650fb2
commit a7809d4f5e
3 changed files with 14 additions and 1 deletions

View File

@@ -329,7 +329,10 @@ void Structure::showMenu(const QModelIndex &index, const QPoint &globalPos)
m_currentDocument->undoStack()->endMacro(); m_currentDocument->undoStack()->endMacro();
} else if (actionType == TagUtils::AddChild) { } else if (actionType == TagUtils::AddChild) {
tag->document()->undoStack()->beginMacro(tr("Add child")); 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) if (childTag && childTag->tagType() <= MetadataItem)
m_structureView->edit(m_structureView->currentIndex()); m_structureView->edit(m_structureView->currentIndex());
tag->document()->undoStack()->endMacro(); tag->document()->undoStack()->endMacro();

View File

@@ -414,6 +414,15 @@ ScxmlTag *addChild(ScxmlTag *tag, const QVariantMap &data, GraphicsScene *scene)
return nullptr; 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 SceneUtils
} // namespace PluginInterface } // namespace PluginInterface
} // namespace ScxmlEditor } // namespace ScxmlEditor

View File

@@ -47,6 +47,7 @@ class ScxmlTag;
namespace SceneUtils { namespace SceneUtils {
ScxmlTag *addChild(ScxmlTag *tag, const QVariantMap &data, GraphicsScene *scene); 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); ScxmlTag *addNewTag(ScxmlTag *parent, TagType type, GraphicsScene *scene);
ConnectableItem *createItem(ItemType type, const QPointF &pos = QPointF()); ConnectableItem *createItem(ItemType type, const QPointF &pos = QPointF());
ConnectableItem *createItemByTagType(TagType type, const QPointF &pos = QPointF()); ConnectableItem *createItemByTagType(TagType type, const QPointF &pos = QPointF());