Kgapi

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

KDE's Doxygen guidelines are available online.