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:
		
							
								
								
									
										26
									
								
								src/ATBAPP/support/TicketUtils.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								src/ATBAPP/support/TicketUtils.cpp
									
									
									
									
									
										Normal 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;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										34
									
								
								src/ATBAPP/support/TicketUtils.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								src/ATBAPP/support/TicketUtils.h
									
									
									
									
									
										Normal 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
 | 
			
		||||
		Reference in New Issue
	
	Block a user