diff options
author | Samuel Gaist <samuel.gaist@edeltech.ch> | 2016-02-20 22:50:23 +0100 |
---|---|---|
committer | Samuel Gaist <samuel.gaist@edeltech.ch> | 2016-02-21 20:50:18 +0000 |
commit | 6129aade0018437d8d65a0051040d7100c8ec681 (patch) | |
tree | 89f56592f5c13b642b39760787ee57266f15fd82 /src/widgets/itemviews/qlistwidget.cpp | |
parent | 923be3f78ca1b2fc4be8bd4b2ac80b4f1b4df152 (diff) |
QListWidget: setup connections when changing selection model.
QListWidget uses a set of slots for its selection model that are
connected only at creation time. This patch adds the missing
connections cleanup and setup when a user changes the selection
model.
Task-number: QTBUG-50891
Change-Id: I942bae6c471ea1ae22637d09b96d6fbd422f653f
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Diffstat (limited to 'src/widgets/itemviews/qlistwidget.cpp')
-rw-r--r-- | src/widgets/itemviews/qlistwidget.cpp | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/src/widgets/itemviews/qlistwidget.cpp b/src/widgets/itemviews/qlistwidget.cpp index 1f129e483b..434e819d9c 100644 --- a/src/widgets/itemviews/qlistwidget.cpp +++ b/src/widgets/itemviews/qlistwidget.cpp @@ -1069,10 +1069,6 @@ void QListWidgetPrivate::setup() QObject::connect(q, SIGNAL(entered(QModelIndex)), q, SLOT(_q_emitItemEntered(QModelIndex))); QObject::connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), q, SLOT(_q_emitItemChanged(QModelIndex))); - QObject::connect(q->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), - q, SLOT(_q_emitCurrentItemChanged(QModelIndex,QModelIndex))); - QObject::connect(q->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), - q, SIGNAL(itemSelectionChanged())); QObject::connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), q, SLOT(_q_dataChanged(QModelIndex,QModelIndex))); QObject::connect(model, SIGNAL(columnsRemoved(QModelIndex,int,int)), q, SLOT(_q_sort())); @@ -1355,6 +1351,31 @@ QListWidget::~QListWidget() } /*! + \reimp +*/ + +void QListWidget::setSelectionModel(QItemSelectionModel *selectionModel) +{ + Q_D(QListWidget); + + if (d->selectionModel) { + QObject::disconnect(d->selectionModel, SIGNAL(currentChanged(QModelIndex,QModelIndex)), + this, SLOT(_q_emitCurrentItemChanged(QModelIndex,QModelIndex))); + QObject::disconnect(d->selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), + this, SIGNAL(itemSelectionChanged())); + } + + QListView::setSelectionModel(selectionModel); + + if (d->selectionModel) { + QObject::connect(d->selectionModel, SIGNAL(currentChanged(QModelIndex,QModelIndex)), + this, SLOT(_q_emitCurrentItemChanged(QModelIndex,QModelIndex))); + QObject::connect(d->selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), + this, SIGNAL(itemSelectionChanged())); + } +} + +/*! Returns the item that occupies the given \a row in the list if one has been set; otherwise returns 0. |