From b7cedf54446f9d398cd45bb229234ab54cb25ba2 Mon Sep 17 00:00:00 2001 From: Siegfried Siegert Date: Mon, 11 Mar 2024 13:31:51 +0100 Subject: [PATCH] Add class Ticket --- DCPlugin.pro | 6 +- src/ATBAPP/support/Ticket.cpp | 166 ++++++++++++++++++++++++++++++++++ src/ATBAPP/support/Ticket.h | 88 ++++++++++++++++++ 3 files changed, 258 insertions(+), 2 deletions(-) create mode 100644 src/ATBAPP/support/Ticket.cpp create mode 100644 src/ATBAPP/support/Ticket.h diff --git a/DCPlugin.pro b/DCPlugin.pro index 190ec8d..2615d7a 100644 --- a/DCPlugin.pro +++ b/DCPlugin.pro @@ -87,7 +87,8 @@ HEADERS += \ src/ATBAPP/support/DBusControllerInterface.h \ src/ATBAPP/support/JSON.h \ src/ATBAPP/support/PTUSystem.h \ - src/ATBAPP/support/PersistentData.h + src/ATBAPP/support/PersistentData.h \ + src/ATBAPP/support/Ticket.h SOURCES += \ src/ATBAPP/ATBHealthEvent.cpp \ @@ -99,7 +100,8 @@ SOURCES += \ src/ATBAPP/support/DBusControllerInterface.cpp \ src/ATBAPP/support/JSON.cpp \ src/ATBAPP/support/PTUSystem.cpp \ - src/ATBAPP/support/PersistentData.cpp + src/ATBAPP/support/PersistentData.cpp \ + src/ATBAPP/support/Ticket.cpp DISTFILES += \ generate-version.sh diff --git a/src/ATBAPP/support/Ticket.cpp b/src/ATBAPP/support/Ticket.cpp new file mode 100644 index 0000000..0d6bf0e --- /dev/null +++ b/src/ATBAPP/support/Ticket.cpp @@ -0,0 +1,166 @@ +#include "Ticket.h" + +#include + +Ticket::Ticket(TICKET_VARIANT ticketVariant, QObject *parent ) + : QObject(parent) + , ticketVariant(ticketVariant) + , _hasTemplateDynData(false) +{ + +} + +TICKET_VARIANT Ticket::variant() +{ + return this->ticketVariant; +} + +QList * Ticket::templateList() +{ + return &(this->_templateList); +} + +bool Ticket::hasTemplateDynData() +{ + return this->_hasTemplateDynData; +} + +quint8 Ticket::getCurrentProcessedTemplateNumber() +{ + return this->currentProcessedTemplateNumber; +} + +void Ticket::setCurrentTemplateProcessed() +{ + this->currentProcessedTemplateNumber++; +} + + +bool Ticket::initNew(TICKET_VARIANT ticketVariant, const QList & templateList, const QHash & printingData) +{ + this->clear(); + + this->ticketVariant = ticketVariant; + this->printingData = printingData; + this->_templateList = templateList; + this->currentProcessedTemplateNumber = 0; + + // DEBUG + qCritical() << "Ticket::initNew():"; + qCritical() << " -> " << ticketVariant; + + int multiplicatorInt; + + switch (this->ticketVariant) { + case TICKET_VARIANT::PARKING_TICKET: + break; + case TICKET_VARIANT::RECEIPT: + break; + case TICKET_VARIANT::ERROR_RECEIPT: + break; + case TICKET_VARIANT::START_RECEIPT: + this->_templateList << 21 << 22 << 23; + break; + case TICKET_VARIANT::STOP_RECEIPT: + this->_templateList << 24 << 25 << 26; + break; + case TICKET_VARIANT::FOOD_STAMP: + if (printingData.contains("dyn1_list")) { + this->_hasTemplateDynData = true; + + this->dyn1List = printingData["dyn1_list"].toStringList(); + this->dyn2List = printingData["dyn2_list"].toStringList(); + } + + if (printingData.contains("multiplicator")) { + multiplicatorInt = printingData["multiplicator"].toInt(); + for (int i = 1; i < multiplicatorInt; i++) { + this->_templateList << 1; + } + // last template: + this->_templateList << 2; + } + + // DEBUG FOOD_STAMP: + qCritical() << " --> printingData[\"multiplicator\"]" << multiplicatorInt; + + break; + } + + + // DEBUG + QString templateListString; + for (int i =0; i < this->_templateList.size(); ++i) { + templateListString.append(QString(" %1").arg(this->_templateList.at(i))); + } + qCritical() << " -> templates: " << templateListString; + + + return true; +} + +void Ticket::clear() +{ + this->ticketVariant = TICKET_VARIANT::PARKING_TICKET; + this->printingData.clear(); + this->_templateList.clear(); + this->errorCode.clear(); + this->errorDescription.clear(); + + this->_hasTemplateDynData = false; + this->dyn1List.clear(); + this->dyn1List.clear(); +} + +QString Ticket::getErrorCode() { return this->errorCode; } +QString Ticket::getErrorDescription() { return this->errorDescription; } + + + + +/** + */ +QStringList Ticket::getDyn1List() +{ + return this->dyn1List; +} + +QStringList Ticket::getDyn2List() +{ + return this->dyn2List; +} + + + + + + +/************************************************************************************************ + * operator + * + */ +QDebug operator<<(QDebug debug, TICKET_VARIANT ticketVariant) +{ + switch (ticketVariant) { + case TICKET_VARIANT::PARKING_TICKET: + debug << "TICKET_VARIANT::PARKING_TICKET"; + break; + case TICKET_VARIANT::RECEIPT: + debug << "TICKET_VARIANT::RECEIPT"; + break; + case TICKET_VARIANT::ERROR_RECEIPT: + debug << "TICKET_VARIANT::ERROR_RECEIPT"; + break; + case TICKET_VARIANT::START_RECEIPT: + debug << "TICKET_VARIANT::START_RECEIPT"; + break; + case TICKET_VARIANT::STOP_RECEIPT: + debug << "TICKET_VARIANT::STOP_RECEIPT"; + break; + case TICKET_VARIANT::FOOD_STAMP: + debug << "TICKET_VARIANT::FOOD_STAMP"; + break; + } + + return debug; +} diff --git a/src/ATBAPP/support/Ticket.h b/src/ATBAPP/support/Ticket.h new file mode 100644 index 0000000..25c8382 --- /dev/null +++ b/src/ATBAPP/support/Ticket.h @@ -0,0 +1,88 @@ +#ifndef TICKET_H +#define TICKET_H + +#include +#include + +#include "../DeviceControllerInterface.h" + +using namespace nsDeviceControllerInterface; + +QDebug operator<<(QDebug debug, TICKET_VARIANT ticketVariant); + + + +class Ticket : public QObject +{ + Q_OBJECT + +public: + Ticket(TICKET_VARIANT ticketVariant, QObject *parent = nullptr); + + bool initNew(TICKET_VARIANT ticketVariant, const QList & templateList, const QHash & printingData); + void clear(); + + TICKET_VARIANT variant(); + + QList * templateList(); + + /** + * @brief getPrintingData - generic getter for printingData + * Used mainly for simple tickets (single tickets e.g. ParkingTicket) + * @return + */ + QHash & getPrintingData(); + + /** + * @brief hasTemplateDynData + * @return true, if ticket has dynamic data for each template. + * + * This depends on TICKET_VARIANT and printingData + */ + bool hasTemplateDynData(); + + /** + * @brief getDyn1List + * contains dynamic template data + * The size of the lists must be exactly the same as the number of templates. + */ + QStringList getDyn1List(); + QStringList getDyn2List(); + + quint8 getCurrentProcessedTemplateNumber(); + + /** + * Mark current template as processed + */ + void setCurrentTemplateProcessed(); + + + // error handling + QString getErrorCode(); + QString getErrorDescription(); + + + + +private: + TICKET_VARIANT ticketVariant; + + // printingData from application + QHash printingData; + + // templateList, from .ini or created by ticketVariant... + QList _templateList; + + bool _hasTemplateDynData; + + quint8 currentProcessedTemplateNumber; + + QStringList dyn1List; + QStringList dyn2List; + + // error handling + QString errorCode; + QString errorDescription; +}; + +#endif // TICKET_H