Kgapi

drivessearchquery.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 "drivessearchquery.h"
8#include "utils.h"
9
10#include <QDateTime>
11#include <QString>
12
13using namespace KGAPI2;
14using namespace KGAPI2::Drive;
15
16QString DrivesSearchQuery::fieldToString(Field field)
17{
18 switch (field) {
19 case Name:
20 return QStringLiteral("name");
21 case Hidden:
22 return QStringLiteral("hidden");
23 case CreatedDate:
24 return QStringLiteral("createdDate");
25 case MemberCount:
26 return QStringLiteral("memberCount");
27 case OrganizerCount:
28 return QStringLiteral("organizerCount");
29 }
30
31 Q_ASSERT(false);
32 return QString();
33}
34
35QString DrivesSearchQuery::valueToString(DrivesSearchQuery::Field field, const QVariant &var)
36{
37 switch (field) {
38 case Name:
39 return QStringLiteral("'%1'").arg(var.toString().replace(QLatin1Char('\''), QLatin1StringView("\\\'")));
40 case Hidden:
41 return Utils::bool2Str(var.toBool());
42 case MemberCount:
43 case OrganizerCount:
44 return var.toString();
45 case CreatedDate:
46 return QStringLiteral("'%1'").arg(var.toDateTime().toUTC().toString(QStringLiteral("yyyy-MM-ddThh:mm:ss")));
47 }
48
49 Q_ASSERT(false);
50 return QString();
51}
52
53void DrivesSearchQuery::addQuery(DrivesSearchQuery::Field field, DrivesSearchQuery::CompareOperator op, const QVariant &value)
54{
55 switch (field) {
56 case Name:
57 Q_ASSERT(op == Contains || op == Equals || op == NotEquals);
58 Q_ASSERT(value.canConvert<QString>());
59 break;
60 case Hidden:
61 Q_ASSERT(op == Equals || op == NotEquals);
62 Q_ASSERT(value.canConvert<bool>());
63 break;
64 case MemberCount:
65 case OrganizerCount:
66 Q_ASSERT(op == LessOrEqual || op == Less || op == Equals || op == NotEquals || op == Greater || op == GreaterOrEqual);
67 Q_ASSERT(value.canConvert<int>());
68 break;
69 case CreatedDate:
70 Q_ASSERT(op == LessOrEqual || op == Less || op == Equals || op == NotEquals || op == Greater || op == GreaterOrEqual);
71 Q_ASSERT(value.canConvert<QDateTime>());
72 break;
73 }
74
75 SearchQuery::addQuery(fieldToString(field), op, valueToString(field, value));
76}
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
bool toBool() 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 Fri Dec 6 2024 12:11:00 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.