aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Vrátil <[email protected]>2017-04-19 16:38:50 +0200
committerDaniel Vrátil <[email protected]>2017-04-19 16:38:50 +0200
commit6b11e0ae58162a05cc895b2d3409eaed18c76e8a (patch)
tree36b8b05cefc48d51fea3642104b4f0ab61b3397e
parentf9a9f19af61dd39673c4bf44d7a29f2e8671e917 (diff)
SearchQuery: handle empty queries properly
-rw-r--r--src/core/searchquery.cpp19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/core/searchquery.cpp b/src/core/searchquery.cpp
index 28ec846..5e345c8 100644
--- a/src/core/searchquery.cpp
+++ b/src/core/searchquery.cpp
@@ -93,9 +93,11 @@ public:
QVariantMap termJSON;
termJSON.insert(QStringLiteral("negated"), term.isNegated());
if (subTerms.isEmpty()) {
- termJSON.insert(QStringLiteral("key"), term.key());
- termJSON.insert(QStringLiteral("value"), term.value());
- termJSON.insert(QStringLiteral("cond"), static_cast<int>(term.condition()));
+ if (!term.isNull()) {
+ termJSON.insert(QStringLiteral("key"), term.key());
+ termJSON.insert(QStringLiteral("value"), term.value());
+ termJSON.insert(QStringLiteral("cond"), static_cast<int>(term.condition()));
+ }
} else {
termJSON.insert(QStringLiteral("rel"), static_cast<int>(term.relation()));
QVariantList subTermsJSON;
@@ -111,7 +113,9 @@ public:
static SearchTerm JSONToTerm(const QVariantMap &map)
{
- if (map.contains(QStringLiteral("key"))) {
+ if (map.isEmpty()) {
+ return SearchTerm();
+ } else if (map.contains(QStringLiteral("key"))) {
SearchTerm term(map[QStringLiteral("key")].toString(),
map[QStringLiteral("value")],
static_cast<SearchTerm::Condition>(map[QStringLiteral("cond")].toInt()));
@@ -278,8 +282,11 @@ int SearchQuery::limit() const
QByteArray SearchQuery::toJSON() const
{
- QVariantMap root = Private::termToJSON(d->rootTerm);
- root.insert(QStringLiteral("limit"), d->limit);
+ QVariantMap root;
+ if (!d->rootTerm.isNull()) {
+ root = Private::termToJSON(d->rootTerm);
+ root.insert(QStringLiteral("limit"), d->limit);
+ }
QJsonObject jo = QJsonObject::fromVariantMap(root);
QJsonDocument jdoc;