summaryrefslogtreecommitdiffstats
path: root/src/corelib/itemmodels/qstringlistmodel.cpp
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2020-01-04 15:32:34 +0100
committerLiang Qi <liang.qi@qt.io>2020-01-04 15:32:34 +0100
commita503bf54705d89204007e8f887b668fe5ef519fc (patch)
treeb2d1a452da39450eac78a1aeb1df116a73f64b23 /src/corelib/itemmodels/qstringlistmodel.cpp
parente65c43fd0ffa57248e7d750570b7deae171a82f5 (diff)
parent1f87fb359fdff14e42662384a9c8a0bcb3837671 (diff)
Merge remote-tracking branch 'origin/5.15' into dev
Conflicts: src/corelib/tools/qvector.h Make QVector(DataPointer dd) public to be able to properly merge 5b4b437b30b320e2cd7c9a566999a39772e5d431 from 5.15 into dev. src/widgets/kernel/qapplication.cpp tests/auto/tools/moc/allmocs_baseline_in.json Done-With: Christian Ehrlicher <ch.ehrlicher@gmx.de> Change-Id: I929ba7c036d570382d0454c2c75f6f0d96ddbc01
Diffstat (limited to 'src/corelib/itemmodels/qstringlistmodel.cpp')
-rw-r--r--src/corelib/itemmodels/qstringlistmodel.cpp23
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();