From aef17ca40cfce34a2330a9fba7d4255aff21ab3b Mon Sep 17 00:00:00 2001 From: vsv Date: Thu, 20 Aug 2015 12:19:05 +0300 Subject: [PATCH] Fix for exception on Delete object --- src/XGUI/XGUI_DataModel.cpp | 10 ++++++++++ src/XGUI/XGUI_Workshop.cpp | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/XGUI/XGUI_DataModel.cpp b/src/XGUI/XGUI_DataModel.cpp index faf2891e3..bba968407 100644 --- a/src/XGUI/XGUI_DataModel.cpp +++ b/src/XGUI/XGUI_DataModel.cpp @@ -489,8 +489,13 @@ QModelIndex XGUI_DataModel::index(int theRow, int theColumn, const QModelIndex & } //****************************************************** +static QModelIndex MYLastDeleted; QModelIndex XGUI_DataModel::parent(const QModelIndex& theIndex) const { + // To avoid additional request about index which was already deleted + if (theIndex == MYLastDeleted) + return QModelIndex(); + int aId = theIndex.internalId(); if (aId != -1) { // The object is not a root folder ModelAPI_Document* aDoc = getSubDocument(theIndex.internalPointer()); @@ -499,6 +504,11 @@ QModelIndex XGUI_DataModel::parent(const QModelIndex& theIndex) const return findDocumentRootIndex(aDoc); } ObjectPtr aObj = object(theIndex); + if (!aObj.get()) { + // To avoid additional request about index which was already deleted + MYLastDeleted = theIndex; + return QModelIndex(); + } // Check is it object a sub-object of a complex object FeaturePtr aFeature = std::dynamic_pointer_cast(aObj); if (aFeature.get()) { diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 59c061997..84b91bcf9 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -1001,7 +1001,7 @@ void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked) QObjectPtrList aObjects = mySelector->selection()->selectedObjects(); if (theId == "DELETE_CMD") deleteObjects(); - if (theId == "MOVE_CMD") + else if (theId == "MOVE_CMD") moveObjects(); else if (theId == "COLOR_CMD") changeColor(aObjects); -- 2.39.2