cleaning up moveRows to be easier to maintain
This commit is contained in:
parent
766dc02b91
commit
aff30cc9e8
1 changed files with 6 additions and 5 deletions
|
@ -326,16 +326,17 @@ bool ServiceItemModel::moveRows(int sourceIndex, int destIndex, int count) {
|
||||||
qDebug() << index(sourceIndex).row();
|
qDebug() << index(sourceIndex).row();
|
||||||
qDebug() << index(destIndex).row();
|
qDebug() << index(destIndex).row();
|
||||||
|
|
||||||
if (sourceIndex < 0 || sourceIndex == destIndex ||
|
const int lastIndex = rowCount() - 1;
|
||||||
destIndex == -1 || destIndex > rowCount() ||
|
|
||||||
sourceIndex >= rowCount()) {
|
if (sourceIndex == destIndex
|
||||||
|
|| (sourceIndex < 0 || sourceIndex > lastIndex)
|
||||||
|
|| (destIndex < 0 || destIndex > lastIndex)) {
|
||||||
return false;
|
return false;
|
||||||
};
|
}
|
||||||
|
|
||||||
const QModelIndex parent = index(sourceIndex).parent();
|
const QModelIndex parent = index(sourceIndex).parent();
|
||||||
const bool isMoveDown = destIndex > sourceIndex;
|
const bool isMoveDown = destIndex > sourceIndex;
|
||||||
|
|
||||||
|
|
||||||
if (!beginMoveRows(parent, sourceIndex, sourceIndex + count - 1,
|
if (!beginMoveRows(parent, sourceIndex, sourceIndex + count - 1,
|
||||||
parent, isMoveDown ? destIndex + 1 : destIndex)) {
|
parent, isMoveDown ? destIndex + 1 : destIndex)) {
|
||||||
qDebug() << "Can't move rows";
|
qDebug() << "Can't move rows";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue