ソースを参照

Added opl namespace

The opl namespace serves as a central point for declaring constants that are used uniformly across the application.
Felix 4 年 前
コミット
19232fa598

+ 1 - 0
openPilotLog.pro

@@ -78,6 +78,7 @@ HEADERS += \
     src/gui/widgets/pilotswidget.h \
     src/gui/widgets/settingswidget.h \
     src/gui/widgets/totalswidget.h \
+    src/oplconstants.h \
     src/testing/abenchmark.h \
     src/testing/adebug.h \
     src/testing/atimer.h

+ 2 - 1
src/classes/aaircraftentry.cpp

@@ -16,13 +16,14 @@
  *along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 #include "aaircraftentry.h"
+#include "src/oplconstants.h"
 
 AAircraftEntry::AAircraftEntry()
     : AEntry::AEntry(DEFAULT_AIRCRAFT_POSITION)
 {}
 
 AAircraftEntry::AAircraftEntry(RowId row_id)
-    : AEntry::AEntry(DataPosition(DB_TABLE_AIRCRAFT, row_id))
+    : AEntry::AEntry(DataPosition(opl::db::TABLE_AIRCRAFT, row_id))
 {}
 
 AAircraftEntry::AAircraftEntry(RowData table_data)

+ 11 - 10
src/classes/aflightentry.cpp

@@ -17,13 +17,14 @@
  */
 #include "aflightentry.h"
 #include "src/database/adatabase.h"
+#include "src/oplconstants.h"
 
 AFlightEntry::AFlightEntry()
     : AEntry::AEntry(DEFAULT_FLIGHT_POSITION)
 {}
 
 AFlightEntry::AFlightEntry(RowId row_id)
-    : AEntry::AEntry(DataPosition(DB_TABLE_FLIGHTS, row_id))
+    : AEntry::AEntry(DataPosition(opl::db::TABLE_FLIGHTS, row_id))
 {}
 
 AFlightEntry::AFlightEntry(RowData table_data)
@@ -36,18 +37,18 @@ const QString AFlightEntry::summary()
         return QString();
 
     QString flight_summary;
-    flight_summary.append(tableData.value(DB_FLIGHTS_DOFT).toString() + " ");
-    flight_summary.append(tableData.value(DB_FLIGHTS_DEPT).toString() + " ");
-    flight_summary.append(ACalc::minutesToString(tableData.value(DB_FLIGHTS_TOFB).toString()) + " ");
-    flight_summary.append(ACalc::minutesToString(tableData.value(DB_FLIGHTS_TONB).toString()) + " ");
-    flight_summary.append(tableData.value(DB_FLIGHTS_DEST).toString() + " ");
+    flight_summary.append(tableData.value(opl::db::FLIGHTS_DOFT).toString() + " ");
+    flight_summary.append(tableData.value(opl::db::FLIGHTS_DEPT).toString() + " ");
+    flight_summary.append(ACalc::minutesToString(tableData.value(opl::db::FLIGHTS_TOFB).toString()) + " ");
+    flight_summary.append(ACalc::minutesToString(tableData.value(opl::db::FLIGHTS_TONB).toString()) + " ");
+    flight_summary.append(tableData.value(opl::db::FLIGHTS_DEST).toString() + " ");
 
     return flight_summary;
 }
 
 const QString AFlightEntry::getRegistration()
 {
-    ATailEntry acft = aDB->resolveForeignTail(tableData.value(DB_FLIGHTS_ACFT).toInt());
+    ATailEntry acft = aDB->resolveForeignTail(tableData.value(opl::db::FLIGHTS_ACFT).toInt());
     return acft.registration();
 }
 
@@ -55,16 +56,16 @@ const QString AFlightEntry::getPilotName(pilotPosition pilot_)
 {
     switch (pilot_) {
     case pilotPosition::pic: {
-        auto foreign_pilot = aDB->resolveForeignPilot(tableData.value(DB_FLIGHTS_PIC).toInt());
+        auto foreign_pilot = aDB->resolveForeignPilot(tableData.value(opl::db::FLIGHTS_PIC).toInt());
         return foreign_pilot.name();
         break;
     }
     case pilotPosition::secondPilot: {
-        auto foreign_pilot = aDB->resolveForeignPilot(tableData.value(DB_FLIGHTS_SECONDPILOT).toInt());
+        auto foreign_pilot = aDB->resolveForeignPilot(tableData.value(opl::db::FLIGHTS_SECONDPILOT).toInt());
         return foreign_pilot.name();
     }
     case pilotPosition::thirdPilot: {
-        auto foreign_pilot = aDB->resolveForeignPilot(tableData.value(DB_FLIGHTS_THIRDPILOT).toInt());
+        auto foreign_pilot = aDB->resolveForeignPilot(tableData.value(opl::db::FLIGHTS_THIRDPILOT).toInt());
         return foreign_pilot.name();
         break;
     } // case scope

+ 5 - 4
src/classes/apilotentry.cpp

@@ -16,13 +16,14 @@
  *along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 #include "apilotentry.h"
+#include "src/oplconstants.h"
 
 APilotEntry::APilotEntry()
     : AEntry::AEntry(DEFAULT_PILOT_POSITION)
 {}
 
 APilotEntry::APilotEntry(RowId row_id)
-    : AEntry::AEntry(DataPosition(DB_TABLE_PILOTS, row_id))
+    : AEntry::AEntry(DataPosition(opl::db::TABLE_PILOTS, row_id))
 {}
 
 APilotEntry::APilotEntry(RowData table_data)
@@ -32,8 +33,8 @@ APilotEntry::APilotEntry(RowData table_data)
 const QString APilotEntry::name()
 {
     if (tableData.isEmpty())
-        return DB_NULL;
+        return QString();
 
-    return tableData.value(DB_PILOTS_LASTNAME).toString() + ','
-           +tableData.value(DB_PILOTS_FIRSTNAME).toString().left(1) + '.';
+    return tableData.value(opl::db::PILOTS_LASTNAME).toString() + ','
+           +tableData.value(opl::db::PILOTS_FIRSTNAME).toString().left(1) + '.';
 }

+ 3 - 3
src/classes/astyle.h

@@ -13,9 +13,9 @@ class AStyle
 {
 public:
     enum StyleSheet{
-        Dark = 0,
-        Light,
-        Default,
+        Default = 0,
+        Dark,
+        Light
     };
 private:
     static QString currentStyle;

+ 9 - 8
src/classes/atailentry.cpp

@@ -16,13 +16,14 @@
  *along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 #include "atailentry.h"
+#include "src/oplconstants.h"
 
 ATailEntry::ATailEntry()
     : AEntry::AEntry(DEFAULT_TAIL_POSITION)
 {}
 
 ATailEntry::ATailEntry(RowId row_id)
-    : AEntry::AEntry(DataPosition(DB_TABLE_TAILS, row_id))
+    : AEntry::AEntry(DataPosition(opl::db::TABLE_TAILS, row_id))
 {}
 
 ATailEntry::ATailEntry(RowData table_data)
@@ -31,18 +32,18 @@ ATailEntry::ATailEntry(RowData table_data)
 
 const QString ATailEntry::registration()
 {
-    return getData().value(DB_TAILS_REGISTRATION).toString();
+    return getData().value(opl::db::TAILS_REGISTRATION).toString();
 }
 
 const QString ATailEntry::type()
 {
     QString type_string;
-    if (!tableData.value(DB_TAILS_MAKE).toString().isEmpty())
-        type_string.append(getData().value(DB_TAILS_MAKE).toString() + ' ');
-    if (!tableData.value(DB_TAILS_MODEL).toString().isEmpty())
-        type_string.append(getData().value(DB_TAILS_MODEL).toString());
-    if (!tableData.value(DB_TAILS_VARIANT).toString().isEmpty())
-        type_string.append('-' + getData().value(DB_TAILS_VARIANT).toString() + ' ');
+    if (!tableData.value(opl::db::TAILS_MAKE).toString().isEmpty())
+        type_string.append(getData().value(opl::db::TAILS_MAKE).toString() + ' ');
+    if (!tableData.value(opl::db::TAILS_MODEL).toString().isEmpty())
+        type_string.append(getData().value(opl::db::TAILS_MODEL).toString());
+    if (!tableData.value(opl::db::TAILS_VARIANT).toString().isEmpty())
+        type_string.append('-' + getData().value(opl::db::TAILS_VARIANT).toString() + ' ');
 
     return type_string;
 }

+ 4 - 3
src/database/adatabase.cpp

@@ -18,6 +18,7 @@
 #include "adatabase.h"
 #include "src/testing/adebug.h"
 #include "src/classes/astandardpaths.h"
+#include "src/oplconstants.h"
 
 
 ADatabaseError::ADatabaseError(QString msg_)
@@ -544,13 +545,13 @@ int ADatabase::getLastEntry(ADatabaseTarget target)
 
     switch (target) {
     case ADatabaseTarget::pilots:
-        statement.append(DB_TABLE_PILOTS);
+        statement.append(opl::db::TABLE_PILOTS);
         break;
     case ADatabaseTarget::aircraft:
-        statement.append(DB_TABLE_AIRCRAFT);
+        statement.append(opl::db::TABLE_AIRCRAFT);
         break;
     case ADatabaseTarget::tails:
-        statement.append(DB_TABLE_TAILS);
+        statement.append(opl::db::TABLE_TAILS);
         break;
     default:
         DEB << "Not a valid completer target for this function.";

+ 4 - 3
src/database/adatabasesetup.cpp

@@ -21,6 +21,7 @@
 #include "src/functions/areadcsv.h"
 #include "src/classes/astandardpaths.h"
 #include "src/classes/adownload.h"
+#include "src/oplconstants.h"
 
 // Statements for creation of database tables, Revision 15
 
@@ -302,12 +303,12 @@ bool ADataBaseSetup::backupOldData()
         return true;
     }
 
-    auto date_string = QDateTime::currentDateTime().toString("yyyy_MM_dd_T_hh_mm");
+    auto date_string = QDateTime::currentDateTime().toString(opl::datetime::DATETIME_BACKUP_FORMAT);
     auto backup_dir = QDir(AStandardPaths::absPathOf(AStandardPaths::DatabaseBackup));
-    auto backup_name = database_file.baseName() % "_bak_" % date_string + ".db";
+    auto backup_name = database_file.baseName() + "_bak_" + date_string + ".db";
     auto file = QFile(aDB->databaseFile.absoluteFilePath());
 
-    if (!file.rename(backup_dir.absolutePath() % '/' % backup_name)) {
+    if (!file.rename(backup_dir.absolutePath() + '/' + backup_name)) {
         DEB << "Unable to backup old database.";
         return false;
     }

+ 5 - 86
src/database/declarations.h

@@ -2,6 +2,7 @@
 #define DECLARATIONS_H
 
 #include <QtCore>
+#include "src/oplconstants.h"
 #include "src/testing/adebug.h"
 
 /*!
@@ -41,92 +42,10 @@ struct DataPosition {
          )
 };
 
-// [F]:
-// In many places throughout the application, we have to programatically access or write data
-// to or from the database using column names as identifiers, doing something like this:
-//
-// newData.insert("dept", ui->deptLocLineEdit->text());
-// newData.value("multipilot") // do stuff
-//
-// Declaring the literals here avoids memory allocation at runtime for construction of temporary qstrings
-// like ("dept"). See https://doc.qt.io/qt-5/qstring.html#QStringLiteral
-//
-
-// Table names
-static const auto DB_TABLE_FLIGHTS  = QStringLiteral("flights");
-static const auto DB_TABLE_PILOTS   = QStringLiteral("pilots");
-static const auto DB_TABLE_TAILS    = QStringLiteral("tails");
-static const auto DB_TABLE_AIRCRAFT = QStringLiteral("aircraft");
-static const auto DB_TABLE_AIRPORTS = QStringLiteral("airports");
 // Default Positions
-static auto const DEFAULT_FLIGHT_POSITION   = DataPosition(DB_TABLE_FLIGHTS, 0);
-static auto const DEFAULT_PILOT_POSITION    = DataPosition(DB_TABLE_PILOTS, 0);
-static auto const DEFAULT_TAIL_POSITION     = DataPosition(DB_TABLE_TAILS, 0);
-static auto const DEFAULT_AIRCRAFT_POSITION = DataPosition(DB_TABLE_AIRCRAFT, 0);
-// Flights table columns
-static const auto DB_FLIGHTS_DOFT           = QStringLiteral("doft");
-static const auto DB_FLIGHTS_DEPT           = QStringLiteral("dept");
-static const auto DB_FLIGHTS_DEST           = QStringLiteral("dest");
-static const auto DB_FLIGHTS_TOFB           = QStringLiteral("tofb");
-static const auto DB_FLIGHTS_TONB           = QStringLiteral("tonb");
-static const auto DB_FLIGHTS_PIC            = QStringLiteral("pic");
-static const auto DB_FLIGHTS_ACFT           = QStringLiteral("acft");
-static const auto DB_FLIGHTS_TBLK           = QStringLiteral("tblk");
-static const auto DB_FLIGHTS_TSPSE          = QStringLiteral("tSPSE");
-static const auto DB_FLIGHTS_TSPME           = QStringLiteral("tSPME");
-static const auto DB_FLIGHTS_TMP            = QStringLiteral("tMP");
-static const auto DB_FLIGHTS_TNIGHT         = QStringLiteral("tNIGHT");
-static const auto DB_FLIGHTS_TIFR           = QStringLiteral("tIFR");
-static const auto DB_FLIGHTS_TPIC           = QStringLiteral("tPIC");
-static const auto DB_FLIGHTS_TPICUS         = QStringLiteral("tPICUS");
-static const auto DB_FLIGHTS_TSIC           = QStringLiteral("tSIC");
-static const auto DB_FLIGHTS_TDUAL          = QStringLiteral("tDUAL");
-static const auto DB_FLIGHTS_TFI            = QStringLiteral("tFI");
-static const auto DB_FLIGHTS_TSIM           = QStringLiteral("tSIM");
-static const auto DB_FLIGHTS_PILOTFLYING    = QStringLiteral("pilotFlying");
-static const auto DB_FLIGHTS_TODAY          = QStringLiteral("toDay");
-static const auto DB_FLIGHTS_TONIGHT        = QStringLiteral("toNight");
-static const auto DB_FLIGHTS_LDGDAY         = QStringLiteral("ldgDay");
-static const auto DB_FLIGHTS_LDGNIGHT       = QStringLiteral("ldgNight");
-static const auto DB_FLIGHTS_AUTOLAND       = QStringLiteral("autoland");
-static const auto DB_FLIGHTS_SECONDPILOT    = QStringLiteral("secondPilot");
-static const auto DB_FLIGHTS_THIRDPILOT     = QStringLiteral("thirdPilot");
-static const auto DB_FLIGHTS_APPROACHTYPE   = QStringLiteral("approachType");
-static const auto DB_FLIGHTS_FLIGHTNUMBER   = QStringLiteral("flightNumber");
-static const auto DB_FLIGHTS_REMARKS        = QStringLiteral("remarks");
-
-// tails table
-
-static const auto DB_TAILS_REGISTRATION   = QStringLiteral("registration");
-static const auto DB_TAILS_COMPANY        = QStringLiteral("company");
-static const auto DB_TAILS_MAKE           = QStringLiteral("make");
-static const auto DB_TAILS_MODEL          = QStringLiteral("model");
-static const auto DB_TAILS_VARIANT        = QStringLiteral("variant");
-static const auto DB_TAILS_MULTIPILOT     = QStringLiteral("multipilot");
-static const auto DB_TAILS_MULTIENGINE    = QStringLiteral("multiengine");
-static const auto DB_TAILS_ENGINETYPE     = QStringLiteral("engineType");
-static const auto DB_TAILS_WEIGHTCLASS    = QStringLiteral("weightClass");
-
-// pilots table
-
-static const auto DB_PILOTS_LASTNAME       = QStringLiteral("lastname");
-static const auto DB_PILOTS_FIRSTNAME      = QStringLiteral("firstname");
-static const auto DB_PILOTS_ALIAS          = QStringLiteral("alias");
-static const auto DB_PILOTS_COMPANY        = QStringLiteral("company");
-static const auto DB_PILOTS_EMPLOYEEID     = QStringLiteral("employeeid");
-static const auto DB_PILOTS_PHONE          = QStringLiteral("phone");
-static const auto DB_PILOTS_EMAIL          = QStringLiteral("email");
-
-// all tables
-
-static const auto DB_ROWID          = QStringLiteral("ROWID");
-static const auto DB_NULL           = QStringLiteral("");
-static const auto DB_NULL_hhmm      = QStringLiteral("00:00");
-/*static const auto DB_               = QStringLiteral("");
-static const auto DB_               = QStringLiteral("");
-static const auto DB_               = QStringLiteral("");
-static const auto DB_               = QStringLiteral("");
-static const auto DB_               = QStringLiteral("");*/
-
+static auto const DEFAULT_FLIGHT_POSITION   = DataPosition(opl::db::TABLE_FLIGHTS, 0);
+static auto const DEFAULT_PILOT_POSITION    = DataPosition(opl::db::TABLE_PILOTS, 0);
+static auto const DEFAULT_TAIL_POSITION     = DataPosition(opl::db::TABLE_TAILS, 0);
+static auto const DEFAULT_AIRCRAFT_POSITION = DataPosition(opl::db::TABLE_AIRCRAFT, 0);
 
 #endif // DECLARATIONS_H

+ 21 - 20
src/functions/acalc.cpp

@@ -2,6 +2,7 @@
 #include "src/testing/adebug.h"
 #include "src/database/adatabase.h"
 #include "src/classes/asettings.h"
+#include "src/oplconstants.h"
 
 using namespace ACalc;
 
@@ -275,23 +276,23 @@ void ACalc::updateAutoTimes(int acft_id)
         auto flight = aDB->getFlightEntry(item.toInt());
         auto flight_data = flight.getData();
 
-        if(acft_data.value(DB_TAILS_MULTIPILOT).toInt() == 0
-                && acft_data.value(DB_TAILS_MULTIENGINE) == 0) {
+        if(acft_data.value(opl::db::TAILS_MULTIPILOT).toInt() == 0
+                && acft_data.value(opl::db::TAILS_MULTIENGINE) == 0) {
             DEB << "SPSE";
-            flight_data.insert(DB_FLIGHTS_TSPSE, flight_data.value(DB_FLIGHTS_TBLK));
-            flight_data.insert(DB_FLIGHTS_TSPME, DB_NULL);
-            flight_data.insert(DB_FLIGHTS_TMP, DB_NULL);
-        } else if ((acft_data.value(DB_TAILS_MULTIPILOT) == 0
-                    && acft.getData().value(DB_TAILS_MULTIENGINE) == 1)) {
+            flight_data.insert(opl::db::FLIGHTS_TSPSE, flight_data.value(opl::db::FLIGHTS_TBLK));
+            flight_data.insert(opl::db::FLIGHTS_TSPME, QStringLiteral(""));
+            flight_data.insert(opl::db::FLIGHTS_TMP, QStringLiteral(""));
+        } else if ((acft_data.value(opl::db::TAILS_MULTIPILOT) == 0
+                    && acft.getData().value(opl::db::TAILS_MULTIENGINE) == 1)) {
             DEB << "SPME";
-            flight_data.insert(DB_FLIGHTS_TSPME, flight_data.value(DB_FLIGHTS_TBLK));
-            flight_data.insert(DB_FLIGHTS_TSPSE, DB_NULL);
-            flight_data.insert(DB_FLIGHTS_TMP, DB_NULL);
-        } else if ((acft_data.value(DB_TAILS_MULTIPILOT) == 1)) {
+            flight_data.insert(opl::db::FLIGHTS_TSPME, flight_data.value(opl::db::FLIGHTS_TBLK));
+            flight_data.insert(opl::db::FLIGHTS_TSPSE, QStringLiteral(""));
+            flight_data.insert(opl::db::FLIGHTS_TMP, QStringLiteral(""));
+        } else if ((acft_data.value(opl::db::TAILS_MULTIPILOT) == 1)) {
             DEB << "MPME";
-            flight_data.insert(DB_FLIGHTS_TMP, flight_data.value(DB_FLIGHTS_TBLK));
-            flight_data.insert(DB_FLIGHTS_TSPSE, DB_NULL);
-            flight_data.insert(DB_FLIGHTS_TSPME, DB_NULL);
+            flight_data.insert(opl::db::FLIGHTS_TMP, flight_data.value(opl::db::FLIGHTS_TBLK));
+            flight_data.insert(opl::db::FLIGHTS_TSPSE, QStringLiteral(""));
+            flight_data.insert(opl::db::FLIGHTS_TSPME, QStringLiteral(""));
         }
         flight.setData(flight_data);
         aDB->commit(flight);
@@ -319,14 +320,14 @@ void ACalc::updateNightTimes()
 
         auto flt = aDB->getFlightEntry(item.toInt());
         auto data = flt.getData();
-        auto dateTime = QDateTime(QDate::fromString(data.value(DB_FLIGHTS_DOFT).toString(), Qt::ISODate),
-                                  QTime().addSecs(data.value(DB_FLIGHTS_TOFB).toInt() * 60),
+        auto dateTime = QDateTime(QDate::fromString(data.value(opl::db::FLIGHTS_DOFT).toString(), Qt::ISODate),
+                                  QTime().addSecs(data.value(opl::db::FLIGHTS_TOFB).toInt() * 60),
                                   Qt::UTC);
-        data.insert(DB_FLIGHTS_TNIGHT,
-                    calculateNightTime(data.value(DB_FLIGHTS_DEPT).toString(),
-                                       data.value(DB_FLIGHTS_DEST).toString(),
+        data.insert(opl::db::FLIGHTS_TNIGHT,
+                    calculateNightTime(data.value(opl::db::FLIGHTS_DEPT).toString(),
+                                       data.value(opl::db::FLIGHTS_DEST).toString(),
                                        dateTime,
-                                       data.value(DB_FLIGHTS_TBLK).toInt(),
+                                       data.value(opl::db::FLIGHTS_TBLK).toInt(),
                                        night_angle));
         flt.setData(data);
         aDB->commit(flt);

+ 7 - 6
src/gui/dialogues/firstrundialog.cpp

@@ -7,6 +7,7 @@
 #include "src/classes/adownload.h"
 #include "src/classes/asettings.h"
 #include "src/classes/astandardpaths.h"
+#include "src/oplconstants.h"
 #include <QErrorMessage>
 
 FirstRunDialog::FirstRunDialog(QWidget *parent) :
@@ -99,12 +100,12 @@ bool FirstRunDialog::finish()
 
     QMap<QString, QVariant> data;
     ASettings::write(ASettings::UserData::DisplaySelfAs, ui->aliasComboBox->currentIndex());
-    data.insert(DB_PILOTS_LASTNAME, ui->lastnameLineEdit->text());
-    data.insert(DB_PILOTS_FIRSTNAME, ui->firstnameLineEdit->text());
-    data.insert(DB_PILOTS_ALIAS, QStringLiteral("self"));
-    data.insert(DB_PILOTS_EMPLOYEEID, ui->employeeidLineEdit->text());
-    data.insert(DB_PILOTS_PHONE, ui->phoneLineEdit->text());
-    data.insert(DB_PILOTS_EMAIL, ui->emailLineEdit->text());
+    data.insert(opl::db::PILOTS_LASTNAME, ui->lastnameLineEdit->text());
+    data.insert(opl::db::PILOTS_FIRSTNAME, ui->firstnameLineEdit->text());
+    data.insert(opl::db::PILOTS_ALIAS, QStringLiteral("self"));
+    data.insert(opl::db::PILOTS_EMPLOYEEID, ui->employeeidLineEdit->text());
+    data.insert(opl::db::PILOTS_PHONE, ui->phoneLineEdit->text());
+    data.insert(opl::db::PILOTS_EMAIL, ui->emailLineEdit->text());
 
     auto db_fail_msg_box = QMessageBox(QMessageBox::Critical, QStringLiteral("Database setup failed"),
                                        QStringLiteral("Errors have ocurred creating the database."

+ 108 - 107
src/gui/dialogues/newflightdialog.cpp

@@ -22,6 +22,7 @@
 #include "src/functions/acalc.h"
 #include "src/testing/atimer.h"
 #include "src/database/adatabase.h"
+#include "src/oplconstants.h"
 
 
 #include "src/testing/adebug.h"
@@ -30,7 +31,7 @@
 ///                                         constants                                           ///
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-static const auto TIME_FORMAT = QLatin1String("hh:mm");
+static const auto EMPTY_STRING=QStringLiteral("");
 static const auto NAME_RX     = QLatin1String("((\\p{L}+)?('|\\-|,)?(\\p{L}+)?)");
 static const auto ADD_NAME_RX = QLatin1String("(\\s?(\\p{L}+('|\\-|,)?\\p{L}+?))?");
 
@@ -99,7 +100,7 @@ NewFlightDialog::NewFlightDialog(QWidget *parent) :
     flightEntry = AFlightEntry();
     setup();
     if (ASettings::read(ASettings::NewFlight::FunctionComboBox).toString() == "SIC") {
-        ui->picNameLineEdit->setText(DB_NULL);
+        ui->picNameLineEdit->setText(QStringLiteral(""));
         ui->secondPilotNameLineEdit->setText("self");
     }
     if(ASettings::read(ASettings::NewFlight::FunctionComboBox).toString() == "PIC"){
@@ -384,12 +385,12 @@ void NewFlightDialog::fillDeductibleData()
                               ui->tDUALTimeLineEdit, ui->tFITimeLineEdit,};
     QList<QLabel*>      LB = {ui->tSPSELabel, ui->tSPMELabel,  ui->tMPLabel,  ui->tIFRLabel,  ui->tNIGHTLabel,
                               ui->tPICLabel,  ui->tPICUSLabel, ui->tSICLabel, ui->tDUALLabel, ui->tFILabel};
-    for(const auto& widget : LE) {widget->setText(DB_NULL);}
-    for(const auto& widget : LB) {widget->setText(DB_NULL_hhmm);}
+    for(const auto& widget : LE) {widget->setText(EMPTY_STRING);}
+    for(const auto& widget : LB) {widget->setText(opl::db::NULL_TIME_hhmm);}
     //Calculate block time
-    auto tofb = QTime::fromString(ui->tofbTimeLineEdit->text(), TIME_FORMAT);
-    auto tonb = QTime::fromString(ui->tonbTimeLineEdit->text(), TIME_FORMAT);
-    QString block_time = ACalc::blocktime(tofb, tonb).toString(TIME_FORMAT);
+    auto tofb = QTime::fromString(ui->tofbTimeLineEdit->text(), opl::datetime::TIME_DEFAULT_FORMAT);
+    auto tonb = QTime::fromString(ui->tonbTimeLineEdit->text(), opl::datetime::TIME_DEFAULT_FORMAT);
+    QString block_time = ACalc::blocktime(tofb, tonb).toString(opl::datetime::TIME_DEFAULT_FORMAT);
     QString block_minutes = QString::number(ACalc::stringToMinutes(block_time));
     ui->tblkTimeLineEdit->setText(block_time);
     // get acft data and fill deductible entries
@@ -399,19 +400,19 @@ void NewFlightDialog::fillDeductibleData()
 
 
     // SP SE
-    if(acft.getData().value(DB_TAILS_MULTIPILOT).toInt() == 0
-            && acft.getData().value(DB_TAILS_MULTIENGINE).toInt() == 0){
+    if(acft.getData().value(opl::db::TAILS_MULTIPILOT).toInt() == 0
+            && acft.getData().value(opl::db::TAILS_MULTIENGINE).toInt() == 0){
         ui->tSPSETimeLineEdit->setText(block_time);
         ui->tSPSELabel->setText(block_time);
     }
     // SP ME
-    if(acft.getData().value(DB_TAILS_MULTIPILOT).toInt() == 0
-            && acft.getData().value(DB_TAILS_MULTIENGINE).toInt() == 1){
+    if(acft.getData().value(opl::db::TAILS_MULTIPILOT).toInt() == 0
+            && acft.getData().value(opl::db::TAILS_MULTIENGINE).toInt() == 1){
         ui->tSPMETimeLineEdit->setText(block_time);
         ui->tSPMELabel->setText(block_time);
     }
     // MP
-    if(acft.getData().value(DB_TAILS_MULTIPILOT).toInt() == 1){
+    if(acft.getData().value(opl::db::TAILS_MULTIPILOT).toInt() == 1){
         ui->tMPTimeLineEdit->setText(block_time);
         ui->tMPLabel->setText(block_time);
     }
@@ -426,7 +427,7 @@ void NewFlightDialog::fillDeductibleData()
         ui->tIFRLabel->setText(block_time);
     }
     // Night
-    QString dept_date = ui->doftLineEdit->text() + 'T' + tofb.toString(TIME_FORMAT);
+    QString dept_date = ui->doftLineEdit->text() + 'T' + tofb.toString(opl::datetime::TIME_DEFAULT_FORMAT);
     QDateTime dept_date_time = QDateTime::fromString(dept_date,"yyyy-MM-ddThh:mm");
     int tblk = block_minutes.toInt();
     const int night_angle = ASettings::read(ASettings::FlightLogging::NightAngle).toInt();
@@ -477,44 +478,44 @@ RowData NewFlightDialog::collectInput()
     RowData newData;
     DEB << "Collecting Input...";
     // Mandatory data
-    newData.insert(DB_FLIGHTS_DOFT, ui->doftLineEdit->text());
-    newData.insert(DB_FLIGHTS_DEPT, ui->deptLocLineEdit->text());
-    newData.insert(DB_FLIGHTS_TOFB, ACalc::stringToMinutes(ui->tofbTimeLineEdit->text()));
-    newData.insert(DB_FLIGHTS_DEST, ui->destLocLineEdit->text());
-    newData.insert(DB_FLIGHTS_TONB, ACalc::stringToMinutes(ui->tonbTimeLineEdit->text()));
+    newData.insert(opl::db::FLIGHTS_DOFT, ui->doftLineEdit->text());
+    newData.insert(opl::db::FLIGHTS_DEPT, ui->deptLocLineEdit->text());
+    newData.insert(opl::db::FLIGHTS_TOFB, ACalc::stringToMinutes(ui->tofbTimeLineEdit->text()));
+    newData.insert(opl::db::FLIGHTS_DEST, ui->destLocLineEdit->text());
+    newData.insert(opl::db::FLIGHTS_TONB, ACalc::stringToMinutes(ui->tonbTimeLineEdit->text()));
     //Block Time
-    const auto tofb = QTime::fromString(ui->tofbTimeLineEdit->text(), TIME_FORMAT);
-    const auto tonb = QTime::fromString(ui->tonbTimeLineEdit->text(), TIME_FORMAT);
-    const QString block_time = ACalc::blocktime(tofb, tonb).toString(TIME_FORMAT);
+    const auto tofb = QTime::fromString(ui->tofbTimeLineEdit->text(), opl::datetime::TIME_DEFAULT_FORMAT);
+    const auto tonb = QTime::fromString(ui->tonbTimeLineEdit->text(), opl::datetime::TIME_DEFAULT_FORMAT);
+    const QString block_time = ACalc::blocktime(tofb, tonb).toString(opl::datetime::TIME_DEFAULT_FORMAT);
     const int block_minutes = ACalc::stringToMinutes(block_time);
 
-    newData.insert(DB_FLIGHTS_TBLK, block_minutes);
+    newData.insert(opl::db::FLIGHTS_TBLK, block_minutes);
     // Aircraft
-    newData.insert(DB_FLIGHTS_ACFT, tailsIdMap.value(ui->acftLineEdit->text()));
+    newData.insert(opl::db::FLIGHTS_ACFT, tailsIdMap.value(ui->acftLineEdit->text()));
     // Pilots
-    newData.insert(DB_FLIGHTS_PIC, pilotsIdMap.value(ui->picNameLineEdit->text()));
-    newData.insert(DB_FLIGHTS_SECONDPILOT, pilotsIdMap.value(ui->secondPilotNameLineEdit->text()));
-    newData.insert(DB_FLIGHTS_THIRDPILOT, pilotsIdMap.value(ui->thirdPilotNameLineEdit->text()));
+    newData.insert(opl::db::FLIGHTS_PIC, pilotsIdMap.value(ui->picNameLineEdit->text()));
+    newData.insert(opl::db::FLIGHTS_SECONDPILOT, pilotsIdMap.value(ui->secondPilotNameLineEdit->text()));
+    newData.insert(opl::db::FLIGHTS_THIRDPILOT, pilotsIdMap.value(ui->thirdPilotNameLineEdit->text()));
 
     // Extra Times
     ui->tSPSETimeLineEdit->text().isEmpty() ?
-                newData.insert(DB_FLIGHTS_TSPSE, DB_NULL)
-              : newData.insert(DB_FLIGHTS_TSPSE, ACalc::stringToMinutes(ui->tSPSETimeLineEdit->text()));
+                newData.insert(opl::db::FLIGHTS_TSPSE, EMPTY_STRING)
+              : newData.insert(opl::db::FLIGHTS_TSPSE, ACalc::stringToMinutes(ui->tSPSETimeLineEdit->text()));
 
     ui->tSPMETimeLineEdit->text().isEmpty() ?
-                newData.insert(DB_FLIGHTS_TSPME, DB_NULL)
-              : newData.insert(DB_FLIGHTS_TSPME, ACalc::stringToMinutes(ui->tSPMETimeLineEdit->text()));
+                newData.insert(opl::db::FLIGHTS_TSPME, EMPTY_STRING)
+              : newData.insert(opl::db::FLIGHTS_TSPME, ACalc::stringToMinutes(ui->tSPMETimeLineEdit->text()));
     ui->tMPTimeLineEdit->text().isEmpty() ?
-                newData.insert(DB_FLIGHTS_TMP, DB_NULL)
-              : newData.insert(DB_FLIGHTS_TMP, ACalc::stringToMinutes(ui->tMPTimeLineEdit->text()));
+                newData.insert(opl::db::FLIGHTS_TMP, EMPTY_STRING)
+              : newData.insert(opl::db::FLIGHTS_TMP, ACalc::stringToMinutes(ui->tMPTimeLineEdit->text()));
 
     if (ui->IfrCheckBox->isChecked()) {
-        newData.insert(DB_FLIGHTS_TIFR, block_minutes);
+        newData.insert(opl::db::FLIGHTS_TIFR, block_minutes);
     } else {
-        newData.insert(DB_FLIGHTS_TIFR, DB_NULL);
+        newData.insert(opl::db::FLIGHTS_TIFR, EMPTY_STRING);
     }
     // Night
-    const auto dept_date = ui->doftLineEdit->text() + QStringLiteral("T") + tofb.toString(TIME_FORMAT);
+    const auto dept_date = ui->doftLineEdit->text() + QStringLiteral("T") + tofb.toString(opl::datetime::TIME_DEFAULT_FORMAT);
     const auto dept_date_time = QDateTime::fromString(dept_date, QStringLiteral("yyyy-MM-ddThh:mm"));
 
     const auto night_angle = ASettings::read(ASettings::FlightLogging::NightAngle).toInt();
@@ -524,96 +525,96 @@ RowData NewFlightDialog::collectInput()
                     dept_date_time,
                     block_minutes,
                     night_angle);
-    newData.insert(DB_FLIGHTS_TNIGHT, night_minutes);
+    newData.insert(opl::db::FLIGHTS_TNIGHT, night_minutes);
 
     // Function times - This is a little explicit but these are mutually exclusive so its better to be safe than sorry here.
     switch (ui->FunctionComboBox->currentIndex()) {
     case 0://PIC
-        newData.insert(DB_FLIGHTS_TPIC, block_minutes);
-        newData.insert(DB_FLIGHTS_TPICUS, DB_NULL);
-        newData.insert(DB_FLIGHTS_TSIC, DB_NULL);
-        newData.insert(DB_FLIGHTS_TDUAL, DB_NULL);
-        newData.insert(DB_FLIGHTS_TFI, DB_NULL);
+        newData.insert(opl::db::FLIGHTS_TPIC, block_minutes);
+        newData.insert(opl::db::FLIGHTS_TPICUS, EMPTY_STRING);
+        newData.insert(opl::db::FLIGHTS_TSIC, EMPTY_STRING);
+        newData.insert(opl::db::FLIGHTS_TDUAL, EMPTY_STRING);
+        newData.insert(opl::db::FLIGHTS_TFI, EMPTY_STRING);
         break;
     case 1://PICUS
-        newData.insert(DB_FLIGHTS_TPIC, DB_NULL);
-        newData.insert(DB_FLIGHTS_TPICUS, block_minutes);
-        newData.insert(DB_FLIGHTS_TSIC, DB_NULL);
-        newData.insert(DB_FLIGHTS_TDUAL, DB_NULL);
-        newData.insert(DB_FLIGHTS_TFI, DB_NULL);
+        newData.insert(opl::db::FLIGHTS_TPIC, EMPTY_STRING);
+        newData.insert(opl::db::FLIGHTS_TPICUS, block_minutes);
+        newData.insert(opl::db::FLIGHTS_TSIC, EMPTY_STRING);
+        newData.insert(opl::db::FLIGHTS_TDUAL, EMPTY_STRING);
+        newData.insert(opl::db::FLIGHTS_TFI, EMPTY_STRING);
         break;
     case 2://Co-Pilot
-        newData.insert(DB_FLIGHTS_TPIC, DB_NULL);
-        newData.insert(DB_FLIGHTS_TPICUS, DB_NULL);
-        newData.insert(DB_FLIGHTS_TSIC, block_minutes);
-        newData.insert(DB_FLIGHTS_TDUAL, DB_NULL);
-        newData.insert(DB_FLIGHTS_TFI, DB_NULL);
+        newData.insert(opl::db::FLIGHTS_TPIC, EMPTY_STRING);
+        newData.insert(opl::db::FLIGHTS_TPICUS, EMPTY_STRING);
+        newData.insert(opl::db::FLIGHTS_TSIC, block_minutes);
+        newData.insert(opl::db::FLIGHTS_TDUAL, EMPTY_STRING);
+        newData.insert(opl::db::FLIGHTS_TFI, EMPTY_STRING);
         break;
     case 3://Dual
-        newData.insert(DB_FLIGHTS_TPIC, DB_NULL);
-        newData.insert(DB_FLIGHTS_TPICUS, DB_NULL);
-        newData.insert(DB_FLIGHTS_TSIC, DB_NULL);
-        newData.insert(DB_FLIGHTS_TDUAL, block_minutes);
-        newData.insert(DB_FLIGHTS_TFI, DB_NULL);
+        newData.insert(opl::db::FLIGHTS_TPIC, EMPTY_STRING);
+        newData.insert(opl::db::FLIGHTS_TPICUS, EMPTY_STRING);
+        newData.insert(opl::db::FLIGHTS_TSIC, EMPTY_STRING);
+        newData.insert(opl::db::FLIGHTS_TDUAL, block_minutes);
+        newData.insert(opl::db::FLIGHTS_TFI, EMPTY_STRING);
         break;
     case 4://Instructor
-        newData.insert(DB_FLIGHTS_TPIC, block_minutes);
-        newData.insert(DB_FLIGHTS_TPICUS, DB_NULL);
-        newData.insert(DB_FLIGHTS_TSIC, DB_NULL);
-        newData.insert(DB_FLIGHTS_TDUAL, DB_NULL);
-        newData.insert(DB_FLIGHTS_TFI, block_minutes);
+        newData.insert(opl::db::FLIGHTS_TPIC, block_minutes);
+        newData.insert(opl::db::FLIGHTS_TPICUS, EMPTY_STRING);
+        newData.insert(opl::db::FLIGHTS_TSIC, EMPTY_STRING);
+        newData.insert(opl::db::FLIGHTS_TDUAL, EMPTY_STRING);
+        newData.insert(opl::db::FLIGHTS_TFI, block_minutes);
     }
     // Pilot Flying
-    newData.insert(DB_FLIGHTS_PILOTFLYING, ui->PilotFlyingCheckBox->isChecked());
+    newData.insert(opl::db::FLIGHTS_PILOTFLYING, ui->PilotFlyingCheckBox->isChecked());
     // TO and LDG - again a bit explicit, but we  need to check for both night to day as well as day to night transitions.
     if (ui->TakeoffCheckBox->isChecked()) {
         if (night_minutes == 0) { // all day
-            newData.insert(DB_FLIGHTS_TODAY, ui->TakeoffSpinBox->value());
-            newData.insert(DB_FLIGHTS_TONIGHT, 0);
+            newData.insert(opl::db::FLIGHTS_TODAY, ui->TakeoffSpinBox->value());
+            newData.insert(opl::db::FLIGHTS_TONIGHT, 0);
         } else if (night_minutes == block_minutes) { // all night
-            newData.insert(DB_FLIGHTS_TODAY, 0);
-            newData.insert(DB_FLIGHTS_TONIGHT, ui->TakeoffSpinBox->value());
+            newData.insert(opl::db::FLIGHTS_TODAY, 0);
+            newData.insert(opl::db::FLIGHTS_TONIGHT, ui->TakeoffSpinBox->value());
         } else {
             if(ACalc::isNight(ui->deptLocLineEdit->text(), dept_date_time,  night_angle)) {
-                newData.insert(DB_FLIGHTS_TODAY, 0);
-                newData.insert(DB_FLIGHTS_TONIGHT, ui->TakeoffSpinBox->value());
+                newData.insert(opl::db::FLIGHTS_TODAY, 0);
+                newData.insert(opl::db::FLIGHTS_TONIGHT, ui->TakeoffSpinBox->value());
             } else {
-                newData.insert(DB_FLIGHTS_TODAY, ui->TakeoffSpinBox->value());
-                newData.insert(DB_FLIGHTS_TONIGHT, 0);
+                newData.insert(opl::db::FLIGHTS_TODAY, ui->TakeoffSpinBox->value());
+                newData.insert(opl::db::FLIGHTS_TONIGHT, 0);
             }
         }
     } else {
-        newData.insert(DB_FLIGHTS_TODAY, 0);
-        newData.insert(DB_FLIGHTS_TONIGHT, 0);
+        newData.insert(opl::db::FLIGHTS_TODAY, 0);
+        newData.insert(opl::db::FLIGHTS_TONIGHT, 0);
     }
 
     if (ui->LandingCheckBox->isChecked()) {
         if (night_minutes == 0) { // all day
-            newData.insert(DB_FLIGHTS_LDGDAY, ui->LandingSpinBox->value());
-            newData.insert(DB_FLIGHTS_LDGNIGHT, 0);
+            newData.insert(opl::db::FLIGHTS_LDGDAY, ui->LandingSpinBox->value());
+            newData.insert(opl::db::FLIGHTS_LDGNIGHT, 0);
         } else if (night_minutes == block_minutes) { // all night
-            newData.insert(DB_FLIGHTS_LDGDAY, 0);
-            newData.insert(DB_FLIGHTS_LDGNIGHT, ui->LandingSpinBox->value());
+            newData.insert(opl::db::FLIGHTS_LDGDAY, 0);
+            newData.insert(opl::db::FLIGHTS_LDGNIGHT, ui->LandingSpinBox->value());
         } else { //check
-            const auto dest_date = ui->doftLineEdit->text() + QStringLiteral("T") + tonb.toString(TIME_FORMAT);
+            const auto dest_date = ui->doftLineEdit->text() + QStringLiteral("T") + tonb.toString(opl::datetime::TIME_DEFAULT_FORMAT);
             const auto dest_date_time = QDateTime::fromString(dest_date, QStringLiteral("yyyy-MM-ddThh:mm"));
             if (ACalc::isNight(ui->destLocLineEdit->text(), dest_date_time,  night_angle)) {
-                newData.insert(DB_FLIGHTS_LDGDAY, 0);
-                newData.insert(DB_FLIGHTS_LDGNIGHT, ui->LandingSpinBox->value());
+                newData.insert(opl::db::FLIGHTS_LDGDAY, 0);
+                newData.insert(opl::db::FLIGHTS_LDGNIGHT, ui->LandingSpinBox->value());
             } else {
-                newData.insert(DB_FLIGHTS_LDGDAY, ui->LandingSpinBox->value());
-                newData.insert(DB_FLIGHTS_LDGNIGHT, 0);
+                newData.insert(opl::db::FLIGHTS_LDGDAY, ui->LandingSpinBox->value());
+                newData.insert(opl::db::FLIGHTS_LDGNIGHT, 0);
             }
         }
     } else {
-        newData.insert(DB_FLIGHTS_LDGDAY, 0);
-        newData.insert(DB_FLIGHTS_LDGNIGHT, 0);
+        newData.insert(opl::db::FLIGHTS_LDGDAY, 0);
+        newData.insert(opl::db::FLIGHTS_LDGNIGHT, 0);
     }
 
-    newData.insert(DB_FLIGHTS_AUTOLAND, ui->AutolandSpinBox->value());
-    newData.insert(DB_FLIGHTS_APPROACHTYPE, ui->ApproachComboBox->currentText());
-    newData.insert(DB_FLIGHTS_FLIGHTNUMBER, ui->FlightNumberLineEdit->text());
-    newData.insert(DB_FLIGHTS_REMARKS, ui->RemarksLineEdit->text());
+    newData.insert(opl::db::FLIGHTS_AUTOLAND, ui->AutolandSpinBox->value());
+    newData.insert(opl::db::FLIGHTS_APPROACHTYPE, ui->ApproachComboBox->currentText());
+    newData.insert(opl::db::FLIGHTS_FLIGHTNUMBER, ui->FlightNumberLineEdit->text());
+    newData.insert(opl::db::FLIGHTS_REMARKS, ui->RemarksLineEdit->text());
 
     DEB << "New Flight Data: " << newData;
 
@@ -698,29 +699,29 @@ void NewFlightDialog::formFiller()
         }
     }
     // Approach Combo Box
-    const QString& app = flightEntry.getData().value(DB_FLIGHTS_APPROACHTYPE).toString();
-    if(app != DB_NULL){
+    const QString& app = flightEntry.getData().value(opl::db::FLIGHTS_APPROACHTYPE).toString();
+    if(app != EMPTY_STRING){
         ui->ApproachComboBox->setCurrentText(app);
     }
     // Task and Rules
-    qint8 PF = flightEntry.getData().value(DB_FLIGHTS_PILOTFLYING).toInt();
+    qint8 PF = flightEntry.getData().value(opl::db::FLIGHTS_PILOTFLYING).toInt();
     if (PF > 0) {
         ui->PilotFlyingCheckBox->setChecked(true);
     } else {
         ui->PilotMonitoringCheckBox->setChecked(true);
     }
-    qint8 FR = flightEntry.getData().value(DB_FLIGHTS_TIFR).toInt();
+    qint8 FR = flightEntry.getData().value(opl::db::FLIGHTS_TIFR).toInt();
     if (FR > 0) {
         ui->IfrCheckBox->setChecked(true);
     } else {
-        ui->tIFRTimeLineEdit->setText(DB_NULL);
+        ui->tIFRTimeLineEdit->setText(EMPTY_STRING);
         ui->VfrCheckBox->setChecked(true);
     }
     // Take Off and Landing
-    qint8 TO = flightEntry.getData().value(DB_FLIGHTS_TODAY).toInt()
-            + flightEntry.getData().value(DB_FLIGHTS_TONIGHT).toInt();
-    qint8 LDG = flightEntry.getData().value(DB_FLIGHTS_LDGDAY).toInt()
-            + flightEntry.getData().value(DB_FLIGHTS_LDGNIGHT).toInt();
+    qint8 TO = flightEntry.getData().value(opl::db::FLIGHTS_TODAY).toInt()
+            + flightEntry.getData().value(opl::db::FLIGHTS_TONIGHT).toInt();
+    qint8 LDG = flightEntry.getData().value(opl::db::FLIGHTS_LDGDAY).toInt()
+            + flightEntry.getData().value(opl::db::FLIGHTS_LDGNIGHT).toInt();
     if(TO > 0) {
         ui->TakeoffCheckBox->setChecked(true);
         ui->TakeoffSpinBox->setValue(TO);
@@ -735,7 +736,7 @@ void NewFlightDialog::formFiller()
         ui->LandingCheckBox->setChecked(false);
         ui->LandingSpinBox->setValue(0);
     }
-    qint8 AL = flightEntry.getData().value(DB_FLIGHTS_AUTOLAND).toInt();
+    qint8 AL = flightEntry.getData().value(opl::db::FLIGHTS_AUTOLAND).toInt();
     if(AL > 0) {
         ui->AutolandCheckBox->setChecked(true);
         ui->AutolandSpinBox->setValue(AL);
@@ -757,18 +758,18 @@ bool NewFlightDialog::isLessOrEqualThanBlockTime(const QString time_string)
         return false;
     }
 
-    auto extra_time = QTime::fromString(time_string,TIME_FORMAT);
+    auto extra_time = QTime::fromString(time_string,opl::datetime::TIME_DEFAULT_FORMAT);
     auto block_time = ACalc::blocktime(QTime::fromString(
-                                           ui->tofbTimeLineEdit->text(),TIME_FORMAT),
+                                           ui->tofbTimeLineEdit->text(),opl::datetime::TIME_DEFAULT_FORMAT),
                                        QTime::fromString(
-                                           ui->tonbTimeLineEdit->text(), TIME_FORMAT));
+                                           ui->tonbTimeLineEdit->text(), opl::datetime::TIME_DEFAULT_FORMAT));
     if (extra_time <= block_time) {
         return true;
     } else {
         auto message_box = QMessageBox(this);
         message_box.setWindowTitle("Error");
         message_box.setText("The flight time you have entered is longer than the total blocktime:<br><center><b>"
-                            + block_time.toString(TIME_FORMAT)
+                            + block_time.toString(opl::datetime::TIME_DEFAULT_FORMAT)
                             + "</b></center>");
         message_box.exec();
         return false;
@@ -802,7 +803,7 @@ void NewFlightDialog::addNewTail(QLineEdit *parent_line_edit)
         parent_line_edit->setText(tailsIdMap.key(aDB->getLastEntry(ADatabaseTarget::tails)));
         emit parent_line_edit->editingFinished();
     } else {
-        parent_line_edit->setText(DB_NULL);
+        parent_line_edit->setText(EMPTY_STRING);
     }
 }
 
@@ -831,7 +832,7 @@ void NewFlightDialog::addNewPilot(QLineEdit *parent_line_edit)
         parent_line_edit->setText(pilotsIdMap.key(aDB->getLastEntry(ADatabaseTarget::pilots)));
         emit parent_line_edit->editingFinished();
     } else {
-        parent_line_edit->setText(DB_NULL);
+        parent_line_edit->setText(EMPTY_STRING);
     }
 }
 
@@ -1113,13 +1114,13 @@ void NewFlightDialog::onTimeLineEdit_editingFinished()
     DEB << line_edit->objectName() << "Editing Finished -" << line_edit->text();
 
     line_edit->setText(ACalc::formatTimeInput(line_edit->text()));
-    const auto time = QTime::fromString(line_edit->text(),TIME_FORMAT);
+    const auto time = QTime::fromString(line_edit->text(),opl::datetime::TIME_DEFAULT_FORMAT);
     if(time.isValid()){
         if(primaryTimeLineEdits.contains(line_edit)) {
             onGoodInputReceived(line_edit);
         } else { // is extra time line edit
             isLessOrEqualThanBlockTime(line_edit->text());
-            line_edit->setText(DB_NULL);
+            line_edit->setText(EMPTY_STRING);
             line_edit->setFocus();
             return;
         }
@@ -1175,7 +1176,7 @@ void NewFlightDialog::onPilotNameLineEdit_editingFinished()
         DEB << "self recognized.";
         line_edit->setText(pilotsIdMap.key(1));
         auto pilot = aDB->getPilotEntry(1);
-        ui->picCompanyLabel->setText(pilot.getData().value(DB_TAILS_COMPANY).toString());
+        ui->picCompanyLabel->setText(pilot.getData().value(opl::db::TAILS_COMPANY).toString());
         onGoodInputReceived(line_edit);
         return;
     }
@@ -1183,7 +1184,7 @@ void NewFlightDialog::onPilotNameLineEdit_editingFinished()
     if(pilotsIdMap.value(line_edit->text()) != 0) {
         DEB << "Mapped: " << line_edit->text() << pilotsIdMap.value(line_edit->text());
         auto pilot = aDB->getPilotEntry(pilotsIdMap.value(line_edit->text()));
-        ui->picCompanyLabel->setText(pilot.getData().value(DB_TAILS_COMPANY).toString());
+        ui->picCompanyLabel->setText(pilot.getData().value(opl::db::TAILS_COMPANY).toString());
         onGoodInputReceived(line_edit);
         return;
     }

+ 9 - 8
src/gui/dialogues/newtaildialog.cpp

@@ -18,6 +18,7 @@
 #include "newtaildialog.h"
 #include "ui_newtail.h"
 #include "src/testing/adebug.h"
+#include "src/oplconstants.h"
 
 static const auto REG_VALID = QPair<QString, QRegularExpression> {
     "registrationLineEdit", QRegularExpression("\\w+-\\w+")};
@@ -127,10 +128,10 @@ void NewTailDialog::fillForm(AEntry entry, bool is_template)
         le->setText(data.value(key).toString());
     }
 
-    ui->operationComboBox->setCurrentIndex(data.value(DB_TAILS_MULTIPILOT).toInt() + 1);
-    ui->ppNumberComboBox ->setCurrentIndex(data.value(DB_TAILS_MULTIENGINE).toInt() + 1);
-    ui->ppTypeComboBox->setCurrentIndex(data.value(DB_TAILS_ENGINETYPE).toInt() + 1);
-    ui->weightComboBox->setCurrentIndex(data.value(DB_TAILS_WEIGHTCLASS).toInt() + 1);
+    ui->operationComboBox->setCurrentIndex(data.value(opl::db::TAILS_MULTIPILOT).toInt() + 1);
+    ui->ppNumberComboBox ->setCurrentIndex(data.value(opl::db::TAILS_MULTIENGINE).toInt() + 1);
+    ui->ppTypeComboBox->setCurrentIndex(data.value(opl::db::TAILS_ENGINETYPE).toInt() + 1);
+    ui->weightComboBox->setCurrentIndex(data.value(opl::db::TAILS_WEIGHTCLASS).toInt() + 1);
 }
 
 /*!
@@ -193,16 +194,16 @@ void NewTailDialog::submitForm()
     }
 
     if (ui->operationComboBox->currentIndex() != 0) { // bool Multipilot
-        new_data.insert(DB_TAILS_MULTIPILOT, ui->operationComboBox->currentIndex() - 1);
+        new_data.insert(opl::db::TAILS_MULTIPILOT, ui->operationComboBox->currentIndex() - 1);
     }
     if (ui->ppNumberComboBox->currentIndex() != 0) { // bool MultiEngine
-        new_data.insert(DB_TAILS_MULTIENGINE, ui->ppNumberComboBox->currentIndex() - 1);
+        new_data.insert(opl::db::TAILS_MULTIENGINE, ui->ppNumberComboBox->currentIndex() - 1);
     }
     if (ui->ppTypeComboBox->currentIndex() != 0) { // int 0=unpowered,....4=jet
-        new_data.insert(DB_TAILS_ENGINETYPE, ui->ppTypeComboBox->currentIndex() - 1);
+        new_data.insert(opl::db::TAILS_ENGINETYPE, ui->ppTypeComboBox->currentIndex() - 1);
     }
     if (ui->weightComboBox->currentIndex() != 0) { // int 0=light...3=super
-        new_data.insert(DB_TAILS_WEIGHTCLASS, ui->weightComboBox->currentIndex() - 1);
+        new_data.insert(opl::db::TAILS_WEIGHTCLASS, ui->weightComboBox->currentIndex() - 1);
     }
 
     //create db object

+ 16 - 16
src/gui/widgets/settingswidget.cpp

@@ -22,7 +22,7 @@
 #include "src/classes/asettings.h"
 #include "src/database/adatabase.h"
 #include "src/classes/apilotentry.h"
-#include "src/database/declarations.h"
+#include "src/oplconstants.h"
 
 #include <QStyleFactory>
 
@@ -84,12 +84,12 @@ void SettingsWidget::readSettings()
     {
         const QSignalBlocker blocker(this); // don't emit editing finished for setting these values
         auto user_data = aDB->getPilotEntry(1).getData();
-        ui->lastnameLineEdit->setText(user_data.value(DB_PILOTS_LASTNAME).toString());
-        ui->firstnameLineEdit->setText(user_data.value(DB_PILOTS_FIRSTNAME).toString());
-        ui->companyLineEdit->setText(user_data.value(DB_PILOTS_COMPANY).toString());
-        ui->employeeidLineEdit->setText(user_data.value(DB_PILOTS_EMPLOYEEID).toString());
-        ui->phoneLineEdit->setText(user_data.value(DB_PILOTS_PHONE).toString());
-        ui->emailLineEdit->setText(user_data.value(DB_PILOTS_EMAIL).toString());
+        ui->lastnameLineEdit->setText(user_data.value(opl::db::PILOTS_LASTNAME).toString());
+        ui->firstnameLineEdit->setText(user_data.value(opl::db::PILOTS_FIRSTNAME).toString());
+        ui->companyLineEdit->setText(user_data.value(opl::db::PILOTS_COMPANY).toString());
+        ui->employeeidLineEdit->setText(user_data.value(opl::db::PILOTS_EMPLOYEEID).toString());
+        ui->phoneLineEdit->setText(user_data.value(opl::db::PILOTS_PHONE).toString());
+        ui->emailLineEdit->setText(user_data.value(opl::db::PILOTS_EMAIL).toString());
     }
 
     /*
@@ -131,10 +131,10 @@ void SettingsWidget::updatePersonalDetails()
     RowData user_data;
     switch (ui->aliasComboBox->currentIndex()) {
     case 0:
-        user_data.insert(DB_PILOTS_ALIAS, QStringLiteral("self"));
+        user_data.insert(opl::db::PILOTS_ALIAS, QStringLiteral("self"));
         break;
     case 1:
-        user_data.insert(DB_PILOTS_ALIAS,QStringLiteral("SELF"));
+        user_data.insert(opl::db::PILOTS_ALIAS, QStringLiteral("SELF"));
         break;
     case 2:{
         QString name;
@@ -142,18 +142,18 @@ void SettingsWidget::updatePersonalDetails()
         name.append(QLatin1String(", "));
         name.append(ui->firstnameLineEdit->text().left(1));
         name.append(QLatin1Char('.'));
-        user_data.insert(DB_PILOTS_ALIAS, name);
+        user_data.insert(opl::db::PILOTS_ALIAS, name);
     }
         break;
     default:
         break;
     }
-    user_data.insert(DB_PILOTS_LASTNAME, ui->lastnameLineEdit->text());
-    user_data.insert(DB_PILOTS_FIRSTNAME, ui->firstnameLineEdit->text());
-    user_data.insert(DB_PILOTS_COMPANY, ui->companyLineEdit->text());
-    user_data.insert(DB_PILOTS_EMPLOYEEID, ui->employeeidLineEdit->text());
-    user_data.insert(DB_PILOTS_PHONE, ui->phoneLineEdit->text());
-    user_data.insert(DB_PILOTS_EMAIL, ui->emailLineEdit->text());
+    user_data.insert(opl::db::PILOTS_LASTNAME, ui->lastnameLineEdit->text());
+    user_data.insert(opl::db::PILOTS_FIRSTNAME, ui->firstnameLineEdit->text());
+    user_data.insert(opl::db::PILOTS_COMPANY, ui->companyLineEdit->text());
+    user_data.insert(opl::db::PILOTS_EMPLOYEEID, ui->employeeidLineEdit->text());
+    user_data.insert(opl::db::PILOTS_PHONE, ui->phoneLineEdit->text());
+    user_data.insert(opl::db::PILOTS_EMAIL, ui->emailLineEdit->text());
 
     auto user = APilotEntry(1);
     user.setData(user_data);

+ 113 - 0
src/oplconstants.h

@@ -0,0 +1,113 @@
+#ifndef OPLCONSTANTS_H
+#define OPLCONSTANTS_H
+
+#include <QtCore>
+
+/*!
+ *  A namespace to collect constants used throughout the application.
+ */
+namespace opl {
+
+/*!
+ * The datetime namespace specifies date and time formats by QDate, QTime
+ * and QDateTime that deviate from standard values included in the Qt Framework
+ * like Qt::ISODate and are to be used in conjunction with the .toString() members
+ * of these classes
+ */
+namespace datetime {
+
+static const auto TIME_DEFAULT_FORMAT    = QStringLiteral("hh:mm");
+static const auto DATETIME_BACKUP_FORMAT = QStringLiteral("yyyy_MM_dd_T_hh_mm");
+
+} // namespace opl::datetime
+
+/*!
+ *  The opl::db namespace provides string literals to programatically access the database
+ *
+ *  Example usage, do:
+ *  newData.insert(opl::db::FLIGHTS_DEP, ui->deptLocLineEdit->text());
+ *  newData.value(opl::db::AIRCRAFT_MULTIPILOT);
+ *
+ *  instead of:
+ *  newData.insert("dept", ui->deptLocLineEdit->text());
+ *  newData.value("multipilot");
+ *
+ *  Declaring these literals here avoids memory allocation at runtime for construction of temporary
+ *  qstrings like ("dept"). See https://doc.qt.io/qt-5/qstring.html#QStringLiteral and ensures
+ *  uniform use throughout the application.
+ */
+namespace db {
+
+
+// Table names
+static const auto TABLE_FLIGHTS          = QStringLiteral("flights");
+static const auto TABLE_PILOTS           = QStringLiteral("pilots");
+static const auto TABLE_TAILS            = QStringLiteral("tails");
+static const auto TABLE_AIRCRAFT         = QStringLiteral("aircraft");
+static const auto TABLE_AIRPORTS         = QStringLiteral("airports");
+
+// Flights table columns
+static const auto FLIGHTS_DOFT           = QStringLiteral("doft");
+static const auto FLIGHTS_DEPT           = QStringLiteral("dept");
+static const auto FLIGHTS_DEST           = QStringLiteral("dest");
+static const auto FLIGHTS_TOFB           = QStringLiteral("tofb");
+static const auto FLIGHTS_TONB           = QStringLiteral("tonb");
+static const auto FLIGHTS_PIC            = QStringLiteral("pic");
+static const auto FLIGHTS_ACFT           = QStringLiteral("acft");
+static const auto FLIGHTS_TBLK           = QStringLiteral("tblk");
+static const auto FLIGHTS_TSPSE          = QStringLiteral("tSPSE");
+static const auto FLIGHTS_TSPME          = QStringLiteral("tSPME");
+static const auto FLIGHTS_TMP            = QStringLiteral("tMP");
+static const auto FLIGHTS_TNIGHT         = QStringLiteral("tNIGHT");
+static const auto FLIGHTS_TIFR           = QStringLiteral("tIFR");
+static const auto FLIGHTS_TPIC           = QStringLiteral("tPIC");
+static const auto FLIGHTS_TPICUS         = QStringLiteral("tPICUS");
+static const auto FLIGHTS_TSIC           = QStringLiteral("tSIC");
+static const auto FLIGHTS_TDUAL          = QStringLiteral("tDUAL");
+static const auto FLIGHTS_TFI            = QStringLiteral("tFI");
+static const auto FLIGHTS_TSIM           = QStringLiteral("tSIM");
+static const auto FLIGHTS_PILOTFLYING    = QStringLiteral("pilotFlying");
+static const auto FLIGHTS_TODAY          = QStringLiteral("toDay");
+static const auto FLIGHTS_TONIGHT        = QStringLiteral("toNight");
+static const auto FLIGHTS_LDGDAY         = QStringLiteral("ldgDay");
+static const auto FLIGHTS_LDGNIGHT       = QStringLiteral("ldgNight");
+static const auto FLIGHTS_AUTOLAND       = QStringLiteral("autoland");
+static const auto FLIGHTS_SECONDPILOT    = QStringLiteral("secondPilot");
+static const auto FLIGHTS_THIRDPILOT     = QStringLiteral("thirdPilot");
+static const auto FLIGHTS_APPROACHTYPE   = QStringLiteral("approachType");
+static const auto FLIGHTS_FLIGHTNUMBER   = QStringLiteral("flightNumber");
+static const auto FLIGHTS_REMARKS        = QStringLiteral("remarks");
+
+// tails table
+
+static const auto TAILS_REGISTRATION     = QStringLiteral("registration");
+static const auto TAILS_COMPANY          = QStringLiteral("company");
+static const auto TAILS_MAKE             = QStringLiteral("make");
+static const auto TAILS_MODEL            = QStringLiteral("model");
+static const auto TAILS_VARIANT          = QStringLiteral("variant");
+static const auto TAILS_MULTIPILOT       = QStringLiteral("multipilot");
+static const auto TAILS_MULTIENGINE      = QStringLiteral("multiengine");
+static const auto TAILS_ENGINETYPE       = QStringLiteral("engineType");
+static const auto TAILS_WEIGHTCLASS      = QStringLiteral("weightClass");
+
+// pilots table
+
+static const auto PILOTS_LASTNAME        = QStringLiteral("lastname");
+static const auto PILOTS_FIRSTNAME       = QStringLiteral("firstname");
+static const auto PILOTS_ALIAS           = QStringLiteral("alias");
+static const auto PILOTS_COMPANY         = QStringLiteral("company");
+static const auto PILOTS_EMPLOYEEID      = QStringLiteral("employeeid");
+static const auto PILOTS_PHONE           = QStringLiteral("phone");
+static const auto PILOTS_EMAIL           = QStringLiteral("email");
+
+// all tables
+
+static const auto ROWID                  = QStringLiteral("ROWID");
+static const auto EMPTY_STRING           = QStringLiteral("");
+static const auto NULL_TIME_hhmm         = QStringLiteral("00:00");
+
+} // namespace opl::db
+
+} // namespace opl
+
+#endif // OPLCONSTANTS_H