Minor: overload constructor
This commit is contained in:
parent
684de4acd1
commit
6a3d183129
@ -21,6 +21,9 @@ public:
|
|||||||
using Status = std::tuple<int, char const*, char const*>;
|
using Status = std::tuple<int, char const*, char const*>;
|
||||||
|
|
||||||
explicit Ticket();
|
explicit Ticket();
|
||||||
|
explicit Ticket(QDateTime const &s, QDateTime const &e,
|
||||||
|
int durationMinutesNetto, int durationMinutesBrutto,
|
||||||
|
uint32_t price, Status status);
|
||||||
|
|
||||||
explicit operator bool() { return std::get<CODE>(m_status) == VALID; }
|
explicit operator bool() { return std::get<CODE>(m_status) == VALID; }
|
||||||
operator QString();
|
operator QString();
|
||||||
@ -35,6 +38,15 @@ public:
|
|||||||
void setValidUntil(QDateTime const &validUnil);
|
void setValidUntil(QDateTime const &validUnil);
|
||||||
void setPrice(uint32_t price);
|
void setPrice(uint32_t price);
|
||||||
|
|
||||||
|
bool isValid() { return operator bool(); }
|
||||||
|
|
||||||
|
static constexpr const Status s[STATUS_END] = {
|
||||||
|
{NOT_INITIALIZED , "NOT_INITIALIZED" , "Ticket not initialized" },
|
||||||
|
{VALID , "VALID" , "Ticket is valid" },
|
||||||
|
{INVALID_FROM_DATETIME , "INVALID_FROM_DATETIME" , "Ticket has invalid start datetime"},
|
||||||
|
{INVALID_UNTIL_DATETIME, "INVALID_UNTIL_DATETIME", "Ticket has invalid end datetime" }
|
||||||
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Status m_status;
|
Status m_status;
|
||||||
|
|
||||||
@ -45,20 +57,8 @@ private:
|
|||||||
int m_durationMinutesBrutto;
|
int m_durationMinutesBrutto;
|
||||||
|
|
||||||
uint32_t m_price;
|
uint32_t m_price;
|
||||||
|
|
||||||
static constexpr const Status s[STATUS_END] = {
|
|
||||||
{NOT_INITIALIZED , "NOT_INITIALIZED" , "Ticket not initialized" },
|
|
||||||
{VALID , "VALID" , "Ticket is valid" },
|
|
||||||
{INVALID_FROM_DATETIME , "INVALID_FROM_DATETIME" , "Ticket has invalid start datetime"},
|
|
||||||
{INVALID_UNTIL_DATETIME, "INVALID_UNTIL_DATETIME", "Ticket has invalid end datetime" }
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
QDebug operator<<(QDebug debug, Ticket::Status const &status) {
|
QDebug operator<<(QDebug debug, Ticket::Status const &status);
|
||||||
QDebugStateSaver saver(debug);
|
|
||||||
debug << "Ticket-Status: " << std::get<1>(status)
|
|
||||||
<< "(" << std::get<2>(status) << ")";
|
|
||||||
return debug;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // TICKET_H_INCLUDED
|
#endif // TICKET_H_INCLUDED
|
||||||
|
@ -12,6 +12,18 @@ Ticket::Ticket()
|
|||||||
qDebug() << m_status;
|
qDebug() << m_status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ticket::Ticket(QDateTime const &s, QDateTime const &e,
|
||||||
|
int durationMinutesNetto, int durationMinutesBrutto,
|
||||||
|
uint32_t price, Ticket::Status status)
|
||||||
|
: m_status(status)
|
||||||
|
, m_validFrom(s)
|
||||||
|
, m_validUntil(e)
|
||||||
|
, m_durationMinutesNetto(durationMinutesNetto)
|
||||||
|
, m_durationMinutesBrutto(durationMinutesBrutto)
|
||||||
|
, m_price(price) {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Ticket::Status Ticket::setStatus(Status status) {
|
Ticket::Status Ticket::setStatus(Status status) {
|
||||||
Status old = m_status;
|
Status old = m_status;
|
||||||
m_status = status;
|
m_status = status;
|
||||||
@ -54,14 +66,23 @@ void Ticket::setPrice(uint32_t price) {
|
|||||||
|
|
||||||
Ticket::operator QString() {
|
Ticket::operator QString() {
|
||||||
QStringList status;
|
QStringList status;
|
||||||
status << QString("Status .............. : %1 (%2)")
|
status << QString("**********************");
|
||||||
|
status << QString("Status ............. : %1 (%2)")
|
||||||
.arg(std::get<0>(m_status))
|
.arg(std::get<0>(m_status))
|
||||||
.arg(std::get<2>(m_status));
|
.arg(std::get<2>(m_status));
|
||||||
status << QString("Valid from ......... : %1").arg(m_validFrom.toString(Qt::ISODate));
|
status << QString("Valid from ......... : %1").arg(m_validFrom.toString(Qt::ISODate));
|
||||||
status << QString("Valid until ........ : %1").arg(m_validUntil.toString(Qt::ISODate));
|
status << QString("Valid until ........ : %1").arg(m_validUntil.toString(Qt::ISODate));
|
||||||
status << QString("Duration (netto) ... : %1").arg(m_durationMinutesNetto);
|
status << QString("Duration (netto) ... : %1").arg(m_durationMinutesNetto);
|
||||||
status << QString("Duration (brutto)... : %1").arg(m_durationMinutesBrutto);
|
status << QString("Duration (brutto)... : %1").arg(m_durationMinutesBrutto);
|
||||||
status << QString("Price ......... : %1").arg(m_price);
|
status << QString("Price .............. : %1").arg(m_price);
|
||||||
|
status << QString("**********************");
|
||||||
|
|
||||||
return status.join('\n');;
|
return status.join('\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
QDebug operator<<(QDebug debug, Ticket::Status const &status) {
|
||||||
|
QDebugStateSaver saver(debug);
|
||||||
|
debug << "Ticket-Status: " << std::get<1>(status)
|
||||||
|
<< "(" << std::get<2>(status) << ")";
|
||||||
|
return debug;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user