16class Akonadi::Search::TermPrivate
19 Term::Operation m_op = Term::None;
20 Term::Comparator m_comp = Term::Auto;
25 bool m_isNegated =
false;
28 QVariantHash m_userData;
36Term::Term(
const Term &t)
37 : d(new TermPrivate(*t.d))
78Term::Term(Term::Operation op)
84Term::Term(Term::Operation op,
const Term &t)
98Term::Term(
const Term &lhs, Term::Operation op,
const Term &rhs)
102 d->m_subTerms << lhs;
103 d->m_subTerms << rhs;
106Term::~Term() =
default;
108bool Term::isValid()
const
110 if (d->m_property.isEmpty()) {
111 if (d->m_op == Term::None) {
115 return d->m_property.isEmpty() && d->m_value.isNull();
123 d->m_isNegated = isNegated;
126bool Term::isNegated()
const
128 return d->m_isNegated;
131bool Term::negated()
const
133 return d->m_isNegated;
136void Term::addSubTerm(
const Term &term)
138 d->m_subTerms << term;
143 d->m_subTerms = terms;
148 if (!d->m_subTerms.isEmpty()) {
149 return d->m_subTerms.first();
157 return d->m_subTerms;
160void Term::setOperation(Term::Operation op)
165Term::Operation Term::operation()
const
170bool Term::empty()
const
175bool Term::isEmpty()
const
177 return d->m_property.isEmpty() && d->m_value.isNull() && d->m_subTerms.isEmpty();
182 return d->m_property;
185void Term::setProperty(
const QString &property)
190void Term::setValue(
const QVariant &value)
200Term::Comparator Term::comparator()
const
205void Term::setComparator(Term::Comparator c)
212 d->m_userData.insert(name, value);
217 return d->m_userData.value(name);
220QVariantMap Term::toVariantMap()
const
223 if (d->m_op != None) {
224 QVariantList variantList;
225 variantList.reserve(d->m_subTerms.count());
226 for (
const Term &term : std::as_const(d->m_subTerms)) {
227 variantList <<
QVariant(term.toVariantMap());
230 if (d->m_op == And) {
231 map[QStringLiteral(
"$and")] = variantList;
233 map[QStringLiteral(
"$or")] = variantList;
242 map[d->m_property] = d->m_value;
246 op = QStringLiteral(
"$ct");
250 op = QStringLiteral(
"$gt");
254 op = QStringLiteral(
"$gte");
258 op = QStringLiteral(
"$lt");
262 op = QStringLiteral(
"$lte");
297Term Term::fromVariantMap(
const QVariantMap &map)
299 if (
map.size() != 1) {
306 if (
map.contains(QStringLiteral(
"$and"))) {
307 andOrString = QStringLiteral(
"$and");
308 term.setOperation(And);
309 }
else if (
map.contains(QStringLiteral(
"$or"))) {
310 andOrString = QStringLiteral(
"$or");
311 term.setOperation(Or);
314 if (andOrString.
size()) {
317 const QVariantList
list =
map[andOrString].toList();
320 subTerms << Term::fromVariantMap(var.
toMap());
323 term.setSubTerms(subTerms);
328 term.setProperty(prop);
333 if (
map.size() != 1) {
338 Term::Comparator com;
339 if (op ==
"$ct"_L1) {
341 }
else if (op ==
"$gt"_L1) {
343 }
else if (op ==
"$gte"_L1) {
345 }
else if (op ==
"$lt"_L1) {
347 }
else if (op ==
"$lte"_L1) {
353 term.setComparator(com);
354 term.setValue(tryConvert(
map.value(op)));
359 term.setComparator(Equal);
360 term.setValue(tryConvert(value));
365bool Term::operator==(
const Term &rhs)
const
367 if (d->m_op != rhs.d->m_op || d->m_comp != rhs.d->m_comp || d->m_isNegated != rhs.d->m_isNegated || d->m_property != rhs.d->m_property
368 || d->m_value != rhs.d->m_value) {
372 if (d->m_subTerms.size() != rhs.d->m_subTerms.size()) {
376 if (d->m_subTerms.isEmpty()) {
380 for (
const Term &t : std::as_const(d->m_subTerms)) {
381 if (!rhs.d->m_subTerms.contains(t)) {
389Term &Term::operator=(
const Term &rhs)
397QString comparatorToString(Term::Comparator c)
401 return QStringLiteral(
"Auto");
403 return QStringLiteral(
"=");
405 return QStringLiteral(
":");
407 return QStringLiteral(
"<");
408 case Term::LessEqual:
409 return QStringLiteral(
"<=");
411 return QStringLiteral(
">");
412 case Term::GreaterEqual:
413 return QStringLiteral(
">=");
419QString operationToString(Term::Operation op)
423 return QStringLiteral(
"NONE");
425 return QStringLiteral(
"AND");
427 return QStringLiteral(
"OR");
436 if (t.subTerms().isEmpty()) {
437 d << QStringLiteral(
"(%1 %2 %3 (%4))")
442 d <<
"(" << operationToString(t.operation()).toUtf8().constData();
444 for (
const Term &term : std::as_const(subterms)) {
void setNegation(bool isNegated)
Negate this term.
QString property() const
Return the property this term is targeting.
Term subTerm() const
Returns the first subTerm in the list of subTerms.
Akonadi search infrastructure.
KCALENDARCORE_EXPORT QDataStream & operator<<(QDataStream &out, const KCalendarCore::Alarm::Ptr &)
KIOCORE_EXPORT QStringList list(const QString &fileClass)
bool isValid() const const
qsizetype count() const const
void reserve(qsizetype size)
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
QString fromLatin1(QByteArrayView str)
qsizetype size() const const
QFuture< void > map(Iterator begin, Iterator end, MapFunctor &&function)
bool canConvert() const const
QDate toDate() const const
QDateTime toDateTime() const const
QMap< QString, QVariant > toMap() const const
QString toString() const const
const char * typeName() const const
int userType() const const