From fa0b4c1ce385d995d1ab1859d5bef33aad47c64d Mon Sep 17 00:00:00 2001 From: rnv Date: Fri, 24 Sep 2010 10:29:08 +0000 Subject: [PATCH] Fix for the Bug "IPAL22014: WinTC5.1.4: Restore view problems" --- .../OCCViewer_CreateRestoreViewDlg.cxx | 65 +++++++++++-------- 1 file changed, 38 insertions(+), 27 deletions(-) diff --git a/src/OCCViewer/OCCViewer_CreateRestoreViewDlg.cxx b/src/OCCViewer/OCCViewer_CreateRestoreViewDlg.cxx index 574e7de73..dcce1dd19 100755 --- a/src/OCCViewer/OCCViewer_CreateRestoreViewDlg.cxx +++ b/src/OCCViewer/OCCViewer_CreateRestoreViewDlg.cxx @@ -181,35 +181,44 @@ viewAspect OCCViewer_CreateRestoreViewDlg::currentItem() const */ void OCCViewer_CreateRestoreViewDlg::deleteSelectedItems() { - if( myListBox->count() ) - { - int curIndex = -1; - for( int i = 0; i < (int)myListBox->count(); i++ ) - if( myListBox->item( i )->isSelected() && ( myListBox->item( i )->flags() & Qt::ItemIsEditable ) ) - { - QListWidgetItem* anItemToDelete = myListBox->takeItem( i ); - delete anItemToDelete; - for( int j = i; j < (int)myParametersMap.count(); j++ ) - if( j != myParametersMap.count() - 1 ) - myParametersMap[ j ] = myParametersMap[ j + 1 ]; - else - myParametersMap.removeAt( j ); - if( i != myListBox->count() ) - curIndex = i; - else - curIndex = i - 1; - i--; - } - if( curIndex >= 0 ) - { - myListBox->setCurrentItem( myListBox->item( curIndex ) ); - changeImage( myListBox->item( curIndex ) ); - } + QList selectedItems = myListBox->selectedItems(); + if( myListBox->count() && selectedItems.count()) + { + int curIndex = -1; + // Iterate by all selected items + for(int i = 0; i < selectedItems.count(); i++) + { + QListWidgetItem* item = selectedItems.at(i); + // get position of the selected item in the list + int position = myListBox->row(item); + + //Calculate current index in case if "item" is last selected item. + if(i == selectedItems.count() - 1) + if(position != myListBox->count() - 1) + curIndex = position; + else + curIndex = position - 1; + + //Delete item + delete item; + + //Shift parameters in the map + for( int j = position; j < (int)myParametersMap.count(); j++ ) + if( j != myParametersMap.count() - 1 ) + myParametersMap[ j ] = myParametersMap[ j + 1 ]; + else + myParametersMap.removeAt( j ); + + } + if( curIndex >= 0 ) + { + myListBox->setCurrentItem( myListBox->item( curIndex ) ); + changeImage( myListBox->item( curIndex ) ); + } } if( !myListBox->count() ) { - myListBox->clear(); - myListBox->insertItem( 0, "No Items" ); + clearList(); } } @@ -220,8 +229,10 @@ void OCCViewer_CreateRestoreViewDlg::clearList() { myListBox->clear(); myListBox->insertItem( 0, "No Items" ); - myParametersMap.clear(); + + //Clear view + myCurViewPort->reset(); } /*! -- 2.39.2