diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2017-12-06 13:26:45 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2017-12-14 10:52:30 +0000 |
commit | ee9ecf86614a78423c6d14893070f6ac221446be (patch) | |
tree | 752e1edd87a795b34bab74e75729bfd4c5fc3f9b /src | |
parent | 585b2c62d5b1e7ba69b651ded580d5283b213655 (diff) | |
download | qt-creator-ee9ecf86614a78423c6d14893070f6ac221446be.tar.gz |
ScxmlEditor: Avoid soft asserts when changing nullptr tags
At least TagCurrentChanged can be triggered with a nullptr tag. That
means the current tag is reset to "none". We should thus handle nullptr
in all receivers of beginTagChange and endTagChange.
Change-Id: Ife558beca9fb1ed5ab246b76bbaab19c1c227e8a
Reviewed-by: Marco Benelli <marco.benelli@qt.io>
Reviewed-by: Tomasz Olszak <olszak.tomasz@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/scxmleditor/common/structuremodel.cpp | 9 | ||||
-rw-r--r-- | src/plugins/scxmleditor/plugin_interface/graphicsscene.cpp | 34 |
2 files changed, 28 insertions, 15 deletions
diff --git a/src/plugins/scxmleditor/common/structuremodel.cpp b/src/plugins/scxmleditor/common/structuremodel.cpp index 65eec4ae45..318a524ab8 100644 --- a/src/plugins/scxmleditor/common/structuremodel.cpp +++ b/src/plugins/scxmleditor/common/structuremodel.cpp @@ -272,6 +272,9 @@ void StructureModel::updateData() void StructureModel::beginTagChange(ScxmlDocument::TagChange change, ScxmlTag *tag, const QVariant &value) { + if (!tag) + return; + switch (change) { case ScxmlDocument::TagAddChild: case ScxmlDocument::TagChangeParentAddChild: @@ -298,6 +301,9 @@ void StructureModel::beginTagChange(ScxmlDocument::TagChange change, ScxmlTag *t void StructureModel::endTagChange(ScxmlDocument::TagChange change, ScxmlTag *tag, const QVariant &value) { + if (!tag) + return; + switch (change) { case ScxmlDocument::TagAttributesChanged: { emit dataChanged(QModelIndex(), QModelIndex()); @@ -322,8 +328,7 @@ void StructureModel::endTagChange(ScxmlDocument::TagChange change, ScxmlTag *tag break; } case ScxmlDocument::TagCurrentChanged: { - if (tag) - emit selectIndex(createIndex(tag->index(), 0, tag)); + emit selectIndex(createIndex(tag->index(), 0, tag)); break; } default: diff --git a/src/plugins/scxmleditor/plugin_interface/graphicsscene.cpp b/src/plugins/scxmleditor/plugin_interface/graphicsscene.cpp index ffbbd0d0ab..e62fc096c2 100644 --- a/src/plugins/scxmleditor/plugin_interface/graphicsscene.cpp +++ b/src/plugins/scxmleditor/plugin_interface/graphicsscene.cpp @@ -465,7 +465,6 @@ void GraphicsScene::beginTagChange(ScxmlDocument::TagChange change, ScxmlTag *ta void GraphicsScene::endTagChange(ScxmlDocument::TagChange change, ScxmlTag *tag, const QVariant &value) { Q_UNUSED(value) - QTC_ASSERT(tag, return); switch (change) { case ScxmlDocument::TagAttributesChanged: { @@ -494,6 +493,7 @@ void GraphicsScene::endTagChange(ScxmlDocument::TagChange change, ScxmlTag *tag, auto childItem = qobject_cast<ConnectableItem*>(findItem(tag)); if (childItem) { + QTC_ASSERT(tag, break); BaseItem *newParentItem = findItem(tag->parentTag()); BaseItem *oldParentItem = childItem->parentBaseItem(); @@ -530,6 +530,9 @@ void GraphicsScene::endTagChange(ScxmlDocument::TagChange change, ScxmlTag *tag, } case ScxmlDocument::TagAddTags: { // Finalize transitions + if (!tag) + break; + QVector<ScxmlTag*> childTransitionTags; if (tag->tagName(false) == "transition") childTransitionTags << tag; @@ -543,7 +546,7 @@ void GraphicsScene::endTagChange(ScxmlDocument::TagChange change, ScxmlTag *tag, } break; case ScxmlDocument::TagAddChild: { - ScxmlTag *childTag = tag->child(value.toInt()); + ScxmlTag *childTag = tag ? tag->child(value.toInt()) : nullptr; if (childTag) { // Check that there is no any item with this tag BaseItem *childItem = findItem(childTag); @@ -578,21 +581,26 @@ void GraphicsScene::endTagChange(ScxmlDocument::TagChange change, ScxmlTag *tag, break; } case ScxmlDocument::TagRemoveChild: { - BaseItem *parentItem = findItem(tag); - if (parentItem) { - parentItem->updateAttributes(); - parentItem->checkInitial(); - } else { - checkInitialState(); + if (tag) { + BaseItem *parentItem = findItem(tag); + if (parentItem) { + parentItem->updateAttributes(); + parentItem->checkInitial(); + } else { + checkInitialState(); + } } break; } case ScxmlDocument::TagChangeOrder: { - BaseItem *parentItem = findItem(tag->parentTag()); - if (parentItem) - parentItem->updateAttributes(); - else - checkInitialState(); + if (tag) { + BaseItem *parentItem = findItem(tag->parentTag()); + if (parentItem) + parentItem->updateAttributes(); + else + checkInitialState(); + } + break; } default: break; |