summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-11-14 18:04:06 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-11-14 18:04:06 +0100
commite86e1f06d2b730c14c90d4c78719a47f3e5350fc (patch)
tree7e6337a45a25ad5ac7ba581ee292f3bd4b68a97f
parent175a49d623a5e37c1c20c80ed7f2077222f3c593 (diff)
downloadsink-e86e1f06d2b730c14c90d4c78719a47f3e5350fc.tar.gz
sink-e86e1f06d2b730c14c90d4c78719a47f3e5350fc.zip
Hide Query::parentProperty
-rw-r--r--common/modelresult.cpp6
-rw-r--r--common/query.cpp2
-rw-r--r--common/query.h15
-rw-r--r--common/queryrunner.cpp6
-rw-r--r--common/test.cpp2
-rw-r--r--tests/clientapitest.cpp8
-rw-r--r--tests/querytest.cpp2
7 files changed, 26 insertions, 15 deletions
diff --git a/common/modelresult.cpp b/common/modelresult.cpp
index 7565eea..16e3857 100644
--- a/common/modelresult.cpp
+++ b/common/modelresult.cpp
@@ -50,8 +50,8 @@ static qint64 getIdentifier(const QModelIndex &idx)
50template <class T, class Ptr> 50template <class T, class Ptr>
51qint64 ModelResult<T, Ptr>::parentId(const Ptr &value) 51qint64 ModelResult<T, Ptr>::parentId(const Ptr &value)
52{ 52{
53 if (!mQuery.parentProperty.isEmpty()) { 53 if (!mQuery.parentProperty().isEmpty()) {
54 const auto identifier = value->getProperty(mQuery.parentProperty).toByteArray(); 54 const auto identifier = value->getProperty(mQuery.parentProperty()).toByteArray();
55 if (!identifier.isEmpty()) { 55 if (!identifier.isEmpty()) {
56 return qHash(T(value->resourceInstanceIdentifier(), identifier, 0, QSharedPointer<Sink::ApplicationDomain::BufferAdaptor>())); 56 return qHash(T(value->resourceInstanceIdentifier(), identifier, 0, QSharedPointer<Sink::ApplicationDomain::BufferAdaptor>()));
57 } 57 }
@@ -149,7 +149,7 @@ QModelIndex ModelResult<T, Ptr>::parent(const QModelIndex &index) const
149template <class T, class Ptr> 149template <class T, class Ptr>
150bool ModelResult<T, Ptr>::hasChildren(const QModelIndex &parent) const 150bool ModelResult<T, Ptr>::hasChildren(const QModelIndex &parent) const
151{ 151{
152 if (mQuery.parentProperty.isEmpty() && parent.isValid()) { 152 if (mQuery.parentProperty().isEmpty() && parent.isValid()) {
153 return false; 153 return false;
154 } 154 }
155 //Figure out whether we have children 155 //Figure out whether we have children
diff --git a/common/query.cpp b/common/query.cpp
index caca775..14acde0 100644
--- a/common/query.cpp
+++ b/common/query.cpp
@@ -52,7 +52,7 @@ QDebug operator<<(QDebug dbg, const Sink::Query &query)
52{ 52{
53 dbg << static_cast<Sink::QueryBase>(query); 53 dbg << static_cast<Sink::QueryBase>(query);
54 dbg.nospace() << " Requested: " << query.requestedProperties << "\n"; 54 dbg.nospace() << " Requested: " << query.requestedProperties << "\n";
55 dbg.nospace() << " Parent: " << query.parentProperty << "\n"; 55 dbg.nospace() << " Parent: " << query.parentProperty() << "\n";
56 dbg.nospace() << " IsLive: " << query.liveQuery() << "\n"; 56 dbg.nospace() << " IsLive: " << query.liveQuery() << "\n";
57 return dbg.maybeSpace(); 57 return dbg.maybeSpace();
58} 58}
diff --git a/common/query.h b/common/query.h
index 8459850..e77bfd9 100644
--- a/common/query.h
+++ b/common/query.h
@@ -296,10 +296,21 @@ public:
296 template <typename T> 296 template <typename T>
297 Query &requestTree() 297 Query &requestTree()
298 { 298 {
299 parentProperty = T::name; 299 mParentProperty = T::name;
300 return *this; 300 return *this;
301 } 301 }
302 302
303 Query &requestTree(const QByteArray &parentProperty)
304 {
305 mParentProperty = parentProperty;
306 return *this;
307 }
308
309 QByteArray parentProperty() const
310 {
311 return mParentProperty;
312 }
313
303 template <typename T> 314 template <typename T>
304 Query &sort() 315 Query &sort()
305 { 316 {
@@ -374,7 +385,6 @@ public:
374 } 385 }
375 386
376 QByteArrayList requestedProperties; 387 QByteArrayList requestedProperties;
377 QByteArray parentProperty;
378 388
379 void setFlags(Flags flags) 389 void setFlags(Flags flags)
380 { 390 {
@@ -442,6 +452,7 @@ private:
442 int mLimit; 452 int mLimit;
443 Flags mFlags; 453 Flags mFlags;
444 Filter mResourceFilter; 454 Filter mResourceFilter;
455 QByteArray mParentProperty;
445}; 456};
446 457
447class SyncScope : public QueryBase { 458class SyncScope : public QueryBase {
diff --git a/common/queryrunner.cpp b/common/queryrunner.cpp
index b6c9aee..cf56268 100644
--- a/common/queryrunner.cpp
+++ b/common/queryrunner.cpp
@@ -221,13 +221,13 @@ QPair<qint64, qint64> QueryWorker<DomainType>::executeInitialQuery(
221 time.start(); 221 time.start();
222 222
223 auto modifiedQuery = query; 223 auto modifiedQuery = query;
224 if (!query.parentProperty.isEmpty()) { 224 if (!query.parentProperty().isEmpty()) {
225 if (parent) { 225 if (parent) {
226 SinkTrace() << "Running initial query for parent:" << parent->identifier(); 226 SinkTrace() << "Running initial query for parent:" << parent->identifier();
227 modifiedQuery.filter(query.parentProperty, Query::Comparator(parent->identifier())); 227 modifiedQuery.filter(query.parentProperty(), Query::Comparator(parent->identifier()));
228 } else { 228 } else {
229 SinkTrace() << "Running initial query for toplevel"; 229 SinkTrace() << "Running initial query for toplevel";
230 modifiedQuery.filter(query.parentProperty, Query::Comparator(QVariant())); 230 modifiedQuery.filter(query.parentProperty(), Query::Comparator(QVariant()));
231 } 231 }
232 } 232 }
233 233
diff --git a/common/test.cpp b/common/test.cpp
index cf2e8a3..1a0d9bc 100644
--- a/common/test.cpp
+++ b/common/test.cpp
@@ -151,7 +151,7 @@ public:
151 for (const auto &res : mTestAccount->entities<T>()) { 151 for (const auto &res : mTestAccount->entities<T>()) {
152 qDebug() << "Parent filter " << query.getFilter("parent").value.toByteArray() << res->identifier() << res->getProperty("parent").toByteArray(); 152 qDebug() << "Parent filter " << query.getFilter("parent").value.toByteArray() << res->identifier() << res->getProperty("parent").toByteArray();
153 auto parentProperty = res->getProperty("parent").toByteArray(); 153 auto parentProperty = res->getProperty("parent").toByteArray();
154 if ((!parent && parentProperty.isEmpty()) || (parent && parentProperty == parent->identifier()) || query.parentProperty.isEmpty()) { 154 if ((!parent && parentProperty.isEmpty()) || (parent && parentProperty == parent->identifier()) || query.parentProperty().isEmpty()) {
155 qDebug() << "Found a match" << res->identifier(); 155 qDebug() << "Found a match" << res->identifier();
156 resultProvider->add(res.template staticCast<T>()); 156 resultProvider->add(res.template staticCast<T>());
157 } 157 }
diff --git a/tests/clientapitest.cpp b/tests/clientapitest.cpp
index 3f500b7..ae9286c 100644
--- a/tests/clientapitest.cpp
+++ b/tests/clientapitest.cpp
@@ -65,7 +65,7 @@ public:
65 for (const auto &res : results) { 65 for (const auto &res : results) {
66 qDebug() << "Parent filter " << query.getFilter("parent").value.toByteArray() << res->identifier() << res->getProperty("parent").toByteArray(); 66 qDebug() << "Parent filter " << query.getFilter("parent").value.toByteArray() << res->identifier() << res->getProperty("parent").toByteArray();
67 auto parentProperty = res->getProperty("parent").toByteArray(); 67 auto parentProperty = res->getProperty("parent").toByteArray();
68 if ((!parent && parentProperty.isEmpty()) || (parent && parentProperty == parent->identifier()) || query.parentProperty.isEmpty()) { 68 if ((!parent && parentProperty.isEmpty()) || (parent && parentProperty == parent->identifier()) || query.parentProperty().isEmpty()) {
69 qDebug() << "Found a hit" << res->identifier(); 69 qDebug() << "Found a hit" << res->identifier();
70 resultProvider->add(res); 70 resultProvider->add(res);
71 } 71 }
@@ -147,7 +147,7 @@ private slots:
147 // Test 147 // Test
148 Sink::Query query; 148 Sink::Query query;
149 query.resourceFilter("dummyresource.instance1"); 149 query.resourceFilter("dummyresource.instance1");
150 query.parentProperty = "parent"; 150 query.requestTree("parent");
151 151
152 auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Folder>(query); 152 auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Folder>(query);
153 QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); 153 QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool());
@@ -169,7 +169,7 @@ private slots:
169 // Test 169 // Test
170 Sink::Query query; 170 Sink::Query query;
171 query.resourceFilter("dummyresource.instance1"); 171 query.resourceFilter("dummyresource.instance1");
172 query.parentProperty = "parent"; 172 query.requestTree("parent");
173 173
174 auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Folder>(query); 174 auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Folder>(query);
175 QSignalSpy spy(model.data(), SIGNAL(rowsInserted(const QModelIndex &, int, int))); 175 QSignalSpy spy(model.data(), SIGNAL(rowsInserted(const QModelIndex &, int, int)));
@@ -192,7 +192,7 @@ private slots:
192 Sink::Query query; 192 Sink::Query query;
193 query.resourceFilter("dummyresource.instance1"); 193 query.resourceFilter("dummyresource.instance1");
194 query.setFlags(Sink::Query::LiveQuery); 194 query.setFlags(Sink::Query::LiveQuery);
195 query.parentProperty = "parent"; 195 query.requestTree("parent");
196 196
197 auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Folder>(query); 197 auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Folder>(query);
198 QTRY_COMPARE(model->rowCount(), 1); 198 QTRY_COMPARE(model->rowCount(), 1);
diff --git a/tests/querytest.cpp b/tests/querytest.cpp
index d823304..2eb1239 100644
--- a/tests/querytest.cpp
+++ b/tests/querytest.cpp
@@ -252,7 +252,7 @@ private slots:
252 // Test 252 // Test
253 Sink::Query query; 253 Sink::Query query;
254 query.resourceFilter("sink.dummy.instance1"); 254 query.resourceFilter("sink.dummy.instance1");
255 query.parentProperty = "parent"; 255 query.requestTree<Folder::Parent>();
256 256
257 // Ensure all local data is processed 257 // Ensure all local data is processed
258 VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(QByteArrayList() << "sink.dummy.instance1")); 258 VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(QByteArrayList() << "sink.dummy.instance1"));