on xenial help sign in
Fix bug when calling setModel twice with the same model
commit39fd092c100e4644f2ef5815dc8bafe3d73f25a7 authorAlbert Astals <albert.astals@canonical.com> dateTue 2 Jul 2013, 16:59 (13 years ago) parente37e13c
2 files changed+19−4
plugins/Utils/qlimitproxymodelqml.cpp+4−4 tests/plugins/Utils/qlimitproxymodeltest.cpp+15
plugins/Utils/qlimitproxymodelqml.cpp+4−4
@@ -39,11 +39,11 @@ QHash<int, QByteArray> QLimitProxyModelQML::roleNames() const
3939void
4040QLimitProxyModelQML::setModel(QAbstractItemModel *itemModel)
4141{
42− if (sourceModel() != NULL) {
43− sourceModel()->disconnect(this);
44− }
45−
4642 if (itemModel != sourceModel()) {
43+ if (sourceModel() != NULL) {
44+ sourceModel()->disconnect(this);
45+ }
46+
4747 setSourceModel(itemModel);
4848
4949 if (sourceModel() != NULL) {
tests/plugins/Utils/qlimitproxymodeltest.cpp+15
@@ -446,6 +446,7 @@ private Q_SLOTS:
446446
447447 ModelTest t1(&proxy);
448448 }
449+
449450 void testModelChanged() {
450451 QLimitProxyModelQML proxy;
451452 MockListModel model, model2;
@@ -464,6 +465,20 @@ private Q_SLOTS:
464465 proxy.setModel(&model);
465466 QCOMPARE(spyOnModelChanged.count(), 3);
466467 }
468+
469+ void setSameModelTwice() {
470+ QLimitProxyModelQML proxy;
471+ MockListModel model;
472+
473+ proxy.setModel(&model);
474+ proxy.setModel(&model);
475+
476+ QSignalSpy spyOnCountChanged(&proxy, SIGNAL(countChanged()));
477+
478+ model.insertRows(0, 5);
479+ QCOMPARE(proxy.rowCount(), 5);
480+ QCOMPARE(spyOnCountChanged.count(), 1);
481+ }
467482};
468483
469484QTEST_MAIN(QLimitProxyModelTest)