The KSPM should never clear or reset the selection of the QItemSelectionModel it refers to. It should be a read-only view on that selection. If the selection changes while the source is being reset, ignore that selection change. The proxy will clear its own cached data when it processes the modelReset signal from the model, and will populate itself with the selection as it is at that point.wilder
parent
9ba41df61b
commit
41b8a5fc84
3 changed files with 61 additions and 5 deletions
@ -0,0 +1,51 @@ |
||||
|
||||
#include <QTest> |
||||
#include <QStringListModel> |
||||
|
||||
#include <kselectionproxymodel.h> |
||||
|
||||
class KSelectionProxyModelTest : public QObject |
||||
{ |
||||
Q_OBJECT |
||||
public: |
||||
KSelectionProxyModelTest(QObject* parent = 0) |
||||
: QObject(parent) |
||||
{ |
||||
|
||||
} |
||||
|
||||
private Q_SLOTS: |
||||
void selectOnSourceReset(); |
||||
}; |
||||
|
||||
void KSelectionProxyModelTest::selectOnSourceReset() |
||||
{ |
||||
QStringListModel strings({ |
||||
"Monday", |
||||
"Tuesday", |
||||
"Wednesday", |
||||
"Thursday" |
||||
}); |
||||
QItemSelectionModel selectionModel(&strings); |
||||
|
||||
connect(&strings, &QAbstractItemModel::modelReset, [&] { |
||||
selectionModel.select(QItemSelection(strings.index(0, 0), strings.index(2, 0)), |
||||
QItemSelectionModel::Select); |
||||
}); |
||||
|
||||
KSelectionProxyModel proxy(&selectionModel); |
||||
proxy.setSourceModel(&strings); |
||||
|
||||
selectionModel.select(QItemSelection(strings.index(0, 0), strings.index(2, 0)), |
||||
QItemSelectionModel::Select); |
||||
|
||||
strings.setStringList({ "One", "Two", "Three", "Four" }); |
||||
|
||||
QVERIFY(selectionModel.selection().contains(strings.index(0, 0))); |
||||
QVERIFY(selectionModel.selection().contains(strings.index(1, 0))); |
||||
QVERIFY(selectionModel.selection().contains(strings.index(2, 0))); |
||||
} |
||||
|
||||
QTEST_MAIN(KSelectionProxyModelTest) |
||||
|
||||
#include "kselectionproxymodeltest.moc" |
||||
Loading…
Reference in new issue