Baloo

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

KDE's Doxygen guidelines are available online.