From: mzn Date: Wed, 19 Mar 2014 15:14:33 +0000 (+0000) Subject: Use beginMoveRows()/endMoveRows() X-Git-Tag: BR_hydro_v1_0_1~46 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=91746830b2d2a44a7099c3f33109d0bac8e54400;p=modules%2Fhydro.git Use beginMoveRows()/endMoveRows() --- 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; }