From ad089218fff16e2f0fccd77888d098f6d4ed8454 Mon Sep 17 00:00:00 2001 From: ana Date: Thu, 28 Mar 2013 09:21:17 +0000 Subject: [PATCH] Fix crash during deleting several objects in OB --- src/SUIT/SUIT_TreeModel.cxx | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/SUIT/SUIT_TreeModel.cxx b/src/SUIT/SUIT_TreeModel.cxx index 321173da3..eebeb4acf 100755 --- a/src/SUIT/SUIT_TreeModel.cxx +++ b/src/SUIT/SUIT_TreeModel.cxx @@ -1611,13 +1611,28 @@ void SUIT_TreeModel::updateItem( SUIT_TreeModel::TreeItem* item, bool emitLayout return; // update all columns corresponding to the given data object - emit layoutAboutToBeChanged(); // Comment by VSR 25/04/2011: fix crash on delete objects. Uncomment by PRascle 18/12/2012 : required by Qt4.8 (original issue 22424 not accessible) - QModelIndex firstIdx = index( obj, 0 ); - QModelIndex lastIdx = index( obj, columnCount() - 1 ); - emit dataChanged( firstIdx, lastIdx ); - obj->setModified(false); - if ( emitLayoutChanged ) - emit layoutChanged(); + /*To avoid crashes we should update any persistent model indexes before emitting layoutChanged(). In other words, when the structure changes: + - emit layoutAboutToBeChanged + - Remember the QModelIndex that will change + - call changePersistentIndex() + - emit layoutChanged + */ + + emit layoutAboutToBeChanged(); + + // Remember the QModelIndex that will change + QModelIndexList fromIndexes; + QModelIndexList toIndexes; + for (int i = 0; i < columnCount() - 1; ++i) { + fromIndexes.append( index( obj, i )); + toIndexes.append(QModelIndex()); + } + changePersistentIndexList(fromIndexes, toIndexes); // Limitation: can lead to loss of selection + + emit dataChanged( toIndexes.first(), toIndexes.last() ); + obj->setModified(false); + if ( emitLayoutChanged ) + emit layoutChanged(); } /*! -- 2.39.2