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 "entities.h"
10 #include "selectquerybuilder.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  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 
27 PartType PartTypeHelper::fromFqName(const QString &fqName)
28 {
29  return std::apply(qOverload<const QString &, const QString &>(PartTypeHelper::fromFqName), parseFqName(fqName));
30 }
31 
32 PartType PartTypeHelper::fromFqName(const QByteArray &fqName)
33 {
34  return fromFqName(QLatin1String(fqName));
35 }
36 
37 PartType 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 
66 QString PartTypeHelper::fullName(const PartType &type)
67 {
68  return type.ns() + QLatin1String(":") + type.name();
69 }
Query::Condition conditionFromFqNames(const QStringList &fqNames)
Returns a query condition that matches the given part type list.
int size() const const
QStringList split(const QString &sep, QString::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
PartType fromFqName(const QString &fqName)
Retrieve (or create) PartType for the given fully qualified name.
Query::Condition conditionFromFqName(const QString &fqName)
Returns a query condition that matches the given part.
SkipEmptyParts
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
Represents a WHERE condition tree.
Definition: query.h:61
void setSubQueryMode(LogicOperator op)
Set how sub-conditions should be combined, default is And.
Definition: query.cpp:49
QString fullName(const PartType &type)
Returns full part name.
std::pair< QString, QString > parseFqName(const QString &fqName)
Parses a fully qualified part type name into namespace/name.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Jun 30 2022 03:51:46 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.