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 +- 5 files changed, 21 insertions(+), 10 deletions(-) (limited to 'common') 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()); } -- cgit v1.2.3