diff options
author | Christian Ehrlicher <ch.ehrlicher@gmx.de> | 2019-12-02 21:04:09 +0100 |
---|---|---|
committer | Christian Ehrlicher <ch.ehrlicher@gmx.de> | 2019-12-16 22:12:52 +0100 |
commit | 4e04132264a1259d28dc55e1ad01f848562c4c6d (patch) | |
tree | ebbf13c5d5675d37fec75fa23d73a4f61b3fd02f /src | |
parent | be9398c8d4ab0b7eba74b607d82dc43cd40443b8 (diff) |
QStringListModel: fix moveRows()
QStringListMode::moveRows() had an issue when the destination was before
the source row.
Change-Id: Icf64e5b4cdd6a39faf3ba4ccc3883196b247ccbd
Reviewed-by: Luca Beldi <v.ronin@yahoo.it>
Reviewed-by: David Faure <david.faure@kdab.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/itemmodels/qstringlistmodel.cpp | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/src/corelib/itemmodels/qstringlistmodel.cpp b/src/corelib/itemmodels/qstringlistmodel.cpp index a248cdcd38..9c87ff853a 100644 --- a/src/corelib/itemmodels/qstringlistmodel.cpp +++ b/src/corelib/itemmodels/qstringlistmodel.cpp @@ -301,24 +301,23 @@ bool QStringListModel::moveRows(const QModelIndex &sourceParent, int sourceRow, { if (sourceRow < 0 || sourceRow + count - 1 >= rowCount(sourceParent) - || destinationChild <= 0 + || destinationChild < 0 || destinationChild > rowCount(destinationParent) + || sourceRow == destinationChild || sourceRow == destinationChild - 1 - || count <= 0) { + || count <= 0 + || sourceParent.isValid() + || destinationParent.isValid()) { return false; } if (!beginMoveRows(QModelIndex(), sourceRow, sourceRow + count - 1, QModelIndex(), destinationChild)) return false; - /* - QList::move assumes that the second argument is the index where the item will end up to - i.e. the valid range for that argument is from 0 to QList::size()-1 - QAbstractItemModel::moveRows when source and destinations have the same parent assumes that - the item will end up being in the row BEFORE the one indicated by destinationChild - i.e. the valid range for that argument is from 1 to QList::size() - For this reason we remove 1 from destinationChild when using it inside QList - */ - destinationChild--; - const int fromRow = destinationChild < sourceRow ? (sourceRow + count - 1) : sourceRow; + + int fromRow = sourceRow; + if (destinationChild < sourceRow) + fromRow += count - 1; + else + destinationChild--; while (count--) lst.move(fromRow, destinationChild); endMoveRows(); |