diff --git a/autotests/kselectionproxymodeltest.cpp b/autotests/kselectionproxymodeltest.cpp index b029964..77ca5e1 100644 --- a/autotests/kselectionproxymodeltest.cpp +++ b/autotests/kselectionproxymodeltest.cpp @@ -48,6 +48,7 @@ private Q_SLOTS: void columnCountShouldBeStable(); void selectOnSourceReset(); void selectionMapping(); + void removeSelected(); #if QT_VERSION >= QT_VERSION_CHECK(5, 5, 0) void selectionModelModelChange(); @@ -169,6 +170,27 @@ void KSelectionProxyModelTest::selectionModelModelChange() QCOMPARE(proxy.rowCount(), 1); QCOMPARE(proxy.index(0, 0).data().toString(), numbers.at(0)); } + +void KSelectionProxyModelTest::removeSelected() +{ + QStringListModel strings(days); + QItemSelectionModel selectionModel; + KSelectionProxyModel proxy(&selectionModel); + proxy.setFilterBehavior(KSelectionProxyModel::ExactSelection); + + proxy.setSourceModel(&strings); + selectionModel.setModel(&strings); + + QSignalSpy beforeSpy(&proxy, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int))); + QSignalSpy afterSpy(&proxy, SIGNAL(rowsRemoved(QModelIndex,int,int))); + + + selectionModel.select(strings.index(0, 0), QItemSelectionModel::Select); + strings.removeRow(0); + + QCOMPARE(beforeSpy.count(), 1); + QCOMPARE(afterSpy.count(), 1); +} #endif void KSelectionProxyModelTest::selectionMapping() diff --git a/src/kselectionproxymodel.cpp b/src/kselectionproxymodel.cpp index a542a17..5169cec 100644 --- a/src/kselectionproxymodel.cpp +++ b/src/kselectionproxymodel.cpp @@ -1291,7 +1291,7 @@ void KSelectionProxyModelPrivate::sourceRowsRemoved(const QModelIndex &parent, i Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true); - if (!m_selectionModel || !m_selectionModel->hasSelection()) { + if (!m_selectionModel) { return; }