-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
141 lines (125 loc) · 4.03 KB
/
Copy pathmainwindow.cpp
File metadata and controls
141 lines (125 loc) · 4.03 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include "mainwindow.h"
#include "qgridlayout.h"
#include "qobjectdefs.h"
#include "ui_mainwindow.h"
#include "planeseatcheckbox.h"
#include "addflightwindow.h"
#include "planetypedatabasecontroller.h"
#include "flightsdatabasecontroller.h"
#include "seatsdatabasecontroller.h"
FlightsDatabaseController flightsDB(flightsDB_path);
//PlaneTypeDatabaseController planeTypeDB(planeTypeDB_path);
QMap<int,int> isCheckedMap;
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
UpdateFlightsList();
}
MainWindow::~MainWindow()
{
delete ui;
}
void *MainWindow::CreateSeatView(QString code)
{
QGroupBox *groupBox = new QGroupBox(tr("Seats"));
QGridLayout *vbox = new QGridLayout;
FlightsDatabaseController flightsDB(flightsDB_path);
QString planeType = flightsDB.GetPlaneTypeByCode(code);
qDebug() << "planetype" + planeType;
PlaneTypeDatabaseController planeTypeDB(planeTypeDB_path);
int columns = planeTypeDB.GetColumnsByPlaneType(planeType);
int seats = planeTypeDB.GetSeatsByPlaneType(planeType);
SeatsDatabaseController seatDB(seatsDB_path);
for(int i=1;i<=seats;i++)
{
QCheckBox* seat = new QCheckBox();
switch(seatDB.IsSeatChecked(i,code))
{
case 1:
seat->setChecked(1);
seat->setDisabled(1);
qDebug()<< "seat checked";
break;
case 0:
seat->setChecked(0);
seat->setDisabled(0);
qDebug()<< "seat not checked";
break;
}
PlaneSeatCheckBox *st = new PlaneSeatCheckBox(seat,i);
vbox->addWidget(st->parentWidget(),(i-1)/columns,(i-1)%columns);
}
groupBox->setLayout(vbox);
QGridLayout *grid = new QGridLayout;
grid->addWidget(groupBox);
ui->horizontalLayout->addLayout(grid);
if(m_isObjectReadyToBeDelete)
{
if ( ui->horizontalLayout->itemAt(2)->layout() != NULL )
{
QLayoutItem* item;
while ( ( item = ui->horizontalLayout->itemAt(2)->layout()->takeAt( 0 ) ) != NULL )
{
delete item->widget();
delete item;
}
delete ui->horizontalLayout->itemAt(2)->layout();
}
}
m_isObjectReadyToBeDelete = true;
}
void MainWindow::on_pushButton_clicked()
{
if(!m_code.isNull())
{
qDebug() << "booking_button: Clicked";
qDebug() << isCheckedMap;
qDebug() << m_code;
qDebug() << isCheckedMap.count();
do
{
qDebug() << " booking" << isCheckedMap;
SeatsDatabaseController seatDB(seatsDB_path);
seatDB.updateSeatCheckedValue(isCheckedMap.lastKey(),isCheckedMap.value(isCheckedMap.lastKey()),m_code);
isCheckedMap.remove(isCheckedMap.lastKey());
}
while (!isCheckedMap.empty());
isCheckedMap.clear();
CreateSeatView(m_code);
}
}
void MainWindow::on_actionAdd_flight_triggered()
{
AddFlightWindow *addFlightWindow = new AddFlightWindow();
addFlightWindow->show();
}
void MainWindow::on_listWidget_itemClicked(QListWidgetItem *item)
{
PlaneTypeDatabaseController planeTypeDB(planeTypeDB_path);
m_code = item->text().first(4);
//qDebug() << code;
CreateSeatView(m_code);
}
void MainWindow::AddFlightToList(int id)
{
//FlightsDatabaseController flightsDB(flightsDB_path);
qDebug() << flightsDB.GetStringRecordByID(id,"code");
ui->listWidget->addItem(flightsDB.GetStringRecordByID(id,"code") + " " + flightsDB.GetStringRecordByID(id,"Departure") + " - " + flightsDB.GetStringRecordByID(id,"Arrival"));
}
void MainWindow::UpdateFlightsList()
{
//FlightsDatabaseController flightsDB(flightsDB_path);
ui->listWidget->clear();
for(int i=1;i<=flightsDB.CountItemsInDatabase();i++)
{
qDebug() << "adding flight to list" << i <<" from "<< flightsDB.CountItemsInDatabase();
AddFlightToList(i);
}
}
void MainWindow::on_pushButton_2_clicked()
{
FlightsDatabaseController flightsDB(flightsDB_path);
UpdateFlightsList();
}