Akonadi

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

KDE's Doxygen guidelines are available online.