Add class Ticket
This commit is contained in:
parent
f81369944c
commit
b7cedf5444
@ -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
|
||||
|
166
src/ATBAPP/support/Ticket.cpp
Normal file
166
src/ATBAPP/support/Ticket.cpp
Normal file
@ -0,0 +1,166 @@
|
||||
#include "Ticket.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
Ticket::Ticket(TICKET_VARIANT ticketVariant, QObject *parent )
|
||||
: QObject(parent)
|
||||
, ticketVariant(ticketVariant)
|
||||
, _hasTemplateDynData(false)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TICKET_VARIANT Ticket::variant()
|
||||
{
|
||||
return this->ticketVariant;
|
||||
}
|
||||
|
||||
QList<quint8> * 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<quint8> & templateList, const QHash<QString, QVariant> & 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;
|
||||
}
|
88
src/ATBAPP/support/Ticket.h
Normal file
88
src/ATBAPP/support/Ticket.h
Normal file
@ -0,0 +1,88 @@
|
||||
#ifndef TICKET_H
|
||||
#define TICKET_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QHash>
|
||||
|
||||
#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<quint8> & templateList, const QHash<QString, QVariant> & printingData);
|
||||
void clear();
|
||||
|
||||
TICKET_VARIANT variant();
|
||||
|
||||
QList<quint8> * templateList();
|
||||
|
||||
/**
|
||||
* @brief getPrintingData - generic getter for printingData
|
||||
* Used mainly for simple tickets (single tickets e.g. ParkingTicket)
|
||||
* @return
|
||||
*/
|
||||
QHash<QString, QVariant> & 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<QString, QVariant> printingData;
|
||||
|
||||
// templateList, from .ini or created by ticketVariant...
|
||||
QList<quint8> _templateList;
|
||||
|
||||
bool _hasTemplateDynData;
|
||||
|
||||
quint8 currentProcessedTemplateNumber;
|
||||
|
||||
QStringList dyn1List;
|
||||
QStringList dyn2List;
|
||||
|
||||
// error handling
|
||||
QString errorCode;
|
||||
QString errorDescription;
|
||||
};
|
||||
|
||||
#endif // TICKET_H
|
Loading…
Reference in New Issue
Block a user