FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
openPilotLog/mainwindow.cpp at main · fiffty-50/openPilotLog · GitHub
fiffty-50
/
openPilotLog
Public
Notifications
You must be signed in to change notification settings
Fork
2
Star
21
Code
Issues
5
Pull requests
0
Discussions
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
openPilotLog
/
mainwindow.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
289 lines (254 loc) · 9.82 KB
Breadcrumbs
openPilotLog
/
mainwindow.cpp
Copy path
File metadata and controls
289 lines (254 loc) · 9.82 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
/*
*openPilotLog - A FOSS Pilot Logbook Application
*Copyright (C) 2020-2023 Felix Turowsky
*
*This program is free software: you can redistribute it and/or modify
*it under the terms of the GNU General Public License as published by
*the Free Software Foundation, either version 3 of the License, or
*(at your option) any later version.
*
*This program is distributed in the hope that it will be useful,
*but WITHOUT ANY WARRANTY; without even the implied warranty of
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
*GNU General Public License for more details.
*
*You should have received a copy of the GNU General Public License
*along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#
include
<
QToolBar
>
#
include
"
mainwindow.h
"
#
include
"
src/gui/dialogues/flightentryeditdialog.h
"
#
include
"
src/gui/widgets/airporttableeditwidget.h
"
#
include
"
src/gui/widgets/logbooktableeditwidget.h
"
#
include
"
src/gui/widgets/pilottableeditwidget.h
"
#
include
"
src/gui/widgets/tailtableeditwidget.h
"
#
include
"
ui_mainwindow.h
"
#
include
"
src/database/database.h
"
#
include
"
src/classes/style.h
"
#
include
"
src/gui/dialogues/firstrundialog.h
"
#
include
"
src/database/databasecache.h
"
#
include
"
src/classes/settings.h
"
//
WIP area - pressing SHIFT + ENTER executes this function
//
this is to provide easy and quick access to a currently worked on functionality
//
#include "src/network/flightawarequery.h"
void
MainWindow::doDebugStuff
()
{
//
FlightAwareQuery query;
//
auto result = query.getFlightData("DY606", QDate::currentDate());
//
LOG << "Querying API...";
//
if(result.isEmpty()) {
//
LOG << "No flights found.";
//
}
//
for(const auto &flight : result) {
//
flight.print();
//
}
FlightEntryEditDialog feed =
new
FlightEntryEditDialog
(
this
);
feed.
exec
();
}
MainWindow::MainWindow
(QWidget *parent)
: QMainWindow(parent)
, ui(
new
Ui::MainWindow)
{
ui->
setupUi
(
this
);
init
();
}
MainWindow::~MainWindow
()
{
delete
ui;
}
void
MainWindow::init
()
{
connectDatabase
();
initialiseWidgets
();
setupToolbar
();
connectWidgets
();
setActionIcons
(
OPL::Style::getStyleType
());
ui->
stackedWidget
->
setCurrentWidget
(homeWidget);
}
void
MainWindow::setupToolbar
()
{
//
Create and set up the toolbar
auto
*toolBar =
new
QToolBar
(
this
);
toolBar->
addAction
(ui->
actionHome
);
toolBar->
addAction
(ui->
actionNewFlight
);
toolBar->
addAction
(ui->
actionNewSim
);
toolBar->
addAction
(ui->
actionLogbook
);
toolBar->
addAction
(ui->
actionAircraft
);
toolBar->
addAction
(ui->
actionPilots
);
toolBar->
addAction
(ui->
actionAirports
);
toolBar->
addAction
(ui->
actionSettings
);
toolBar->
addAction
(ui->
actionQuit
);
toolBar->
setSizePolicy
(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
toolBar->
setMovable
(
false
);
addToolBar
(Qt::ToolBarArea::LeftToolBarArea, toolBar);
}
void
MainWindow::initialiseWidgets
()
{
//
Construct Widgets
homeWidget =
new
HomeWidget
(
this
);
ui->
stackedWidget
->
addWidget
(homeWidget);
logbookWidget =
new
LogbookTableEditWidget
(
this
);
logbookWidget->
init
();
ui->
stackedWidget
->
addWidget
(logbookWidget);
tailsWidget =
new
TailTableEditWidget
(
this
);
tailsWidget->
init
();
ui->
stackedWidget
->
addWidget
(tailsWidget);
pilotsWidget =
new
PilotTableEditWidget
(
this
);
pilotsWidget->
init
();
ui->
stackedWidget
->
addWidget
(pilotsWidget);
airportWidget =
new
AirportTableEditWidget
(
this
);
airportWidget->
init
();
ui->
stackedWidget
->
addWidget
(airportWidget);
settingsWidget =
new
SettingsWidget
(
this
);
ui->
stackedWidget
->
addWidget
(settingsWidget);
debugWidget =
new
DebugWidget
(
this
);
ui->
stackedWidget
->
addWidget
(debugWidget);
}
void
MainWindow::connectDatabase
()
{
//
connect to the Database
if
(
OPL::Paths::databaseFileInfo
().
size
() ==
0
)
onDatabaseInvalid
();
if
(!
DB
->
connect
()){
WARN
(
tr
(
"
Error establishing database connection. The following error has ocurred:<br><br>%1
"
)
.
arg
(
DB
->
lastError
.
text
()));
}
//
Load Cache
DBCache->
init
();
}
void
MainWindow::setActionIcons
(
OPL
::Style::StyleType style)
{
switch
(style){
case
OPL
::Style::StyleType::Light:
LOG
<<
"
Setting Light Icon theme
"
;
ui->
actionHome
->
setIcon
(
QIcon
(
OPL
::Assets::
ICON_TOOLBAR_HOME
));
ui->
actionNewFlight
->
setIcon
(
QIcon
(
OPL
::Assets::
ICON_TOOLBAR_NEW_FLIGHT
));
ui->
actionNewSim
->
setIcon
(
QIcon
(
OPL
::Assets::
ICON_TOOLBAR_NEW_FLIGHT
));
//
TODO seperate icon
ui->
actionLogbook
->
setIcon
(
QIcon
(
OPL
::Assets::
ICON_TOOLBAR_LOGBOOK
));
ui->
actionAircraft
->
setIcon
(
QIcon
(
OPL
::Assets::
ICON_TOOLBAR_AIRCRAFT
));
ui->
actionPilots
->
setIcon
(
QIcon
(
OPL
::Assets::
ICON_TOOLBAR_PILOT
));
ui->
actionAirports
->
setIcon
(
QIcon
(
OPL
::Assets::
ICON_TOOLBAR_BACKUP
));
ui->
actionSettings
->
setIcon
(
QIcon
(
OPL
::Assets::
ICON_TOOLBAR_SETTINGS
));
ui->
actionQuit
->
setIcon
(
QIcon
(
OPL
::Assets::
ICON_TOOLBAR_QUIT
));
break
;
case
OPL
::Style::StyleType::Dark:
LOG
<<
"
Setting Dark Icon theme
"
;
ui->
actionHome
->
setIcon
(
QIcon
(
OPL
::Assets::
ICON_TOOLBAR_HOME_DARK
));
ui->
actionNewFlight
->
setIcon
(
QIcon
(
OPL
::Assets::
ICON_TOOLBAR_NEW_FLIGHT_DARK
));
ui->
actionNewSim
->
setIcon
(
QIcon
(
OPL
::Assets::
ICON_TOOLBAR_NEW_FLIGHT_DARK
));
//
pending separate icon
ui->
actionLogbook
->
setIcon
(
QIcon
(
OPL
::Assets::
ICON_TOOLBAR_LOGBOOK_DARK
));
ui->
actionAircraft
->
setIcon
(
QIcon
(
OPL
::Assets::
ICON_TOOLBAR_AIRCRAFT_DARK
));
ui->
actionPilots
->
setIcon
(
QIcon
(
OPL
::Assets::
ICON_TOOLBAR_PILOT_DARK
));
ui->
actionAirports
->
setIcon
(
QIcon
(
OPL
::Assets::
ICON_TOOLBAR_BACKUP_DARK
));
ui->
actionSettings
->
setIcon
(
QIcon
(
OPL
::Assets::
ICON_TOOLBAR_SETTINGS_DARK
));
ui->
actionQuit
->
setIcon
(
QIcon
(
OPL
::Assets::
ICON_TOOLBAR_QUIT_DARK
));
break
;
}
}
void
MainWindow::nope
()
{
QMessageBox
message_box
(
this
);
//
error box
message_box.
setText
(
tr
(
"
This feature is not yet available!
"
));
message_box.
exec
();
}
/*
!
* \brief Connect the widgets to signals that are emitted when an update of the widegts' contents,
* is required, either because the database has changed (model and view need to be refreshed) or
* because a setting that affects the widgets layout has changed.
*/
void
MainWindow::connectWidgets
()
{
QObject::connect
(settingsWidget, &SettingsWidget::settingChanged,
logbookWidget, &LogbookTableEditWidget::viewSelectionChanged);
QObject::connect
(
this
, &MainWindow::addFlightEntryRequested,
logbookWidget, &LogbookTableEditWidget::addEntryRequested);
QObject::connect
(
this
, &MainWindow::addSimulatorEntryRequested,
logbookWidget, &LogbookTableEditWidget::addSimulatorEntryRequested);
QObject::connect
(settingsWidget, &SettingsWidget::settingChanged,
this
, &MainWindow::onStyleChanged);
}
void
MainWindow::onDatabaseInvalid
()
{
QMessageBox
db_error
(
this
);
db_error.
addButton
(
tr
(
"
Restore Backup
"
), QMessageBox::ButtonRole::AcceptRole);
db_error.
addButton
(
tr
(
"
Create New Database
"
), QMessageBox::ButtonRole::RejectRole);
db_error.
addButton
(
tr
(
"
Abort
"
), QMessageBox::ButtonRole::DestructiveRole);
db_error.
setIcon
(QMessageBox::Warning);
db_error.
setWindowTitle
(
tr
(
"
No valid database found
"
));
db_error.
setText
(
tr
(
"
No valid database has been found.<br>
"
"
Would you like to create a new database or import a backup?<br><br>
"
));
int
ret = db_error.
exec
();
if
(ret == QMessageBox::DestructiveRole) {
DEB
<<
"
No valid database found. Exiting.
"
;
on_actionQuit_triggered
();
}
else
if
(ret == QMessageBox::ButtonRole::AcceptRole) {
DEB
<<
"
Yes(Import Backup)
"
;
QString db_path =
QDir::toNativeSeparators
(
(
QFileDialog::getOpenFileName
(
this
,
tr
(
"
Select Database
"
),
OPL::Paths::directory
(
OPL
::Paths::Backup).
canonicalPath
(),
tr
(
"
Database file (*.db)
"
))));
if
(!db_path.
isEmpty
()) {
if
(!
DB
->
restoreBackup
(db_path)) {
WARN
(
tr
(
"
Unable to restore backup file:<br><br>%1
"
).
arg
(db_path));
on_actionQuit_triggered
();
}
}
}
else
if
(ret == QMessageBox::ButtonRole::RejectRole){
DEB
<<
"
No(Create New)
"
;
if
(
FirstRunDialog
().
exec
() == QDialog::Rejected){
LOG
<<
"
Initial setup incomplete or unsuccessfull.
"
;
on_actionQuit_triggered
();
}
Settings::setSetupCompleted
(
true
);
LOG
<<
"
Initial Setup Completed successfully
"
;
}
}
/*
* Slots
*/
void
MainWindow::on_actionHome_triggered
()
{
ui->
stackedWidget
->
setCurrentWidget
(homeWidget);
}
void
MainWindow::on_actionNewFlight_triggered
()
{
ui->
stackedWidget
->
setCurrentWidget
(logbookWidget);
emit
addFlightEntryRequested
();
}
void
MainWindow::on_actionNewSim_triggered
()
{
//
auto nsd = NewSimDialog(this);
//
nsd.exec();
ui->
stackedWidget
->
setCurrentWidget
(logbookWidget);
emit
addSimulatorEntryRequested
();
}
void
MainWindow::on_actionLogbook_triggered
()
{
ui->
stackedWidget
->
setCurrentWidget
(logbookWidget);
}
void
MainWindow::on_actionAircraft_triggered
()
{
ui->
stackedWidget
->
setCurrentWidget
(tailsWidget);
}
void
MainWindow::on_actionPilots_triggered
()
{
ui->
stackedWidget
->
setCurrentWidget
(pilotsWidget);
}
void
MainWindow::on_actionAirports_triggered
()
{
ui->
stackedWidget
->
setCurrentWidget
(airportWidget);
}
void
MainWindow::on_actionSettings_triggered
()
{
ui->
stackedWidget
->
setCurrentWidget
(settingsWidget);
}
void
MainWindow::on_actionQuit_triggered
()
{
QApplication::quit
();
exit
(
0
);
}
void
MainWindow::on_actionDebug_triggered
()
{
ui->
stackedWidget
->
setCurrentWidget
(debugWidget);
}
Back
|
FazBrowse Home
|
New Git URL