diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-12-17 19:16:55 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-12-17 19:16:55 +0100 |
commit | ef6150aa4c7c05ba4879dcf9274506ccd1b38f15 (patch) | |
tree | f1dfe73cd0f3a8e857ec450ccffc861a74a6653f | |
parent | b4168a61fbf56afea00f06d308eddbe1a562c1bf (diff) | |
download | sink-ef6150aa4c7c05ba4879dcf9274506ccd1b38f15.tar.gz sink-ef6150aa4c7c05ba4879dcf9274506ccd1b38f15.zip |
Make queries by id work
-rw-r--r-- | common/queryrunner.cpp | 5 | ||||
-rw-r--r-- | tests/querytest.cpp | 33 |
2 files changed, 38 insertions, 0 deletions
diff --git a/common/queryrunner.cpp b/common/queryrunner.cpp index b3c9f07..9e23eed 100644 --- a/common/queryrunner.cpp +++ b/common/queryrunner.cpp | |||
@@ -221,6 +221,11 @@ template<class DomainType> | |||
221 | std::function<bool(const Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr &domainObject)> QueryRunner<DomainType>::getFilter(const QSet<QByteArray> remainingFilters, const Akonadi2::Query &query) | 221 | std::function<bool(const Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr &domainObject)> QueryRunner<DomainType>::getFilter(const QSet<QByteArray> remainingFilters, const Akonadi2::Query &query) |
222 | { | 222 | { |
223 | return [remainingFilters, query](const Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr &domainObject) -> bool { | 223 | return [remainingFilters, query](const Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr &domainObject) -> bool { |
224 | if (!query.ids.isEmpty()) { | ||
225 | if (!query.ids.contains(domainObject->identifier())) { | ||
226 | return false; | ||
227 | } | ||
228 | } | ||
224 | for (const auto &filterProperty : remainingFilters) { | 229 | for (const auto &filterProperty : remainingFilters) { |
225 | const auto property = domainObject->getProperty(filterProperty); | 230 | const auto property = domainObject->getProperty(filterProperty); |
226 | if (property.isValid()) { | 231 | if (property.isValid()) { |
diff --git a/tests/querytest.cpp b/tests/querytest.cpp index 1ba37f4..e09f7a4 100644 --- a/tests/querytest.cpp +++ b/tests/querytest.cpp | |||
@@ -106,6 +106,39 @@ private Q_SLOTS: | |||
106 | QCOMPARE(model->rowCount(), 1); | 106 | QCOMPARE(model->rowCount(), 1); |
107 | } | 107 | } |
108 | 108 | ||
109 | void testById() | ||
110 | { | ||
111 | QByteArray id; | ||
112 | //Setup | ||
113 | { | ||
114 | Akonadi2::ApplicationDomain::Mail mail("org.kde.dummy.instance1"); | ||
115 | Akonadi2::Store::create<Akonadi2::ApplicationDomain::Mail>(mail).exec().waitForFinished(); | ||
116 | Akonadi2::Store::create<Akonadi2::ApplicationDomain::Mail>(mail).exec().waitForFinished(); | ||
117 | |||
118 | Akonadi2::Query query; | ||
119 | query.resources << "org.kde.dummy.instance1"; | ||
120 | |||
121 | //Ensure all local data is processed | ||
122 | Akonadi2::Store::synchronize(query).exec().waitForFinished(); | ||
123 | |||
124 | //We fetch before the data is available and rely on the live query mechanism to deliver the actual data | ||
125 | auto model = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::Mail>(query); | ||
126 | model->fetchMore(QModelIndex()); | ||
127 | QTRY_VERIFY(model->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool()); | ||
128 | QVERIFY(model->rowCount() >= 1); | ||
129 | id = model->index(0, 0).data(Akonadi2::Store::DomainObjectRole).value<Akonadi2::ApplicationDomain::Mail::Ptr>()->identifier(); | ||
130 | } | ||
131 | |||
132 | //Test | ||
133 | Akonadi2::Query query; | ||
134 | query.resources << "org.kde.dummy.instance1"; | ||
135 | query.ids << id; | ||
136 | auto model = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::Mail>(query); | ||
137 | model->fetchMore(QModelIndex()); | ||
138 | QTRY_VERIFY(model->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool()); | ||
139 | QCOMPARE(model->rowCount(), 1); | ||
140 | } | ||
141 | |||
109 | void testFolder() | 142 | void testFolder() |
110 | { | 143 | { |
111 | //Setup | 144 | //Setup |