forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -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,7 +328,6 @@ void StructureModel::endTagChange(ScxmlDocument::TagChange change, ScxmlTag *tag
|
||||
break;
|
||||
}
|
||||
case ScxmlDocument::TagCurrentChanged: {
|
||||
if (tag)
|
||||
emit selectIndex(createIndex(tag->index(), 0, tag));
|
||||
break;
|
||||
}
|
||||
|
@@ -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,6 +581,7 @@ void GraphicsScene::endTagChange(ScxmlDocument::TagChange change, ScxmlTag *tag,
|
||||
break;
|
||||
}
|
||||
case ScxmlDocument::TagRemoveChild: {
|
||||
if (tag) {
|
||||
BaseItem *parentItem = findItem(tag);
|
||||
if (parentItem) {
|
||||
parentItem->updateAttributes();
|
||||
@@ -585,15 +589,19 @@ void GraphicsScene::endTagChange(ScxmlDocument::TagChange change, ScxmlTag *tag,
|
||||
} else {
|
||||
checkInitialState();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ScxmlDocument::TagChangeOrder: {
|
||||
if (tag) {
|
||||
BaseItem *parentItem = findItem(tag->parentTag());
|
||||
if (parentItem)
|
||||
parentItem->updateAttributes();
|
||||
else
|
||||
checkInitialState();
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
Reference in New Issue
Block a user