diff options
Diffstat (limited to 'src/widgets/itemviews/qlistwidget.cpp')
-rw-r--r-- | src/widgets/itemviews/qlistwidget.cpp | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/src/widgets/itemviews/qlistwidget.cpp b/src/widgets/itemviews/qlistwidget.cpp index 72e0a67a64..895622616e 100644 --- a/src/widgets/itemviews/qlistwidget.cpp +++ b/src/widgets/itemviews/qlistwidget.cpp @@ -227,6 +227,22 @@ bool QListModel::setData(const QModelIndex &index, const QVariant &value, int ro return true; } +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +bool QListModel::clearItemData(const QModelIndex &index) +{ + if (!checkIndex(index, CheckIndexOption::IndexIsValid)) + return false; + QListWidgetItem *item = items.at(index.row()); + const auto beginIter = item->d->values.cbegin(); + const auto endIter = item->d->values.cend(); + if (std::all_of(beginIter, endIter, [](const QWidgetItemData& data) -> bool { return !data.value.isValid(); })) + return true; //it's already cleared + item->d->values.clear(); + emit dataChanged(index, index, QVector<int>{}); + return true; +} +#endif + QMap<int, QVariant> QListModel::itemData(const QModelIndex &index) const { QMap<int, QVariant> roles; @@ -277,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) @@ -289,7 +329,7 @@ void QListModel::sort(int column, Qt::SortOrder order) if (column != 0) return; - emit layoutAboutToBeChanged(); + emit layoutAboutToBeChanged({}, QAbstractItemModel::VerticalSortHint); QVector < QPair<QListWidgetItem*,int> > sorting(items.count()); for (int i = 0; i < items.count(); ++i) { @@ -313,7 +353,7 @@ void QListModel::sort(int column, Qt::SortOrder order) } changePersistentIndexList(fromIndexes, toIndexes); - emit layoutChanged(); + emit layoutChanged({}, QAbstractItemModel::VerticalSortHint); } /** |