Kgapi

teamdrivesearchquery.cpp
1 /*
2  * SPDX-FileCopyrightText: 2019 David Barchiesi <[email protected]>
3  *
4  * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5  */
6 
7 #include "teamdrivesearchquery.h"
8 
9 #include <QString>
10 #include <QDateTime>
11 
12 using namespace KGAPI2;
13 using namespace KGAPI2::Drive;
14 
15 
16 QString TeamdriveSearchQuery::fieldToString(Field field)
17 {
18  switch (field) {
19  case Name:
20  return QStringLiteral("name");
21  case CreatedTime:
22  return QStringLiteral("createdTime");
23  case MemberCount:
24  return QStringLiteral("memberCount");
25  case OrganizerCount:
26  return QStringLiteral("organizerCount");
27  }
28 
29  Q_ASSERT(false);
30  return QString();
31 }
32 
33 QString TeamdriveSearchQuery::valueToString(TeamdriveSearchQuery::Field field, const QVariant &var)
34 {
35  switch (field) {
36  case Name:
37  return QStringLiteral("'%1'").arg(var.toString().replace(QLatin1Char('\''), QLatin1String("\\\'")));
38  case MemberCount:
39  case OrganizerCount:
40  return var.toString();
41  case CreatedTime:
42  return QStringLiteral("'%1'").arg(var.toDateTime().toUTC().toString(QStringLiteral("yyyy-MM-ddThh:mm:ss")));
43  }
44 
45  Q_ASSERT(false);
46  return QString();
47 }
48 
49 void TeamdriveSearchQuery::addQuery(TeamdriveSearchQuery::Field field, TeamdriveSearchQuery::CompareOperator op, const QVariant &value)
50 {
51  switch (field) {
52  case Name:
53  Q_ASSERT(op == Contains || op == Equals || op == NotEquals);
54  Q_ASSERT(value.canConvert<QString>());
55  break;
56  case MemberCount:
57  case OrganizerCount:
58  Q_ASSERT(op == LessOrEqual || op == Less || op == Equals || op == NotEquals || op == Greater || op == GreaterOrEqual);
59  Q_ASSERT(value.canConvert<int>());
60  break;
61  case CreatedTime:
62  Q_ASSERT(op == LessOrEqual || op == Less || op == Equals || op == NotEquals || op == Greater || op == GreaterOrEqual);
63  Q_ASSERT(value.canConvert<QDateTime>());
64  break;
65  }
66 
67  SearchQuery::addQuery(fieldToString(field), op, valueToString(field, value));
68 }
bool canConvert(int targetTypeId) const const
QString toString(Qt::DateFormat format) const const
QDateTime toUTC() const const
QDateTime toDateTime() const const
A job to fetch a single map tile described by a StaticMapUrl.
Definition: blog.h:16
QString & replace(int position, int n, QChar after)
QString toString() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat Jul 11 2020 23:09:38 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.