diff options
author | Leander Beernaert <leander.beernaert@qt.io> | 2020-01-22 13:47:08 +0100 |
---|---|---|
committer | Leander Beernaert <leander.beernaert@qt.io> | 2020-01-24 13:17:33 +0100 |
commit | 502d3d6744913899da87acfda5ebdab42c40329e (patch) | |
tree | 16658a328503bfd5a62b4fd5d69ffb66e9854b18 /src/widgets/itemviews/qlistwidget.cpp | |
parent | d1be8b9ceb2c7b20bbe53a07154c79699540ea3d (diff) | |
parent | 06bb315beb6c2c398223cfe52cbc7f66e14a8557 (diff) |
Merge remote-tracking branch 'origin/dev' into merge-dev
Change-Id: I31b761cfd5ea01373c60d02a5da8c33398d34739
Diffstat (limited to 'src/widgets/itemviews/qlistwidget.cpp')
-rw-r--r-- | src/widgets/itemviews/qlistwidget.cpp | 46 |
1 files changed, 29 insertions, 17 deletions
diff --git a/src/widgets/itemviews/qlistwidget.cpp b/src/widgets/itemviews/qlistwidget.cpp index c45d41dab5..4aca923151 100644 --- a/src/widgets/itemviews/qlistwidget.cpp +++ b/src/widgets/itemviews/qlistwidget.cpp @@ -75,7 +75,7 @@ void QListModel::clear() for (int i = 0; i < items.count(); ++i) { if (items.at(i)) { items.at(i)->d->theid = -1; - items.at(i)->view = 0; + items.at(i)->view = nullptr; delete items.at(i); } } @@ -96,7 +96,7 @@ void QListModel::remove(QListWidgetItem *item) Q_ASSERT(row != -1); beginRemoveRows(QModelIndex(), row, row); items.at(row)->d->theid = -1; - items.at(row)->view = 0; + items.at(row)->view = nullptr; items.removeAt(row); endRemoveRows(); } @@ -156,11 +156,11 @@ void QListModel::insert(int row, const QStringList &labels) QListWidgetItem *QListModel::take(int row) { if (row < 0 || row >= items.count()) - return 0; + return nullptr; beginRemoveRows(QModelIndex(), row, row); items.at(row)->d->theid = -1; - items.at(row)->view = 0; + items.at(row)->view = nullptr; QListWidgetItem *item = items.takeAt(row); endRemoveRows(); return item; @@ -263,7 +263,7 @@ bool QListModel::insertRows(int row, int count, const QModelIndex &parent) beginInsertRows(QModelIndex(), row, row + count - 1); QListWidget *view = qobject_cast<QListWidget*>(QObject::parent()); - QListWidgetItem *itm = 0; + QListWidgetItem *itm = nullptr; for (int r = row; r < row + count; ++r) { itm = new QListWidgetItem; @@ -282,10 +282,10 @@ bool QListModel::removeRows(int row, int count, const QModelIndex &parent) return false; beginRemoveRows(QModelIndex(), row, row + count - 1); - QListWidgetItem *itm = 0; + QListWidgetItem *itm = nullptr; for (int r = row; r < row + count; ++r) { itm = items.takeAt(row); - itm->view = 0; + itm->view = nullptr; itm->d->theid = -1; delete itm; } @@ -301,16 +301,23 @@ bool QListModel::moveRows(const QModelIndex &sourceParent, int sourceRow, int co { 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; - destinationChild--; - const int fromRow = destinationChild < sourceRow ? (sourceRow + count - 1) : sourceRow; + + int fromRow = sourceRow; + if (destinationChild < sourceRow) + fromRow += count - 1; + else + destinationChild--; while (count--) items.move(fromRow, destinationChild); endMoveRows(); @@ -987,8 +994,9 @@ QDataStream &operator>>(QDataStream &in, QListWidgetItem &item) \fn void QListWidgetItem::setSizeHint(const QSize &size) \since 4.1 - Sets the size hint for the list item to be \a size. If no size hint is set, - the item delegate will compute the size hint based on the item data. + Sets the size hint for the list item to be \a size. + If no size hint is set or \a size is invalid, the item + delegate will compute the size hint based on the item data. */ /*! @@ -1119,6 +1127,8 @@ void QListWidgetItem::setFlags(Qt::ItemFlags aflags) \since 4.2 Sets the background brush of the list item to the given \a brush. + Setting a default-constructed brush will let the view use the + default color from the style. \sa background(), setForeground() */ @@ -1137,6 +1147,8 @@ void QListWidgetItem::setFlags(Qt::ItemFlags aflags) \since 4.2 Sets the foreground brush of the list item to the given \a brush. + Setting a default-constructed brush will let the view use the + default color from the style. \sa foreground(), setBackground() */ @@ -1215,7 +1227,7 @@ void QListWidgetPrivate::_q_emitCurrentItemChanged(const QModelIndex ¤t, //persistentCurrent is invalid if something changed the model in response //to the currentItemChanged signal emission and the item was removed if (!persistentCurrent.isValid()) { - currentItem = 0; + currentItem = nullptr; } emit q->currentTextChanged(currentItem ? currentItem->text() : QString()); @@ -1473,7 +1485,7 @@ QListWidgetItem *QListWidget::item(int row) const { Q_D(const QListWidget); if (row < 0 || row >= d->model->rowCount()) - return 0; + return nullptr; return d->listModel()->at(row); } @@ -1543,7 +1555,7 @@ QListWidgetItem *QListWidget::takeItem(int row) { Q_D(QListWidget); if (row < 0 || row >= d->model->rowCount()) - return 0; + return nullptr; return d->listModel()->take(row); } @@ -2059,7 +2071,7 @@ QListWidgetItem *QListWidget::itemFromIndex(const QModelIndex &index) const Q_D(const QListWidget); if (d->isIndexValid(index)) return d->listModel()->at(index.row()); - return 0; + return nullptr; } /*! |