From e86e1f06d2b730c14c90d4c78719a47f3e5350fc Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 14 Nov 2016 18:04:06 +0100 Subject: Hide Query::parentProperty --- common/modelresult.cpp | 6 +++--- common/query.cpp | 2 +- common/query.h | 15 +++++++++++++-- common/queryrunner.cpp | 6 +++--- common/test.cpp | 2 +- tests/clientapitest.cpp | 8 ++++---- tests/querytest.cpp | 2 +- 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) template qint64 ModelResult::parentId(const Ptr &value) { - if (!mQuery.parentProperty.isEmpty()) { - const auto identifier = value->getProperty(mQuery.parentProperty).toByteArray(); + if (!mQuery.parentProperty().isEmpty()) { + const auto identifier = value->getProperty(mQuery.parentProperty()).toByteArray(); if (!identifier.isEmpty()) { return qHash(T(value->resourceInstanceIdentifier(), identifier, 0, QSharedPointer())); } @@ -149,7 +149,7 @@ QModelIndex ModelResult::parent(const QModelIndex &index) const template bool ModelResult::hasChildren(const QModelIndex &parent) const { - if (mQuery.parentProperty.isEmpty() && parent.isValid()) { + if (mQuery.parentProperty().isEmpty() && parent.isValid()) { return false; } //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) { dbg << static_cast(query); dbg.nospace() << " Requested: " << query.requestedProperties << "\n"; - dbg.nospace() << " Parent: " << query.parentProperty << "\n"; + dbg.nospace() << " Parent: " << query.parentProperty() << "\n"; dbg.nospace() << " IsLive: " << query.liveQuery() << "\n"; return dbg.maybeSpace(); } 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: template Query &requestTree() { - parentProperty = T::name; + mParentProperty = T::name; return *this; } + Query &requestTree(const QByteArray &parentProperty) + { + mParentProperty = parentProperty; + return *this; + } + + QByteArray parentProperty() const + { + return mParentProperty; + } + template Query &sort() { @@ -374,7 +385,6 @@ public: } QByteArrayList requestedProperties; - QByteArray parentProperty; void setFlags(Flags flags) { @@ -442,6 +452,7 @@ private: int mLimit; Flags mFlags; Filter mResourceFilter; + QByteArray mParentProperty; }; class 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 QueryWorker::executeInitialQuery( time.start(); auto modifiedQuery = query; - if (!query.parentProperty.isEmpty()) { + if (!query.parentProperty().isEmpty()) { if (parent) { SinkTrace() << "Running initial query for parent:" << parent->identifier(); - modifiedQuery.filter(query.parentProperty, Query::Comparator(parent->identifier())); + modifiedQuery.filter(query.parentProperty(), Query::Comparator(parent->identifier())); } else { SinkTrace() << "Running initial query for toplevel"; - modifiedQuery.filter(query.parentProperty, Query::Comparator(QVariant())); + modifiedQuery.filter(query.parentProperty(), Query::Comparator(QVariant())); } } 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: for (const auto &res : mTestAccount->entities()) { qDebug() << "Parent filter " << query.getFilter("parent").value.toByteArray() << res->identifier() << res->getProperty("parent").toByteArray(); auto parentProperty = res->getProperty("parent").toByteArray(); - if ((!parent && parentProperty.isEmpty()) || (parent && parentProperty == parent->identifier()) || query.parentProperty.isEmpty()) { + if ((!parent && parentProperty.isEmpty()) || (parent && parentProperty == parent->identifier()) || query.parentProperty().isEmpty()) { qDebug() << "Found a match" << res->identifier(); resultProvider->add(res.template staticCast()); } 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: for (const auto &res : results) { qDebug() << "Parent filter " << query.getFilter("parent").value.toByteArray() << res->identifier() << res->getProperty("parent").toByteArray(); auto parentProperty = res->getProperty("parent").toByteArray(); - if ((!parent && parentProperty.isEmpty()) || (parent && parentProperty == parent->identifier()) || query.parentProperty.isEmpty()) { + if ((!parent && parentProperty.isEmpty()) || (parent && parentProperty == parent->identifier()) || query.parentProperty().isEmpty()) { qDebug() << "Found a hit" << res->identifier(); resultProvider->add(res); } @@ -147,7 +147,7 @@ private slots: // Test Sink::Query query; query.resourceFilter("dummyresource.instance1"); - query.parentProperty = "parent"; + query.requestTree("parent"); auto model = Sink::Store::loadModel(query); QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); @@ -169,7 +169,7 @@ private slots: // Test Sink::Query query; query.resourceFilter("dummyresource.instance1"); - query.parentProperty = "parent"; + query.requestTree("parent"); auto model = Sink::Store::loadModel(query); QSignalSpy spy(model.data(), SIGNAL(rowsInserted(const QModelIndex &, int, int))); @@ -192,7 +192,7 @@ private slots: Sink::Query query; query.resourceFilter("dummyresource.instance1"); query.setFlags(Sink::Query::LiveQuery); - query.parentProperty = "parent"; + query.requestTree("parent"); auto model = Sink::Store::loadModel(query); 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: // Test Sink::Query query; query.resourceFilter("sink.dummy.instance1"); - query.parentProperty = "parent"; + query.requestTree(); // Ensure all local data is processed VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(QByteArrayList() << "sink.dummy.instance1")); -- cgit v1.2.3