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 { Auto, Equal, Contains, Greater, GreaterEqual, Less, LessEqual };
30
31 enum Operation { None, And, Or };
32
33 Term();
34 Term(const Term &t);
35
36 /**
37 * The Item must contain the property \p property
38 */
39 Term(const QString &property);
40
41 /**
42 * The Item must contain the property \p property with
43 * value \value.
44 *
45 * The default comparator is Auto which has the following behavior
46 * For Strings - Contains
47 * For DateTime - Contains
48 * For any other type - Equals
49 */
50 Term(const QString &property, const QVariant &value, Comparator c = Auto);
51
52 /**
53 * This term is a combination of other terms
54 */
55 Term(Operation op);
56 Term(Operation op, const Term &t);
57 Term(Operation op, const QList<Term> &t);
58 Term(const Term &lhs, Operation op, const Term &rhs);
59 ~Term();
60
61 [[nodiscard]] bool isValid() const;
62
63 /**
64 * Negate this term. Negation only applies for Equal or Contains
65 * For other Comparators you must invert it yourself
66 */
67 void setNegation(bool isNegated);
68
69 [[nodiscard]] bool negated() const;
70 [[nodiscard]] bool isNegated() const;
71
72 void addSubTerm(const Term &term);
73 void setSubTerms(const QList<Term> &terms);
74
75 /**
76 * Returns the first subTerm in the list of subTerms
77 */
78 [[nodiscard]] Term subTerm() const;
79 [[nodiscard]] QList<Term> subTerms() const;
80
81 void setOperation(Operation op);
82 [[nodiscard]] Operation operation() const;
83
84 [[nodiscard]] bool isEmpty() const;
85 [[nodiscard]] bool empty() const;
86
87 /**
88 * Return the property this term is targeting
89 */
90 [[nodiscard]] QString property() const;
91 void setProperty(const QString &property);
92
93 [[nodiscard]] QVariant value() const;
94 void setValue(const QVariant &value);
95
96 [[nodiscard]] Comparator comparator() const;
97 void setComparator(Comparator c);
98
99 void setUserData(const QString &name, const QVariant &value);
100 [[nodiscard]] QVariant userData(const QString &name) const;
101
102 [[nodiscard]] QVariantMap toVariantMap() const;
103 static Term fromVariantMap(const QVariantMap &map);
104
105 bool operator==(const Term &rhs) const;
106
107 Term &operator=(const Term &rhs);
108
109private:
110 std::unique_ptr<TermPrivate> const d;
111};
112
113inline Term operator&&(const Term &lhs, const Term &rhs)
114{
115 Term t(Term::And);
116 t.addSubTerm(lhs);
117 t.addSubTerm(rhs);
118 return t;
119}
120
121inline Term operator||(const Term &lhs, const Term &rhs)
122{
123 Term t(Term::Or);
124 t.addSubTerm(lhs);
125 t.addSubTerm(rhs);
126 return t;
127}
128
129inline Term operator!(const Term &rhs)
130{
131 Term t(rhs);
132 t.setNegation(!rhs.isNegated());
133 return t;
134}
135}
136}
137
138AKONADI_SEARCH_CORE_EXPORT QDebug operator<<(QDebug d, const Akonadi::Search::Term &t);
Search term.
Definition term.h:27
KCALENDARCORE_EXPORT QDataStream & operator<<(QDataStream &out, const KCalendarCore::Alarm::Ptr &)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jun 7 2024 12:04:41 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.