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)
|
void StructureModel::beginTagChange(ScxmlDocument::TagChange change, ScxmlTag *tag, const QVariant &value)
|
||||||
{
|
{
|
||||||
|
if (!tag)
|
||||||
|
return;
|
||||||
|
|
||||||
switch (change) {
|
switch (change) {
|
||||||
case ScxmlDocument::TagAddChild:
|
case ScxmlDocument::TagAddChild:
|
||||||
case ScxmlDocument::TagChangeParentAddChild:
|
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)
|
void StructureModel::endTagChange(ScxmlDocument::TagChange change, ScxmlTag *tag, const QVariant &value)
|
||||||
{
|
{
|
||||||
|
if (!tag)
|
||||||
|
return;
|
||||||
|
|
||||||
switch (change) {
|
switch (change) {
|
||||||
case ScxmlDocument::TagAttributesChanged: {
|
case ScxmlDocument::TagAttributesChanged: {
|
||||||
emit dataChanged(QModelIndex(), QModelIndex());
|
emit dataChanged(QModelIndex(), QModelIndex());
|
||||||
@@ -322,8 +328,7 @@ void StructureModel::endTagChange(ScxmlDocument::TagChange change, ScxmlTag *tag
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ScxmlDocument::TagCurrentChanged: {
|
case ScxmlDocument::TagCurrentChanged: {
|
||||||
if (tag)
|
emit selectIndex(createIndex(tag->index(), 0, tag));
|
||||||
emit selectIndex(createIndex(tag->index(), 0, tag));
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
@@ -465,7 +465,6 @@ void GraphicsScene::beginTagChange(ScxmlDocument::TagChange change, ScxmlTag *ta
|
|||||||
void GraphicsScene::endTagChange(ScxmlDocument::TagChange change, ScxmlTag *tag, const QVariant &value)
|
void GraphicsScene::endTagChange(ScxmlDocument::TagChange change, ScxmlTag *tag, const QVariant &value)
|
||||||
{
|
{
|
||||||
Q_UNUSED(value)
|
Q_UNUSED(value)
|
||||||
QTC_ASSERT(tag, return);
|
|
||||||
|
|
||||||
switch (change) {
|
switch (change) {
|
||||||
case ScxmlDocument::TagAttributesChanged: {
|
case ScxmlDocument::TagAttributesChanged: {
|
||||||
@@ -494,6 +493,7 @@ void GraphicsScene::endTagChange(ScxmlDocument::TagChange change, ScxmlTag *tag,
|
|||||||
auto childItem = qobject_cast<ConnectableItem*>(findItem(tag));
|
auto childItem = qobject_cast<ConnectableItem*>(findItem(tag));
|
||||||
|
|
||||||
if (childItem) {
|
if (childItem) {
|
||||||
|
QTC_ASSERT(tag, break);
|
||||||
BaseItem *newParentItem = findItem(tag->parentTag());
|
BaseItem *newParentItem = findItem(tag->parentTag());
|
||||||
BaseItem *oldParentItem = childItem->parentBaseItem();
|
BaseItem *oldParentItem = childItem->parentBaseItem();
|
||||||
|
|
||||||
@@ -530,6 +530,9 @@ void GraphicsScene::endTagChange(ScxmlDocument::TagChange change, ScxmlTag *tag,
|
|||||||
}
|
}
|
||||||
case ScxmlDocument::TagAddTags: {
|
case ScxmlDocument::TagAddTags: {
|
||||||
// Finalize transitions
|
// Finalize transitions
|
||||||
|
if (!tag)
|
||||||
|
break;
|
||||||
|
|
||||||
QVector<ScxmlTag*> childTransitionTags;
|
QVector<ScxmlTag*> childTransitionTags;
|
||||||
if (tag->tagName(false) == "transition")
|
if (tag->tagName(false) == "transition")
|
||||||
childTransitionTags << tag;
|
childTransitionTags << tag;
|
||||||
@@ -543,7 +546,7 @@ void GraphicsScene::endTagChange(ScxmlDocument::TagChange change, ScxmlTag *tag,
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ScxmlDocument::TagAddChild: {
|
case ScxmlDocument::TagAddChild: {
|
||||||
ScxmlTag *childTag = tag->child(value.toInt());
|
ScxmlTag *childTag = tag ? tag->child(value.toInt()) : nullptr;
|
||||||
if (childTag) {
|
if (childTag) {
|
||||||
// Check that there is no any item with this tag
|
// Check that there is no any item with this tag
|
||||||
BaseItem *childItem = findItem(childTag);
|
BaseItem *childItem = findItem(childTag);
|
||||||
@@ -578,21 +581,26 @@ void GraphicsScene::endTagChange(ScxmlDocument::TagChange change, ScxmlTag *tag,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ScxmlDocument::TagRemoveChild: {
|
case ScxmlDocument::TagRemoveChild: {
|
||||||
BaseItem *parentItem = findItem(tag);
|
if (tag) {
|
||||||
if (parentItem) {
|
BaseItem *parentItem = findItem(tag);
|
||||||
parentItem->updateAttributes();
|
if (parentItem) {
|
||||||
parentItem->checkInitial();
|
parentItem->updateAttributes();
|
||||||
} else {
|
parentItem->checkInitial();
|
||||||
checkInitialState();
|
} else {
|
||||||
|
checkInitialState();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ScxmlDocument::TagChangeOrder: {
|
case ScxmlDocument::TagChangeOrder: {
|
||||||
BaseItem *parentItem = findItem(tag->parentTag());
|
if (tag) {
|
||||||
if (parentItem)
|
BaseItem *parentItem = findItem(tag->parentTag());
|
||||||
parentItem->updateAttributes();
|
if (parentItem)
|
||||||
else
|
parentItem->updateAttributes();
|
||||||
checkInitialState();
|
else
|
||||||
|
checkInitialState();
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
Reference in New Issue
Block a user