Commit 0a9aecfe authored by Volker Krause's avatar Volker Krause
Browse files

Deduplicate the JS barcode API wrapper code a bit

parent 9f131d87
......@@ -9,7 +9,6 @@
#include <era/ssbticketreader.h>
#include <pdf/pdfbarcodeutil_p.h>
#include <KItinerary/BarcodeDecoder>
#include <KItinerary/PdfDocument>
#include <KItinerary/Uic9183Parser>
#include <KItinerary/VdvTicket>
......@@ -26,26 +25,12 @@ void JsApi::Barcode::setDecoder(BarcodeDecoder *decoder)
QString JsApi::Barcode::decodePdf417(const QVariant &img) const
{
if (img.userType() == qMetaTypeId<PdfImage>()) {
const auto pdfImg = img.value<PdfImage>();
if (!PdfBarcodeUtil::maybeBarcode(pdfImg, BarcodeDecoder::PDF417)) {
return {};
}
return m_decoder->decodeString(pdfImg.image(), BarcodeDecoder::PDF417);
}
return {};
return decodeBarcode(img, BarcodeDecoder::PDF417);
}
QString JsApi::Barcode::decodeAztec(const QVariant &img) const
{
if (img.userType() == qMetaTypeId<PdfImage>()) {
const auto pdfImg = img.value<PdfImage>();
if (!PdfBarcodeUtil::maybeBarcode(pdfImg, BarcodeDecoder::Aztec)) {
return {};
}
return m_decoder->decodeString(pdfImg.image(), BarcodeDecoder::Aztec);
}
return {};
return decodeBarcode(img, BarcodeDecoder::Aztec);
}
QVariant JsApi::Barcode::decodeAztecBinary(const QVariant &img) const
......@@ -66,33 +51,31 @@ QVariant JsApi::Barcode::decodeAztecBinary(const QVariant &img) const
QString JsApi::Barcode::decodeQR(const QVariant &img) const
{
if (img.userType() == qMetaTypeId<PdfImage>()) {
const auto pdfImg = img.value<PdfImage>();
if (!PdfBarcodeUtil::maybeBarcode(pdfImg, BarcodeDecoder::QRCode)) {
return {};
}
return m_decoder->decodeString(pdfImg.image(), BarcodeDecoder::QRCode);
}
return {};
return decodeBarcode(img, BarcodeDecoder::QRCode);
}
QString JsApi::Barcode::decodeDataMatrix(const QVariant &img) const
{
return decodeBarcode(img, BarcodeDecoder::DataMatrix);
}
QString JsApi::Barcode::decodeAnyBarcode(const QVariant& img) const
{
if (img.userType() == qMetaTypeId<PdfImage>()) {
const auto pdfImg = img.value<PdfImage>();
if (!PdfBarcodeUtil::maybeBarcode(pdfImg, BarcodeDecoder::DataMatrix)) {
return {};
}
return m_decoder->decodeString(pdfImg.image(), BarcodeDecoder::DataMatrix);
return m_decoder->decodeString(pdfImg.image(), BarcodeDecoder::Any | BarcodeDecoder::IgnoreAspectRatio);
}
return {};
}
QString JsApi::Barcode::decodeAnyBarcode(const QVariant& img) const
QString JsApi::Barcode::decodeBarcode(const QVariant &img, BarcodeDecoder::BarcodeTypes hints) const
{
if (img.userType() == qMetaTypeId<PdfImage>()) {
const auto pdfImg = img.value<PdfImage>();
return m_decoder->decodeString(pdfImg.image(), BarcodeDecoder::Any | BarcodeDecoder::IgnoreAspectRatio);
if (!PdfBarcodeUtil::maybeBarcode(pdfImg, hints)) {
return {};
}
return m_decoder->decodeString(pdfImg.image(), hints);
}
return {};
}
......
......@@ -6,6 +6,8 @@
#pragma once
#include <KItinerary/BarcodeDecoder>
#include <QDateTime>
#include <QObject>
......@@ -83,6 +85,8 @@ public:
///@endcond
private:
QString decodeBarcode(const QVariant &img, BarcodeDecoder::BarcodeTypes hints) const;
QDateTime m_contextDate;
BarcodeDecoder *m_decoder = nullptr;
};
......
Supports Markdown
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