summaryrefslogtreecommitdiffstats
path: root/src/widgets/itemviews/qlistwidget.cpp
diff options
context:
space:
mode:
authorChristian Ehrlicher <ch.ehrlicher@gmx.de>2018-10-31 20:11:58 +0100
committerChristian Ehrlicher <ch.ehrlicher@gmx.de>2018-12-04 21:01:18 +0000
commite2f473f4d43afc0c2b8d6256b57ea74ad256e437 (patch)
tree40f82af1790dbe6ad2a18fa3d68b5d064adc3a8d /src/widgets/itemviews/qlistwidget.cpp
parent009a5538ebce4c5517a717a201707f2b79749f64 (diff)
QListWidget: mark (is|set)Item(Selected|Hidden) as deprecated
QListWidget::(is|set)Item(Selected|Hidden)() are deprecated for a long time but not marked as such. Therefore explicitly mark them as deprecated so they can get removed with Qt6. Change-Id: I4567e740f1ebb5841b2e5b50c601fb83a782950c Reviewed-by: Konstantin Shegunov <kshegunov@gmail.com> Reviewed-by: Samuel Gaist <samuel.gaist@idiap.ch> Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'src/widgets/itemviews/qlistwidget.cpp')
-rw-r--r--src/widgets/itemviews/qlistwidget.cpp85
1 files changed, 51 insertions, 34 deletions
diff --git a/src/widgets/itemviews/qlistwidget.cpp b/src/widgets/itemviews/qlistwidget.cpp
index 6e0bdb3f22..ea92c5605b 100644
--- a/src/widgets/itemviews/qlistwidget.cpp
+++ b/src/widgets/itemviews/qlistwidget.cpp
@@ -583,24 +583,6 @@ Qt::DropActions QListModel::supportedDropActions() const
*/
/*!
- \fn void QListWidgetItem::setSelected(bool select)
- \since 4.2
-
- Sets the selected state of the item to \a select.
-
- \sa isSelected()
-*/
-
-/*!
- \fn bool QListWidgetItem::isSelected() const
- \since 4.2
-
- Returns \c true if the item is selected; otherwise returns \c false.
-
- \sa setSelected()
-*/
-
-/*!
\fn void QListWidgetItem::setHidden(bool hide)
\since 4.2
@@ -1002,6 +984,50 @@ QDataStream &operator>>(QDataStream &in, QListWidgetItem &item)
*/
/*!
+ \fn void QListWidgetItem::setSelected(bool select)
+ \since 4.2
+
+ Sets the selected state of the item to \a select.
+
+ \sa isSelected()
+*/
+void QListWidgetItem::setSelected(bool select)
+{
+ const QListModel *model = listModel();
+ if (!model || !view->selectionModel())
+ return;
+ const QAbstractItemView::SelectionMode selectionMode = view->selectionMode();
+ if (selectionMode == QAbstractItemView::NoSelection)
+ return;
+ const QModelIndex index = model->index(this);
+ if (selectionMode == QAbstractItemView::SingleSelection)
+ view->selectionModel()->select(index, select
+ ? QItemSelectionModel::ClearAndSelect
+ : QItemSelectionModel::Deselect);
+ else
+ view->selectionModel()->select(index, select
+ ? QItemSelectionModel::Select
+ : QItemSelectionModel::Deselect);
+}
+
+/*!
+ \fn bool QListWidgetItem::isSelected() const
+ \since 4.2
+
+ Returns \c true if the item is selected; otherwise returns \c false.
+
+ \sa setSelected()
+*/
+bool QListWidgetItem::isSelected() const
+{
+ const QListModel *model = listModel();
+ if (!model || !view->selectionModel())
+ return false;
+ const QModelIndex index = model->index(this);
+ return view->selectionModel()->isSelected(index);
+}
+
+/*!
\fn void QListWidgetItem::setFlags(Qt::ItemFlags flags)
Sets the item flags for the list item to \a flags.
@@ -1743,6 +1769,7 @@ void QListWidget::setItemWidget(QListWidgetItem *item, QWidget *widget)
QAbstractItemView::setIndexWidget(index, widget);
}
+#if QT_DEPRECATED_SINCE(5, 13)
/*!
Returns \c true if \a item is selected; otherwise returns \c false.
@@ -1752,9 +1779,7 @@ void QListWidget::setItemWidget(QListWidgetItem *item, QWidget *widget)
*/
bool QListWidget::isItemSelected(const QListWidgetItem *item) const
{
- Q_D(const QListWidget);
- QModelIndex index = d->listModel()->index(const_cast<QListWidgetItem*>(item));
- return selectionModel()->isSelected(index);
+ return ((item && item->listWidget() == this) ? item->isSelected() : false);
}
/*!
@@ -1767,20 +1792,10 @@ bool QListWidget::isItemSelected(const QListWidgetItem *item) const
*/
void QListWidget::setItemSelected(const QListWidgetItem *item, bool select)
{
- Q_D(QListWidget);
- QModelIndex index = d->listModel()->index(const_cast<QListWidgetItem*>(item));
-
- if (d->selectionMode == SingleSelection) {
- selectionModel()->select(index, select
- ? QItemSelectionModel::ClearAndSelect
- : QItemSelectionModel::Deselect);
- } else if (d->selectionMode != NoSelection) {
- selectionModel()->select(index, select
- ? QItemSelectionModel::Select
- : QItemSelectionModel::Deselect);
- }
-
+ if (item && item->listWidget() == this)
+ const_cast<QListWidgetItem*>(item)->setSelected(select);
}
+#endif
/*!
Returns a list of all selected items in the list widget.
@@ -1816,6 +1831,7 @@ QList<QListWidgetItem*> QListWidget::findItems(const QString &text, Qt::MatchFla
return items;
}
+#if QT_DEPRECATED_SINCE(5, 13)
/*!
Returns \c true if the \a item is explicitly hidden; otherwise returns \c false.
@@ -1839,6 +1855,7 @@ void QListWidget::setItemHidden(const QListWidgetItem *item, bool hide)
{
setRowHidden(row(item), hide);
}
+#endif
/*!
Scrolls the view if necessary to ensure that the \a item is visible.