6#include "config-prison-scanner.h"
10#include "scanresult_p.h"
13#include <ZXing/TextUtfEncoding.h>
17ScanResult::ScanResult()
18 : d(new ScanResultPrivate)
22ScanResult::ScanResult(
const ScanResult &) =
default;
23ScanResult::~ScanResult() =
default;
26bool ScanResult::operator==(
const ScanResult &other)
const
28 return d->content == other.d->content && d->boundingRect == other.d->boundingRect && d->format == other.d->format;
31bool ScanResult::hasContent()
const
33 return !d->content.isNull();
41bool ScanResult::hasText()
const
48 return hasText() ? d->content.toString() :
QString();
51bool ScanResult::hasBinaryData()
const
58 return hasBinaryData() ? d->content.toByteArray() :
QByteArray();
66QRect ScanResult::boundingRect()
const
68 return d->boundingRect;
71ScanResult ScanResultPrivate::fromZXingResult(
const ZXing::Result &zxRes,
const QTransform &transform)
74 if (!zxRes.isValid()) {
78#if ZXING_VERSION < QT_VERSION_CHECK(1, 4, 0)
80 const auto hasWideChars = std::any_of(zxRes.text().begin(), zxRes.text().end(), [](
auto c) {
83 const auto hasControlChars = std::any_of(zxRes.text().begin(), zxRes.text().end(), [](
auto c) {
84 return c < 0x20 && c != 0x0a && c != 0x0d;
86 if (hasWideChars || !hasControlChars) {
90 b.
resize(zxRes.text().size());
91 std::copy(zxRes.text().begin(), zxRes.text().end(), b.
begin());
95 if (zxRes.contentType() == ZXing::ContentType::Text) {
99 b.
resize(zxRes.bytes().size());
100 std::copy(zxRes.bytes().begin(), zxRes.bytes().end(), b.
begin());
108 const auto p = zxRes.position();
109 int x1 = std::numeric_limits<int>::max();
110 int y1 = std::numeric_limits<int>::max();
111 int x2 = std::numeric_limits<int>::min();
112 int y2 = std::numeric_limits<int>::min();
113 for (
int i = 0; i < 4; ++i) {
114 x1 = std::min(x1, p[i].x);
115 y1 = std::min(y1, p[i].y);
116 x2 = std::max(x2, p[i].x);
117 y2 = std::max(y2, p[i].y);
122 res.d->boundingRect =
transform.mapRect(res.d->boundingRect);
123 res.d->format = Format::toFormat(zxRes.format());
127#include "moc_scanresult.cpp"
Result of a barcode scan attempt.
Provides classes and methods for generating barcodes.
void resize(qsizetype newSize, char c)
QString fromStdString(const std::string &str)