Commit cc4ee48c authored by Volker Krause's avatar Volker Krause
Browse files

Allow always matching extractor filters

That is, allowing to list all nodes of a specific type without any
further constraints.
parent e1f32a18
......@@ -4,6 +4,8 @@
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "config-kitinerary.h"
#include <KItinerary/ExtractorDocumentNode>
#include <KItinerary/ExtractorDocumentNodeFactory>
#include <KItinerary/ExtractorDocumentProcessor>
......@@ -124,6 +126,29 @@ private Q_SLOTS:
filter.setPattern(s("Milan"));
QVERIFY(filter.matches(root));
}
void testIataBcbpFilter()
{
QFile f(s(SOURCE_DIR "/extractordata/synthetic/iata-bcbp-demo.pdf"));
QVERIFY(f.open(QFile::ReadOnly));
ExtractorEngine engine;
engine.setData(f.readAll());
engine.extract();
const auto root = engine.rootDocumentNode();
QVERIFY(!root.isNull());
#ifdef HAVE_ZXING
ExtractorFilter filter;
filter.setMimeType(s("internal/iata-bcbp"));
filter.setScope(ExtractorFilter::Descendants);
QVERIFY(filter.matches(root));
std::vector<ExtractorDocumentNode> matches;
filter.allMatches(root, matches);
QCOMPARE(matches.size(), 1);
#endif
}
};
QTEST_GUILESS_MAIN(ExtractorFilterTest)
......
......@@ -156,7 +156,8 @@ static bool filterMachesNode(const ExtractorFilter &filter, ExtractorFilter::Sco
return false;
}
if (filter.mimeType() == node.mimeType() && node.processor()->matches(filter, node)) {
// filter without field/pattern always match, if the mimetype does
if (filter.mimeType() == node.mimeType() && ((filter.fieldName().isEmpty() && filter.pattern().isEmpty()) || node.processor()->matches(filter, node))) {
if (matchMode == All) {
matches.push_back(node);
}
......@@ -249,8 +250,14 @@ ExtractorFilter ExtractorFilter::fromJSValue(const QJSValue &js)
{
ExtractorFilter f;
f.setMimeType(js.property(QLatin1String("mimeType")).toString());
f.setFieldName(js.property(QLatin1String("field")).toString());
f.setPattern(js.property(QLatin1String("match")).toString());
const auto fieldName = js.property(QLatin1String("field"));
if (fieldName.isString()) {
f.setFieldName(fieldName.toString());
}
const auto match = js.property(QLatin1String("match"));
if (match.isString()) {
f.setPattern(match.toString());
}
f.setScope(readEnum<ExtractorFilter::Scope>(js.property(QLatin1String("scope")).toString(), ExtractorFilter::Current));
return f;
}
......@@ -6,7 +6,7 @@
function main(pdf, node) {
var res = [];
for (barcode of node.findChildNodes({ scope: "Descendants", mimeType: "text/plain", match: "M.*" })) {
for (barcode of node.findChildNodes({ scope: "Descendants", mimeType: "internal/iata-bcbp" })) {
if (barcode.location == undefined)
continue;
res.push(parsePage(pdf.pages[barcode.location], barcode));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment