KItinerary

extractorfilter.h
1 /*
2  SPDX-FileCopyrightText: 2017-2021 Volker Krause <[email protected]>
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 
14 class QJsonObject;
15 class QJSValue;
16 
17 namespace KItinerary {
18 
19 class ExtractorDocumentNode;
20 class ExtractorFilterPrivate;
21 
22 /** Determines whether an extractor is applicable to a given email. */
23 class KITINERARY_EXPORT ExtractorFilter
24 {
25  Q_GADGET
26 public:
28  ~ExtractorFilter();
30  ExtractorFilter(ExtractorFilter&&) noexcept;
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 
79 private:
80  QExplicitlySharedDataPointer<ExtractorFilterPrivate> d;
81 };
82 
83 }
84 
match the direct child nodes
Scope
Specifies which document nodes should match this filter, relative to the one being extracted...
Classes for reservation/travel data models, data extraction and data augmentation.
match the direct parent node
match any direct or indirect child nodes
match any direct or indirect parent nodes
Determines whether an extractor is applicable to a given email.
A node in the extracted document object tree.
match the node being extracted
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Mon Jan 17 2022 23:06:16 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.