From f571f3c2e76f6fb9cb4e88775bd21c36633e062c Mon Sep 17 00:00:00 2001 From: vsv Date: Thu, 5 May 2016 11:54:50 +0300 Subject: [PATCH] Improve deletion behavior: select last item if last item was deleted --- .../ModuleBase_WidgetMultiSelector.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp index b7f2995af..a651aa185 100755 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp @@ -326,9 +326,6 @@ bool ModuleBase_WidgetMultiSelector::processDelete() getSelectedAttributeIndices(anAttributeIds); QModelIndexList aIndexes = myListControl->selectionModel()->selectedIndexes(); - //foreach(QModelIndex aIndex, aIndexes) { - // aIndex.row(); - //} // refill attribute by the items which indices are not in the list of ids bool aDone = false; @@ -363,8 +360,18 @@ bool ModuleBase_WidgetMultiSelector::processDelete() myWorkshop->module()->customizeObject(myFeature, ModuleBase_IModule::CustomizeArguments, true); /// hope that something is redisplayed by object updated } - foreach(QModelIndex aIndex, aIndexes) { - myListControl->selectionModel()->select(aIndex, QItemSelectionModel::Select); + + // Restore selection + int aRows = myListControl->model()->rowCount(); + if (aRows > 0) { + foreach(QModelIndex aIndex, aIndexes) { + if (aIndex.row() < aRows) + myListControl->selectionModel()->select(aIndex, QItemSelectionModel::Select); + else { + QModelIndex aIdx = myListControl->model()->index(aRows - 1, 0); + myListControl->selectionModel()->select(aIdx, QItemSelectionModel::Select); + } + } } return aDone; } -- 2.39.2