openPilotLog
opl.h
1 /*
2  *openPilotLog - A FOSS Pilot Logbook Application
3  *Copyright (C) 2020-2022 Felix Turowsky
4  *
5  *This program is free software: you can redistribute it and/or modify
6  *it under the terms of the GNU General Public License as published by
7  *the Free Software Foundation, either version 3 of the License, or
8  *(at your option) any later version.
9  *
10  *This program is distributed in the hope that it will be useful,
11  *but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  *GNU General Public License for more details.
14  *
15  *You should have received a copy of the GNU General Public License
16  *along with this program. If not, see <https://www.gnu.org/licenses/>.
17  */
18 #ifndef OPLCONSTANTS_H
19 #define OPLCONSTANTS_H
20 
21 #include <QtCore>
22 #include <QMessageBox>
23 #include <QComboBox>
24 
39 namespace OPL {
40 
41 #define OPL_VERSION 0
42 #define OPL_SUBVERSION 1
43 #define OPL_VERSION_STRING QString(QString::number(OPL_VERSION) + "." + QString::number(OPL_SUBVERSION))
44 
45 #if defined(__GNUC__) || defined(__clang__)
46  #define FUNC_IDENT __PRETTY_FUNCTION__
47 #elif defined(_MSC_VER)
48  #define FUNC_IDENT __FUNCSIG__
49 #else
50  #define FUNC_IDENT __func__
51 #endif
52 
53 #define DEB qDebug() // Use for debugging
54 #define LOG qInfo() // Use for logging milestones (silently, will be written to log file and console out only)
55 #define TODO qCritical() << "TO DO:\t"
56 
57 #define INFO(msg) OPL::ANotificationHandler::info(msg, this) // Use for messages of interest to the user (will be displayed in GUI)
58 #define WARN(msg) OPL::ANotificationHandler::warn(msg, this) // Use for warnings (will be displayed in GUI)
59 #define CRIT(msg) OPL::ANotificationHandler::crit(msg, this) // Use for critical warnings (will be displayed in GUI)
60 
67 public:
68  static inline void info(const QString msg, QWidget *parent = nullptr){
69 
70  qInfo() << msg;
71  auto mb = QMessageBox(QMessageBox::Information, QStringLiteral("Info"), msg, QMessageBox::StandardButton::Ok, parent);
72  mb.exec();
73  };
74  static inline void warn(const QString msg, QWidget *parent = nullptr){
75  qWarning() << msg;
76  auto mb = QMessageBox(QMessageBox::Warning, QStringLiteral("Warning"), msg, QMessageBox::StandardButton::Ok, parent);
77  mb.exec();
78  };
79  static inline void crit(const QString msg, QWidget *parent = nullptr){
80  qCritical() << msg;
81  auto mb = QMessageBox(QMessageBox::Critical, QStringLiteral("Warning"), msg, QMessageBox::StandardButton::Ok, parent);
82  mb.exec();
83  };
84 }; // class ANotificationHandler
85 
86 using RowData_T = QHash<QString, QVariant>;
87 
92 enum class DateFormat {ISODate, DE, EN };
93 
94 enum class FlightTimeFormat {Default, Decimal};
95 
96 enum class DateTimeFormat {Default, Backup};
97 
102 enum class PilotFunction {PIC = 0, PICUS = 1, SIC = 2, DUAL = 3, FI = 4};
103 
107 enum class Translation {English, German, Spanish};
108 
112 enum class DbViewName {Default, DefaultWithSim, Easa, EasaWithSim, SimulatorOnly};
113 
117 enum class SimulatorType {FNPTI = 0, FNPTII = 1, FSTD = 2};
118 
122 enum class DbTable {Any, Flights, Simulators, Pilots, Tails, Aircraft, Airports, Currencies, Changelog};
123 
127 enum class CurrencyName {Licence = 1, TypeRating = 2, LineCheck = 3, Medical = 4, Custom1 = 5, Custom2 = 6};
128 
134 class OplGlobals : public QObject {
135 public:
136  OplGlobals() = default;
137 
138  void fillLanguageComboBox(QComboBox *combo_box) const;
139  void fillViewNamesComboBox(QComboBox *combo_box) const;
140  void loadPilotFunctios(QComboBox *combo_box) const;
141  void loadSimulatorTypes(QComboBox *combo_box) const;
142  void loadApproachTypes(QComboBox *combo_box) const;
143 
144  inline const QStringList &getApproachTypes() const {return APPROACH_TYPES;}
145  inline const QString getLanguageFilePath(Translation language) const {return L10N_FilePaths.value(language);}
146  inline const QString getViewIdentifier(DbViewName view_name) const {return DATABASE_VIEWS.value(view_name);}
147  inline const QString getDbTableName(DbTable table_name) const {return DB_TABLES.value(table_name);}
148 
149 private:
150  Q_OBJECT
151 
152 #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
153  const static inline QHash<Translation, QString> L10N_FilePaths {
154  {Translation::English, QStringLiteral("l10n/openpilotlog_en")},
155  {Translation::German, QStringLiteral("l10n/openpilotlog_de")},
156  {Translation::Spanish, QStringLiteral("l10n/openpilotlog_es")},
157  };
158  const static inline QHash<Translation, QString> L10N_DisplayNames {
159  {Translation::English, QStringLiteral("English")},
160  {Translation::German, QStringLiteral("Deutsch")},
161  {Translation::Spanish, QStringLiteral("Español")},
162  };
163  const static inline QHash<DbViewName, QString> DATABASE_VIEWS = {
164  {DbViewName::Default, QStringLiteral("viewDefault")},
165  {DbViewName::DefaultWithSim, QStringLiteral("viewDefaultSim")},
166  {DbViewName::Easa, QStringLiteral("viewEasa")},
167  {DbViewName::EasaWithSim, QStringLiteral("viewEasaSim")},
168  {DbViewName::SimulatorOnly, QStringLiteral("viewSimulators")},
169  };
170  const QHash<DbViewName, QString> DATABASE_VIEW_DISPLAY_NAMES = {
171  {DbViewName::Default, tr("Default")},
172  {DbViewName::DefaultWithSim, tr("Default with Simulator")},
173  {DbViewName::Easa, tr("EASA-FCL")},
174  {DbViewName::EasaWithSim, tr("EASA-FCL with Simulator")},
175  {DbViewName::SimulatorOnly, tr("Simulator Sessions Only")},
176  };
177  const static inline QHash<PilotFunction, QString> PILOT_FUNCTIONS = {
178  {PilotFunction::PIC, QStringLiteral("PIC")},
179  {PilotFunction::PICUS, QStringLiteral("PICUS")},
180  {PilotFunction::SIC, QStringLiteral("SIC")},
181  {PilotFunction::DUAL, QStringLiteral("DUAL")},
182  {PilotFunction::FI, QStringLiteral("FI")},
183  };
184  const static inline QHash<SimulatorType, QString> SIMULATOR_TYPES = {
185  {SimulatorType::FNPTI, QStringLiteral("FNPT I")},
186  {SimulatorType::FNPTII, QStringLiteral("FNPT II")},
187  {SimulatorType::FSTD, QStringLiteral("FSTD")},
188  };
189  const static inline QHash<DbTable, QString> DB_TABLES = {
190  //Flights, Simulators, Pilots, Tails, Aircraft, Airports
191  {DbTable::Flights, QStringLiteral("flights")},
192  {DbTable::Simulators, QStringLiteral("simulators")},
193  {DbTable::Pilots, QStringLiteral("pilots")},
194  {DbTable::Tails, QStringLiteral("tails")},
195  {DbTable::Aircraft, QStringLiteral("aircraft")},
196  {DbTable::Airports, QStringLiteral("airports")},
197  {DbTable::Currencies, QStringLiteral("currencies")},
198  {DbTable::Changelog, QStringLiteral("changelog")},
199  };
200 #else
201  const static inline QMap<Translation, QString> L10N_FilePaths {
202  {Translation::English, QStringLiteral("l10n/openpilotlog_en")},
203  {Translation::German, QStringLiteral("l10n/openpilotlog_de")},
204  {Translation::Spanish, QStringLiteral("l10n/openpilotlog_es")},
205  };
206  const static inline QMap<Translation, QString> L10N_DisplayNames {
207  {Translation::English, QStringLiteral("English")},
208  {Translation::German, QStringLiteral("Deutsch")},
209  {Translation::Spanish, QStringLiteral("Español")},
210  };
211  const static inline QMap<DbViewName, QString> DATABASE_VIEWS = {
212  {DbViewName::Default, QStringLiteral("viewDefault")},
213  {DbViewName::DefaultWithSim, QStringLiteral("viewDefaultSim")},
214  {DbViewName::Easa, QStringLiteral("viewEasa")},
215  {DbViewName::EasaWithSim, QStringLiteral("viewEasaSim")},
216  {DbViewName::SimulatorOnly, QStringLiteral("viewSimulators")},
217  };
218  const QMap<DbViewName, QString> DATABASE_VIEW_DISPLAY_NAMES = {
219  {DbViewName::Default, tr("Default")},
220  {DbViewName::DefaultWithSim, tr("Default with Simulator")},
221  {DbViewName::Easa, tr("EASA-FCL")},
222  {DbViewName::EasaWithSim, tr("EASA-FCL with Simulator")},
223  {DbViewName::SimulatorOnly, tr("Simulator Sessions Only")},
224  };
225  const static inline QMap<PilotFunction, QString> PILOT_FUNCTIONS = {
226  {PilotFunction::PIC, QStringLiteral("PIC")},
227  {PilotFunction::PICUS, QStringLiteral("PICUS")},
228  {PilotFunction::SIC, QStringLiteral("SIC")},
229  {PilotFunction::DUAL, QStringLiteral("DUAL")},
230  {PilotFunction::FI, QStringLiteral("FI")},
231  };
232  const static inline QMap<SimulatorType, QString> SIMULATOR_TYPES = {
233  {SimulatorType::FNPTI, QStringLiteral("FNPT I")},
234  {SimulatorType::FNPTII, QStringLiteral("FNPT II")},
235  {SimulatorType::FSTD, QStringLiteral("FSTD")},
236  };
237  const static inline QMap<DbTable, QString> DB_TABLES = {
238  {DbTable::Flights, QStringLiteral("flights")},
239  {DbTable::Simulators, QStringLiteral("simulators")},
240  {DbTable::Pilots, QStringLiteral("pilots")},
241  {DbTable::Tails, QStringLiteral("tails")},
242  {DbTable::Aircraft, QStringLiteral("aircraft")},
243  {DbTable::Airports, QStringLiteral("airports")},
244  {DbTable::Currencies, QStringLiteral("currencies")},
245  {DbTable::Changelog, QStringLiteral("changelog")},
246  };
247 #endif
248 
249  const static inline QStringList APPROACH_TYPES = {
250  QStringLiteral("VISUAL"),
251  QStringLiteral("ILS CAT I"),
252  QStringLiteral("ILS CAT II"),
253  QStringLiteral("ILS CAT III"),
254  QStringLiteral("GLS"),
255  QStringLiteral("MLS"),
256  QStringLiteral("LOC"),
257  QStringLiteral("LOC/DME"),
258  QStringLiteral("RNAV"),
259  QStringLiteral("RNAV (LNAV)"),
260  QStringLiteral("RNAV (LNAV/VNAV)"),
261  QStringLiteral("RNAV (LPV)"),
262  QStringLiteral("RNAV (RNP)"),
263  QStringLiteral("RNAV (RNP-AR)"),
264  QStringLiteral("VOR"),
265  QStringLiteral("VOR/DME"),
266  QStringLiteral("NDB"),
267  QStringLiteral("NDB/DME"),
268  QStringLiteral("TACAN"),
269  QStringLiteral("SRA"),
270  QStringLiteral("PAR"),
271  QStringLiteral("OTHER")
272  };
273 };
274 //Make available as a global static
275 Q_GLOBAL_STATIC(OplGlobals, GLOBALS)
276 
277 
291 namespace Db {
292 
293 
294 // Table names
295 const inline auto TABLE_FLIGHTS = QStringLiteral("flights");
296 const inline auto TABLE_PILOTS = QStringLiteral("pilots");
297 const inline auto TABLE_TAILS = QStringLiteral("tails");
298 const inline auto TABLE_AIRCRAFT = QStringLiteral("aircraft");
299 const inline auto TABLE_AIRPORTS = QStringLiteral("airports");
300 const inline auto TABLE_CURRENCIES = QStringLiteral("currencies");
301 const inline auto TABLE_SIMULATORS = QStringLiteral("simulators");
302 
303 // Flights table columns
304 const inline auto FLIGHTS_ROWID = QStringLiteral("flight_id");
305 const inline auto FLIGHTS_DOFT = QStringLiteral("doft");
306 const inline auto FLIGHTS_DEPT = QStringLiteral("dept");
307 const inline auto FLIGHTS_DEST = QStringLiteral("dest");
308 const inline auto FLIGHTS_TOFB = QStringLiteral("tofb");
309 const inline auto FLIGHTS_TONB = QStringLiteral("tonb");
310 const inline auto FLIGHTS_PIC = QStringLiteral("pic");
311 const inline auto FLIGHTS_ACFT = QStringLiteral("acft");
312 const inline auto FLIGHTS_TBLK = QStringLiteral("tblk");
313 const inline auto FLIGHTS_TSPSE = QStringLiteral("tSPSE");
314 const inline auto FLIGHTS_TSPME = QStringLiteral("tSPME");
315 const inline auto FLIGHTS_TMP = QStringLiteral("tMP");
316 const inline auto FLIGHTS_TNIGHT = QStringLiteral("tNIGHT");
317 const inline auto FLIGHTS_TIFR = QStringLiteral("tIFR");
318 const inline auto FLIGHTS_TPIC = QStringLiteral("tPIC");
319 const inline auto FLIGHTS_TPICUS = QStringLiteral("tPICUS");
320 const inline auto FLIGHTS_TSIC = QStringLiteral("tSIC");
321 const inline auto FLIGHTS_TDUAL = QStringLiteral("tDUAL");
322 const inline auto FLIGHTS_TFI = QStringLiteral("tFI");
323 const inline auto FLIGHTS_TSIM = QStringLiteral("tSIM");
324 const inline auto FLIGHTS_PILOTFLYING = QStringLiteral("pilotFlying");
325 const inline auto FLIGHTS_TODAY = QStringLiteral("toDay");
326 const inline auto FLIGHTS_TONIGHT = QStringLiteral("toNight");
327 const inline auto FLIGHTS_LDGDAY = QStringLiteral("ldgDay");
328 const inline auto FLIGHTS_LDGNIGHT = QStringLiteral("ldgNight");
329 const inline auto FLIGHTS_AUTOLAND = QStringLiteral("autoland");
330 const inline auto FLIGHTS_SECONDPILOT = QStringLiteral("secondPilot");
331 const inline auto FLIGHTS_THIRDPILOT = QStringLiteral("thirdPilot");
332 const inline auto FLIGHTS_APPROACHTYPE = QStringLiteral("approachType");
333 const inline auto FLIGHTS_FLIGHTNUMBER = QStringLiteral("flightNumber");
334 const inline auto FLIGHTS_REMARKS = QStringLiteral("remarks");
335 
336 // tails table
337 
338 const inline auto TAILS_ROWID = QStringLiteral("tail_id");
339 const inline auto TAILS_REGISTRATION = QStringLiteral("registration");
340 const inline auto TAILS_COMPANY = QStringLiteral("company");
341 const inline auto TAILS_MAKE = QStringLiteral("make");
342 const inline auto TAILS_MODEL = QStringLiteral("model");
343 const inline auto TAILS_VARIANT = QStringLiteral("variant");
344 const inline auto TAILS_MULTIPILOT = QStringLiteral("multipilot");
345 const inline auto TAILS_MULTIENGINE = QStringLiteral("multiengine");
346 const inline auto TAILS_ENGINETYPE = QStringLiteral("engineType");
347 const inline auto TAILS_WEIGHTCLASS = QStringLiteral("weightClass");
348 
349 // pilots table
350 
351 const inline auto PILOTS_ROWID = QStringLiteral("pilot_id");
352 const inline auto PILOTS_LASTNAME = QStringLiteral("lastname");
353 const inline auto PILOTS_FIRSTNAME = QStringLiteral("firstname");
354 const inline auto PILOTS_ALIAS = QStringLiteral("alias");
355 const inline auto PILOTS_COMPANY = QStringLiteral("company");
356 const inline auto PILOTS_EMPLOYEEID = QStringLiteral("employeeid");
357 const inline auto PILOTS_PHONE = QStringLiteral("phone");
358 const inline auto PILOTS_EMAIL = QStringLiteral("email");
359 
360 // Currencies table
361 const inline auto CURRENCIES_EXPIRYDATE = QStringLiteral("expiryDate");
362 const inline auto CURRENCIES_CURRENCYNAME = QStringLiteral("currencyName");
363 
364 // Simulators table
365 const inline auto SIMULATORS_ROWID = QStringLiteral("session_id");
366 const inline auto SIMULATORS_DATE = QStringLiteral("date");
367 const inline auto SIMULATORS_TIME = QStringLiteral("totalTime");
368 const inline auto SIMULATORS_TYPE = QStringLiteral("deviceType");
369 const inline auto SIMULATORS_ACFT = QStringLiteral("aircraftType");
370 const inline auto SIMULATORS_REG = QStringLiteral("registration");
371 const inline auto SIMULATORS_REMARKS = QStringLiteral("remarks");
372 
373 // Airports table
374 const inline auto AIRPORTS_ICAO = QStringLiteral("icao");
375 const inline auto AIRPORTS_IATA = QStringLiteral("iata");
376 const inline auto AIRPORTS_NAME = QStringLiteral("name");
377 const inline auto AIRPORTS_LAT = QStringLiteral("lat");
378 const inline auto AIRPORTS_LON = QStringLiteral("long");
379 const inline auto AIRPORTS_COUNTRY = QStringLiteral("country");
380 const inline auto AIRPORTS_ALTITIDUE = QStringLiteral("alt");
381 const inline auto AIRPORTS_UTC_OFFSET = QStringLiteral("utcoffset");
382 const inline auto AIRPORTS_TZ_OLSON = QStringLiteral("tzolson");
383 
384 // all tables
385 const inline auto ROWID = QStringLiteral("rowid");
386 const inline auto NULL_TIME_hhmm = QStringLiteral("00:00");
387 
388 } // namespace OPL::db
389 
390 namespace Assets {
391 
392 const inline auto DATABASE_SCHEMA = QStringLiteral(":/database/database_schema.sql");
393 const inline auto DATABASE_TEMPLATE_AIRCRAFT = QStringLiteral(":/database/templates/aircraft.json");
394 const inline auto DATABASE_TEMPLATE_AIRPORT = QStringLiteral(":/database/templates/airports.json");
395 const inline auto DATABASE_TEMPLATE_CHANGELOG = QStringLiteral(":/database/templates/changelog.json");
396 const inline auto DATABASE_TEMPLATE_CURRENCIES = QStringLiteral(":/database/templates/currencies.json");
397 
398 const inline auto LOGO = QStringLiteral(":/icons/opl-icons/logos/logo_text.png");
399 const inline auto ICON_MAIN = QStringLiteral(":/icons/opl-icons/app/icon_main.png");
400 const inline auto ICON_APPICON_LINUX = QStringLiteral(":/icons/opl-icons/app/icon_linux.svg");
401 const inline auto ICON_APPICON_IOS = QStringLiteral(":/icons/opl-icons/app/icon_ios.svg");
402 const inline auto ICON_APPICON_WIN = QStringLiteral(":/icons/opl-icons/app/icon_windows.ico");
403 
404 const inline auto ICON_TOOLBAR_HOME = QStringLiteral(":/icons/opl-icons/toolbar/thick/light/icon_home.svg");
405 const inline auto ICON_TOOLBAR_NEW_FLIGHT = QStringLiteral(":/icons/opl-icons/toolbar/thick/light/icon_new_flight.svg");
406 const inline auto ICON_TOOLBAR_LOGBOOK = QStringLiteral(":/icons/opl-icons/toolbar/thick/light/icon_logbook.svg");
407 const inline auto ICON_TOOLBAR_AIRCRAFT = QStringLiteral(":/icons/opl-icons/toolbar/thick/light/icon_airplane.svg");
408 const inline auto ICON_TOOLBAR_PILOT = QStringLiteral(":/icons/opl-icons/toolbar/thick/light/icon_pilot.svg");
409 const inline auto ICON_TOOLBAR_SETTINGS = QStringLiteral(":/icons/opl-icons/toolbar/thick/light/icon_settings.svg");
410 const inline auto ICON_TOOLBAR_QUIT = QStringLiteral(":/icons/opl-icons/toolbar/thick/light/icon_exit.svg");
411 
412 const inline auto ICON_TOOLBAR_BACKUP = QStringLiteral(":/icons/opl-icons/toolbar/thick/light/icon_backup.svg");
413 
414 const inline auto ICON_TOOLBAR_HOME_DARK = QStringLiteral(":/icons/opl-icons/toolbar/thick/dark/icon_home_dm.svg");
415 const inline auto ICON_TOOLBAR_NEW_FLIGHT_DARK = QStringLiteral(":/icons/opl-icons/toolbar/thick/dark/icon_new_flight_dm.svg");
416 const inline auto ICON_TOOLBAR_LOGBOOK_DARK = QStringLiteral(":/icons/opl-icons/toolbar/thick/dark/icon_logbook_dm.svg");
417 const inline auto ICON_TOOLBAR_AIRCRAFT_DARK = QStringLiteral(":/icons/opl-icons/toolbar/thick/dark/icon_airplane_dm.svg");
418 const inline auto ICON_TOOLBAR_PILOT_DARK = QStringLiteral(":/icons/opl-icons/toolbar/thick/dark/icon_pilot_dm.svg");
419 const inline auto ICON_TOOLBAR_SETTINGS_DARK = QStringLiteral(":/icons/opl-icons/toolbar/thick/dark/icon_settings_dm.svg");
420 const inline auto ICON_TOOLBAR_QUIT_DARK = QStringLiteral(":/icons/opl-icons/toolbar/thick/dark/icon_exit_dm.svg");
421 
422 const inline auto ICON_TOOLBAR_BACKUP_DARK = QStringLiteral(":/icons/opl-icons/toolbar/thick/dark/icon_backup_dm.svg");
423 
424 }
425 
426 namespace Styles {
427 
428 const inline auto RED_BORDER = QStringLiteral("border: 1px solid red");
429 } // namespace Styles
430 
431 } // namespace opl
432 
433 #endif // OPLCONSTANTS_H
The ANotificationHandler class handles displaying of user-directed messages. It displays information ...
Definition: opl.h:66
The OplGlobals class encapsulates non-POD globals to avoid making them static. It is available as a g...
Definition: opl.h:134
A namespace to collect constants and enums used throughout the application.
Definition: paths.cpp:3
SimulatorType
Enumerates the Simulator Types: Flight and Navigation Procedures Trainer 1/2, Flight Simulation Train...
Definition: opl.h:117
CurrencyName
Enumerates the currency names.
Definition: opl.h:127
PilotFunction
PilotFunction Pilot in Command, Pilot in Command under Supervision, Second in Command (Co-Pilot),...
Definition: opl.h:102
Translation
Enumerates the available translations.
Definition: opl.h:107
DbTable
Enumerates the tables in the database.
Definition: opl.h:122
DbViewName
Enumerates the available SQL views in the database.
Definition: opl.h:112
DateFormat
ADateFormats enumerates the accepted date formats for QDateEdits.
Definition: opl.h:92