-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathticket.cpp
More file actions
69 lines (56 loc) · 2.33 KB
/
Copy pathticket.cpp
File metadata and controls
69 lines (56 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "ticket.h"
#include "ui_ticket.h"
#include "QMessageBox"
// --- Конструктор та Деструктор ---
Ticket::Ticket(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Ticket)
{
ui->setupUi(this);
}
Ticket::~Ticket()
{
delete ui;
}
// --- Основний функціонал ---
// Заповнює візуальні елементи даними
void Ticket::fillTicket(CSeasonTicket* current)
{
ui->cityLabel->setText(QString::fromStdString(current->getCity()));
ui->transportLabel->setText(QString::fromStdString(transportTypeToString(current->getTransportType())));
ui->categoryLabel->setText(QString::fromStdString(categoryToString(current->getCitizenCategory())));
double priceInUAH = current->getpriceInCents() / 100.0;
ui->priceLabel->setText(QString::number(priceInUAH, 'f', 2) + " грн");
auto duration = current->getDuration();
using namespace std::chrono;
if (duration == hours(24 * 30)) ui->durationLabel->setText("1 місяць");
else if (duration == hours(24 * 90)) ui->durationLabel->setText("3 місяці");
else if (duration == hours(24 * 180)) ui->durationLabel->setText("6 місяців");
else if (duration == hours(24 * 365)) ui->durationLabel->setText("1 рік");
else ui->durationLabel->setText("Невідомо");
auto startDate = current->getStartDate();
std::time_t timeT = system_clock::to_time_t(startDate);
QDateTime dateTime = QDateTime::fromSecsSinceEpoch(timeT);
QDate qDate = dateTime.date();
ui->startDate->setDate(qDate);
id_ = current->getId();
if (auto named = dynamic_cast<CNamedTicket*>(current))
{
ui->ownerLabel->setText(QString::fromStdString(named->getOwnerName()+ " " + named->getOwnerSurname()));
}
else ui->ownerLabel->setText("Без власника ");
}
// --- Слоти ---
// Відкриття вікна редагування
void Ticket::on_changeDataBtn_clicked()
{
ticketInfoChange *window = new ticketInfoChange(id_, nullptr);
window->setAttribute(Qt::WA_DeleteOnClose);
window->show();
connect(window, &ticketInfoChange::refresh, this, &Ticket::refresh);
}
// Натискання кнопки видалення
void Ticket::on_removeBtn_clicked()
{
emit removeRequested(id_);
}