Akonadi Search

term.h
1/*
2 * This file is part of the KDE Akonadi Search Project
3 * SPDX-FileCopyrightText: 2013 Vishesh Handa <me@vhanda.in>
4 *
5 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6 *
7 */
8
9#pragma once
10
11#include "search_core_export.h"
12
13#include <QDebug>
14#include <QString>
15#include <QVariant>
16
17#include <memory>
18
19namespace Akonadi
20{
21namespace Search
22{
23class TermPrivate;
24
25/** Search term. */
26class AKONADI_SEARCH_CORE_EXPORT Term
27{
28public:
29 enum Comparator : uint8_t {
30 Auto,
31 Equal,
32 Contains,
33 Greater,
34 GreaterEqual,
35 Less,
36 LessEqual
37 };
38
39 enum Operation : uint8_t {
40 None,
41 And,
42 Or
43 };
44
45 Term();
46 Term(const Term &t);
47
48 /**
49 * The Item must contain the property \p property
50 */
51 Term(const QString &property);
52
53 /**
54 * The Item must contain the property \p property with
55 * value \value.
56 *
57 * The default comparator is Auto which has the following behavior
58 * For Strings - Contains
59 * For DateTime - Contains
60 * For any other type - Equals
61 */
62 Term(const QString &property, const QVariant &value, Comparator c = Auto);
63
64 /**
65 * This term is a combination of other terms
66 */
67 Term(Operation op);
68 Term(Operation op, const Term &t);
69 Term(Operation op, const QList<Term> &t);
70 Term(const Term &lhs, Operation op, const Term &rhs);
71 ~Term();
72
73 [[nodiscard]] bool isValid() const;
74
75 /**
76 * Negate this term. Negation only applies for Equal or Contains
77 * For other Comparators you must invert it yourself
78 */
79 void setNegation(bool isNegated);
80
81 [[nodiscard]] bool negated() const;
82 [[nodiscard]] bool isNegated() const;
83
84 void addSubTerm(const Term &term);
85 void setSubTerms(const QList<Term> &terms);
86
87 /**
88 * Returns the first subTerm in the list of subTerms
89 */
90 [[nodiscard]] Term subTerm() const;
91 [[nodiscard]] QList<Term> subTerms() const;
92
93 void setOperation(Operation op);
94 [[nodiscard]] Operation operation() const;
95
96 [[nodiscard]] bool isEmpty() const;
97 [[nodiscard]] bool empty() const;
98
99 /**
100 * Return the property this term is targeting
101 */
102 [[nodiscard]] QString property() const;
103 void setProperty(const QString &property);
104
105 [[nodiscard]] QVariant value() const;
106 void setValue(const QVariant &value);
107
108 [[nodiscard]] Comparator comparator() const;
109 void setComparator(Comparator c);
110
111 void setUserData(const QString &name, const QVariant &value);
112 [[nodiscard]] QVariant userData(const QString &name) const;
113
114 [[nodiscard]] QVariantMap toVariantMap() const;
115 static Term fromVariantMap(const QVariantMap &map);
116
117 bool operator==(const Term &rhs) const;
118
119 Term &operator=(const Term &rhs);
120
121private:
122 std::unique_ptr<TermPrivate> const d;
123};
124
125inline Term operator&&(const Term &lhs, const Term &rhs)
126{
127 Term t(Term::And);
128 t.addSubTerm(lhs);
129 t.addSubTerm(rhs);
130 return t;
131}
132
133inline Term operator||(const Term &lhs, const Term &rhs)
134{
135 Term t(Term::Or);
136 t.addSubTerm(lhs);
137 t.addSubTerm(rhs);
138 return t;
139}
140
141inline Term operator!(const Term &rhs)
142{
143 Term t(rhs);
144 t.setNegation(!rhs.isNegated());
145 return t;
146}
147}
148}
149
150AKONADI_SEARCH_CORE_EXPORT QDebug operator<<(QDebug d, const Akonadi::Search::Term &t);
Search term.
Definition term.h:27
QDebug operator<<(QDebug dbg, const DcrawInfoContainer &c)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:56:07 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.