diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-02-11 12:04:38 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-02-13 19:42:39 +0100 |
commit | 720079d6a839b4d03eb0ceaa06d0ad2b446f7de1 (patch) | |
tree | 83ca22e1ef489a4ef7b7de7395c58130bb9ecf7f | |
parent | 1259b236704e790fa1284a63ec537525bce23841 (diff) | |
download | sink-720079d6a839b4d03eb0ceaa06d0ad2b446f7de1.tar.gz sink-720079d6a839b4d03eb0ceaa06d0ad2b446f7de1.zip |
Don't emit superfluous remove signals.
We often let removal updates through and expect the model to deal with
superfluous updates, this now actually implements that.
-rw-r--r-- | common/modelresult.cpp | 14 | ||||
-rw-r--r-- | tests/querytest.cpp | 38 |
2 files changed, 46 insertions, 6 deletions
diff --git a/common/modelresult.cpp b/common/modelresult.cpp index 0825518..f935419 100644 --- a/common/modelresult.cpp +++ b/common/modelresult.cpp | |||
@@ -228,12 +228,14 @@ void ModelResult<T, Ptr>::remove(const Ptr &value) | |||
228 | auto parent = createIndexFromId(id); | 228 | auto parent = createIndexFromId(id); |
229 | SinkTraceCtx(mLogCtx) << "Removed entity" << childId; | 229 | SinkTraceCtx(mLogCtx) << "Removed entity" << childId; |
230 | auto index = mTree[id].indexOf(childId); | 230 | auto index = mTree[id].indexOf(childId); |
231 | beginRemoveRows(parent, index, index); | 231 | if (index >= 0) { |
232 | mEntities.remove(childId); | 232 | beginRemoveRows(parent, index, index); |
233 | mTree[id].removeAll(childId); | 233 | mEntities.remove(childId); |
234 | mParents.remove(childId); | 234 | mTree[id].removeAll(childId); |
235 | // TODO remove children | 235 | mParents.remove(childId); |
236 | endRemoveRows(); | 236 | // TODO remove children |
237 | endRemoveRows(); | ||
238 | } | ||
237 | } | 239 | } |
238 | 240 | ||
239 | template <class T, class Ptr> | 241 | template <class T, class Ptr> |
diff --git a/tests/querytest.cpp b/tests/querytest.cpp index 328448f..b358621 100644 --- a/tests/querytest.cpp +++ b/tests/querytest.cpp | |||
@@ -1,6 +1,7 @@ | |||
1 | #include <QtTest> | 1 | #include <QtTest> |
2 | 2 | ||
3 | #include <QString> | 3 | #include <QString> |
4 | #include <QSignalSpy> | ||
4 | 5 | ||
5 | #include "resource.h" | 6 | #include "resource.h" |
6 | #include "store.h" | 7 | #include "store.h" |
@@ -786,6 +787,12 @@ private slots: | |||
786 | auto model = Sink::Store::loadModel<Mail>(query); | 787 | auto model = Sink::Store::loadModel<Mail>(query); |
787 | QTRY_COMPARE(model->rowCount(), 1); | 788 | QTRY_COMPARE(model->rowCount(), 1); |
788 | 789 | ||
790 | QSignalSpy insertedSpy(model.data(), &QAbstractItemModel::rowsInserted); | ||
791 | QSignalSpy removedSpy(model.data(), &QAbstractItemModel::rowsRemoved); | ||
792 | QSignalSpy changedSpy(model.data(), &QAbstractItemModel::dataChanged); | ||
793 | QSignalSpy layoutChangedSpy(model.data(), &QAbstractItemModel::layoutChanged); | ||
794 | QSignalSpy resetSpy(model.data(), &QAbstractItemModel::modelReset); | ||
795 | |||
789 | //The leader should change to mail2 after the modification | 796 | //The leader should change to mail2 after the modification |
790 | { | 797 | { |
791 | auto mail2 = Mail::createEntity<Mail>("sink.dummy.instance1"); | 798 | auto mail2 = Mail::createEntity<Mail>("sink.dummy.instance1"); |
@@ -802,6 +809,13 @@ private slots: | |||
802 | QTRY_COMPARE(mail->getMessageId(), QByteArray{"mail2"}); | 809 | QTRY_COMPARE(mail->getMessageId(), QByteArray{"mail2"}); |
803 | QCOMPARE(mail->getProperty("count").toInt(), 2); | 810 | QCOMPARE(mail->getProperty("count").toInt(), 2); |
804 | QCOMPARE(mail->getProperty("folders").toList().size(), 2); | 811 | QCOMPARE(mail->getProperty("folders").toList().size(), 2); |
812 | |||
813 | //This should eventually be just one modification instead of remove + add (See datastorequery reduce component) | ||
814 | QCOMPARE(insertedSpy.size(), 1); | ||
815 | QCOMPARE(removedSpy.size(), 1); | ||
816 | QCOMPARE(changedSpy.size(), 0); | ||
817 | QCOMPARE(layoutChangedSpy.size(), 0); | ||
818 | QCOMPARE(resetSpy.size(), 0); | ||
805 | } | 819 | } |
806 | 820 | ||
807 | void testBloom() | 821 | void testBloom() |
@@ -875,12 +889,28 @@ private slots: | |||
875 | auto model = Sink::Store::loadModel<Mail>(query); | 889 | auto model = Sink::Store::loadModel<Mail>(query); |
876 | QTRY_COMPARE(model->rowCount(), 1); | 890 | QTRY_COMPARE(model->rowCount(), 1); |
877 | 891 | ||
892 | QSignalSpy insertedSpy(model.data(), &QAbstractItemModel::rowsInserted); | ||
893 | QSignalSpy removedSpy(model.data(), &QAbstractItemModel::rowsRemoved); | ||
894 | QSignalSpy changedSpy(model.data(), &QAbstractItemModel::dataChanged); | ||
895 | QSignalSpy layoutChangedSpy(model.data(), &QAbstractItemModel::layoutChanged); | ||
896 | QSignalSpy resetSpy(model.data(), &QAbstractItemModel::modelReset); | ||
897 | |||
898 | //This modification should make it through | ||
899 | { | ||
900 | //This should not trigger an entity already in model warning | ||
901 | mail1.setUnread(false); | ||
902 | VERIFYEXEC(Sink::Store::modify(mail1)); | ||
903 | } | ||
904 | |||
905 | //This mail should make it through | ||
878 | { | 906 | { |
879 | auto mail = Mail::createEntity<Mail>("sink.dummy.instance1"); | 907 | auto mail = Mail::createEntity<Mail>("sink.dummy.instance1"); |
880 | mail.setExtractedMessageId("mail2"); | 908 | mail.setExtractedMessageId("mail2"); |
881 | mail.setFolder(folder1); | 909 | mail.setFolder(folder1); |
882 | VERIFYEXEC(Sink::Store::create(mail)); | 910 | VERIFYEXEC(Sink::Store::create(mail)); |
883 | } | 911 | } |
912 | |||
913 | //This mail shouldn't make it through | ||
884 | { | 914 | { |
885 | auto mail = Mail::createEntity<Mail>("sink.dummy.instance1"); | 915 | auto mail = Mail::createEntity<Mail>("sink.dummy.instance1"); |
886 | mail.setExtractedMessageId("mail3"); | 916 | mail.setExtractedMessageId("mail3"); |
@@ -892,6 +922,14 @@ private slots: | |||
892 | QTRY_COMPARE(model->rowCount(), 2); | 922 | QTRY_COMPARE(model->rowCount(), 2); |
893 | QTest::qWait(100); | 923 | QTest::qWait(100); |
894 | QCOMPARE(model->rowCount(), 2); | 924 | QCOMPARE(model->rowCount(), 2); |
925 | |||
926 | //From mail2 | ||
927 | QCOMPARE(insertedSpy.size(), 1); | ||
928 | QCOMPARE(removedSpy.size(), 0); | ||
929 | //From the modification | ||
930 | QCOMPARE(changedSpy.size(), 1); | ||
931 | QCOMPARE(layoutChangedSpy.size(), 0); | ||
932 | QCOMPARE(resetSpy.size(), 0); | ||
895 | } | 933 | } |
896 | }; | 934 | }; |
897 | 935 | ||