14class Baloo::Term::Private {
16 Operation m_op =
None;
17 Comparator m_comp = Auto;
22 bool m_isNegated =
false;
25 QVariantHash m_userData;
33Term::Term(
const Term& t)
34 : d(new Private(*t.d))
38Term::Term(
const QString& property)
41 d->m_property = property;
44Term::Term(
const QString& property,
const QVariant& value, Term::Comparator c)
47 d->m_property = property;
75Term::Term(Term::Operation op)
81Term::Term(Term::Operation op,
const Term& t)
95Term::Term(
const Term& lhs, Term::Operation op,
const Term& rhs)
108 if (lhs.operation() == op) {
109 d->m_subTerms << lhs.subTerms();
111 d->m_subTerms << lhs;
114 if (rhs.operation() == op) {
115 d->m_subTerms << rhs.subTerms();
117 d->m_subTerms << rhs;
121Term::~Term() =
default;
123bool Term::isValid()
const
126 if (d->m_op != Term::None) {
130 if (d->m_comp == Term::Auto) {
137void Term::setNegation(
bool isNegated)
139 d->m_isNegated = isNegated;
142bool Term::isNegated()
const
144 return d->m_isNegated;
147bool Term::negated()
const
149 return d->m_isNegated;
152void Term::addSubTerm(
const Term& term)
154 d->m_subTerms << term;
159 d->m_subTerms = terms;
162Term Term::subTerm()
const
164 if (!d->m_subTerms.isEmpty()) {
165 return d->m_subTerms.first();
173 return d->m_subTerms;
176void Term::setOperation(Term::Operation op)
181Term::Operation Term::operation()
const
186bool Term::empty()
const
191bool Term::isEmpty()
const
193 return d->m_property.isEmpty() && d->m_value.isNull() && d->m_subTerms.isEmpty();
198 return d->m_property;
201void Term::setProperty(
const QString& property)
203 d->m_property = property;
206void Term::setValue(
const QVariant& value)
216Term::Comparator Term::comparator()
const
221void Term::setComparator(Term::Comparator c)
228 d->m_userData.insert(name, value);
233 return d->m_userData.
value(name);
236QVariantMap Term::toVariantMap()
const
239 if (d->m_op != None) {
240 QVariantList variantList;
241 for (
const Term& term : std::as_const(d->m_subTerms)) {
242 variantList <<
QVariant(term.toVariantMap());
245 if (d->m_op == And) {
246 map[QStringLiteral(
"$and")] = variantList;
248 map[QStringLiteral(
"$or")] = variantList;
257 map[d->m_property] = d->m_value;
261 op = QStringLiteral(
"$ct");
265 op = QStringLiteral(
"$gt");
269 op = QStringLiteral(
"$gte");
273 op = QStringLiteral(
"$lt");
277 op = QStringLiteral(
"$lte");
310Term Term::fromVariantMap(
const QVariantMap& map)
312 if (
map.size() != 1) {
320 andOrString = QStringLiteral(
"$and");
321 term.setOperation(And);
324 andOrString = QStringLiteral(
"$or");
325 term.setOperation(Or);
331 const QVariantList
list =
map[andOrString].toList();
333 subTerms << Term::fromVariantMap(var.
toMap());
336 term.setSubTerms(subTerms);
341 term.setProperty(prop);
345 QVariantMap mapVal = value.
toMap();
346 if (mapVal.size() != 1) {
351 Term::Comparator com;
366 term.setComparator(com);
367 term.setValue(tryConvert(mapVal.value(op)));
372 term.setComparator(Equal);
373 term.setValue(tryConvert(value));
378bool Term::operator==(
const Term& rhs)
const
380 if (d->m_op != rhs.d->m_op || d->m_comp != rhs.d->m_comp ||
381 d->m_isNegated != rhs.d->m_isNegated || d->m_property != rhs.d->m_property ||
382 d->m_value != rhs.d->m_value)
387 if (d->m_subTerms.size() != rhs.d->m_subTerms.size()) {
391 if (d->m_subTerms.isEmpty()) {
395 for (
const Term& t : std::as_const(d->m_subTerms)) {
396 if (!rhs.d->m_subTerms.contains(t)) {
404Term& Term::operator=(
const Term& rhs)
410char *toString(
const Term& term)
421 QString comparatorToString(Baloo::Term::Comparator c) {
423 case Baloo::Term::Auto:
424 return QStringLiteral(
"Auto");
425 case Baloo::Term::Equal:
426 return QStringLiteral(
"=");
427 case Baloo::Term::Contains:
428 return QStringLiteral(
":");
429 case Baloo::Term::Less:
430 return QStringLiteral(
"<");
431 case Baloo::Term::LessEqual:
432 return QStringLiteral(
"<=");
433 case Baloo::Term::Greater:
434 return QStringLiteral(
">");
435 case Baloo::Term::GreaterEqual:
436 return QStringLiteral(
">=");
442 QString operationToString(Baloo::Term::Operation op) {
444 case Baloo::Term::None:
445 return QStringLiteral(
"NONE");
446 case Baloo::Term::And:
447 return QStringLiteral(
"AND");
448 case Baloo::Term::Or:
449 return QStringLiteral(
"OR");
464 d << comparatorToString(t.comparator());
473 d <<
"[" << operationToString(t.operation());
474 const auto subTerms = t.subTerms();
475 for (
const Baloo::Term& term : subTerms) {
Implements storage for docIds without any associated data Instantiated for:
KIOCORE_EXPORT QStringList list(const QString &fileClass)
const char * constData() const const
bool isValid() const const
bool isEmpty() const const
const_iterator cbegin() const const
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
QByteArray toUtf8() 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