KItinerary

extractorfilter.h
1/*
2 SPDX-FileCopyrightText: 2017-2021 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#pragma once
8
9#include "kitinerary_export.h"
10
11#include <QExplicitlySharedDataPointer>
12#include <qobjectdefs.h>
13
14class QJsonObject;
15class QJSValue;
16
17namespace KItinerary {
18
19class ExtractorDocumentNode;
20class ExtractorFilterPrivate;
21
22/** Determines whether an extractor is applicable to a given email. */
23class KITINERARY_EXPORT ExtractorFilter
24{
25 Q_GADGET
26public:
31 ExtractorFilter& operator=(const ExtractorFilter&);
32 ExtractorFilter& operator=(ExtractorFilter&&);
33
34 /** MIME type of the document part this filter can match. */
35 QString mimeType() const;
36 /** The field to filter on. */
37 QString fieldName() const;
38 /** Check if @p data matches this filter. */
39 bool matches(const QString &data) const;
40 /** Pattern to match field value against. */
41 QString pattern() const;
42
43 /** Specifies which document nodes should match this filter, relative to the one being extracted. */
44 enum Scope {
45 Current, ///< match the node being extracted
46 Parent, ///< match the direct parent node
47 Children, ///< match the direct child nodes
48 Ancestors, ///< match any direct or indirect parent nodes
49 Descendants, ///< match any direct or indirect child nodes
50 };
51 Q_ENUM(Scope)
52 /** Evaluation scope of this filter, in relation to the node being extracted. */
53 Scope scope() const;
54
55 /** Checks whether this filter applies to @p node. */
56 bool matches(const ExtractorDocumentNode &node) const;
57
58 /** Checks whether this filter applies to @p node.
59 * Unlike matches() this returns all nodes triggering this filter.
60 * This matters in particular for matching child nodes, where multiple
61 * ones can match the filter.
62 */
63 void allMatches(const ExtractorDocumentNode &node, std::vector<ExtractorDocumentNode> &matches) const;
64
65 ///@cond internal
66 /** Load filter from @p obj. */
67 bool load(const QJsonObject &obj);
68 /** Serialize filter to a JSON object. */
69 QJsonObject toJson() const;
70 /** Create a filter from a JS object value. */
71 static ExtractorFilter fromJSValue(const QJSValue &js);
72
73 void setMimeType(const QString &mimeType);
74 void setFieldName(const QString &fieldName);
75 void setPattern(const QString &pattern);
76 void setScope(Scope scope);
77 ///@endcond
78
79private:
81};
82
83}
84
A node in the extracted document object tree.
Determines whether an extractor is applicable to a given email.
Scope
Specifies which document nodes should match this filter, relative to the one being extracted.
@ Current
match the node being extracted
@ Children
match the direct child nodes
@ Descendants
match any direct or indirect child nodes
@ Ancestors
match any direct or indirect parent nodes
@ Parent
match the direct parent node
Classes for reservation/travel data models, data extraction and data augmentation.
Definition berelement.h:17
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:28:48 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.