From 91746830b2d2a44a7099c3f33109d0bac8e54400 Mon Sep 17 00:00:00 2001 From: mzn Date: Wed, 19 Mar 2014 15:14:33 +0000 Subject: [PATCH] Use beginMoveRows()/endMoveRows() --- src/ZLEVEL/HYDROGUI_ZLevelsModel.cxx | 59 ++++++++++++++-------------- 1 file changed, 29 insertions(+), 30 deletions(-) diff --git a/src/ZLEVEL/HYDROGUI_ZLevelsModel.cxx b/src/ZLEVEL/HYDROGUI_ZLevelsModel.cxx index e36287c8..25572638 100644 --- a/src/ZLEVEL/HYDROGUI_ZLevelsModel.cxx +++ b/src/ZLEVEL/HYDROGUI_ZLevelsModel.cxx @@ -205,51 +205,50 @@ bool HYDROGUI_ZLevelsModel::move( const int theItem, const OpType theType, return aRes; } + int aDestinationRow = -1; + switch ( theType ) { case Up: - { - if ( theItem > 0 ) { - int aSwapItem = theItem - 1; - if ( theIsVisibleOnly ) { - while ( aSwapItem >= 0 && !myObjects.at( aSwapItem ).second ) { - aSwapItem--; - } - } - if ( aSwapItem >= 0 ) { - myObjects.move( theItem, aSwapItem ); - aRes = true; + if ( theItem > 0 ) { + aDestinationRow = theItem - 1; + if ( theIsVisibleOnly ) { + while ( aDestinationRow >= 0 && !myObjects.at( aDestinationRow ).second ) { + aDestinationRow--; } } } break; case Down: if ( theItem < myObjects.count() - 1 ) { - int aSwapItem = theItem + 1; + aDestinationRow = theItem + 1; if ( theIsVisibleOnly ) { - while ( aSwapItem < myObjects.count() && !myObjects.at( aSwapItem ).second ) { - aSwapItem++; + while ( aDestinationRow < myObjects.count() && !myObjects.at( aDestinationRow ).second ) { + aDestinationRow++; } } - if ( aSwapItem < myObjects.count() ) { - myObjects.move( theItem, aSwapItem ); - aRes = true; - } } break; case Top: if ( theItem > 0 ) { - myObjects.move( theItem, 0 ); - aRes = true; + aDestinationRow = 0; } break; case Bottom: if ( theItem < myObjects.count() - 1 ) { - myObjects.move( theItem, myObjects.count() - 1 ); - aRes = true; + aDestinationRow = myObjects.count() - 1; } break; } + if ( aDestinationRow >= 0 && aDestinationRow < myObjects.count() ) { + int aDestination = (theType == Up || theType == Top) ? aDestinationRow : aDestinationRow + 1; + if ( beginMoveRows( QModelIndex(), theItem, theItem, QModelIndex(), aDestination ) ) { + myObjects.move( theItem, aDestinationRow ); //TODO ??? + endMoveRows(); + aRes = true; + } + } + return aRes; } @@ -260,35 +259,35 @@ bool HYDROGUI_ZLevelsModel::move( const QList& theItems, const OpType theTy bool isReverse = theType == Top || theType == Down; QListIterator anIt( theItems ); - bool isFirst = true; + int aShift = 0; if ( isReverse ) { anIt.toBack(); while ( anIt.hasPrevious() ) { int anId = anIt.previous(); - if ( theType == Top && !isFirst ) { - anId++; + if ( theType == Top ) { + anId += aShift; + aShift++; } if ( !move( anId, theType, theIsVisibleOnly, theDropItem ) ) { aRes = false; break; } - isFirst = false; } } else { while ( anIt.hasNext() ) { int anId = anIt.next(); - if ( theType == Bottom && !isFirst ) { - anId--; + if ( theType == Bottom ) { + anId -= aShift; + aShift++; } if ( !move( anId, theType, theIsVisibleOnly, theDropItem ) ) { aRes = false; break; } - isFirst = false; } } - reset(); //TODO dataChanged? + // reset(); //TODO dataChanged? return aRes; } -- 2.39.2