File indexing completed on 2024-05-12 04:01:32

0001 /*
0002     SPDX-FileCopyrightText: 2022 Volker Krause <vkrause@kde.org>
0003     SPDX-License-Identifier: MIT
0004 */
0005 
0006 #ifndef PRISON_SCANRESULT_H
0007 #define PRISON_SCANRESULT_H
0008 
0009 #include "format.h"
0010 #include "prisonscanner_export.h"
0011 
0012 #include <QExplicitlySharedDataPointer>
0013 #include <QMetaType>
0014 #include <QRect>
0015 #include <QVariant>
0016 
0017 namespace Prison
0018 {
0019 
0020 class ScanResultPrivate;
0021 
0022 /** Result of a barcode scan attempt.
0023  *
0024  *  A scan result consists of the barcode content (which can be text or
0025  *  binary data), the barcode format and the position in the video frame
0026  *  the barcode was detected.
0027  *
0028  *  @since 5.94
0029  */
0030 class PRISONSCANNER_EXPORT ScanResult
0031 {
0032     Q_GADGET
0033     Q_PROPERTY(bool hasContent READ hasContent)
0034     Q_PROPERTY(QVariant content READ content)
0035 
0036     Q_PROPERTY(bool hasText READ hasText)
0037     Q_PROPERTY(QString text READ text)
0038 
0039     Q_PROPERTY(bool hasBinaryData READ hasBinaryData)
0040     Q_PROPERTY(QByteArray binaryData READ binaryData)
0041 
0042     Q_PROPERTY(Prison::Format::BarcodeFormat format READ format)
0043     Q_PROPERTY(QRect boundingRect READ boundingRect)
0044 
0045 public:
0046     explicit ScanResult();
0047     ScanResult(const ScanResult &);
0048     ~ScanResult();
0049     ScanResult &operator=(const ScanResult &);
0050 
0051     bool operator==(const ScanResult &other) const;
0052 
0053     /** Returns @c true if a barcode has been found. */
0054     bool hasContent() const;
0055     /** The barcode content, either a QString or a QByteArray. */
0056     QVariant content() const;
0057 
0058     /** Returns @c true if the found barcode contained a textual payload. */
0059     bool hasText() const;
0060     /**
0061      * Returns the textual barcode content, if the content was text rather than binary data,
0062      * otherwise returns an empty string.
0063      */
0064     QString text() const;
0065 
0066     /** Returns @c true if the found barcode contained a binary data payload. */
0067     bool hasBinaryData() const;
0068     /**
0069      * Returns the binary data content, if the content was binary data rather than text,
0070      * otherwise returns an empty QByteArray.
0071      */
0072     QByteArray binaryData() const;
0073 
0074     /** The format of the detected barcode. */
0075     Format::BarcodeFormat format() const;
0076 
0077     /** The bounding rectangle of the detected barcode in source coordinates.
0078      *  @note When using this to display an overlay in a view finder, this needs
0079      *  to be mapped to item coordinates.
0080      */
0081     QRect boundingRect() const;
0082 
0083 private:
0084     friend class ScanResultPrivate;
0085     QExplicitlySharedDataPointer<ScanResultPrivate> d;
0086 };
0087 
0088 }
0089 
0090 #endif // PRISON_SCANRESULT_H