cleaning up moveRows to be easier to maintain

This commit is contained in:
Chris Cochrun 2022-12-04 06:39:08 -06:00
parent 766dc02b91
commit aff30cc9e8

View file

@ -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";