Commit 04efe0ab authored by Volker Krause's avatar Volker Krause
Browse files

Move member variables to private class for KPkPass::Barcode too

parent 1ade009d
......@@ -23,38 +23,53 @@
using namespace KPkPass;
namespace KPkPass {
class BarcodePrivate
{
public:
const Pass *pass = nullptr;
QJsonObject obj;
};
}
Barcode::Barcode()
: d(new BarcodePrivate)
{
}
Barcode::Barcode(const QJsonObject &obj, const Pass *pass)
: d(new BarcodePrivate)
{
m_altText = pass->d->message(obj.value(QLatin1String("altText")).toString());
const auto format = obj.value(QLatin1String("format")).toString();
if (format == QLatin1String("PKBarcodeFormatQR"))
m_format = QR;
else if (format == QLatin1String("PKBarcodeFormatPDF417"))
m_format = PDF417;
else if (format == QLatin1String("PKBarcodeFormatAztec"))
m_format = Aztec;
else if (format == QLatin1String("PKBarcodeFormatCode128"))
m_format = Code128;
m_message = obj.value(QLatin1String("message")).toString();
d->pass = pass;
d->obj = obj;
}
Barcode::~Barcode() = default;
QString Barcode::alternativeText() const
{
return m_altText;
if (d->pass) {
return d->pass->d->message(d->obj.value(QLatin1String("altText")).toString());
}
return {};
}
Barcode::Format KPkPass::Barcode::format() const
{
return m_format;
const auto format = d->obj.value(QLatin1String("format")).toString();
if (format == QLatin1String("PKBarcodeFormatQR")) {
return QR;
} else if (format == QLatin1String("PKBarcodeFormatPDF417")) {
return PDF417;
} else if (format == QLatin1String("PKBarcodeFormatAztec")) {
return Aztec;
} else if (format == QLatin1String("PKBarcodeFormatCode128")) {
return Code128;
}
return Invalid;
}
QString Barcode::message() const
{
return m_message;
return d->obj.value(QLatin1String("message")).toString();
}
......@@ -23,19 +23,25 @@
#include <QMetaType>
#include <QString>
#include <memory>
class QJsonObject;
namespace KPkPass {
class BarcodePrivate;
class Pass;
/** A pass barcode element. */
/** A pass barcode element.
* @see https://developer.apple.com/library/content/documentation/UserExperience/Reference/PassKit_Bundle/Chapters/LowerLevel.html
*/
class KPKPASS_EXPORT Barcode
{
Q_GADGET
Q_PROPERTY(QString alternativeText READ alternativeText CONSTANT)
Q_PROPERTY(Format format READ format CONSTANT)
Q_PROPERTY(QString message READ message CONSTANT)
public:
enum Format {
Invalid,
......@@ -56,13 +62,11 @@ public:
/** The message encoded in the barcode. */
QString message() const;
// TODO add codec property
private:
friend class Pass;
explicit Barcode(const QJsonObject &obj, const Pass *file);
QString m_altText;
QString m_message;
Format m_format = Invalid;
std::shared_ptr<BarcodePrivate> d;
};
}
......
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