Akonadi

parttypehelper.cpp
1/*
2 SPDX-FileCopyrightText: 2011 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "parttypehelper.h"
8
9#include "entities.h"
10#include "selectquerybuilder.h"
11
12#include <QStringList>
13
14#include <tuple>
15
16using namespace Akonadi::Server;
17
18std::pair<QString, QString> PartTypeHelper::parseFqName(const QString &fqName)
19{
20 const QStringList name = fqName.split(QLatin1Char(':'), Qt::SkipEmptyParts);
21 if (name.size() != 2) {
22 throw PartTypeException("Invalid part type name.");
23 }
24 return {name.first(), name.last()};
25}
26
27PartType PartTypeHelper::fromFqName(const QString &fqName)
28{
29 return std::apply(qOverload<const QString &, const QString &>(PartTypeHelper::fromFqName), parseFqName(fqName));
30}
31
33{
34 return fromFqName(QLatin1StringView(fqName));
35}
36
37PartType PartTypeHelper::fromFqName(const QString &ns, const QString &name)
38{
39 const PartType partType = PartType::retrieveByFQNameOrCreate(ns, name);
40 if (!partType.isValid()) {
41 throw PartTypeException("Failed to append part type");
42 }
43 return partType;
44}
45
47{
48 const auto [ns, name] = parseFqName(fqName);
50 c.setSubQueryMode(Query::And);
51 c.addValueCondition(PartType::nsFullColumnName(), Query::Equals, ns);
52 c.addValueCondition(PartType::nameFullColumnName(), Query::Equals, name);
53 return c;
54}
55
57{
59 c.setSubQueryMode(Query::Or);
60 for (const QString &fqName : fqNames) {
62 }
63 return c;
64}
65
66QString PartTypeHelper::fullName(const PartType &type)
67{
68 return type.ns() + QLatin1StringView(":") + type.name();
69}
Represents a WHERE condition tree.
Definition query.h:62
void setSubQueryMode(LogicOperator op)
Set how sub-conditions should be combined, default is And.
Definition query.cpp:49
void addValueCondition(const QString &column, CompareOperator op, const QVariant &value)
Add a WHERE condition which compares a column with a given value.
Definition query.cpp:12
void addCondition(const Condition &condition)
Add a WHERE condition.
Definition query.cpp:54
Query::Condition conditionFromFqNames(const QStringList &fqNames)
Returns a query condition that matches the given part type list.
std::pair< QString, QString > parseFqName(const QString &fqName)
Parses a fully qualified part type name into namespace/name.
Query::Condition conditionFromFqName(const QString &fqName)
Returns a query condition that matches the given part.
PartType fromFqName(const QString &fqName)
Retrieve (or create) PartType for the given fully qualified name.
QString fullName(const PartType &type)
Returns full part name.
QString first(qsizetype n) const const
QString last(qsizetype n) const const
qsizetype size() const const
QStringList split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
SkipEmptyParts
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:08:30 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.