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;
}
bool isReverse = theType == Top || theType == Down;
QListIterator<int> 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;
}