diff options
author | Luca Beldi <v.ronin@yahoo.it> | 2018-09-04 20:09:23 +0100 |
---|---|---|
committer | Luca Beldi <v.ronin@yahoo.it> | 2018-09-06 09:26:58 +0000 |
commit | fcdb459c06c0756637e3301430290df5560494e0 (patch) | |
tree | 6ad1fd9836c0944acefdbf93146529d3c8f8fefd /src/widgets/itemviews/qlistwidget.cpp | |
parent | 551e11c286b45d3e94b38f0e5df95f443c15f0bd (diff) |
Implement QListModel::moveRows
Implemented the virtual method moveRows to allow row movement.
[ChangeLog][QtWidgets][QListWidget] Implemented moveRows in model
Task-number: QTBUG-69807
Change-Id: I212b560b8778306a0315d9d5e4710efcc7dbbe44
Reviewed-by: David Faure <david.faure@kdab.com>
Diffstat (limited to 'src/widgets/itemviews/qlistwidget.cpp')
-rw-r--r-- | src/widgets/itemviews/qlistwidget.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/widgets/itemviews/qlistwidget.cpp b/src/widgets/itemviews/qlistwidget.cpp index cd1b93d629..193e5bcb9c 100644 --- a/src/widgets/itemviews/qlistwidget.cpp +++ b/src/widgets/itemviews/qlistwidget.cpp @@ -293,6 +293,30 @@ bool QListModel::removeRows(int row, int count, const QModelIndex &parent) return true; } +/*! + \since 5.13 + \reimp +*/ +bool QListModel::moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild) +{ + if (sourceRow < 0 + || sourceRow + count - 1 >= rowCount(sourceParent) + || destinationChild <= 0 + || destinationChild > rowCount(destinationParent) + || sourceRow == destinationChild - 1 + || count <= 0) { + return false; + } + if (!beginMoveRows(QModelIndex(), sourceRow, sourceRow + count - 1, QModelIndex(), destinationChild)) + return false; + destinationChild--; + const int fromRow = destinationChild < sourceRow ? (sourceRow + count - 1) : sourceRow; + while (count--) + items.move(fromRow, destinationChild); + endMoveRows(); + return true; +} + Qt::ItemFlags QListModel::flags(const QModelIndex &index) const { if (!index.isValid() || index.row() >= items.count() || index.model() != this) |