Add TicketUtils class for ...

Ticket helper methods e.g. string format helpers.
Currently only on method for getting a date string in short format
according to selected language.
This commit is contained in:
Siegfried Siegert 2024-08-08 10:10:27 +02:00
parent a43af8ab86
commit 1bcdb5ba21
Signed by: SiegfriedSiegert
GPG Key ID: 68371E015E8F0B03
3 changed files with 64 additions and 2 deletions

View File

@ -88,7 +88,8 @@ HEADERS += \
src/ATBAPP/support/JSON.h \
src/ATBAPP/support/PTUSystem.h \
src/ATBAPP/support/PersistentData.h \
src/ATBAPP/support/Ticket.h
src/ATBAPP/support/Ticket.h \
src/ATBAPP/support/TicketUtils.h
SOURCES += \
src/ATBAPP/ATBHealthEvent.cpp \
@ -101,7 +102,8 @@ SOURCES += \
src/ATBAPP/support/JSON.cpp \
src/ATBAPP/support/PTUSystem.cpp \
src/ATBAPP/support/PersistentData.cpp \
src/ATBAPP/support/Ticket.cpp
src/ATBAPP/support/Ticket.cpp \
src/ATBAPP/support/TicketUtils.cpp
DISTFILES += \
generate-version.sh

View File

@ -0,0 +1,26 @@
#include "TicketUtils.h"
#include <QLocale>
#include <QDate>
TicketUtils::TicketUtils(QObject *parent) : QObject(parent)
{
}
QString TicketUtils::getLocaleDateString(const QLocale & qLocale, const QDate & qDate)
{
QString dateString;
if (qLocale.language() == QLocale::Lithuanian) {
// QLocale::ShortFormat produces date string: "yyyy-mm-dd" ...
// this is to long for the printer.
dateString = qDate.toString("YY-MM-dd");
}
else {
dateString = qLocale.toString(qDate, QLocale::ShortFormat);
}
return dateString;
}

View File

@ -0,0 +1,34 @@
#ifndef TICKETUTILS_H
#define TICKETUTILS_H
#include <QObject>
class TicketUtils : public QObject
{
Q_OBJECT
public:
explicit TicketUtils(QObject *parent = nullptr);
/**
* @brief getLocaleDateString
* @param qLocale
* @param qDate
* @return a localized date string short format
*
* Note QLocale::ShortFormat does not result to the
* string we need for ticket printing therefore this
* helper method was created.
*
* e.g. using Lithuanian (lt_LT) we get a date in short format:
* "2024-08-08" unfortunately this is to long, we need
* the year with only two digits.
* e.g. in German (de_DE) it is enought: "08.08.24"
*
*/
static QString getLocaleDateString(const QLocale &qLocale, const QDate &qDate);
signals:
};
#endif // TICKETUTILS_H