Commit ee9ecf86 authored by Ulf Hermann's avatar Ulf Hermann

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: 's avatarMarco Benelli <marco.benelli@qt.io>
Reviewed-by: 's avatarTomasz Olszak <olszak.tomasz@gmail.com>
parent 585b2c62
......@@ -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:
......
......@@ -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;
......
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