on xenial help sign in
Fix bug when calling setModel twice with the same model
39fd092Albert Astals
plugins/Utils/qlimitproxymodelqml.cpp+4−4
@@ -39,11 +39,11 @@ QHash<int, QByteArray> QLimitProxyModelQML::roleNames() const
39void
39void
40QLimitProxyModelQML::setModel(QAbstractItemModel *itemModel)
40QLimitProxyModelQML::setModel(QAbstractItemModel *itemModel)
41{
41{
42− if (sourceModel() != NULL) {
43− sourceModel()->disconnect(this);
44− }
45−
46 if (itemModel != sourceModel()) {
42 if (itemModel != sourceModel()) {
43+ if (sourceModel() != NULL) {
44+ sourceModel()->disconnect(this);
45+ }
46+
47 setSourceModel(itemModel);
47 setSourceModel(itemModel);
48
48
49 if (sourceModel() != NULL) {
49 if (sourceModel() != NULL) {
tests/plugins/Utils/qlimitproxymodeltest.cpp+15
@@ -446,6 +446,7 @@ private Q_SLOTS:
446
446
447 ModelTest t1(&proxy);
447 ModelTest t1(&proxy);
448 }
448 }
449+
449 void testModelChanged() {
450 void testModelChanged() {
450 QLimitProxyModelQML proxy;
451 QLimitProxyModelQML proxy;
451 MockListModel model, model2;
452 MockListModel model, model2;
@@ -464,6 +465,20 @@ private Q_SLOTS:
464 proxy.setModel(&model);
465 proxy.setModel(&model);
465 QCOMPARE(spyOnModelChanged.count(), 3);
466 QCOMPARE(spyOnModelChanged.count(), 3);
466 }
467 }
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+ }
467};
482};
468
483
469QTEST_MAIN(QLimitProxyModelTest)
484QTEST_MAIN(QLimitProxyModelTest)