Selaa lähdekoodia

Removing obsolete code

Removed obsolete code and classes, removed experimental namespace, added standardpaths for storing settings and database
Felix Turowsky 4 vuotta sitten
vanhempi
commit
640f6edd8f
71 muutettua tiedostoa jossa 913 lisäystä ja 2206 poistoa
  1. 25 44
      main.cpp
  2. 17 19
      mainwindow.cpp
  3. 0 1
      mainwindow.h
  4. 15 29
      openPilotLog.pro
  5. 45 0
      src/astandardpaths.cpp
  6. 34 0
      src/astandardpaths.h
  7. 3 7
      src/classes/aaircraftentry.cpp
  8. 5 8
      src/classes/aaircraftentry.h
  9. 4 4
      src/classes/adownload.cpp
  10. 4 8
      src/classes/aentry.cpp
  11. 9 13
      src/classes/aentry.h
  12. 73 0
      src/classes/aflightentry.cpp
  13. 54 0
      src/classes/aflightentry.h
  14. 0 86
      src/classes/aircraft.cpp
  15. 0 36
      src/classes/aircraft.h
  16. 6 10
      src/classes/apilotentry.cpp
  17. 5 8
      src/classes/apilotentry.h
  18. 15 4
      src/classes/asettings.cpp
  19. 14 6
      src/classes/asettings.h
  20. 0 27
      src/classes/astrictrxvalidator.cpp
  21. 0 34
      src/classes/astrictrxvalidator.h
  22. 10 14
      src/classes/atailentry.cpp
  23. 4 8
      src/classes/atailentry.h
  24. 0 88
      src/classes/flight.cpp
  25. 0 36
      src/classes/flight.h
  26. 0 88
      src/classes/pilot.cpp
  27. 0 32
      src/classes/pilot.h
  28. 124 92
      src/database/adatabase.cpp
  29. 37 20
      src/database/adatabase.h
  30. 57 57
      src/database/adatabasesetup.cpp
  31. 0 3
      src/database/adatabasesetup.h
  32. 0 276
      src/database/db.cpp
  33. 0 169
      src/database/db.h
  34. 0 57
      src/database/dbinfo.cpp
  35. 0 41
      src/database/dbinfo.h
  36. 75 10
      src/database/declarations.h
  37. 0 247
      src/database/entry_deprecated.cpp
  38. 0 60
      src/database/entry_deprecated.h
  39. 0 47
      src/experimental/UserInput.h
  40. 0 81
      src/experimental/aflightentry.cpp
  41. 0 39
      src/experimental/aflightentry.h
  42. 0 65
      src/experimental/decl.h
  43. 48 52
      src/functions/acalc.cpp
  44. 0 6
      src/functions/acalc.h
  45. 3 4
      src/functions/astat.cpp
  46. 0 2
      src/functions/astat.h
  47. 9 6
      src/gui/dialogues/firstrundialog.cpp
  48. 0 6
      src/gui/dialogues/firstrundialog.h
  49. 63 59
      src/gui/dialogues/newflightdialog.cpp
  50. 5 11
      src/gui/dialogues/newflightdialog.h
  51. 15 14
      src/gui/dialogues/newpilotdialog.cpp
  52. 2 7
      src/gui/dialogues/newpilotdialog.h
  53. 17 22
      src/gui/dialogues/newtaildialog.cpp
  54. 7 8
      src/gui/dialogues/newtaildialog.h
  55. 10 10
      src/gui/widgets/aircraftwidget.cpp
  56. 0 8
      src/gui/widgets/aircraftwidget.h
  57. 16 43
      src/gui/widgets/debugwidget.cpp
  58. 3 5
      src/gui/widgets/debugwidget.h
  59. 1 5
      src/gui/widgets/homewidget.h
  60. 13 10
      src/gui/widgets/logbookwidget.cpp
  61. 0 6
      src/gui/widgets/logbookwidget.h
  62. 4 3
      src/gui/widgets/pilotswidget.cpp
  63. 0 1
      src/gui/widgets/pilotswidget.h
  64. 9 8
      src/gui/widgets/settingswidget.cpp
  65. 1 4
      src/gui/widgets/settingswidget.h
  66. 2 2
      src/gui/widgets/totalswidget.cpp
  67. 0 1
      src/gui/widgets/totalswidget.h
  68. 12 12
      src/testing/abenchmark.cpp
  69. 0 5
      src/testing/abenchmark.h
  70. 28 2
      src/testing/adebug.h
  71. 10 10
      src/testing/atimer.cpp

+ 25 - 44
main.cpp

@@ -18,66 +18,48 @@
 #include "mainwindow.h"
 #include "src/gui/dialogues/firstrundialog.h"
 #include "src/classes/arunguard.h"
-#include "src/experimental/adatabase.h"
+#include "src/database/adatabase.h"
+#include "src/classes/asettings.h"
+#include "src/astandardpaths.h"
 #include "src/classes/asettings.h"
 #include <QApplication>
 #include <QProcess>
 #include <QSettings>
 #include <QFileInfo>
+#include <QStandardPaths>
+#include <QDebug>
 
-
-const auto DATA_DIR = QLatin1String("data");
-/*!
- * \brief setup checks if data folder and settings files exists.
- * \return
- */
-bool setup()
-{
-    if (!QDir(DATA_DIR).exists())
-        QDir().mkdir(DATA_DIR);
-
-    QDir      settingspath(DATA_DIR + QLatin1Char('/') + QCoreApplication::organizationName());
-    QString   settingsfile = QCoreApplication::applicationName() + QLatin1String(".ini");
-    QFileInfo check_file(settingspath,settingsfile);
-
-    QSettings settings;
-    settings.setValue("setup/touch", true);
-    settings.sync();
-
-    return check_file.exists() && check_file.isFile();
-};
+#define APPNAME QStringLiteral("openPilotLog")
+#define ORGNAME QStringLiteral("opl")
+#define ORGDOMAIN QStringLiteral("https://github.com/fiffty-50/openpilotlog")
 
 int main(int argc, char *argv[])
 {
-    QCoreApplication::setOrganizationName("openPilotLog");
-    QCoreApplication::setOrganizationDomain("https://github.com/fiffty-50/openpilotlog");
-    QCoreApplication::setApplicationName("openPilotLog");
-
-    QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, DATA_DIR);
-    QSettings::setDefaultFormat(QSettings::IniFormat);
-    QSettings settings;
-
-    experimental::aDB()->connect();
-
     QApplication openPilotLog(argc, argv);
-    if(!setup()){
-        DEB("error creating required directories");
-        return 0;
+    QCoreApplication::setOrganizationName(ORGNAME);
+    QCoreApplication::setOrganizationDomain(ORGDOMAIN);
+    QCoreApplication::setApplicationName(APPNAME);
+
+    AStandardPaths::setup();
+    AStandardPaths::scan_paths();
+    if(!AStandardPaths::validate_paths()){
+        DEB << "Standard paths not valid.";
+        return 1;
     }
 
+    ASettings::setup();
+
+    aDB()->connect();
+
     if (!ASettings::read("setup/setup_complete").toBool()) {
         FirstRunDialog dialog;
         dialog.exec();
     }
 
-
-
     //Theming
-    int selectedtheme = settings.value("main/theme").toInt();
-    QDir::setCurrent("/themes");
-    switch (selectedtheme) {
+    switch (ASettings::read("main/theme").toInt()) {
     case 1:{
-        qDebug() << "main :: Loading light theme";
+        DEB << "main :: Loading light theme";
         QFile file(":light.qss");
         file.open(QFile::ReadOnly | QFile::Text);
         QTextStream stream(&file);
@@ -85,7 +67,7 @@ int main(int argc, char *argv[])
         break;
     }
     case 2:{
-        qDebug() << "Loading dark theme";
+        DEB << "Loading dark theme";
         QFile file(":dark.qss");
         file.open(QFile::ReadOnly | QFile::Text);
         QTextStream stream(&file);
@@ -96,11 +78,10 @@ int main(int argc, char *argv[])
         break;
     }
 
-
     //sqlite does not deal well with multiple connections, ensure only one instance is running
     ARunGuard guard("opl_single_key");
         if ( !guard.tryToRun() ){
-            qDebug() << "Another Instance is already running. Exiting.";
+            DEB << "Another Instance is already running. Exiting.";
             return 0;
         }
 

+ 17 - 19
mainwindow.cpp

@@ -18,6 +18,7 @@
 #include "mainwindow.h"
 #include "ui_mainwindow.h"
 #include "src/testing/adebug.h"
+#include "src/database/adatabase.h"
 
 MainWindow::MainWindow(QWidget *parent)
     : QMainWindow(parent)
@@ -50,7 +51,7 @@ MainWindow::MainWindow(QWidget *parent)
     ui->toolBar->insertWidget(ui->actionDebug, spacer);
 
 
-    DEB("Construction MainWindow Widgets\n");
+    DEB << "Construction MainWindow Widgets\n";
     // Construct Widgets
     homeWidget = new HomeWidget(this);
     ui->stackedWidget->addWidget(homeWidget);
@@ -75,20 +76,17 @@ MainWindow::MainWindow(QWidget *parent)
     //// START DEBUG ////
     /// [F] I understand how it is annoying to not have the database
     /// working when something has changed. Hopefully this check
-    /// helps to avoid that in the future!
-    const int DATABASE_REVISION_NUMBER = 14;
-    QSqlQuery query;
-    query.prepare("SELECT COUNT (*) FROM changelog");
-    query.exec();
-    query.next();
-    if (query.value(0).toInt() != DATABASE_REVISION_NUMBER) {
-        DEB("##########################################");
-        DEB("Your database is out of date.");
-        DEB("Current Revision:  " << DATABASE_REVISION_NUMBER);
-        DEB("You have revision: " << query.value(0).toInt());
-        DEB("Use of DebugWidget to udpate recommended.");
-        DEB("##########################################");
-    }
+    /// helps to avoid that in the future! 
+    #if DATABASE < 15
+    DEB << "Your database is up to date with the latest revision.";
+    #else
+    DEB << "##########################################";
+    DEB << "Your database is out of date.";
+    DEB << "Current Revision:  " << DATABASE_REVISION_NUMBER;
+    DEB << "You have revision: " << query.value(0).toInt();
+    DEB << "Use of DebugWidget to udpate recommended.";
+    DEB << "##########################################";
+    #endif
     //// END DEBUG ////
 
 }
@@ -132,11 +130,11 @@ void MainWindow::on_actionDebug_triggered()
 
 void MainWindow::connectWidgets()
 {
-    QObject::connect(experimental::aDB(), &experimental::ADatabase::dataBaseUpdated,
+    QObject::connect(aDB(), &ADatabase::dataBaseUpdated,
                      logbookWidget, &LogbookWidget::onDisplayModel_dataBaseUpdated);
-    QObject::connect(experimental::aDB(), &experimental::ADatabase::dataBaseUpdated,
+    QObject::connect(aDB(), &ADatabase::dataBaseUpdated,
                      pilotsWidget, &PilotsWidget::onDisplayModel_dataBaseUpdated);
-    QObject::connect(experimental::aDB(), &experimental::ADatabase::dataBaseUpdated,
+    QObject::connect(aDB(), &ADatabase::dataBaseUpdated,
                      aircraftWidget, &AircraftWidget::onDisplayModel_dataBaseUpdated);
 
     QObject::connect(settingsWidget, &SettingsWidget::viewSelectionChanged,
@@ -173,6 +171,6 @@ void MainWindow::on_actionNewAircraft_triggered()
 
 void MainWindow::on_actionNewPilot_triggered()
 {
-    NewPilotDialog np = NewPilotDialog(Db::createNew, this);
+    NewPilotDialog np = NewPilotDialog(this);
     np.exec();
 }

+ 0 - 1
mainwindow.h

@@ -36,7 +36,6 @@
 #include "src/gui/dialogues/newtaildialog.h"
 #include "src/gui/dialogues/newpilotdialog.h"
 #include "src/classes/arunguard.h"
-#include "src/experimental/adatabase.h"
 #include "src/testing/atimer.h"
 
 QT_BEGIN_NAMESPACE

+ 15 - 29
openPilotLog.pro

@@ -18,23 +18,17 @@ DEFINES += QT_DEPRECATED_WARNINGS
 SOURCES += \
     main.cpp \
     mainwindow.cpp \
+    src/astandardpaths.cpp \
+    src/classes/aaircraftentry.cpp \
     src/classes/adownload.cpp \
-    src/classes/aircraft.cpp \
+    src/classes/aentry.cpp \
+    src/classes/aflightentry.cpp \
+    src/classes/apilotentry.cpp \
     src/classes/arunguard.cpp \
     src/classes/asettings.cpp \
-    src/classes/astrictrxvalidator.cpp \
-    src/classes/flight.cpp \
-    src/classes/pilot.cpp \
+    src/classes/atailentry.cpp \
+    src/database/adatabase.cpp \
     src/database/adatabasesetup.cpp \
-    src/database/db.cpp \
-    src/database/dbinfo.cpp \
-    src/database/entry_deprecated.cpp \
-    src/experimental/aaircraftentry.cpp \
-    src/experimental/adatabase.cpp \
-    src/experimental/aentry.cpp \
-    src/experimental/aflightentry.cpp \
-    src/experimental/apilotentry.cpp \
-    src/experimental/atailentry.cpp \
     src/functions/acalc.cpp \
     src/functions/areadcsv.cpp \
     src/functions/astat.cpp \
@@ -54,26 +48,18 @@ SOURCES += \
 
 HEADERS += \
     mainwindow.h \
+    src/astandardpaths.h \
+    src/classes/aaircraftentry.h \
     src/classes/adownload.h \
-    src/classes/aircraft.h \
+    src/classes/aentry.h \
+    src/classes/aflightentry.h \
+    src/classes/apilotentry.h \
     src/classes/arunguard.h \
     src/classes/asettings.h \
-    src/classes/astrictrxvalidator.h \
-    src/classes/flight.h \
-    src/classes/pilot.h \
+    src/classes/atailentry.h \
+    src/database/adatabase.h \
     src/database/adatabasesetup.h \
-    src/database/db.h \
-    src/database/dbinfo.h \
-    src/database/entry_deprecated.h \
-    src/database/tablecolumnliterals.h \
-    src/experimental/UserInput.h \
-    src/experimental/aaircraftentry.h \
-    src/experimental/adatabase.h \
-    src/experimental/aentry.h \
-    src/experimental/aflightentry.h \
-    src/experimental/apilotentry.h \
-    src/experimental/atailentry.h \
-    src/experimental/decl.h \
+    src/database/declarations.h \
     src/functions/acalc.h \
     src/functions/areadcsv.h \
     src/functions/astat.h \

+ 45 - 0
src/astandardpaths.cpp

@@ -0,0 +1,45 @@
+#include "src/astandardpaths.h"
+
+QMap<QStandardPaths::StandardLocation, QString> AStandardPaths::paths;
+
+void AStandardPaths::setup()
+{
+    auto settings_location = QStandardPaths::AppConfigLocation;
+    auto data_location = QStandardPaths::AppDataLocation;
+    paths = {
+        {settings_location, QStandardPaths::writableLocation(settings_location)},
+        {data_location, QStandardPaths::writableLocation(data_location)},
+    };
+}
+
+QString AStandardPaths::getPath(QStandardPaths::StandardLocation loc)
+{
+    return paths[loc];
+}
+
+QMap<QStandardPaths::StandardLocation, QString> AStandardPaths::getPaths()
+{
+    return paths;
+}
+
+void AStandardPaths::scan_paths()
+{
+    for(auto& path : paths.values()){
+        auto dir = QDir(path);
+        DEB << "Scanning " << dir.path();
+        if(!dir.exists()) {
+            DEB <<"Creating " << dir.path();
+            dir.mkpath(path);
+        }
+    }
+}
+
+bool AStandardPaths::validate_paths()
+{
+    for(auto& path : paths.values()){
+        DEB << "Validating " << path;
+        if(false)  // determine path as valid (scan contents and parse for correctness)
+            return false;
+    }
+    return true;
+}

+ 34 - 0
src/astandardpaths.h

@@ -0,0 +1,34 @@
+#ifndef ASTANDARDPATHS_H
+#define ASTANDARDPATHS_H
+
+#include "src/testing/adebug.h"
+#include <QStandardPaths>
+#include <QString>
+#include <QMap>
+#include <QDir>
+
+/*!
+ * \brief The AStandardAppPaths class encapsulates a static QMap holding
+ * the standard paths of the application. Setup should be called after
+ * `QCoreApplication::setWhateverName`.
+ */
+class AStandardPaths{
+private:
+    static
+    QMap<QStandardPaths::StandardLocation, QString> paths;
+public:
+    /// Initialise paths with corresponding StandardLocation paths
+    static void setup();
+
+    static QString getPath(QStandardPaths::StandardLocation loc);
+    static QMap<QStandardPaths::StandardLocation, QString> getPaths();
+
+    /// Ensure standard app paths exist, if not mkdir them.
+    static void scan_paths();
+
+    /// Validate standard app paths are valid in structure and contents.
+    static bool validate_paths();
+};
+
+
+#endif // ASTANDARDPATHS_H

+ 3 - 7
src/experimental/aaircraftentry.cpp → src/classes/aaircraftentry.cpp

@@ -17,18 +17,14 @@
  */
 #include "aaircraftentry.h"
 
-namespace experimental {
-
 AAircraftEntry::AAircraftEntry()
     : AEntry::AEntry(DEFAULT_AIRCRAFT_POSITION)
 {}
 
-AAircraftEntry::AAircraftEntry(int row_id)
-    : AEntry::AEntry(DataPosition(QLatin1String("aircraft"), row_id))
+AAircraftEntry::AAircraftEntry(RowId row_id)
+    : AEntry::AEntry(DataPosition(DB_TABLE_AIRCRAFT, row_id))
 {}
 
-AAircraftEntry::AAircraftEntry(TableData table_data)
+AAircraftEntry::AAircraftEntry(RowData table_data)
     : AEntry::AEntry(DEFAULT_AIRCRAFT_POSITION, table_data)
 {}
-
-} // namespace experimental

+ 5 - 8
src/experimental/aaircraftentry.h → src/classes/aaircraftentry.h

@@ -1,20 +1,17 @@
 #ifndef AAIRCRAFTENTRY_H
 #define AAIRCRAFTENTRY_H
 
-#include "src/experimental/aentry.h"
-#include "src/experimental/decl.h"
-
-namespace experimental {
+#include "src/classes/aentry.h"
+#include "src/database/declarations.h"
 
 struct AAircraftEntry : public AEntry {
 public:
     AAircraftEntry();
+    AAircraftEntry(RowId row_id);
+    AAircraftEntry(RowData table_data);
+
     AAircraftEntry(const AAircraftEntry& te) = default;
     AAircraftEntry& operator=(const AAircraftEntry& te) = default;
-    AAircraftEntry(int row_id);
-    AAircraftEntry(TableData table_data);
 };
 
-} // namespace experimental
-
 #endif // AAIRCRAFTENTRY_H

+ 4 - 4
src/classes/adownload.cpp

@@ -28,7 +28,7 @@ ADownload::ADownload() : QObject(nullptr)
 
 ADownload::~ADownload()
 {
-    DEB("Deleting Download object");
+    DEB << "Deleting Download object" ;
 }
 
 void ADownload::setTarget(const QUrl &value)
@@ -44,7 +44,7 @@ void ADownload::setFileName(const QString &value)
 void ADownload::download()
 {
     QNetworkRequest request(target);
-    DEB("Downloading from: " << target.toString());
+    DEB << "Downloading from: " << target.toString();
 
     QObject::connect(manager.get(request), SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(downloadProgress(qint64,qint64)));
 }
@@ -52,7 +52,7 @@ void ADownload::download()
 
 void ADownload::downloadProgress(qint64 received, qint64 total)
 {
-    DEB("Received " << received << " bytes of " << total);
+    DEB << "Received " << received << " bytes of " << total;
 }
 
 
@@ -65,7 +65,7 @@ void ADownload::downloadFinished(QNetworkReply *data)
     const QByteArray sdata = data->readAll();
     localFile.write(sdata);
     localFile.close();
-    qDebug() << "Download finished. Output file: " << fileName;
+    DEB << "Download finished. Output file: " << fileName;
 
     emit done();
 }

+ 4 - 8
src/experimental/aentry.cpp → src/classes/aentry.cpp

@@ -17,21 +17,19 @@
  */
 #include "aentry.h"
 
-namespace experimental {
-
 AEntry::AEntry(DataPosition position_)
     : position(position_)
 {}
 
-AEntry::AEntry(TableData table_data)
+AEntry::AEntry(RowData table_data)
     : tableData(table_data)
 {}
 
-AEntry::AEntry(DataPosition position_, TableData table_data)
+AEntry::AEntry(DataPosition position_, RowData table_data)
     : position(position_), tableData(table_data)
 {}
 
-void AEntry::setData(TableData table_data)
+void AEntry::setData(RowData table_data)
 {
     tableData = table_data;
 }
@@ -41,9 +39,7 @@ const DataPosition& AEntry::getPosition()
     return position;
 }
 
-const TableData& AEntry::getData()
+const RowData& AEntry::getData()
 {
     return tableData;
 }
-
-}  // namespace experimental

+ 9 - 13
src/experimental/aentry.h → src/classes/aentry.h

@@ -15,8 +15,8 @@
  *You should have received a copy of the GNU General Public License
  *along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
-#ifndef ENTRY_H
-#define ENTRY_H
+#ifndef AENTRY_H
+#define AENTRY_H
 
 #include <QString>
 #include <QStringList>
@@ -24,9 +24,7 @@
 #include <QPair>
 #include <QVariant>
 
-#include "decl.h"
-
-namespace experimental {
+#include "src/database/declarations.h"
 
 // [G]: Define what data is public and what not. For objects such as
 // DataPosition which are consumable its no biggy. Are entries the same?
@@ -43,23 +41,21 @@ class AEntry {
 protected:
     DataPosition position;
 public:
-    TableData tableData;
+    RowData tableData;
 public:
     AEntry() = delete; // Demand specificity from default constructor
     AEntry(const AEntry&) = default;
     AEntry& operator=(const AEntry&) = default;
     AEntry(DataPosition position_);
-    AEntry(TableData table_data);
-    AEntry(DataPosition position_, TableData table_data);
+    AEntry(RowData table_data);
+    AEntry(DataPosition position_, RowData table_data);
 
-    void setData(TableData table_data);
+    void setData(RowData table_data);
     void setPosition(DataPosition position_);
 
     const DataPosition& getPosition();
-    const TableData& getData();
+    const RowData& getData();
 
 };
 
-}
-
-#endif // ENTRY_H
+#endif // AENTRY_H

+ 73 - 0
src/classes/aflightentry.cpp

@@ -0,0 +1,73 @@
+/*
+ *openPilot Log - A FOSS Pilot Logbook Application
+ *Copyright (C) 2020  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 "aflightentry.h"
+#include "src/database/adatabase.h"
+
+AFlightEntry::AFlightEntry()
+    : AEntry::AEntry(DEFAULT_FLIGHT_POSITION)
+{}
+
+AFlightEntry::AFlightEntry(RowId row_id)
+    : AEntry::AEntry(DataPosition(DB_TABLE_FLIGHTS, row_id))
+{}
+
+AFlightEntry::AFlightEntry(RowData table_data)
+    : AEntry::AEntry(DEFAULT_FLIGHT_POSITION, table_data)
+{}
+
+const QString AFlightEntry::summary()
+{
+    if(tableData.isEmpty())
+        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() + " ");
+
+    return flight_summary;
+}
+
+const QString AFlightEntry::getRegistration()
+{
+    ATailEntry acft = aDB()->resolveForeignTail(tableData.value(DB_FLIGHTS_ACFT).toInt());
+    return acft.registration();
+}
+
+const QString AFlightEntry::getPilotName(pilotPosition pilot_)
+{
+    switch (pilot_) {
+    case pilotPosition::pic: {
+        auto foreign_pilot = aDB()->resolveForeignPilot(tableData.value(DB_FLIGHTS_PIC).toInt());
+        return foreign_pilot.name();
+        break;
+    }
+    case pilotPosition::secondPilot: {
+        auto foreign_pilot = aDB()->resolveForeignPilot(tableData.value(DB_FLIGHTS_SECONDPILOT).toInt());
+        return foreign_pilot.name();
+    }
+    case pilotPosition::thirdPilot: {
+        auto foreign_pilot = aDB()->resolveForeignPilot(tableData.value(DB_FLIGHTS_THIRDPILOT).toInt());
+        return foreign_pilot.name();
+        break;
+    } // case scope
+    } // switch (pilot_)
+    return QString();
+}

+ 54 - 0
src/classes/aflightentry.h

@@ -0,0 +1,54 @@
+/*
+ *openPilot Log - A FOSS Pilot Logbook Application
+ *Copyright (C) 2020  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/>.
+ */
+#ifndef AFLIGHTENTRY_H
+#define AFLIGHTENTRY_H
+
+#include "src/classes/aentry.h"
+#include "src/functions/acalc.h"
+
+class AFlightEntry : public AEntry {
+public:
+    AFlightEntry();
+    AFlightEntry(RowId row_id);
+    AFlightEntry(RowData table_data);
+
+    AFlightEntry(const AFlightEntry& pe) = default;
+    AFlightEntry& operator=(const AFlightEntry& pe) = default;
+
+
+    enum class pilotPosition { pic, secondPilot, thirdPilot };
+
+    /*!
+     * \brief Returs a summary of the flight data, if struct holds data
+     * \return "doft, dept, tofb, dest, tonb"
+     */
+    const QString summary();
+    /*!
+     * \brief Returns the tails' registration from the database.
+     */
+    const QString getRegistration();
+    /*!
+     * \brief Returns the pilots name from the Database
+     *
+     * \param pilot_number - 1=pic, 2=second Pilot, 3 = third Pilot
+     * \return "Lastname, Firstname"
+     */
+    const QString getPilotName(pilotPosition);
+};
+
+#endif // AFLIGHTENTRY_H

+ 0 - 86
src/classes/aircraft.cpp

@@ -1,86 +0,0 @@
-/*
- *openPilot Log - A FOSS Pilot Logbook Application
- *Copyright (C) 2020  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 "aircraft.h"
-#include "src/testing/adebug.h"
-
-
-Aircraft::Aircraft()
-{
-
-}
-
-Aircraft::Aircraft(int tail_id)
-{
-    //retreive database layout
-    const auto dbContent = DbInfo();
-    auto table = QLatin1String("tails");
-
-    //Check database for row id
-    QString statement = "SELECT COUNT(*) FROM " + table + " WHERE _rowid_=" + QString::number(tail_id);
-    QSqlQuery q(statement);
-    q.next();
-    int rows = q.value(0).toInt();
-    if (rows == 0) {
-        DEB("No Entry found for row id: " << tail_id );
-        position.second = 0;
-    } else {
-        //DEB("Retreiving data for row id: " << tail_id);
-        QString statement = "SELECT * FROM " + table + " WHERE _rowid_=" + QString::number(tail_id);
-
-        QSqlQuery q(statement);
-        q.exec();
-        q.next();
-        for (int i = 0; i < dbContent.format.value(table).length(); i++) {
-            data.insert(dbContent.format.value(table)[i], q.value(i).toString());
-        }
-
-        error = q.lastError().text();
-        if (error.length() > 2) {
-            DEB("Error: " << q.lastError().text());
-            position.second = 0;
-            position.first = "invalid";
-        } else {
-            position.second = tail_id;
-            position.first = "tails";
-        }
-    }
-}
-
-Aircraft::Aircraft(QMap<QString, QString> newData)
-{
-    QString table = "tails";
-
-    //retreive database layout
-    const auto dbContent = DbInfo();
-    columns = dbContent.format.value(table);
-    //Check validity of newData
-    QVector<QString> badkeys;
-    QMap<QString, QString>::iterator i;
-    for (i = newData.begin(); i != newData.end(); ++i) {
-        if (!columns.contains(i.key())) {
-            DEB(i.key() << "Not in column list for table " << table << ". Discarding.");
-            badkeys << i.key();
-        }
-    }
-    for (const auto &var : badkeys) {
-        newData.remove(var);
-    }
-    data = newData;
-    position.first = table;
-    position.second = 0;
-}

+ 0 - 36
src/classes/aircraft.h

@@ -1,36 +0,0 @@
-/*
- *openPilot Log - A FOSS Pilot Logbook Application
- *Copyright (C) 2020  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/>.
- */
-#ifndef AIRCRAFT_H
-#define AIRCRAFT_H
-#include <QCoreApplication>
-#include "src/database/entry_deprecated.h"
-
-/*!
- * \brief The aircraft class
- *
- */
-class Aircraft : public Entry_deprecated
-{
-//    using Entry::Entry;
-public:
-    Aircraft();
-    Aircraft(int tail_id);
-    Aircraft(QMap<QString, QString> newData);
-};
-
-#endif // AIRCRAFT_H

+ 6 - 10
src/experimental/apilotentry.cpp → src/classes/apilotentry.cpp

@@ -17,27 +17,23 @@
  */
 #include "apilotentry.h"
 
-namespace experimental {
-
 APilotEntry::APilotEntry()
     : AEntry::AEntry(DEFAULT_PILOT_POSITION)
 {}
 
-APilotEntry::APilotEntry(int row_id)
-    : AEntry::AEntry(DataPosition(QStringLiteral("pilots"), row_id))
+APilotEntry::APilotEntry(RowId row_id)
+    : AEntry::AEntry(DataPosition(DB_TABLE_PILOTS, row_id))
 {}
 
-APilotEntry::APilotEntry(TableData table_data)
+APilotEntry::APilotEntry(RowData table_data)
     : AEntry::AEntry(DEFAULT_PILOT_POSITION, table_data)
 {}
 
 const QString APilotEntry::name()
 {
     if (tableData.isEmpty())
-        return QLatin1String("");
+        return DB_NULL;
 
-    return tableData.value(QStringLiteral("lastname")).toString() + ','
-           +tableData.value(QStringLiteral("firstname")).toString().left(1) + '.';
+    return tableData.value(DB_PILOTS_LASTNAME).toString() + ','
+           +tableData.value(DB_PILOTS_FIRSTNAME).toString().left(1) + '.';
 }
-
-} // namespace experimental

+ 5 - 8
src/experimental/apilotentry.h → src/classes/apilotentry.h

@@ -18,22 +18,19 @@
 #ifndef APILOTENTRY_H
 #define APILOTENTRY_H
 
-#include "src/experimental/aentry.h"
-#include "src/experimental/decl.h"
-
-namespace experimental {
+#include "src/classes/aentry.h"
+#include "src/database/declarations.h"
 
 struct APilotEntry : public AEntry {
 public:
     APilotEntry();
+    APilotEntry(RowId row_id);
+    APilotEntry(RowData table_data);
+
     APilotEntry(const APilotEntry& pe) = default;
     APilotEntry& operator=(const APilotEntry& pe) = default;
-    APilotEntry(int row_id);
-    APilotEntry(TableData table_data);
 
     const QString name();
 };
 
-} // namespace experimental
-
 #endif // APILOTENTRY_H

+ 15 - 4
src/classes/asettings.cpp

@@ -16,15 +16,26 @@
  *along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 #include "asettings.h"
+#include "src/astandardpaths.h"
+#include <QSettings>
+
+void ASettings::setup()
+{
+    QSettings::setDefaultFormat(QSettings::IniFormat);
+    QSettings();
+}
 
 QVariant ASettings::read(const QString &key)
 {
-    QSettings settings;
-    return settings.value(key);
+    return QSettings().value(key);
 }
 
 void ASettings::write(const QString &key, const QVariant &val)
 {
-    QSettings settings;
-    settings.setValue(key, val);
+    QSettings().setValue(key, val);
+}
+
+QSettings ASettings::settings()
+{
+    return QSettings();
 }

+ 14 - 6
src/classes/asettings.h

@@ -21,15 +21,23 @@
 #include <QSettings>
 
 /*!
- * \brief The Settings class is a thin wrapper for the QSettings class,
+ * \brief Thin (namespace) wrapper for the QSettings class,
  * simplifying reading and writing of settings.
  */
-class ASettings
+namespace ASettings
 {
-public:
-    static QVariant read(const QString &key);
 
-    static void write(const QString &key, const QVariant &val);
-};
+/*!
+ * \brief Should be called after QCoreApplication::set...Name have been called.
+ */
+void setup();
+
+QVariant read(const QString &key);
+
+void write(const QString &key, const QVariant &val);
+
+QSettings settings();
+
+}
 
 #endif // ASETTINGS_H

+ 0 - 27
src/classes/astrictrxvalidator.cpp

@@ -1,27 +0,0 @@
-/*
- *openPilot Log - A FOSS Pilot Logbook Application
- *Copyright (C) 2020  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 "astrictrxvalidator.h"
-
-QValidator::State AStrictRxValidator::validate(QString &txt, int &pos) const
-{
-    auto validation = QRegularExpressionValidator::validate(txt, pos);
-    if (validation == QValidator::Intermediate) {
-        return QValidator::Invalid;
-    }
-    return validation;
-}

+ 0 - 34
src/classes/astrictrxvalidator.h

@@ -1,34 +0,0 @@
-/*
- *openPilot Log - A FOSS Pilot Logbook Application
- *Copyright (C) 2020  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/>.
- */
-#ifndef STRICTRXVALIDATOR_H
-#define STRICTRXVALIDATOR_H
-
-#include <QRegularExpression>
-#include <QValidator>
-
-/*!
- * \brief The AStrictRxValidator class only returns Invalid or Acceptable
- */
-class AStrictRxValidator : public QRegularExpressionValidator
-{
-    using QRegularExpressionValidator::QRegularExpressionValidator;
-public:
-    QValidator::State validate(QString &txt, int &pos) const;
-};
-
-#endif

+ 10 - 14
src/experimental/atailentry.cpp → src/classes/atailentry.cpp

@@ -17,36 +17,32 @@
  */
 #include "atailentry.h"
 
-namespace experimental {
-
 ATailEntry::ATailEntry()
     : AEntry::AEntry(DEFAULT_TAIL_POSITION)
 {}
 
-ATailEntry::ATailEntry(int row_id)
-    : AEntry::AEntry(DataPosition(QLatin1String("tails"), row_id))
+ATailEntry::ATailEntry(RowId row_id)
+    : AEntry::AEntry(DataPosition(DB_TABLE_TAILS, row_id))
 {}
 
-ATailEntry::ATailEntry(TableData table_data)
+ATailEntry::ATailEntry(RowData table_data)
     : AEntry::AEntry(DEFAULT_TAIL_POSITION, table_data)
 {}
 
 const QString ATailEntry::registration()
 {
-    return getData().value(QLatin1String("registration")).toString();
+    return getData().value(DB_TAILS_REGISTRATION).toString();
 }
 
 const QString ATailEntry::type()
 {
     QString type_string;
-    if (!getData().value(QLatin1String("make")).toString().isEmpty())
-        type_string.append(getData().value(QLatin1String("make")).toString() + ' ');
-    if (!getData().value(QLatin1String("model")).toString().isEmpty())
-        type_string.append(getData().value(QLatin1String("model")).toString());
-    if (!getData().value(QLatin1String("variant")).toString().isEmpty())
-        type_string.append('-' + getData().value(QLatin1String("variant")).toString() + ' ');
+    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() + ' ');
 
     return type_string;
 }
-
-} // namespace experimental

+ 4 - 8
src/experimental/atailentry.h → src/classes/atailentry.h

@@ -18,25 +18,21 @@
 #ifndef ATAILENTRY_H
 #define ATAILENTRY_H
 
-#include "src/experimental/aentry.h"
-#include "src/experimental/decl.h"
-#include <QVariant>
-
-namespace experimental {
+#include "src/classes/aentry.h"
+#include "src/database/declarations.h"
 
 struct ATailEntry : public AEntry {
 public:
     ATailEntry();
     ATailEntry(const ATailEntry& te) = default;
     ATailEntry& operator=(const ATailEntry& te) = default;
-    ATailEntry(int row_id);
-    ATailEntry(TableData table_data);
+    ATailEntry(RowId row_id);
+    ATailEntry(RowData table_data);
 
     const QString registration();
 
     const QString type();
 };
 
-} // namespace experimental
 
 #endif // ATAILENTRY_H

+ 0 - 88
src/classes/flight.cpp

@@ -1,88 +0,0 @@
-/*
- *openPilot Log - A FOSS Pilot Logbook Application
- *Copyright (C) 2020  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 "flight.h"
-#include "src/testing/adebug.h"
-
-Flight::Flight()
-{
-
-}
-
-Flight::Flight(int flight_id)
-{
-    //retreive database layout
-    const auto dbContent = DbInfo();
-
-    auto table = QLatin1String("flights");
-
-
-    //Check database for row id
-    QString statement = "SELECT COUNT(*) FROM " + table + " WHERE _rowid_=" + QString::number(flight_id);
-    QSqlQuery q(statement);
-    q.next();
-    int rows = q.value(0).toInt();
-    if (rows == 0) {
-        DEB("No Entry found for row id: " << flight_id );
-        position.second = 0;
-    } else {
-        DEB("Retreiving data for row id: " << flight_id);
-        QString statement = "SELECT * FROM " + table + " WHERE _rowid_=" + QString::number(flight_id);
-
-        QSqlQuery q(statement);
-        q.exec();
-        q.next();
-        for (int i = 0; i < dbContent.format.value(table).length(); i++) {
-            data.insert(dbContent.format.value(table)[i], q.value(i).toString());
-        }
-
-        error = q.lastError().text();
-        if (error.length() > 2) {
-            DEB("Error: " << q.lastError().text());
-            position.second = 0;
-            position.first = "invalid";
-        } else {
-            position.second = flight_id;
-            position.first = "flights";
-        }
-    }
-}
-
-Flight::Flight(QMap<QString, QString> newData)
-{
-    QString table = "flights";
-
-    //retreive database layout
-    const auto dbContent = DbInfo();
-    columns = dbContent.format.value(table);
-
-    //Check validity of newData
-    QVector<QString> badkeys;
-    QMap<QString, QString>::iterator i;
-    for (i = newData.begin(); i != newData.end(); ++i) {
-        if (!columns.contains(i.key())) {
-            DEB(i.key() << "Not in column list for table " << table << ". Discarding.");
-            badkeys << i.key();
-        }
-    }
-    for (const auto &var : badkeys) {
-        newData.remove(var);
-    }
-    data = newData;
-    position.first = table;
-    position.second = 0;
-}

+ 0 - 36
src/classes/flight.h

@@ -1,36 +0,0 @@
-/*
- *openPilot Log - A FOSS Pilot Logbook Application
- *Copyright (C) 2020  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/>.
- */
-#ifndef FLIGHT_H
-#define FLIGHT_H
-
-#include <QCoreApplication>
-#include <QDateTime>
-#include <QDebug>
-#include "src/database/entry_deprecated.h"
-
-
-class Flight : public Entry_deprecated
-{
-//    using Entry::Entry;
-public:
-    Flight();
-    Flight(int flight_id);
-    Flight(QMap<QString, QString> newData);
-};
-
-#endif // FLIGHT_H

+ 0 - 88
src/classes/pilot.cpp

@@ -1,88 +0,0 @@
-/*
- *openPilot Log - A FOSS Pilot Logbook Application
- *Copyright (C) 2020  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 "pilot.h"
-#include "src/testing/adebug.h"
-
-
-
-Pilot::Pilot()
-{
-
-}
-
-Pilot::Pilot(int pilot_id)
-{
-    //retreive database layout
-    const auto dbContent = DbInfo();
-    auto table = QLatin1String("pilots");
-
-    //Check database for row id
-    QString statement = "SELECT COUNT(*) FROM " + table + " WHERE _rowid_=" + QString::number(pilot_id);
-    QSqlQuery q(statement);
-    q.next();
-    int rows = q.value(0).toInt();
-    if (rows == 0) {
-        DEB("No Entry found for row id: " << pilot_id );
-        position.second = 0;
-    } else {
-        DEB("Retreiving data for row id: " << pilot_id);
-        QString statement = "SELECT * FROM " + table + " WHERE _rowid_=" + QString::number(pilot_id);
-
-        QSqlQuery q(statement);
-        q.exec();
-        q.next();
-        for (int i = 0; i < dbContent.format.value(table).length(); i++) {
-            data.insert(dbContent.format.value(table)[i], q.value(i).toString());
-        }
-
-        error = q.lastError().text();
-        if (error.length() > 2) {
-            DEB("Error: " << q.lastError().text());
-            position.second = 0;
-            position.first = "invalid";
-        } else {
-            position.second = pilot_id;
-            position.first = "pilots";
-        }
-    }
-}
-
-Pilot::Pilot(QMap<QString, QString> newData)
-{
-    QString table = "pilots";
-
-    //retreive database layout
-    const auto dbContent = DbInfo();
-    columns = dbContent.format.value(table);
-
-    //Check validity of newData
-    QVector<QString> badkeys;
-    QMap<QString, QString>::iterator i;
-    for (i = newData.begin(); i != newData.end(); ++i) {
-        if (!columns.contains(i.key())) {
-            DEB(i.key() << "Not in column list for table " << table << ". Discarding.");
-            badkeys << i.key();
-        }
-    }
-    for (const auto &var : badkeys) {
-        newData.remove(var);
-    }
-    data = newData;
-    position.first = table;
-    position.second = 0;
-}

+ 0 - 32
src/classes/pilot.h

@@ -1,32 +0,0 @@
-/*
- *openPilot Log - A FOSS Pilot Logbook Application
- *Copyright (C) 2020  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/>.
- */
-#ifndef PILOT_H
-#define PILOT_H
-#include "src/database/entry_deprecated.h"
-
-
-class Pilot : public Entry_deprecated
-{
-//    using Entry::Entry;
-public:
-    Pilot();
-    Pilot(int pilot_id);
-    Pilot(QMap<QString, QString> newData);
-};
-
-#endif // PILOT_H

+ 124 - 92
src/experimental/adatabase.cpp → src/database/adatabase.cpp

@@ -16,9 +16,11 @@
  *along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 #include "adatabase.h"
-#include "src/database/tablecolumnliterals.h"
+#include "src/testing/adebug.h"
+#include "src/astandardpaths.h"
 
-namespace experimental {
+#define DATABASE_VERSION 15
+const auto SQL_DRIVER = QStringLiteral("QSQLITE");
 
 ADatabaseError::ADatabaseError(QString msg_)
     : QSqlError::QSqlError(msg_)
@@ -31,6 +33,16 @@ QString ADatabaseError::text() const
 
 ADatabase* ADatabase::instance = nullptr;
 
+TableNames ADatabase::getTableNames() const
+{
+    return tableNames;
+}
+
+TableColumns ADatabase::getTableColumns() const
+{
+    return tableColumns;
+}
+
 ADatabase* ADatabase::getInstance()
 {
     if(!instance)
@@ -38,24 +50,37 @@ ADatabase* ADatabase::getInstance()
     return instance;
 }
 
-bool ADatabase::connect()
+/*!
+ * \brief ADatabase::sqliteVersion returns database sqlite version.
+ * \return sqlite version string
+ */
+const QString ADatabase::sqliteVersion()
 {
-    const QString driver("QSQLITE");
+    QSqlQuery query;
+    query.prepare(QStringLiteral("SELECT sqlite_version()"));
+    query.exec();
+    query.next();
+    return query.value(0).toString();
+}
 
-    if (!QSqlDatabase::isDriverAvailable(driver))
+bool ADatabase::connect()
+{
+    if (!QSqlDatabase::isDriverAvailable(SQL_DRIVER))
         return false;
 
-    QDir directory("data");
-    QString databaseLocation = directory.filePath("logbook.db");
-    QSqlDatabase db = QSqlDatabase::addDatabase(driver);
+    QString path = AStandardPaths::getPath(QStandardPaths::AppDataLocation);
+    QDir directory(path);
+    // [G]: Where would it make sense to define the database file?. In the class perhaps?
+    QString databaseLocation = directory.filePath(QStringLiteral("logbook.db"));
+    QSqlDatabase db = QSqlDatabase::addDatabase(SQL_DRIVER);
     db.setDatabaseName(databaseLocation);
 
     if (!db.open())
         return false;
 
-    DEB("Database connection established.");
+    DEB << "Database connection established." << db.lastError().text();
     // Enable foreign key restrictions
-    QSqlQuery query("PRAGMA foreign_keys = ON;");
+    QSqlQuery query(QStringLiteral("PRAGMA foreign_keys = ON;"));
     tableNames = db.tables();
 
     QStringList column_names;
@@ -67,8 +92,8 @@ bool ADatabase::connect()
             tableColumns.insert(table, column_names);
         }
     }
-    DEB("Database Tables: " << tableNames);
-    DEB("Tables and Columns: " << tableColumns);
+    DEB << "Database Tables: " << tableNames;
+    DEB << "Tables and Columns: " << tableColumns;
     return true;
 }
 
@@ -76,13 +101,12 @@ void ADatabase::disconnect()
 {
     auto db = ADatabase::database();
     db.close();
-    db.removeDatabase(db.connectionName());
-    DEB("Database connection closed.");
+    DEB << "Database connection closed.";
 }
 
 QSqlDatabase ADatabase::database()
 {
-    return QSqlDatabase::database("qt_sql_default_connection");
+    return QSqlDatabase::database(QStringLiteral("qt_sql_default_connection"));
 }
 
 bool ADatabase::commit(AEntry entry)
@@ -97,8 +121,8 @@ bool ADatabase::commit(AEntry entry)
 bool ADatabase::remove(AEntry entry)
 {
     if (!exists(entry)) {
-        DEB("Error: Database entry not found.");
-        lastError = ADatabaseError("Database entry not found.");
+        DEB << "Error: Database entry not found.";
+        lastError = ADatabaseError(QStringLiteral("Database entry not found."));
         return false;
     }
 
@@ -112,14 +136,14 @@ bool ADatabase::remove(AEntry entry)
 
     if (query.lastError().type() == QSqlError::NoError)
     {
-        DEB("Entry " << entry.getPosition().tableName << entry.getPosition().rowId << " removed.");
+        DEB << "Entry " << entry.getPosition() << " removed.";
         emit dataBaseUpdated();
         lastError = QString();
         return true;
     } else {
-        DEB("Unable to delete.");
-        DEB("Query: " << statement);
-        DEB("Query Error: " << query.lastError().text());
+        DEB << "Unable to delete.";
+        DEB << "Query: " << statement;
+        DEB << "Query Error: " << query.lastError().text();
         lastError = query.lastError().text();
         return false;
     }
@@ -129,7 +153,7 @@ bool ADatabase::removeMany(QList<DataPosition> data_position_list)
 {
     int errorCount = 0;
     QSqlQuery query;
-    query.prepare("BEGIN EXCLUSIVE TRANSACTION");
+    query.prepare(QStringLiteral("BEGIN EXCLUSIVE TRANSACTION"));
     query.exec();
 
     for (const auto& data_position : data_position_list) {
@@ -137,11 +161,11 @@ bool ADatabase::removeMany(QList<DataPosition> data_position_list)
             lastError = ADatabaseError("Database entry not found.");
             errorCount++;
         }
-        QString statement = "DELETE FROM " + data_position.first +
+        QString statement = "DELETE FROM " + data_position.tableName +
                 " WHERE ROWID=?";
 
         query.prepare(statement);
-        query.addBindValue(data_position.second);
+        query.addBindValue(data_position.rowId);
         query.exec();
 
         if (!(query.lastError().type() == QSqlError::NoError))
@@ -149,7 +173,7 @@ bool ADatabase::removeMany(QList<DataPosition> data_position_list)
     }
 
     if (errorCount == 0) {
-        query.prepare("COMMIT");
+        query.prepare(QStringLiteral("COMMIT"));
         query.exec();
         if(query.lastError().type() == QSqlError::NoError) {
             emit dataBaseUpdated();
@@ -160,7 +184,7 @@ bool ADatabase::removeMany(QList<DataPosition> data_position_list)
             return false;
         }
     } else {
-        query.prepare("ROLLBACK");
+        query.prepare(QStringLiteral("ROLLBACK"));
         query.exec();
         lastError = "Transaction unsuccessful (no changes have been made). Error count: " + QString::number(errorCount);
         return false;
@@ -169,7 +193,7 @@ bool ADatabase::removeMany(QList<DataPosition> data_position_list)
 
 bool ADatabase::exists(AEntry entry)
 {
-    if(entry.getPosition().second == 0)
+    if(entry.getPosition().rowId == 0)
         return false;
 
     //Check database for row id
@@ -183,7 +207,7 @@ bool ADatabase::exists(AEntry entry)
     //this returns either 1 or 0 since row ids are unique
     if (!query.isActive()) {
         lastError = query.lastError().text();
-        DEB("Query Error: " << query.lastError().text() << statement);
+        DEB << "Query Error: " << query.lastError().text() << statement;
         return false;
     }
     query.next();
@@ -191,37 +215,37 @@ bool ADatabase::exists(AEntry entry)
     if (rowId) {
         return true;
     } else {
-        DEB("Database entry not found.");
-        lastError = ADatabaseError("Database entry not found.");
+        DEB << "Database entry not found.";
+        lastError = ADatabaseError(QStringLiteral("Database entry not found."));
         return false;
     }
 }
 
 bool ADatabase::exists(DataPosition data_position)
 {
-    if(data_position.second == 0)
+    if(data_position.rowId == 0)
         return false;
 
     //Check database for row id
-    QString statement = "SELECT COUNT(*) FROM " + data_position.first +
+    QString statement = "SELECT COUNT(*) FROM " + data_position.tableName +
             " WHERE ROWID=?";
     QSqlQuery query;
     query.prepare(statement);
-    query.addBindValue(data_position.second);
+    query.addBindValue(data_position.rowId);
     query.setForwardOnly(true);
     query.exec();
     //this returns either 1 or 0 since row ids are unique
     if (!query.isActive()) {
         lastError = query.lastError().text();
-        DEB("Query Error: " << query.lastError().text() << statement);
+        DEB << "Query Error: " << query.lastError().text() << statement;
     }
     query.next();
     int rowId = query.value(0).toInt();
     if (rowId) {
         return true;
     } else {
-        DEB("No entry exists at DataPosition: " << data_position);
-        lastError = ADatabaseError("Database entry not found.");
+        DEB << "No entry exists at DataPosition: " << data_position.tableName << data_position.rowId;
+        lastError = ADatabaseError(QStringLiteral("Database entry not found."));
         return false;
     }
 }
@@ -250,14 +274,14 @@ bool ADatabase::update(AEntry updated_entry)
 
     if (query.lastError().type() == QSqlError::NoError)
     {
-        DEB("Entry successfully committed.");
+        DEB << "Entry successfully committed.";
         emit dataBaseUpdated();
         lastError = QString();
         return true;
     } else {
-        DEB("Unable to commit.");
-        DEB("Query: " << statement);
-        DEB("Query Error: " << query.lastError().text());
+        DEB << "Unable to commit.";
+        DEB << "Query: " << statement;
+        DEB << "Query Error: " << query.lastError().text();
         lastError = query.lastError().text();
         return false;
     }
@@ -295,72 +319,72 @@ bool ADatabase::insert(AEntry new_entry)
     //check result.
     if (query.lastError().type() == QSqlError::NoError)
     {
-        DEB("Entry successfully committed.");
+        DEB << "Entry successfully committed.";
         emit dataBaseUpdated();
         lastError = QString();
         return true;
     } else {
-        DEB("Unable to commit.");
-        DEB("Query: " << statement);
-        DEB("Query Error: " << query.lastError().text());
+        DEB << "Unable to commit.";
+        DEB << "Query: " << statement;
+        DEB << "Query Error: " << query.lastError().text();
         lastError = query.lastError().text();
         return false;
     }
 
 }
 
-TableData ADatabase::getEntryData(DataPosition data_position)
+RowData ADatabase::getEntryData(DataPosition data_position)
 {
     // check table exists
-    if (!tableNames.contains(data_position.first)) {
-        DEB(data_position.first << " not a table in the database. Unable to retreive Entry data.");
-        return TableData();
+    if (!tableNames.contains(data_position.tableName)) {
+        DEB << data_position.tableName << " not a table in the database. Unable to retreive Entry data.";
+        return RowData();
     }
 
     //Check Database for rowId
-    QString statement = "SELECT COUNT(*) FROM " + data_position.first
+    QString statement = "SELECT COUNT(*) FROM " + data_position.tableName
                       + " WHERE ROWID=?";
     QSqlQuery check_query;
     check_query.prepare(statement);
-    check_query.addBindValue(data_position.second);
+    check_query.addBindValue(data_position.rowId);
     check_query.setForwardOnly(true);
     check_query.exec();
 
     if (check_query.lastError().type() != QSqlError::NoError) {
-        DEB("SQL error: " << check_query.lastError().text());
-        DEB("Statement: " << statement);
+        DEB << "SQL error: " << check_query.lastError().text();
+        DEB << "Statement: " << statement;
         lastError = check_query.lastError().text();
-        return TableData();
+        return RowData();
     }
 
     check_query.next();
     if (check_query.value(0).toInt() == 0) {
-        DEB("No Entry found for row id: " << data_position.second );
+        DEB << "No Entry found for row id: " << data_position.rowId;
         lastError = ADatabaseError("Database entry not found.");
-        return TableData();
+        return RowData();
     }
 
     // Retreive TableData
-    statement = "SELECT * FROM " + data_position.first
+    statement = "SELECT * FROM " + data_position.tableName
               + " WHERE ROWID=?";
 
     QSqlQuery select_query;
     select_query.prepare(statement);
-    select_query.addBindValue(data_position.second);
+    select_query.addBindValue(data_position.rowId);
     select_query.setForwardOnly(true);
     select_query.exec();
 
     if (select_query.lastError().type() != QSqlError::NoError) {
-        DEB("SQL error: " << select_query.lastError().text());
-        DEB("Statement: " << statement);
+        DEB << "SQL error: " << select_query.lastError().text();
+        DEB << "Statement: " << statement;
         lastError = select_query.lastError().text();
-        return TableData();
+        return RowData();
     }
 
     select_query.next();
-    TableData entry_data;
+    RowData entry_data;
 
-    for (const auto &column : tableColumns.value(data_position.first)) {
+    for (const auto &column : tableColumns.value(data_position.tableName)) {
         entry_data.insert(column, select_query.value(column));
     }
     return entry_data;
@@ -407,24 +431,24 @@ const QStringList ADatabase::getCompletionList(ADatabaseTarget target)
 
     switch (target) {
     case ADatabaseTarget::pilots:
-        statement.append("SELECT lastname||', '||firstname FROM pilots");
+        statement.append(QStringLiteral("SELECT lastname||', '||firstname FROM pilots"));
         break;
     case ADatabaseTarget::aircraft:
-        statement.append("SELECT make||' '||model FROM aircraft WHERE model IS NOT NULL "
+        statement.append(QStringLiteral("SELECT make||' '||model FROM aircraft WHERE model IS NOT NULL "
                          "UNION "
-                         "SELECT make||' '||model||'-'||variant FROM aircraft WHERE variant IS NOT NULL");
+                         "SELECT make||' '||model||'-'||variant FROM aircraft WHERE variant IS NOT NULL"));
         break;
     case ADatabaseTarget::airport_identifier_all:
-        statement.append("SELECT icao FROM airports UNION SELECT iata FROM airports");
+        statement.append(QStringLiteral("SELECT icao FROM airports UNION SELECT iata FROM airports"));
         break;
     case ADatabaseTarget::registrations:
-        statement.append("SELECT registration FROM tails");
+        statement.append(QStringLiteral("SELECT registration FROM tails"));
         break;
     case ADatabaseTarget::companies:
-        statement.append("SELECT company FROM pilots");
+        statement.append(QStringLiteral("SELECT company FROM pilots"));
         break;
     default:
-        DEB("Not a valid completer target for this function.");
+        DEB << "Not a valid completer target for this function.";
         return QStringList();
     }
 
@@ -455,36 +479,36 @@ const QMap<QString, int> ADatabase::getIdMap(ADatabaseTarget target)
 
     switch (target) {
     case ADatabaseTarget::pilots:
-        statement.append("SELECT ROWID, lastname||', '||firstname FROM pilots");
+        statement.append(QStringLiteral("SELECT ROWID, lastname||', '||firstname FROM pilots"));
         break;
     case ADatabaseTarget::aircraft:
-        statement.append("SELECT ROWID, make||' '||model FROM aircraft WHERE model IS NOT NULL "
+        statement.append(QStringLiteral("SELECT ROWID, make||' '||model FROM aircraft WHERE model IS NOT NULL "
                          "UNION "
-                         "SELECT ROWID, make||' '||model||'-'||variant FROM aircraft WHERE variant IS NOT NULL");
+                         "SELECT ROWID, make||' '||model||'-'||variant FROM aircraft WHERE variant IS NOT NULL"));
         break;
     case ADatabaseTarget::airport_identifier_icao:
-        statement.append("SELECT ROWID, icao FROM airports");
+        statement.append(QStringLiteral("SELECT ROWID, icao FROM airports"));
         break;
     case ADatabaseTarget::airport_identifier_iata:
-        statement.append("SELECT ROWID, iata FROM airports WHERE iata NOT NULL");
+        statement.append(QStringLiteral("SELECT ROWID, iata FROM airports WHERE iata NOT NULL"));
         break;
     case ADatabaseTarget::airport_names:
-        statement.append("SELECT ROWID, name FROM airports");
+        statement.append(QStringLiteral("SELECT ROWID, name FROM airports"));
         break;
     case ADatabaseTarget::tails:
-        statement.append("SELECT ROWID, registration FROM tails");
+        statement.append(QStringLiteral("SELECT ROWID, registration FROM tails"));
         break;
     default:
-        DEB("Not a valid completer target for this function.");
+        DEB << "Not a valid completer target for this function.";
         return QMap<QString, int>();
     }
 
     auto id_map = QMap<QString, int>();
     auto query = QSqlQuery(statement);
     if (!query.isActive()) {
-        DEB("No result found. Check Query and Error.");
-        DEB("Query: " << statement);
-        DEB("Error: " << query.lastError().text());
+        DEB << "No result found. Check Query and Error.";
+        DEB << "Query: " << statement;
+        DEB << "Error: " << query.lastError().text();
         lastError = query.lastError().text();
         return QMap<QString, int>();
     } else {
@@ -511,15 +535,15 @@ int ADatabase::getLastEntry(ADatabaseTarget target)
         statement.append(DB_TABLE_TAILS);
         break;
     default:
-        DEB("Not a valid completer target for this function.");
+        DEB << "Not a valid completer target for this function.";
         return 0;
     }
     auto query = QSqlQuery(statement);
     if (query.first()) {
         return query.value(0).toInt();
     } else {
-        lastError = ADatabaseError("Database entry not found.");
-        DEB("No entry found.");
+        lastError = ADatabaseError(QStringLiteral("Database entry not found."));
+        DEB << "No entry found.";
         return 0;
     }
 }
@@ -536,7 +560,7 @@ QList<int> ADatabase::getForeignKeyConstraints(int foreign_row_id, ADatabaseTarg
         statement.append("acft=?");
         break;
     default:
-        DEB("Not a valid target for this function.");
+        DEB << "Not a valid target for this function.";
         return QList<int>();
         break;
     }
@@ -548,9 +572,9 @@ QList<int> ADatabase::getForeignKeyConstraints(int foreign_row_id, ADatabaseTarg
 
     if (!query.isActive()) {
         lastError = query.lastError().text();
-        DEB("Error");
-        DEB(statement);
-        DEB(query.lastError().text());
+        DEB << "Error";
+        DEB << statement;
+        DEB << query.lastError().text();
         return QList<int>();
     }
 
@@ -561,15 +585,25 @@ QList<int> ADatabase::getForeignKeyConstraints(int foreign_row_id, ADatabaseTarg
     return row_ids;
 }
 
+APilotEntry ADatabase::resolveForeignPilot(int foreign_key)
+{
+    return aDB()->getPilotEntry(foreign_key);
+}
+
+ATailEntry ADatabase::resolveForeignTail(int foreign_key)
+{
+    return aDB()->getTailEntry(foreign_key);
+}
+
 QVector<QString> ADatabase::customQuery(QString statement, int return_values)
 {
     QSqlQuery query(statement);
     query.exec();
 
     if (!query.first()) {
-        DEB("No result found. Check Query and Error.");
-        DEB("Error: " << query.lastError().text());
-        DEB("Statement: " << statement);
+        DEB << "No result found. Check Query and Error.";
+        DEB << "Error: " << query.lastError().text();
+        DEB << "Statement: " << statement;
         lastError = query.lastError().text();
         return QVector<QString>();
     } else {
@@ -588,5 +622,3 @@ QVector<QString> ADatabase::customQuery(QString statement, int return_values)
 }
 
 ADatabase* aDB() { return ADatabase::getInstance(); }
-
-}// namespace experimental

+ 37 - 20
src/experimental/adatabase.h → src/database/adatabase.h

@@ -15,41 +15,42 @@
  *You should have received a copy of the GNU General Public License
  *along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
-#ifndef __DB_H__
-#define __DB_H__
+#ifndef ADATABASE_H
+#define ADATABASE_H
 
 #include <QPair>
 #include <QMap>
 #include <QString>
+#include <QDir>
+#include <QSqlDatabase>
+#include <QSqlDriver>
 #include <QSqlQuery>
 #include <QSqlError>
 #include <QSqlTableModel>
-#include "src/database/dbinfo.h"
-#include "src/testing/adebug.h"
-
-#include "aentry.h"
-#include "apilotentry.h"
-#include "atailentry.h"
-#include "aaircraftentry.h"
-#include "aflightentry.h"
-
-namespace experimental {
+#include <QSqlQuery>
+#include <QSqlRecord>
+#include <QSqlField>
 
+#include "src/database/declarations.h"
+#include "src/classes/aentry.h"
+#include "src/classes/apilotentry.h"
+#include "src/classes/atailentry.h"
+#include "src/classes/aaircraftentry.h"
+#include "src/classes/aflightentry.h"
 
-// [G]: Suspicious documentation -,O
 /*!
- * \brief The DBTarget enum provides the items for which QCompleter
- * completion lists are provided from the database.
+ * \brief The DBTarget enum lists database items that are
+ * used by completers, for content matching or need to be accessed programatically.
  */
 enum class ADatabaseTarget
 {
+    aircraft,
     airport_identifier_icao,
     airport_identifier_iata,
     airport_identifier_all,
     airport_names,
     pilots,
     registrations,
-    aircraft,
     companies,
     tails
 };
@@ -84,6 +85,10 @@ public:
     ADatabase(const ADatabase&) = delete;
     void operator=(const ADatabase&) = delete;
     static ADatabase* getInstance();
+    TableNames getTableNames() const;
+    TableColumns getTableColumns() const;
+    const QString sqliteVersion();
+
     ADatabaseError lastError;
 
     /*!
@@ -145,7 +150,7 @@ public:
     /*!
      * \brief retreive entry data from the database to create an entry object
      */
-    TableData getEntryData(DataPosition data_position);
+    RowData getEntryData(DataPosition data_position);
 
     /*!
      * \brief retreive an Entry from the database.
@@ -215,6 +220,20 @@ public:
      */
     QList<int> getForeignKeyConstraints(int foreign_row_id, ADatabaseTarget target);
 
+    /*!
+     * \brief Resolves the foreign key in a flight entry
+     * \return The Pilot Entry referencted by the foreign key.
+     */
+    APilotEntry resolveForeignPilot(int foreign_key);
+
+    /*!
+     * \brief Resolves the foreign key in a flight entry
+     * \return The Tail Entry referencted by the foreign key.
+     */
+    ATailEntry resolveForeignTail(int foreign_key);
+
+
+
 signals:
     /*!
      * \brief updated is emitted whenever the database contents have been updated.
@@ -234,6 +253,4 @@ signals:
  */
 ADatabase* aDB();
 
-}  // namespace experimental
-
-#endif
+#endif // ADATABASE_H

+ 57 - 57
src/database/adatabasesetup.cpp

@@ -16,12 +16,14 @@
  *along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 #include "adatabasesetup.h"
+#include "src/database/adatabase.h"
 #include "src/testing/adebug.h"
+#include "src/functions/areadcsv.h"
 
 
-// Statements for creation of database tables, Revision 13
+// Statements for creation of database tables, Revision 15
 
-const QString createTablePilots = "CREATE TABLE pilots ( "
+const auto createTablePilots = QStringLiteral("CREATE TABLE pilots ( "
             " pilot_id       INTEGER NOT NULL, "
             " lastname       TEXT    NOT NULL, "
             " firstname      TEXT, "
@@ -31,9 +33,9 @@ const QString createTablePilots = "CREATE TABLE pilots ( "
             " phone          TEXT, "
             " email          TEXT, "
             " PRIMARY KEY(pilot_id AUTOINCREMENT)"
-            ")";
+            ")");
 
-const QString createTableTails = "CREATE TABLE tails ("
+const auto createTableTails = QStringLiteral("CREATE TABLE tails ("
             " tail_id        INTEGER NOT NULL,"
             " registration   TEXT NOT NULL,"
             " company        TEXT,"
@@ -45,9 +47,9 @@ const QString createTableTails = "CREATE TABLE tails ("
             " engineType     INTEGER,"
             " weightClass    INTEGER,"
             " PRIMARY KEY(tail_id AUTOINCREMENT)"
-            ")";
+            ")");
 
-const QString createTableFlights = "CREATE TABLE flights ("
+const auto createTableFlights = QStringLiteral("CREATE TABLE flights ("
             " flight_id      INTEGER NOT NULL, "
             " doft           NUMERIC NOT NULL, "
             " dept           TEXT NOT NULL, "
@@ -82,9 +84,9 @@ const QString createTableFlights = "CREATE TABLE flights ("
             " FOREIGN KEY(pic)  REFERENCES pilots(pilot_id) ON DELETE RESTRICT, "
             " FOREIGN KEY(acft) REFERENCES tails(tail_id)   ON DELETE RESTRICT, "
             " PRIMARY KEY(flight_id    AUTOINCREMENT) "
-        ")";
+        ")");
 
-const QString createTableAirports = "CREATE TABLE airports ( "
+const auto createTableAirports = QStringLiteral("CREATE TABLE airports ( "
             " airport_id     INTEGER NOT NULL, "
             " icao           TEXT NOT NULL, "
             " iata           TEXT, "
@@ -96,9 +98,9 @@ const QString createTableAirports = "CREATE TABLE airports ( "
             " utcoffset      INTEGER, "
             " tzolson        TEXT, "
             " PRIMARY KEY(airport_id AUTOINCREMENT) "
-            ")";
+            ")");
 
-const QString createTableAircraft = "CREATE TABLE aircraft ("
+const auto createTableAircraft = QStringLiteral("CREATE TABLE aircraft ("
             " aircraft_id   INTEGER NOT NULL,"
             " make          TEXT,"
             " model         TEXT,"
@@ -111,17 +113,17 @@ const QString createTableAircraft = "CREATE TABLE aircraft ("
             " engineType    INTEGER,"
             " weightClass   INTEGER,"
             " PRIMARY KEY(aircraft_id AUTOINCREMENT)"
-            ")";
+            ")");
 
-const QString createTableChangelog = "CREATE TABLE changelog ( "
+const auto createTableChangelog = QStringLiteral("CREATE TABLE changelog ( "
             " revision   INTEGER NOT NULL, "
             " comment    TEXT, "
             " date       NUMERIC, "
             " PRIMARY KEY(revision) "
-            ")";
+            ")");
 
 // Statements for creation of views in the database
-const QString createViewDefault = "CREATE VIEW viewDefault AS "
+const auto createViewDefault = QStringLiteral("CREATE VIEW viewDefault AS "
         " SELECT flight_id, doft as 'Date', "
         " dept AS 'Dept', "
         " printf('%02d',(tofb/60))||':'||printf('%02d',(tofb%60)) AS 'Time', "
@@ -139,9 +141,9 @@ const QString createViewDefault = "CREATE VIEW viewDefault AS "
         " FROM flights "
         " INNER JOIN pilots on flights.pic = pilots.pilot_id "
         " INNER JOIN tails on flights.acft = tails.tail_id "
-        " ORDER BY date DESC ";
+        " ORDER BY date DESC ");
 
-const QString createViewEASA = "CREATE VIEW viewEASA AS "
+const auto createViewEASA = QStringLiteral("CREATE VIEW viewEASA AS "
         " SELECT "
         " flight_id, doft as 'Date', "
         " dept AS 'Dept', "
@@ -170,9 +172,9 @@ const QString createViewEASA = "CREATE VIEW viewEASA AS "
         " FROM flights "
         " INNER JOIN pilots on flights.pic = pilots.pilot_id "
         " INNER JOIN tails on flights.acft = tails.tail_id "
-        " ORDER BY date DESC";
+        " ORDER BY date DESC");
 
-const QString createViewTails = "CREATE VIEW viewTails AS "
+const auto createViewTails = QStringLiteral("CREATE VIEW viewTails AS "
         " SELECT "
         " tail_id AS 'ID', "
         " registration AS 'Registration', "
@@ -185,24 +187,24 @@ const QString createViewTails = "CREATE VIEW viewTails AS "
         " registration AS 'Registration', "
         " make||' '||model||'-'||variant AS 'Type', "
         " company AS 'Company' "
-        " FROM tails WHERE variant IS NOT NULL";
+        " FROM tails WHERE variant IS NOT NULL");
 
-const QString createViewPilots = "CREATE VIEW viewPilots AS "
+const auto createViewPilots = QStringLiteral("CREATE VIEW viewPilots AS "
         " SELECT "
         " pilot_id AS 'ID', "
         " lastname AS 'Last Name', "
         " firstname AS 'First Name', "
         " company AS 'Company' "
-        " FROM pilots";
+        " FROM pilots");
 
-const QString createViewQCompleter = "CREATE VIEW viewQCompleter AS "
+const auto createViewQCompleter = QStringLiteral("CREATE VIEW viewQCompleter AS "
         " SELECT airport_id, icao, iata, tail_id, registration, pilot_id, "
         " lastname||', '||firstname AS 'pilot_name', alias "
         " FROM airports "
         " LEFT JOIN tails ON airports.airport_id = tails.tail_id "
-        " LEFT JOIN pilots ON airports.airport_id = pilots.pilot_id";
+        " LEFT JOIN pilots ON airports.airport_id = pilots.pilot_id");
 
-const QString createViewTotals = "CREATE VIEW viewTotals AS "
+const auto createViewTotals = QStringLiteral("CREATE VIEW viewTotals AS "
         " SELECT "
         " printf(\"%02d\",CAST(SUM(tblk) AS INT)/60)||\":\"||printf(\"%02d\",CAST(SUM(tblk) AS INT)%60) AS \"TOTAL\", "
         " printf(\"%02d\",CAST(SUM(tSPSE) AS INT)/60)||\":\"||printf(\"%02d\",CAST(SUM(tSPSE) AS INT)%60) AS \"SP SE\", "
@@ -218,14 +220,7 @@ const QString createViewTotals = "CREATE VIEW viewTotals AS "
         " printf(\"%02d\",CAST(SUM(tMP) AS INT)/60)||\":\"||printf(\"%02d\",CAST(SUM(tMP) AS INT)%60) AS \"MultPilot\", "
         " CAST(SUM(toDay) AS INT) AS \"TO Day\", CAST(SUM(toNight) AS INT) AS \"TO Night\", "
         " CAST(SUM(ldgDay) AS INT) AS \"LDG Day\", CAST(SUM(ldgNight) AS INT) AS \"LDG Night\" "
-        " FROM flights";
-
-/*const QString createViewPilotsTailsMap = "CREATE VIEW viewPilotsTailsMap AS "
-        "SELECT "
-        "pilot_id, lastname, firstname, tail_id, registration "
-        "FROM pilots "
-        "LEFT JOIN tails "
-        "ON pilots.pilot_id = tails.tail_id";*/
+        " FROM flights");
 
 const QStringList tables = {
     createTablePilots,
@@ -257,25 +252,29 @@ const QStringList templateTables= {
 
 bool ADataBaseSetup::createDatabase()
 {
-    DEB("Creating tables...");
+
+    DEB << "Creating tables...";
     if (!createSchemata(tables)) {
-        DEB("Creating tables has failed.");
+        DEB << "Creating tables has failed.";
         return false;
     }
 
-    DEB("Creating views...");
+    DEB << "Creating views...";
     if (!createSchemata(views)) {
-        DEB("Creating views failed.");
+        DEB << "Creating views failed.";
         return false;
     }
 
-    DEB("Populating tables...");
+    // call connect again to (re-)populate tableNames and columnNames
+    aDB()->connect();
+
+    DEB << "Populating tables...";
     if (!importDefaultData()) {
-        DEB("Populating tables failed.");
+        DEB << "Populating tables failed.";
         return false;
     }
 
-    DEB("Database successfully created!");
+    DEB << "Database successfully created!";
     return true;
 }
 
@@ -288,11 +287,11 @@ bool ADataBaseSetup::importDefaultData()
         //clear tables
         query.prepare("DELETE FROM " + table);
         if (!query.exec()) {
-            DEB("Error: " << query.lastError().text());
+            DEB << "Error: " << query.lastError().text();
         }
         //fill with data from csv
         if (!commitData(aReadCsv("data/templates/" + table + ".csv"), table)) {
-            DEB("Error importing data.");
+            DEB << "Error importing data.";
             return false;
         }
     }
@@ -311,7 +310,7 @@ bool ADataBaseSetup::resetToDefault()
     for (const auto& table : userTables) {
         query.prepare("DELETE FROM " + table);
         if (!query.exec()) {
-            DEB("Error: " << query.lastError().text());
+            DEB << "Error: " << query.lastError().text();
         }
     }
     return true;
@@ -322,7 +321,7 @@ bool ADataBaseSetup::resetToDefault()
  */
 void ADataBaseSetup::debug()
 {
-    DEB("Database tables and views: ");
+    DEB << "Database tables and views: ";
     QSqlQuery query;
     const QVector<QString> types = { "table", "view" };
     for (const auto& var : types){
@@ -332,7 +331,7 @@ void ADataBaseSetup::debug()
             QString table = query.value(0).toString();
             QSqlQuery entries("SELECT COUNT(*) FROM " + table);
             entries.next();
-            DEB("Element " << query.value(0).toString()) << "with"
+            DEB << "Element " << query.value(0).toString() << "with"
                 << entries.value(0).toString() << "rows";
         }
     }
@@ -352,19 +351,20 @@ bool ADataBaseSetup::createSchemata(const QStringList &statements)
         query.exec();
         if(!query.isActive()) {
             errors << statement.section(QLatin1Char(' '),2,2) + " ERROR - " + query.lastError().text();
+            DEB << "Query: " << query.lastQuery();
         } else {
-            DEB("Schema added: " << statement.section(QLatin1Char(' '),2,2));
+            DEB << "Schema added: " << statement.section(QLatin1Char(' '),2,2);
         }
     }
 
     if (!errors.isEmpty()) {
-        DEB("The following errors have ocurred: ");
+        DEB << "The following errors have ocurred: ";
         for (const auto& error : errors) {
-            DEB(error);
+            DEB << error;
         }
         return false;
     } else {
-        DEB("All schemas added successfully");
+        DEB << "All schemas added successfully";
         return true;
     }
 }
@@ -378,24 +378,24 @@ bool ADataBaseSetup::createSchemata(const QStringList &statements)
  */
 bool ADataBaseSetup::commitData(QVector<QStringList> fromCSV, const QString &tableName)
 {
-    DEB("Importing Data to" << tableName);
-    auto dbLayout = DbInfo();
-    if (!dbLayout.tables.contains(tableName)){
-        DEB(tableName << "is not a table in the database. Aborting.");
-        DEB("Please check input data.");
+    DEB << "Table names: " << aDB()->getTableNames();
+    DEB << "Importing Data to" << tableName;
+    if (!aDB()->getTableNames().contains(tableName)){
+        DEB << tableName << "is not a table in the database. Aborting.";
+        DEB << "Please check input data.";
         return false;
     }
     // create insert statement
     QString statement = "INSERT INTO " + tableName + " (";
     QString placeholder = ") VALUES (";
     for (auto& csvColumn : fromCSV) {
-        if(dbLayout.format.value(tableName).contains(csvColumn.first())){
+        if(aDB()->getTableColumns().value(tableName).contains(csvColumn.first())) {
             statement += csvColumn.first() + ',';
             csvColumn.removeFirst();
             placeholder.append("?,");
         } else {
-            DEB(csvColumn.first() << "is not a column of " << tableName << "Aborting.");
-            DEB("Please check input data.");
+            DEB << csvColumn.first() << "is not a column of " << tableName << "Aborting.";
+            DEB << "Please check input data.";
             return false;
         }
     }
@@ -423,7 +423,7 @@ bool ADataBaseSetup::commitData(QVector<QStringList> fromCSV, const QString &tab
 
     query.exec("COMMIT;"); //commit transaction
     if (query.lastError().text().length() > 3) {
-        DEB("Error:" << query.lastError().text());
+        DEB << "Error:" << query.lastError().text();
         return false;
     } else {
         qDebug() << tableName << "Database successfully updated!";

+ 0 - 3
src/database/adatabasesetup.h

@@ -19,9 +19,6 @@
 #define DBSETUP_H
 
 #include <QCoreApplication>
-#include "src/database/db.h"
-#include "src/database/dbinfo.h"
-#include "src/functions/areadcsv.h"
 
 /*!
  * \brief The ADataBaseSetup class is responsible for the inital setup of the database when

+ 0 - 276
src/database/db.cpp

@@ -1,276 +0,0 @@
-/*
- *openPilot Log - A FOSS Pilot Logbook Application
- *Copyright (C) 2020  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 "db.h"
-#include "dbinfo.h"
-#include "src/testing/adebug.h"
-
-/*!
- * \brief Db::iconnect - see Db::connect
- */
-void Db::iconnect()
-{
-    const QString driver("QSQLITE");
-
-    if (QSqlDatabase::isDriverAvailable(driver)) {
-
-        QDir directory("data");
-        QString databaseLocation = directory.filePath("logbook.db");
-        QSqlDatabase db = QSqlDatabase::addDatabase(driver);
-        db.setDatabaseName(databaseLocation);
-
-        if (!db.open()) {
-            DEB("DatabaseConnect - ERROR: " << db.lastError().text());
-        } else {
-            DEB("Database connection established.");
-            //Enable foreign key restrictions
-            QSqlQuery query("PRAGMA foreign_keys = ON;");
-        }
-    } else {
-        DEB("DatabaseConnect - ERROR: no driver " << driver << " available");
-    }
-}
-
-void Db::idisconnect()
-{
-    auto db = Db::Database();
-    db.close();
-    db.removeDatabase(db.connectionName());
-    DEB("Database connection closed.");
-}
-
-QSqlDatabase Db::iDatabase()
-{
-    auto db = QSqlDatabase::database("qt_sql_default_connection");
-    return db;
-}
-/*!
- * \brief Db::iexists - see Db::exists
- */
-bool Db::iexists(QString column, QString table, QString checkColumn, QString value,
-                Db::matchType match)
-{
-    bool output = false;
-    QString statement = "SELECT " + column + " FROM " + table + " WHERE " + checkColumn;
-
-    switch (match) {
-    case Db::exactMatch:
-        statement += " = '" + value + QLatin1Char('\'');
-        break;
-    case Db::partialMatch:
-        value.append(QLatin1Char('%'));
-        value.prepend(QLatin1Char('%'));
-        statement.append(" LIKE '" + value + QLatin1Char('\''));
-        break;
-    }
-
-
-    QSqlQuery q(statement);
-    q.exec();
-
-    if (!q.first()) {
-        DEB("No result found. Check Query and Error.");
-        DEB("Error: " << q.lastError().text());
-    } else {
-        output = true;
-        if (q.next()) {
-            DEB("More than one result in Database for your query");
-        }
-    }
-// Debug:
-    q.first();
-    q.previous();
-    while (q.next()) {
-        DEB("Query result: " << q.value(0).toString());
-    }
-// end of Debug
-    return output;
-}
-
-/*!
- * \brief Db::isingleSelect - see Db::singleSelect
- */
-QString Db::isingleSelect(QString column, QString table, QString checkColumn, QString value,
-                         Db::matchType match)
-{
-    QString statement = "SELECT " + column + " FROM " + table + " WHERE " + checkColumn;
-    QString result;
-
-    switch (match) {
-    case Db::exactMatch:
-        statement += " = '" + value + QLatin1Char('\'');
-        break;
-    case Db::partialMatch:
-        value.append(QLatin1Char('%'));
-        value.prepend(QLatin1Char('%'));
-        statement.append(" LIKE '" + value + QLatin1Char('\''));
-        break;
-    }
-
-    QSqlQuery q(statement);
-    q.exec();
-
-    if (!q.first()) {
-        DEB("No result found. Check Query and Error.");
-        DEB("Error: " << q.lastError().text());
-        return QString();
-    } else {
-        result.append(q.value(0).toString());
-        if (q.next()) {
-            DEB("More than one result in Database for your query");
-        }
-        return result;
-    }
-}
-
-/*!
- * \brief Db::imultiSelect - see Db::multiSelect
- */
-QVector<QString> Db::imultiSelect(QVector<QString> columns, QString table, QString checkColumn,
-                                 QString value, Db::matchType match)
-{
-    QString statement = "SELECT ";
-    for (const auto &column : columns) {
-        statement.append(column);
-        if (column != columns.last()) {
-            statement.append(QLatin1String(", "));
-        }
-    }
-    statement.append(" FROM " + table + " WHERE " + checkColumn);
-
-    switch (match) {
-    case Db::exactMatch:
-        statement += " = '" + value + QLatin1Char('\'');
-        break;
-    case Db::partialMatch:
-        value.append(QLatin1Char('%'));
-        value.prepend(QLatin1Char('%'));
-        statement.append(" LIKE '" + value + QLatin1Char('\''));
-        break;
-    }
-
-    QSqlQuery q(statement);
-    q.exec();
-
-    if (!q.first()) {
-        DEB("No result found. Check Query and Error.");
-        DEB("Error: " << q.lastError().text());
-        return QVector<QString>();
-    } else {
-        q.first();
-        q.previous();
-        QVector<QString> result;
-        while (q.next()) {
-            for (int i = 0; i < columns.size() ; i++) {
-                result.append(q.value(i).toString());
-            }
-        }
-        return result;
-    }
-}
-
-/*!
- * \brief Db::imultiSelect - see Db::multiSelect
- */
-QVector<QString> Db::imultiSelect(QVector<QString> columns, QString table)
-{
-    QString statement = "SELECT ";
-    for (const auto &column : columns) {
-        statement.append(column);
-        if (column != columns.last()) {
-            statement.append(QLatin1String(", "));
-        }
-    }
-    statement.append(" FROM " + table);
-
-    QSqlQuery q(statement);
-    q.exec();
-
-    if (!q.first()) {
-        DEB("No result found. Check Query and Error.");
-        DEB("Error: " << q.lastError().text());
-        return QVector<QString>();
-    } else {
-        q.first();
-        q.previous();
-        QVector<QString> result;
-        while (q.next()) {
-            for (int i = 0; i < columns.size() ; i++) {
-                result.append(q.value(i).toString());
-            }
-        }
-        return result;
-    }
-}
-
-/*!
- * \brief Db::isingleUpdate - see Db::singleUpdate
- */
-bool Db::isingleUpdate(QString table, QString column, QString value, QString checkColumn,
-                      QString checkvalue, Db::matchType match)
-{
-    QString statement = "UPDATE " + table;
-    statement.append(QLatin1String(" SET ") + column + QLatin1String(" = '") + value);
-    statement.append(QLatin1String("' WHERE "));
-
-    switch (match) {
-    case Db::exactMatch:
-        statement.append(checkColumn + " = '" + checkvalue + QLatin1Char('\''));
-        break;
-    case Db::partialMatch:
-        value.append(QLatin1Char('%'));
-        value.prepend(QLatin1Char('%'));
-        statement.append(checkColumn + " LIKE '" + checkvalue + QLatin1Char('\''));
-        break;
-    }
-
-    QSqlQuery q(statement);
-    q.exec();
-    QString error = q.lastError().text();
-
-    if (error.length() > 1) {
-        DEB("Errors have occured: " << error);
-        return false;
-    } else {
-        DEB("Success!");
-        return true;
-    }
-}
-/*!
- * \brief Db::icustomQuery - see Db::customQuery
- */
-QVector<QString> Db::icustomQuery(QString query, int returnValues)
-{
-    QSqlQuery q(query);
-    q.exec();
-
-    if (!q.first()) {
-        DEB("No result found. Check Query and Error.");
-        DEB("Error: " << q.lastError().text());
-        return QVector<QString>();
-    } else {
-        q.first();
-        q.previous();
-        QVector<QString> result;
-        while (q.next()) {
-            for (int i = 0; i < returnValues ; i++) {
-                result.append(q.value(i).toString());
-            }
-        }
-        return result;
-    }
-}

+ 0 - 169
src/database/db.h

@@ -1,169 +0,0 @@
-/*
- *openPilot Log - A FOSS Pilot Logbook Application
- *Copyright (C) 2020  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/>.
- */
-#ifndef DB_H
-#define DB_H
-
-#include <QCoreApplication>
-#include <QSqlDatabase>
-#include <QSqlDriver>
-#include <QSqlError>
-#include <QSqlQuery>
-#include <QSqlRecord>
-#include <QSqlField>
-#include <QDir>
-#include <QDebug>
-
-/*!
- * \brief The Db class provides a basic API for accessing the database programatically.
- * It is used to set up the initial connection and various basic queries can be
- * executed using a set of static functions. When interfacing with the database
- * for the purpose of adding, deleting or updating entries, the use of the entry class
- * and its subclasses is recommended. This clas is not supposed to be instantiated,
- * if you need a database object, use QSqlDatabase::database("qt_sql_default_connection");
- */
-class Db
-{
-    public:
-        static Db& get()
-        {
-            static Db instance;
-
-            return instance;
-        }
-        /*!
-         * \brief The editRole enum {createNew, editExisting} is used to differentiate
-         * between creating a new entry in the database vs editing an existing one
-         */
-        enum editRole {createNew, editExisting};
-        /*!
-         * \brief The matchType enum {exactMatch, partialMatch} is used to determine the
-         * matching when using a WHERE sql statement. exactMatch results in a "=" operator,
-         * whereas partiasMatch results in a "LIKE" operator
-         */
-        enum matchType {exactMatch, partialMatch};       
-        /*!
-         * \brief connect establishes the database connection. Only needs to be called once
-         * within the application. Database is available thereafter, objects can be
-         * instantiated with QSqlDatabase::database("qt_sql_default_connection") as required.
-         */
-        static void             connect(){get().iconnect();}
-        /*!
-         * \brief disconnect Closes and removes the default database connection.
-         */
-        static void             disconnect(){get().idisconnect();}
-
-        /*!
-         * \brief Can be used to access the database connection.
-         * \return a pointer to the default database connection
-         */
-        static QSqlDatabase     Database(){return get().iDatabase();}
-
-        /*!
-         * \brief Db::exists checks if a certain value exists in the database with a sqlite WHERE statement
-         * \param table - Name of the table
-         * \param column - Name of the column
-         * \param value - The value to be checked
-         * \return
-         */
-        static bool             exists(QString column, QString table, QString checkColumn,
-                                       QString value, Db::matchType match)
-        {
-            return get().iexists(column, table, checkColumn, value, match);
-        }
-        /*!
-         * \brief Db::singleUpdate Updates a single value in the database.
-         * Query format: UPDATE table SET column = value WHERE checkcolumn =/LIKE checkvalue
-         * \param table Name of the table to be updated
-         * \param column Name of the column to be updated
-         * \param checkColumn Name of the column for WHERE statement
-         * \param value The value to be set
-         * \param checkvalue The value for the WHERE statement
-         * \param match enum Db::exactMatch or Db::partialMatch
-         * \return true on success, otherwise error messages in debug out
-         */
-        static bool             singleUpdate(QString table, QString column, QString value,
-                                             QString checkColumn, QString checkvalue, Db::matchType match){
-            return get().isingleUpdate(table,column,value,checkColumn,checkvalue,match);
-        }
-        /*!
-         * \brief singleSelect Returns a single value from the database with a sqlite WHERE statement
-         * \param table - Name of the table
-         * \param column - Name of the column
-         * \param value - Identifier for WHERE statement
-         * \param match - enum Db::exactMatch or Db::partialMatch
-         * \return QString
-         */
-        static QString          singleSelect(QString column, QString table, QString checkColumn,
-                                             QString value, Db::matchType match){
-            return get().isingleSelect(column,table,checkColumn,value,match);
-        }
-        /*!
-         * \brief Db::multiSelect Returns multiple values from the database with a sqlite WHERE statement
-         * \param table - Name of the table
-         * \param columns - QVector<QString> Names of the columns to be queried
-         * \param value - Identifier for WHERE statement
-         * \param checkColumn - column to match value to
-         * \param match - enum Db::exactMatch or Db::partialMatch
-         * \return QVector<QString>
-         */
-        static QVector<QString> multiSelect(QVector<QString> columns, QString table,
-                                            QString checkColumn, QString value, Db::matchType match){
-            return get().imultiSelect(columns,table,checkColumn,value,match);
-        }
-        /*!
-         * \brief Db::multiSelect Returns a complete column(s) for a given table.
-         * \param column - QVector<QString> Names of the columns to be queried
-         * \param table - QString Name of the table
-         * \return
-         */
-        static QVector<QString> multiSelect(QVector<QString> columns, QString table){
-            return get().imultiSelect(columns, table);
-        }
-        /*!
-         * \brief Db::customQuery Can be used to send a complex query to the database.
-         * \param query - the full sql query statement
-         * \param returnValues - the number of expected return values
-         * \return QVector<QString> of results
-         */
-        static QVector<QString> customQuery(QString query, int returnValues){
-            return get().icustomQuery(query, returnValues);
-        }
-
-    private:
-        Db() {}
-        void             iconnect();
-        void             idisconnect();
-        QSqlDatabase     iDatabase();
-        bool             iexists(QString column, QString table, QString checkColumn,
-                                       QString value, Db::matchType match);
-        bool             isingleUpdate(QString table, QString column, QString value,
-                                             QString checkColumn, QString checkvalue, Db::matchType match);
-        QString          isingleSelect(QString column, QString table, QString checkColumn,
-                                             QString value, Db::matchType match);
-        QVector<QString> imultiSelect(QVector<QString> columns, QString table,
-                                            QString checkColumn, QString value, Db::matchType match);
-        QVector<QString> imultiSelect(QVector<QString> columns, QString table);
-        QVector<QString> icustomQuery(QString query, int returnValues);
-
-    public:
-        // [George]: Why delete these in particular?
-        Db(Db const&)              = delete;
-        void operator=(Db const&)  = delete;
-};
-
-#endif // DB_H

+ 0 - 57
src/database/dbinfo.cpp

@@ -1,57 +0,0 @@
-/*
- *openPilot Log - A FOSS Pilot Logbook Application
- *Copyright (C) 2020  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 "dbinfo.h"
-#include "src/testing/adebug.h"
-
-DbInfo::DbInfo()
-{
-    QSqlDatabase db = QSqlDatabase::database("qt_sql_default_connection");
-    tables = db.tables().toVector();
-    getColumnNames();
-    sqliteversion();
-}
-
-/*!
- * \brief DbInfo::getColumnNames Looks up column names for all tables
- * in the database.
- */
-void DbInfo::getColumnNames()
-{
-    QSqlDatabase db = QSqlDatabase::database("qt_sql_default_connection");
-    QVector<QString> columnNames;
-    for (const auto &table : tables) {
-        columnNames.clear();
-        QSqlRecord fields = db.record(table);
-        for (int i = 0; i < fields.count(); i++) {
-            columnNames << fields.field(i).name();
-            format.insert(table, columnNames);
-        }
-    }
-}
-
-/*!
- * \brief db::sqliteversion queries database version.
- */
-void DbInfo::sqliteversion()
-{
-    QSqlQuery q;
-    q.prepare("SELECT sqlite_version()");
-    q.exec();
-    q.next();
-    version = q.value(0).toString();
-}

+ 0 - 41
src/database/dbinfo.h

@@ -1,41 +0,0 @@
-/*
- *openPilot Log - A FOSS Pilot Logbook Application
- *Copyright (C) 2020  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/>.
- */
-#ifndef DBINFO_H
-#define DBINFO_H
-
-#include <QCoreApplication>
-#include <QDebug>
-#include "db.h"
-
-class DbInfo
-{
-public:
-    DbInfo();
-
-    QString version = QString();
-
-    QMap<QString, QVector<QString>> format;
-
-    QVector<QString> tables;
-
-    void getColumnNames();
-
-    void sqliteversion();
-};
-
-#endif // DBINFO_H

+ 75 - 10
src/database/tablecolumnliterals.h → src/database/declarations.h

@@ -1,17 +1,77 @@
-#ifndef TABLECOLUMNLITERALS_H
-#define TABLECOLUMNLITERALS_H
+#ifndef DECLARATIONS_H
+#define DECLARATIONS_H
 
-#include <QString>
-#include <QStringLiteral>
+#include <QtCore>
+#include "src/testing/adebug.h"
 
-// [F]: These constants deviate slightly from const naming convention to reflect their sql column name.
+/*!
+ * \brief An alias for QString
+ *
+ * Very long description *with* **markdown?**
+ * - - -
+ * # Header
+ */
+using ColName = QString;
+using ColData = QVariant;
+using TableName = QString;
+using RowId = int;
+
+using TableNames = QStringList;
+// [G]: May lead to some confusion. TableData suggest data for the entire table.
+// but in reallity it is data per column *of single row* (unless i misunderstand)
+// [F]: That's correct. We could maybe call it EntryData or RowData?
+using RowData = QMap<ColName, ColData>;
+using ColumnData = QPair<ColName, ColData>;
+using ColumnNames = QStringList;
+using TableColumns = QMap<TableName, ColumnNames>;
+
+// [G]: Needs some work. Inheriting from QPair may be helpful but
+// may also be overkill. Lets determine the specific uses of DataPosition
+// and provide our own interface i would say.
+// [F]: Good idea! Implementing something similar to first and second methods
+// of QPair would be useful to carry over, or some other way of quickly and
+// unambiguously accessing the elements.
+/*struct DataPosition : QPair<TableName, RowId> {
+    TableName tableName;
+    RowId rowId;
+    DataPosition()
+        : tableName(first), rowId(second)
+    {}
+    DataPosition(TableName table_name, RowId row_id)
+        : QPair<TableName, RowId>::QPair(table_name, row_id),
+          tableName(first), rowId(second)
+    {}
+    DataPosition(const DataPosition& other) = default;
+    DataPosition& operator=(const DataPosition& other) = default;
+};*/
+
+//[F]: How about something like this?
+struct DataPosition {
+    TableName tableName;
+    RowId rowId;
+    DataPosition()
+        : tableName(TableName())
+    {};
+    DataPosition(TableName table_name, RowId row_id)
+        : tableName(table_name), rowId(row_id)
+    {};
+
+    DataPosition(const DataPosition& other) = default;
+    DataPosition& operator=(const DataPosition& other) = default;
+
+    REPR(DataPosition,
+         "tableName=" + object.tableName + ", "
+         "rowId=" + object.rowId
+         )
+};
+
+// [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
 //
@@ -22,8 +82,12 @@ 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");
-
-// Flights table
+// 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");
@@ -33,7 +97,7 @@ 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_SPME           = QStringLiteral("tSPME");
+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");
@@ -88,4 +152,5 @@ static const auto DB_               = QStringLiteral("");
 static const auto DB_               = QStringLiteral("");
 static const auto DB_               = QStringLiteral("");*/
 
-#endif // TABLECOLUMNLITERALS_H
+
+#endif // DECLARATIONS_H

+ 0 - 247
src/database/entry_deprecated.cpp

@@ -1,247 +0,0 @@
-/*
- *openPilot Log - A FOSS Pilot Logbook Application
- *Copyright (C) 2020  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 "entry_deprecated.h"
-#include "src/testing/adebug.h"
-#include "db.h"
-
-Entry_deprecated::Entry_deprecated()
-{
-}
-
-Entry_deprecated::Entry_deprecated(QString table, int row)
-{
-    //retreive database layout
-    const auto dbContent = DbInfo();
-
-    if (dbContent.tables.contains(table)) {
-        position.first = table;
-        columns = dbContent.format.value(table);
-    } else {
-        DEB(table << " not a table in database. Unable to create Entry object.");
-        position.first = QString();
-    }
-
-    //Check database for row id
-    QString statement = "SELECT COUNT(*) FROM " + table + " WHERE _rowid_=" + QString::number(row);
-    QSqlQuery q(statement);
-    q.next();
-    int rows = q.value(0).toInt();
-    if (rows == 0) {
-        DEB("No Entry found for row id: " << row );
-        position.second = 0;
-    } else {
-        DEB("Retreiving data for row id: " << row);
-        QString statement = "SELECT * FROM " + table + " WHERE _rowid_=" + QString::number(row);
-
-        QSqlQuery q(statement);
-        q.exec();
-        q.next();
-        for (int i = 0; i < dbContent.format.value(table).length(); i++) {
-            data.insert(dbContent.format.value(table)[i], q.value(i).toString());
-        }
-
-        error = q.lastError().text();
-        if (error.length() > 2) {
-            DEB("Error: " << q.lastError().text());
-            position.second = 0;
-        } else {
-            position.second = row;
-        }
-    }
-}
-
-Entry_deprecated::Entry_deprecated(QString table, QMap<QString, QString> newData)
-{
-    //retreive database layout
-    const auto dbContent = DbInfo();
-
-    if (dbContent.tables.contains(table)) {
-        position.first = table;
-        position.second = 0;
-        columns = dbContent.format.value(table);
-    } else {
-        DEB(table << " not a table in database. Unable to create Entry object.");
-        position.first = QString();
-    }
-    //Check validity of newData
-    QVector<QString> badkeys;
-    QMap<QString, QString>::iterator i;
-    for (i = newData.begin(); i != newData.end(); ++i) {
-        if (!columns.contains(i.key())) {
-            DEB(i.key() << "Not in column list for table " << table << ". Discarding.");
-            badkeys << i.key();
-        }
-    }
-    for (const auto &var : badkeys) {
-        newData.remove(var);
-    }
-    data = newData;
-}
-
-void Entry_deprecated::setData(QMap<QString, QString> &value)
-{
-    //retreive database layout
-    const auto dbContent = DbInfo();
-    columns = dbContent.format.value(position.first);
-
-    //Check validity of newData
-    QVector<QString> badkeys;
-    QMap<QString, QString>::iterator i;
-    for (i = value.begin(); i != value.end(); ++i) {
-        if (!columns.contains(i.key())) {
-            DEB(i.key() << "Not in column list for table " << position.first << ". Discarding.");
-            badkeys << i.key();
-        }
-    }
-    for (const auto &var : badkeys) {
-        value.remove(var);
-    }
-    data = value;
-}
-
-bool Entry_deprecated::commit()
-{
-    if (exists()) {
-        return update();
-    } else {
-        return insert();
-    }
-}
-
-bool Entry_deprecated::remove()
-{
-    if (exists()) {
-        QString statement = "DELETE FROM " + position.first +
-                            " WHERE _rowid_=" + QString::number(position.second);
-        QSqlQuery q(statement);
-        error = q.lastError().text();
-
-        if (error.length() > 1) {
-            DEB("Errors have occured: " << error);
-            return false;
-        } else {
-            DEB("Entry removed.");
-            return true;
-        }
-    } else {
-        return false;
-    }
-}
-
-bool Entry_deprecated::exists()
-{
-    //Check database for row id
-    QString statement = "SELECT COUNT(*) FROM " + position.first +
-                        " WHERE _rowid_=" + QString::number(position.second);
-    QSqlQuery q(statement);
-    q.next();
-    int rows = q.value(0).toInt();
-    if (rows) {
-        DEB("Entry exists. " << rows);
-        return true;
-    } else {
-        DEB("Entry does not exist. " << rows);
-        return false;
-    }
-}
-
-bool Entry_deprecated::insert()
-{
-    DEB("Inserting...");
-    //check prerequisites
-
-    if (data.isEmpty()) {
-        DEB("Object Contains no data. Aborting.");
-        return false;
-    }
-    QString statement = "INSERT INTO " + position.first + QLatin1String(" (");
-    QMap<QString, QString>::iterator i;
-    for (i = data.begin(); i != data.end(); ++i) {
-        statement += i.key() + QLatin1String(", ");
-    }
-    statement.chop(2);
-    statement += QLatin1String(") VALUES (");
-    for (i = data.begin(); i != data.end(); ++i) {
-        statement += QLatin1String("'") + i.value() + QLatin1String("', ");
-    }
-    statement.chop(2);
-    statement += QLatin1String(")");
-
-    QSqlQuery q(statement);
-    error = q.lastError().text();
-    if (error.length() < 2) {
-        DEB("Entry successfully committed.");
-        return true;
-    } else {
-        DEB("Unable to commit. Query Error: " << q.lastError().text());
-        return false;
-    }
-}
-
-bool Entry_deprecated::update()
-{
-    //create query
-    QString statement = "UPDATE " + position.first + " SET ";
-
-    QMap<QString, QString>::const_iterator i;
-    for (i = data.constBegin(); i != data.constEnd(); ++i) {
-        if (i.key() != QString()) {
-            statement += i.key() + QLatin1String("='") + i.value() + QLatin1String("', ");
-        } else {
-            DEB(i.key() << "is empty key. skipping.");
-        }
-    }
-    statement.chop(2); // Remove last comma
-    statement.append(QLatin1String(" WHERE _rowid_=") + QString::number(position.second));
-
-    //execute query
-    DEB("UPDATE QUERY: " << statement);
-    QSqlQuery q(statement);
-    //check result. Upon success, error should be " "
-    error = q.lastError().text();
-    if (error.length() < 2) {
-        DEB("Object successfully updated.");
-        return true;
-    } else {
-        DEB("Query Error: " << q.lastError().text());
-        return false;
-    }
-}
-
-//Debug
-void Entry_deprecated::print()
-{
-    QString v = "Object status:\t\033[38;2;0;255;0;48;2;0;0;0m VALID \033[0m\n";
-    QString nv = "Object status:\t\033[38;2;255;0;0;48;2;0;0;0m INVALID \033[0m\n";
-    QTextStream cout(stdout, QIODevice::WriteOnly);
-
-    cout << "=========Database Entry=========\n";
-    //if(isValid){cout << v;}else{cout << nv;}
-    cout << "Record from table: " << position.first << ", row: " << position.second << "\n";
-    cout << "=================================\n";
-    QMap<QString, QString>::const_iterator i;
-    for (i = data.constBegin(); i != data.constEnd(); ++i) {
-        cout << i.key() << ":\t" << i.value() << "\n";
-    }
-}
-
-QString Entry_deprecated::debug()
-{
-    print();
-    return QString();
-}

+ 0 - 60
src/database/entry_deprecated.h

@@ -1,60 +0,0 @@
-/*
- *openPilot Log - A FOSS Pilot Logbook Application
- *Copyright (C) 2020  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/>.
- */
-#ifndef ENTRY1_H
-#define ENTRY1_H
-
-#include <QCoreApplication>
-#include "db.h"
-#include "dbinfo.h"
-/*!
- * \brief The Entry class is the base class for database entries.
- * It can be seen as a row in a table within the database.
- *
- */
-class Entry_deprecated
-{
-public:
-    Entry_deprecated();
-    Entry_deprecated(QString table, int row);
-    Entry_deprecated(QString table, QMap<QString, QString> newData);
-
-    QPair   <QString, int>       position = QPair<QString, int>();    // Position within the database, i.e. <table,row>
-    QVector <QString>            columns  = QVector<QString>();       // The columns within the table
-    QMap    <QString, QString>   data     = QMap<QString, QString>(); // Tha data to fill that table, <column,value>
-    QString                      error    = QString();                // holds sql errors (if they ocurred)
-
-    void setData(QMap<QString, QString> &value);
-
-    bool commit();
-    bool remove();
-    bool exists();
-
-    // Debug functionality
-    void print();
-    QString debug();
-    operator QString()
-    {
-        return debug();    //overload for compatibility with qDebug()
-    }
-
-private:
-    bool insert();
-    bool update();
-};
-
-#endif // ENTRY_H

+ 0 - 47
src/experimental/UserInput.h

@@ -1,47 +0,0 @@
-#ifndef __USERINPUT_H__
-#define __USERINPUT_H__
-
-#include <QPair>
-#include <QString>
-#include <QBitArray>
-#include <QMap>
-#include <QStringList>
-#include <algorithm>
-
-namespace experimental {
-
-using EntryData = QMap<QString, QString>;
-
-/*!
- * \brief The EntryData struct. Contains ALL possible data.
- * However depending on who is constructing it, different types are initialised.
- * FUTURE: Would it be necessary to able to change data?
- * 	 George: I would say no because we dont want to fuck around with the entry.
- * Collect data from user -> Pack it up in the entry -> Consume it.
- * \todo Figure out exactly what the database would prefer as return value
- *   George: I would assume key: value pairs where the keys are what you would
- * put in the queries. This will affect data aswell (and propably simplify it)
- */
-class UserInput {
-private:
-    const EntryData data;
-public:
-    const enum class MetaTag {Pilot, Flight, Aircraft} meta_tag;
-
-public:
-    UserInput() = delete;
-    explicit
-    UserInput(EntryData new_data, MetaTag tag)
-        :  data(new_data), meta_tag(tag) {}
-
-    QString only(QString data_type) const { return data.value(data_type); }
-    const EntryData& all() const { return data; }
-};
-
-UserInput newPilotInput(EntryData ed) { return UserInput(ed, UserInput::MetaTag::Pilot); }
-UserInput newFlightInput(EntryData ed) { return UserInput(ed, UserInput::MetaTag::Flight); }
-UserInput newAircraftInput(EntryData ed) { return UserInput(ed, UserInput::MetaTag::Aircraft); }
-
-}
-
-#endif

+ 0 - 81
src/experimental/aflightentry.cpp

@@ -1,81 +0,0 @@
-#include "aflightentry.h"
-#include "src/experimental/adatabase.h"
-
-namespace experimental {
-
-AFlightEntry::AFlightEntry()
-    : AEntry::AEntry(DEFAULT_FLIGHT_POSITION)
-{}
-
-AFlightEntry::AFlightEntry(int row_id)
-    : AEntry::AEntry(DataPosition(QStringLiteral("flights"), row_id))
-{}
-
-AFlightEntry::AFlightEntry(TableData table_data)
-    : AEntry::AEntry(DEFAULT_FLIGHT_POSITION, table_data)
-{}
-
-const QString AFlightEntry::summary()
-{
-    if(tableData.isEmpty())
-        return QString();
-
-    QString flight_summary;
-    flight_summary.append(tableData.value("doft").toString() + " ");
-    flight_summary.append(tableData.value("dept").toString() + " ");
-    flight_summary.append(ACalc::minutesToString(tableData.value("tofb").toString()) + " ");
-    flight_summary.append(ACalc::minutesToString(tableData.value("tonb").toString()) + " ");
-    flight_summary.append(tableData.value("dest").toString() + " ");
-
-    return flight_summary;
-}
-
-const QString AFlightEntry::getRegistration()
-{
-    QString tail_id = tableData.value(QLatin1String("acft")).toString();
-    if(tail_id.isEmpty())
-        return QString();
-
-    QString statement = "SELECT registration "
-                        "FROM tails "
-                        "WHERE ROWID =" + tail_id;
-
-    auto tail_registration = aDB()->customQuery(statement, 1);
-
-    if(tail_registration.isEmpty()) {
-        return QString();
-    } else {
-        return tail_registration.first();
-    }
-}
-
-const QString AFlightEntry::getPilotName(pilot pilot_)
-{
-    QString row_id;
-    switch (pilot_) {
-    case pilot::pic:
-        row_id = tableData.value(QLatin1String("pic")).toString();
-        break;
-    case pilot::sic:
-        row_id = tableData.value(QLatin1String("sic")).toString();
-        break;
-    case pilot::thirdPilot:
-        row_id = tableData.value(QLatin1String("thirdPilot")).toString();
-        break;
-    }
-    if(row_id == QString())
-        return row_id;
-
-    QString statement = "SELECT lastname||', '||firstname "
-                        "FROM pilots "
-                        "WHERE ROWID =" + row_id;
-
-    auto pilot_name = aDB()->customQuery(statement, 1);
-    if(pilot_name.isEmpty()) {
-        return QString();
-    } else {
-        return pilot_name.first();
-    }
-}
-
-} // namespace experimental

+ 0 - 39
src/experimental/aflightentry.h

@@ -1,39 +0,0 @@
-#ifndef AFLIGHTENTRY_H
-#define AFLIGHTENTRY_H
-
-#include "src/experimental/aentry.h"
-#include "src/functions/acalc.h"
-
-namespace experimental {
-
-class AFlightEntry : public AEntry {
-public:
-    AFlightEntry();
-    AFlightEntry(const AFlightEntry& pe) = default;
-    AFlightEntry& operator=(const AFlightEntry& pe) = default;
-    AFlightEntry(int row_id);
-    AFlightEntry(TableData table_data);
-
-    enum pilot { pic, sic, thirdPilot };
-
-    /*!
-     * \brief Returs a summary of the flight data, if struct holds data
-     * \return "doft, dept, tofb, dest, tonb"
-     */
-    const QString summary();
-    /*!
-     * \brief Returns the tails' registration from the database.
-     */
-    const QString getRegistration();
-    /*!
-     * \brief Returns the pilots name from the Database
-     *
-     * \param pilot_number - 1=pic, 2=second Pilot, 3 = third Pilot
-     * \return "Lastname, Firstname"
-     */
-    const QString getPilotName(pilot);
-};
-
-} // namespace experimental
-
-#endif // AFLIGHTENTRY_H

+ 0 - 65
src/experimental/decl.h

@@ -1,65 +0,0 @@
-#ifndef DECL_H
-#define DECL_H
-
-#include <QString>
-#include <QPair>
-#include <QMap>
-#include <QObject>
-
-/*!
- * \brief Temporary namespace for experimental features.
- * Will be removed in later versions.
- * \todo Remove this namespace (and learn about some nice \something of doxygen)
- * Decide documentation style. https://www.doxygen.nl/manual/docblocks.html#specialblock
- */
-namespace experimental {
-
-
-/*!
- * \brief An alias for QString
- *
- * Very long description *with* **markdown?**
- * - - -
- * # Header
- */
-using ColName = QString;
-using ColData = QVariant;
-using TableName = QString;
-using RowId = int;
-
-using TableNames = QStringList;
-// [G]: May lead to some confusion. TableData suggest data for the entire table.
-// but in reallity it is data per column *of single row* (unless i misunderstand)
-// [F]: That's correct. We could maybe call it EntryData or RowData?
-using TableData = QMap<ColName, ColData>;
-using ColumnData = QPair<ColName, ColData>;
-using ColumnNames = QStringList;
-using TableColumns = QMap<TableName, ColumnNames>;
-
-// [G]: Needs some work. Inheriting from QPair may be helpful but
-// may also be overkill. Lets determine the specific uses of DataPosition
-// and provide our own interface i would say.
-// [F]: Good idea! Implementing something similar to first and second methods
-// of QPair would be useful to carry over, or some other way of quickly and
-// unambiguously accessing the elements.
-struct DataPosition : QPair<TableName, RowId> {
-    TableName tableName;
-    RowId rowId;
-    DataPosition()
-        : tableName(first), rowId(second)
-    {}
-    DataPosition(TableName table_name, RowId row_id)
-        : QPair<TableName, RowId>::QPair(table_name, row_id),
-          tableName(first), rowId(second)
-    {}
-    DataPosition(const DataPosition& other) = default;
-    DataPosition& operator=(const DataPosition& other) = default;
-};
-auto const DEFAULT_PILOT_POSITION = DataPosition("pilots", 0);
-auto const DEFAULT_TAIL_POSITION = DataPosition("tails", 0);
-auto const DEFAULT_AIRCRAFT_POSITION = DataPosition("aircraft", 0);
-auto const DEFAULT_FLIGHT_POSITION = DataPosition("flights", 0);
-
-}
-
-#endif // DECL_H

+ 48 - 52
src/functions/acalc.cpp

@@ -1,9 +1,9 @@
 #include "acalc.h"
 #include "src/testing/adebug.h"
-#include "src/experimental/adatabase.h"
+#include "src/database/adatabase.h"
+#include "src/classes/asettings.h"
 
 using namespace ACalc;
-using namespace experimental;
 
 /*!
  * \brief ACalc::formatTimeInput verifies user input and formats to hh:mm
@@ -17,25 +17,25 @@ QString ACalc::formatTimeInput(QString user_input)
     QString output; //
     QTime temp_time; //empty time object is invalid by default
 
-    bool contains_seperator = user_input.contains(":");
+    bool contains_seperator = user_input.contains(':');
     if (user_input.length() == 4 && !contains_seperator) {
-        temp_time = QTime::fromString(user_input, "hhmm");
+        temp_time = QTime::fromString(user_input, QStringLiteral("hhmm"));
     } else if (user_input.length() == 3 && !contains_seperator) {
         if (user_input.toInt() < 240) { //Qtime is invalid if time is between 000 and 240 for this case
-            QString tempstring = user_input.prepend("0");
-            temp_time = QTime::fromString(tempstring, "hhmm");
+            QString tempstring = user_input.prepend(QStringLiteral("0"));
+            temp_time = QTime::fromString(tempstring, QStringLiteral("hhmm"));
         } else {
-            temp_time = QTime::fromString(user_input, "Hmm");
+            temp_time = QTime::fromString(user_input, QStringLiteral("Hmm"));
         }
     } else if (user_input.length() == 4 && contains_seperator) {
-        temp_time = QTime::fromString(user_input, "h:mm");
+        temp_time = QTime::fromString(user_input, QStringLiteral("h:mm"));
     } else if (user_input.length() == 5 && contains_seperator) {
-        temp_time = QTime::fromString(user_input, "hh:mm");
+        temp_time = QTime::fromString(user_input, QStringLiteral("hh:mm"));
     }
 
-    output = temp_time.toString("hh:mm");
+    output = temp_time.toString(QStringLiteral("hh:mm"));
     if (output.isEmpty()) {
-        qDebug() << "Time input is invalid.";
+        DEB << "Time input is invalid.";
     }
     return output;
 }
@@ -86,12 +86,12 @@ double ACalc::greatCircleDistance(double lat1, double lon1, double lat2, double
 
 double ACalc::greatCircleDistanceBetweenAirports(const QString &dept, const QString &dest)
 {
-    auto statement = "SELECT lat, long FROM airports WHERE icao = '" + dept;
-    statement.append("' OR icao = '" + dest + "'");
+    auto statement = "SELECT lat, long FROM airports WHERE icao = '"
+            + dept + "' OR icao = '" + dest + "'";
     auto lat_lon = aDB()->customQuery(statement, 2);
 
     if (lat_lon.length() != 4) {
-        DEB("Invalid input. Aborting.");
+        DEB << "Invalid input. Aborting.";
         return 0;
     }
 
@@ -205,12 +205,11 @@ double ACalc::solarElevation(QDateTime utc_time_point, double lat, double lon)
 int ACalc::calculateNightTime(const QString &dept, const QString &dest, QDateTime departureTime, int tblk, int nightAngle)
 {
 
-    auto statement = "SELECT lat, long FROM airports WHERE icao = '" + dept;
-    statement.append("' OR icao = '" + dest + "'");
+    auto statement = "SELECT lat, long FROM airports WHERE icao = '" + dept + "' OR icao = '" + dest + "'";
     auto lat_lon = aDB()->customQuery(statement, 2);
 
     if (lat_lon.length() != 4) {
-        DEB("Invalid input. Aborting.");
+        DEB << "Invalid input. Aborting.";
         return 0;
     }
 
@@ -238,7 +237,7 @@ bool ACalc::isNight(const QString &icao, QDateTime event_time, int night_angle)
     auto lat_lon = aDB()->customQuery(statement, 2);
 
     if (lat_lon.length() != 2) {
-        DEB("Invalid input. Aborting.");
+        DEB << "Invalid input. Aborting.";
         return 0;
     }
 
@@ -262,40 +261,37 @@ bool ACalc::isNight(const QString &icao, QDateTime event_time, int night_angle)
 void ACalc::updateAutoTimes(int acft_id)
 {
     //find all flights for aircraft
-    auto statement = "SELECT flight_id FROM flights WHERE acft = " + QString::number(acft_id);
+    const QString statement = QStringLiteral("SELECT flight_id FROM flights WHERE acft = ") + QString::number(acft_id);
     auto flight_list = aDB()->customQuery(statement, 1);
-
     if (flight_list.isEmpty()) {
-        DEB("No flights for this tail found.");
+        DEB << "No flights for this tail found.";
         return;
     }
-
-    DEB("Updating " << flight_list.length() << " flights with this aircraft.");
+    DEB << "Updating " << flight_list.length() << " flights with this aircraft.";
 
     auto acft = aDB()->getTailEntry(acft_id);
     auto acft_data = acft.getData();
     for (const auto& item : flight_list) {
-
         auto flight = aDB()->getFlightEntry(item.toInt());
         auto flight_data = flight.getData();
 
-        if(acft_data.value("multipilot").toInt() == 0
-                && acft_data.value("multiengine") == 0) {
-            DEB("SPSE");
-            flight_data.insert("tSPSE", flight_data.value("tblk"));
-            flight_data.insert("tSPME", "");
-            flight_data.insert("tMP", "");
-        } else if ((acft_data.value("multipilot") == 0
-                    && acft.getData().value("multiengine") == 1)) {
-            DEB("SPME");
-            flight_data.insert("tSPME", flight_data.value("tblk"));
-            flight_data.insert("tSPSE", "");
-            flight_data.insert("tMP", "");
-        } else if ((acft_data.value("multipilot") == 1)) {
-            DEB("MPME");
-            flight_data.insert("tMP", flight_data.value("tblk"));
-            flight_data.insert("tSPSE", "");
-            flight_data.insert("tSPME", "");
+        if(acft_data.value(DB_TAILS_MULTIPILOT).toInt() == 0
+                && acft_data.value(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)) {
+            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)) {
+            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.setData(flight_data);
         aDB()->commit(flight);
@@ -307,31 +303,31 @@ void ACalc::updateAutoTimes(int acft_id)
  */
 void ACalc::updateNightTimes()
 {
-    const int night_angle = ASettings::read("flightlogging/nightangle").toInt();
+    const int night_angle = ASettings::read(QStringLiteral("flightlogging/nightangle")).toInt();
 
     //find all flights for aircraft
     auto statement = "SELECT ROWID FROM flights";
     auto flight_list = aDB()->customQuery(statement, 1);
 
     if (flight_list.isEmpty()) {
-        DEB("No flights found.");
+        DEB << "No flights found.";
         return;
     }
-    DEB("Updating " << flight_list.length() << " flights in the database.");
+    DEB << "Updating " << flight_list.length() << " flights in the database.";
 
     for (const auto& item : flight_list) {
 
         auto flt = aDB()->getFlightEntry(item.toInt());
         auto data = flt.getData();
-        auto dateTime = QDateTime(QDate::fromString(data.value(QLatin1String("doft")).toString(), Qt::ISODate),
-                                  QTime().addSecs(data.value(QLatin1String("tofb")).toInt() * 60),
+        auto dateTime = QDateTime(QDate::fromString(data.value(DB_FLIGHTS_DOFT).toString(), Qt::ISODate),
+                                  QTime().addSecs(data.value(DB_FLIGHTS_TOFB).toInt() * 60),
                                   Qt::UTC);
-        data.insert(QLatin1String("tNIGHT"), QString::number(
-                             calculateNightTime(data.value(QLatin1String("dept")).toString(),
-                             data.value(QLatin1String("dest")).toString(),
-                             dateTime,
-                             data.value(QLatin1String("tblk")).toInt(),
-                             night_angle)));
+        data.insert(DB_FLIGHTS_TNIGHT,
+                    calculateNightTime(data.value(DB_FLIGHTS_DEPT).toString(),
+                                       data.value(DB_FLIGHTS_DEST).toString(),
+                                       dateTime,
+                                       data.value(DB_FLIGHTS_TBLK).toInt(),
+                                       night_angle));
         flt.setData(data);
         aDB()->commit(flt);
     }

+ 0 - 6
src/functions/acalc.h

@@ -1,10 +1,6 @@
 #ifndef ACALC_H
 #define ACALC_H
 
-#include "src/database/db.h"
-#include "src/classes/aircraft.h"
-#include "src/classes/flight.h"
-#include "src/classes/asettings.h"
 #include <QDateTime>
 #include <cmath>
 #include <QDebug>
@@ -201,8 +197,6 @@ QString formatTimeInput(QString user_input);
 
 void updateAutoTimes(int acft_id);
 
-void autoTimes(Flight, Aircraft);
-
 void updateNightTimes();
 } // namespace ACalc
 

+ 3 - 4
src/functions/astat.cpp

@@ -16,10 +16,9 @@
  *along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 #include "astat.h"
+#include "src/database/adatabase.h"
 #include "src/testing/adebug.h"
 
-using namespace experimental;
-
 /*!
  * \brief AStat::totalTime Looks up Total Blocktime in the flights database
  * \param yearType - Whether the calculation is based on total time, last
@@ -56,8 +55,8 @@ QString AStat::totalTime(yearType year_type)
     QSqlQuery query(statement);
 
     if (!query.first()) {
-        DEB("No result found. Check Query and Error.");
-        DEB("Error: " << query.lastError().text());
+        DEB << "No result found. Check Query and Error.";
+        DEB << "Error: " << query.lastError().text();
         return "00:00";
     } else {
         query.previous();

+ 0 - 2
src/functions/astat.h

@@ -20,11 +20,9 @@
 #include <QtCore>
 #include <QSqlQuery>
 #include <QSqlError>
-#include "src/experimental/adatabase.h"
 
 namespace AStat {
 
-
 /*!
  * \brief The AStat namespace provides functionality for retreiving various statistics
  * from the database, such as total times or recency. In general, most values are

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

@@ -1,10 +1,13 @@
 #include "firstrundialog.h"
 #include "ui_firstrundialog.h"
-
+#include "src/testing/adebug.h"
+#include "src/database/adatabase.h"
+#include "src/database/adatabasesetup.h"
+#include "src/classes/apilotentry.h"
+#include "src/classes/adownload.h"
+#include "src/classes/asettings.h"
 const auto TEMPLATE_URL = QLatin1String("https://raw.githubusercontent.com/fiffty-50/openpilotlog/develop/assets/database/templates/");
 
-using namespace experimental;
-
 FirstRunDialog::FirstRunDialog(QWidget *parent) :
     QDialog(parent),
     ui(new Ui::FirstRunDialog)
@@ -121,7 +124,7 @@ bool FirstRunDialog::finishSetup()
 
     //check if template dir exists and create if needed.
     QDir dir("data/templates");
-    DEB(dir.path());
+    DEB << dir.path();
     if (!dir.exists())
         dir.mkpath(".");
 
@@ -155,9 +158,9 @@ bool FirstRunDialog::finishSetup()
     auto oldDatabase = QFile("data/logbook.db");
     if (oldDatabase.exists()) {
         auto dateString = QDateTime::currentDateTime().toString(Qt::ISODate);
-        DEB("Backing up old database as: " << "logbook-backup-" + dateString);
+        DEB << "Backing up old database as: " << "logbook-backup-" + dateString;
         if (!oldDatabase.rename("data/logbook-backup-" + dateString)) {
-            DEB("Warning: Creating backup of old database has failed.");
+            DEB << "Warning: Creating backup of old database has failed.";
         }
     }
     // re-connect and create new database

+ 0 - 6
src/gui/dialogues/firstrundialog.h

@@ -4,12 +4,6 @@
 #include <QDialog>
 #include <QButtonGroup>
 #include <QMessageBox>
-#include "src/classes/asettings.h"
-#include "src/testing/adebug.h"
-#include "src/experimental/apilotentry.h"
-#include "src/experimental/adatabase.h"
-#include "src/classes/adownload.h"
-#include "src/database/adatabasesetup.h"
 
 namespace Ui {
 class FirstRunDialog;

+ 63 - 59
src/gui/dialogues/newflightdialog.cpp

@@ -17,17 +17,21 @@
  */
 #include "newflightdialog.h"
 #include "ui_newflight.h"
-#include "src/testing/adebug.h"
-#include "src/database/tablecolumnliterals.h"
+#include "src/gui/dialogues/newtaildialog.h"
+#include "src/gui/dialogues/newpilotdialog.h"
+#include "src/functions/acalc.h"
+#include "src/testing/atimer.h"
+#include "src/database/adatabase.h"
+
 
-using namespace experimental;
+#include "src/testing/adebug.h"
 
 /////////////////////////////////////// DEBUG /////////////////////////////////////////////////////
 void NewFlightDialog::onInputRejected()
 {
     auto sender_object = sender();
     auto line_edit = this->findChild<QLineEdit*>(sender_object->objectName());
-    DEB(line_edit->objectName() << "Input Rejected - " << line_edit->text());
+    DEB << line_edit->objectName() << "Input Rejected - " << line_edit->text();
 }
 /////////////////////////////////////// DEBUG /////////////////////////////////////////////////////
 
@@ -154,7 +158,7 @@ void NewFlightDialog::setup()
 }
 void NewFlightDialog::readSettings()
 {
-    DEB("Reading Settings...");
+    DEB << "Reading Settings...";
     QSettings settings;
     ui->FunctionComboBox->setCurrentText(ASettings::read("flightlogging/function").toString());
     ui->ApproachComboBox->setCurrentText(ASettings::read("flightlogging/approach").toString());
@@ -181,7 +185,7 @@ void NewFlightDialog::readSettings()
 
 void NewFlightDialog::writeSettings()
 {
-    DEB("Writing Settings...");
+    DEB << "Writing Settings...";
 
     ASettings::write("flightlogging/function", ui->FunctionComboBox->currentText());
     ASettings::write("flightlogging/approach", ui->ApproachComboBox->currentText());
@@ -237,7 +241,7 @@ void NewFlightDialog::setupRawInputValidation()
     for (const auto &item : line_edit_settings) {
         for (const auto &line_edit : line_edits) {
             if(line_edit->objectName().contains(std::get<0>(item))) {
-                DEB("Setting up: " << line_edit->objectName());
+                DEB << "Setting up: " << line_edit->objectName();
                 // Set Validator
                 auto validator = new QRegularExpressionValidator(std::get<2>(item), line_edit);
                 line_edit->setValidator(validator);
@@ -317,7 +321,7 @@ void NewFlightDialog::setPopUpCalendarEnabled(bool state)
     ui->flightDataTabWidget->removeTab(2); // hide calendar widget
 
     if (state) {
-        DEB("Enabling pop-up calendar widget...");
+        DEB << "Enabling pop-up calendar widget...";
         ui->calendarWidget->installEventFilter(this);
         ui->placeLabel1->installEventFilter(this);
         ui->doftLineEdit->installEventFilter(this);
@@ -327,7 +331,7 @@ void NewFlightDialog::setPopUpCalendarEnabled(bool state)
         QObject::connect(ui->calendarWidget, &QCalendarWidget::activated,
                          this, &NewFlightDialog::onCalendarWidget_selected);
     } else {
-        DEB("Disabling pop-up calendar widget...");
+        DEB << "Disabling pop-up calendar widget...";
         ui->calendarWidget->removeEventFilter(this);
         ui->placeLabel1->removeEventFilter(this);
         ui->doftLineEdit->removeEventFilter(this);
@@ -349,7 +353,7 @@ bool NewFlightDialog::eventFilter(QObject* object, QEvent* event)
     if (line_edit != nullptr) {
         if (mandatoryLineEdits.contains(line_edit) && event->type() == QEvent::FocusIn) {
             mandatoryLineEditsGood.setBit(mandatoryLineEdits.indexOf(line_edit), false);
-            DEB("Editing " << line_edit->objectName());
+            DEB << "Editing " << line_edit->objectName();
             // set verification bit to false when entering a mandatory line edit
             return false;
         }
@@ -357,7 +361,7 @@ bool NewFlightDialog::eventFilter(QObject* object, QEvent* event)
             // show completion menu when pressing down arrow
             QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
             if (keyEvent->key() == Qt::Key_Down) {
-                DEB("Key down event.");
+                DEB << "Key down event.";
                 line_edit->completer()->complete();
             }
             return false;
@@ -366,7 +370,7 @@ bool NewFlightDialog::eventFilter(QObject* object, QEvent* event)
             // show completion menu when pressing down arrow
             QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
             if (keyEvent->key() == Qt::Key_Down) {
-                DEB("Key down event.");
+                DEB << "Key down event.";
                 line_edit->completer()->complete();
             }
             return false;
@@ -404,7 +408,7 @@ void NewFlightDialog::fillDeductibleData()
     // get acft data and fill deductible entries
     auto acft = aDB()->getTailEntry(tailsIdMap.value(ui->acftLineEdit->text()));
     if (acft.getData().isEmpty())
-        DEB("Error: No valid aircraft object available, unable to deterime auto times.");
+        DEB << "Error: No valid aircraft object available, unable to deterime auto times.";
 
 
     // SP SE
@@ -481,10 +485,10 @@ void NewFlightDialog::fillDeductibleData()
  * no input validation is done in this step and input data is assumed to be valid.
  * \return
  */
-TableData NewFlightDialog::collectInput()
+RowData NewFlightDialog::collectInput()
 {
-    TableData newData;
-    DEB("Collecting Input...");
+    RowData newData;
+    DEB << "Collecting Input...";
     // Mandatory data
     newData.insert(DB_FLIGHTS_DOFT, ui->doftLineEdit->text());
     newData.insert(DB_FLIGHTS_DEPT, ui->deptLocLineEdit->text());
@@ -511,8 +515,8 @@ TableData NewFlightDialog::collectInput()
               : newData.insert(DB_FLIGHTS_TSPSE, ACalc::stringToMinutes(ui->tSPSETimeLineEdit->text()));
 
     ui->tSPMETimeLineEdit->text().isEmpty() ?
-                newData.insert(DB_FLIGHTS_SPME, DB_NULL)
-              : newData.insert(DB_FLIGHTS_SPME, ACalc::stringToMinutes(ui->tSPMETimeLineEdit->text()));
+                newData.insert(DB_FLIGHTS_TSPME, DB_NULL)
+              : newData.insert(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()));
@@ -624,14 +628,14 @@ TableData NewFlightDialog::collectInput()
     newData.insert(DB_FLIGHTS_FLIGHTNUMBER, ui->FlightNumberLineEdit->text());
     newData.insert(DB_FLIGHTS_REMARKS, ui->RemarksLineEdit->text());
 
-    DEB("New Flight Data: " << newData);
+    DEB << "New Flight Data: " << newData;
 
     return newData;
 }
 
 void NewFlightDialog::formFiller()
 {
-    DEB("Filling Line Edits...");
+    DEB << "Filling Line Edits...";
     // get Line Edits
     auto line_edits = this->findChildren<QLineEdit *>();
     QStringList line_edits_names;
@@ -646,7 +650,7 @@ void NewFlightDialog::formFiller()
         auto rx = QRegularExpression(data_key + "LineEdit");//acftLineEdit
         for(const auto& leName : line_edits_names){
             if(rx.match(leName).hasMatch())  {
-                //DEB("Loc Match found: " << key << " - " << leName);
+                //DEB << "Loc Match found: " << key << " - " << leName);
                 auto line_edit = this->findChild<QLineEdit *>(leName);
                 if(line_edit != nullptr){
                     line_edit->setText(flightEntry.getData().value(data_key).toString());
@@ -658,7 +662,7 @@ void NewFlightDialog::formFiller()
         rx = QRegularExpression(data_key + "Loc\\w+?");
         for(const auto& leName : line_edits_names){
             if(rx.match(leName).hasMatch())  {
-                //DEB("Loc Match found: " << key << " - " << leName);
+                //DEB << "Loc Match found: " << key << " - " << leName);
                 auto line_edit = this->findChild<QLineEdit *>(leName);
                 if(line_edit != nullptr){
                     line_edit->setText(flightEntry.getData().value(data_key).toString());
@@ -670,10 +674,10 @@ void NewFlightDialog::formFiller()
         rx = QRegularExpression(data_key + "Time\\w+?");
         for(const auto& leName : line_edits_names){
             if(rx.match(leName).hasMatch())  {
-                //DEB("Time Match found: " << key << " - " << leName);
+                //DEB << "Time Match found: " << key << " - " << leName);
                 auto line_edits = this->findChild<QLineEdit *>(leName);
                 if(line_edits != nullptr){
-                    DEB("Setting " << line_edits->objectName() << " to " << ACalc::minutesToString(flightEntry.getData().value(data_key).toInt()));
+                    DEB << "Setting " << line_edits->objectName() << " to " << ACalc::minutesToString(flightEntry.getData().value(data_key).toInt());
                     line_edits->setText(ACalc::minutesToString(
                                             flightEntry.getData().value(data_key).toInt()));
                     line_edits_names.removeOne(leName);
@@ -686,7 +690,7 @@ void NewFlightDialog::formFiller()
             if(rx.match(leName).hasMatch())  {
                 auto line_edits = this->findChild<QLineEdit *>(leName);
                 if(line_edits != nullptr){
-                    DEB(pilotsIdMap.key(1));
+                    DEB << pilotsIdMap.key(1);
                     line_edits->setText(pilotsIdMap.key(flightEntry.getData().value(data_key).toInt()));
                     line_edits_names.removeOne(leName);
                 }
@@ -797,7 +801,7 @@ void NewFlightDialog::addNewTail(QLineEdit *parent_line_edit)
                                   "add the registration to the database first.<br><br>Would you like to add a new aircraft to the database?",
                                   QMessageBox::Yes|QMessageBox::No);
     if (reply == QMessageBox::Yes) {
-        DEB("Add new aircraft selected");
+        DEB << "Add new aircraft selected";
         // create and open new aircraft dialog
         auto na = NewTailDialog(ui->acftLineEdit->text(), this);
         na.exec();
@@ -805,8 +809,8 @@ void NewFlightDialog::addNewTail(QLineEdit *parent_line_edit)
         tailsIdMap  = aDB()->getIdMap(ADatabaseTarget::tails);
         tailsList   = aDB()->getCompletionList(ADatabaseTarget::registrations);
 
-        DEB("New Entry added. Id:" << aDB()->getLastEntry(ADatabaseTarget::tails));
-        DEB("AC Map: " << tailsIdMap);
+        DEB << "New Entry added. Id:" << aDB()->getLastEntry(ADatabaseTarget::tails);
+        DEB << "AC Map: " << tailsIdMap;
 
         parent_line_edit->setText(tailsIdMap.key(aDB()->getLastEntry(ADatabaseTarget::tails)));
         emit parent_line_edit->editingFinished();
@@ -829,14 +833,14 @@ void NewFlightDialog::addNewPilot(QLineEdit *parent_line_edit)
                                   "add the name to the database first.<br><br>Would you like to add a new pilot to the database?",
                                   QMessageBox::Yes|QMessageBox::No);
     if (reply == QMessageBox::Yes) {
-        DEB("Add new pilot selected");
+        DEB << "Add new pilot selected";
         // create and open new pilot dialog
         auto np = NewPilotDialog(this);
         np.exec();
         // update map and list, set line edit
         pilotsIdMap  = aDB()->getIdMap(ADatabaseTarget::pilots);
         pilotList    = aDB()->getCompletionList(ADatabaseTarget::pilots);
-        DEB("Setting new entry: " << pilotsIdMap.key(aDB()->getLastEntry(ADatabaseTarget::pilots)));
+        DEB << "Setting new entry: " << pilotsIdMap.key(aDB()->getLastEntry(ADatabaseTarget::pilots));
         parent_line_edit->setText(pilotsIdMap.key(aDB()->getLastEntry(ADatabaseTarget::pilots)));
         emit parent_line_edit->editingFinished();
     } else {
@@ -850,7 +854,7 @@ void NewFlightDialog::addNewPilot(QLineEdit *parent_line_edit)
 
 void NewFlightDialog::on_cancelButton_clicked()
 {
-    DEB("Cancel Button clicked.");
+    DEB << "Cancel Button clicked.";
     reject();
 }
 
@@ -859,7 +863,7 @@ void NewFlightDialog::on_submitButton_clicked()
     for (const auto &line_edit : mandatoryLineEdits) {
         emit line_edit->editingFinished();
     }
-    DEB("editing finished emitted. good count: " << mandatoryLineEditsGood.count(true));
+    DEB << "editing finished emitted. good count: " << mandatoryLineEditsGood.count(true);
     if (mandatoryLineEditsGood.count(true) != 7) {
         QString error_message = "Not all mandatory entries are valid.<br>The following"
                                 " item(s) are empty or missing:<br><br><center><b>";
@@ -877,11 +881,11 @@ void NewFlightDialog::on_submitButton_clicked()
         return;
     }
 
-    DEB("Submit Button clicked. Mandatory good (out of 7): " << mandatoryLineEditsGood.count(true));
+    DEB << "Submit Button clicked. Mandatory good (out of 7): " << mandatoryLineEditsGood.count(true);
     auto newData = collectInput();
-    DEB("Setting Data for flightEntry...");
+    DEB << "Setting Data for flightEntry...";
     flightEntry.setData(newData);
-    DEB("Committing...");
+    DEB << "Committing...";
     if (!aDB()->commit(flightEntry)) {
         auto message_box = QMessageBox(this);
         message_box.setText("The following error has ocurred:\n\n"
@@ -903,7 +907,7 @@ void NewFlightDialog::on_submitButton_clicked()
 
 void NewFlightDialog::onGoodInputReceived(QLineEdit *line_edit)
 {
-    DEB(line_edit->objectName() << " - Good input received - " << line_edit->text());
+    DEB << line_edit->objectName() << " - Good input received - " << line_edit->text();
     line_edit->setStyleSheet("");
 
     if (mandatoryLineEdits.contains(line_edit))
@@ -912,18 +916,18 @@ void NewFlightDialog::onGoodInputReceived(QLineEdit *line_edit)
     if (mandatoryLineEditsGood.count(true) == 7)
         onMandatoryLineEditsFilled();
 
-    DEB("Mandatory good: " << mandatoryLineEditsGood.count(true)
-        << " (out of 7) " << mandatoryLineEditsGood);
+    DEB << "Mandatory good: " << mandatoryLineEditsGood.count(true)
+        << " (out of 7) " << mandatoryLineEditsGood;
 
 }
 
 void NewFlightDialog::onBadInputReceived(QLineEdit *line_edit)
 {
-    DEB(line_edit->objectName() << " - Bad input received - " << line_edit->text());
+    DEB << line_edit->objectName() << " - Bad input received - " << line_edit->text();
     line_edit->setStyleSheet("border: 1px solid red");
 
-    DEB("Mandatory Good: " << mandatoryLineEditsGood.count(true) << " out of "
-        << mandatoryLineEditsGood.size() << ". Array: " << mandatoryLineEditsGood);
+    DEB << "Mandatory Good: " << mandatoryLineEditsGood.count(true) << " out of "
+        << mandatoryLineEditsGood.size() << ". Array: " << mandatoryLineEditsGood;
     ui->submissonReadyLabel->setText("INCOMPLETE");
     ui->submissonReadyLabel->setStyleSheet("color: rgb(237, 212, 0);");
 }
@@ -933,7 +937,7 @@ void NewFlightDialog::onToUpperTriggered_textChanged(const QString &text)
 {
     auto sender_object = sender();
     auto line_edit = this->findChild<QLineEdit*>(sender_object->objectName());
-    DEB("Text changed - " << line_edit->objectName() << line_edit->text());
+    DEB << "Text changed - " << line_edit->objectName() << line_edit->text();
     {
         const QSignalBlocker blocker(line_edit);
         line_edit->setText(text.toUpper());
@@ -944,13 +948,13 @@ void NewFlightDialog::onToUpperTriggered_textChanged(const QString &text)
 void NewFlightDialog::onMandatoryLineEditsFilled()
 {
     if (!(mandatoryLineEditsGood.count(true) == 7)) {
-        DEB("erroneously called.");
+        DEB << "erroneously called.";
         return;
     };
 
     if (updateEnabled)
         fillDeductibleData();
-    DEB(mandatoryLineEditsGood);
+    DEB << mandatoryLineEditsGood;
 }
 
 // make sure that when using keyboard to scroll through completer sugggestions, line edit is up to date
@@ -958,7 +962,7 @@ void NewFlightDialog::onCompleter_highlighted(const QString &completion)
 {
     auto sender_object = sender();
     auto line_edit = this->findChild<QLineEdit*>(sender_object->objectName());
-    DEB("Completer highlighted - " << line_edit->objectName() << completion);
+    DEB << "Completer highlighted - " << line_edit->objectName() << completion;
     line_edit->setText(completion);
 }
 
@@ -966,7 +970,7 @@ void NewFlightDialog::onCompleter_activated(const QString &)
 {
     auto sender_object = sender();
     auto line_edit = this->findChild<QLineEdit*>(sender_object->objectName());
-    DEB("Line edit " << line_edit->objectName() << "completer activated.");
+    DEB << "Line edit " << line_edit->objectName() << "completer activated.";
     emit line_edit->editingFinished();
 }
 
@@ -979,7 +983,7 @@ void NewFlightDialog::on_doftLineEdit_editingFinished()
     auto line_edit = ui->doftLineEdit;
     auto text = ui->doftLineEdit->text();
     auto label = ui->doftDisplayLabel;
-    DEB(line_edit->objectName() << "Editing finished - " << text);
+    DEB << line_edit->objectName() << "Editing finished - " << text;
 
     auto date = QDate::fromString(text, Qt::ISODate);
     if (date.isValid()) {
@@ -990,7 +994,7 @@ void NewFlightDialog::on_doftLineEdit_editingFinished()
 
     //try to correct input if only numbers are entered, eg 20200101
     if(text.length() == 8) {
-        DEB("Trying to fix input...");
+        DEB << "Trying to fix input...";
         text.insert(4,'-');
         text.insert(7,'-');
         date = QDate::fromString(text, Qt::ISODate);
@@ -1060,7 +1064,7 @@ void NewFlightDialog::onDoftLineEdit_entered()
 void NewFlightDialog::on_calendarCheckBox_stateChanged(int arg1)
 {
     ASettings::write("NewFlight/calendarCheckBox", ui->calendarCheckBox->isChecked());
-    DEB("Calendar check box state changed.");
+    DEB << "Calendar check box state changed.";
     switch (arg1) {
     case 0: // unchecked
         setPopUpCalendarEnabled(false);
@@ -1090,7 +1094,7 @@ void NewFlightDialog::on_destLocLineEdit_editingFinished()
 void NewFlightDialog::onLocationEditingFinished(QLineEdit *line_edit, QLabel *name_label)
 {
     const auto &text = line_edit->text();
-    //DEB(line_edit->objectName() << " Editing finished. " << text);
+    //DEB << line_edit->objectName() << " Editing finished. " << text);
     int airport_id = 0;
 
     // try to map iata or icao code to airport id;
@@ -1119,7 +1123,7 @@ void NewFlightDialog::onTimeLineEdit_editingFinished()
 {
     auto sender_object = sender();
     auto line_edit = this->findChild<QLineEdit*>(sender_object->objectName());
-    DEB(line_edit->objectName() << "Editing Finished -" << line_edit->text());
+    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);
@@ -1145,10 +1149,10 @@ void NewFlightDialog::onTimeLineEdit_editingFinished()
 void NewFlightDialog::on_acftLineEdit_editingFinished()
 {
     auto line_edit = ui->acftLineEdit;
-    //DEB(line_edit->objectName() << "Editing Finished!" << line_edit->text());
+    //DEB << line_edit->objectName() << "Editing Finished!" << line_edit->text());
 
     if (tailsIdMap.value(line_edit->text()) != 0) {
-        DEB("Mapped: " << line_edit->text() << tailsIdMap.value(line_edit->text()));
+        DEB << "Mapped: " << line_edit->text() << tailsIdMap.value(line_edit->text());
         auto acft = aDB()->getTailEntry(tailsIdMap.value(line_edit->text()));
         ui->acftTypeLabel->setText(acft.type());
         onGoodInputReceived(line_edit);
@@ -1158,7 +1162,7 @@ void NewFlightDialog::on_acftLineEdit_editingFinished()
     // try to fix input
     if (!line_edit->completer()->currentCompletion().isEmpty()
             && !line_edit->text().isEmpty()) {
-        DEB("Trying to fix input...");
+        DEB << "Trying to fix input...";
         line_edit->setText(line_edit->completer()->currentCompletion());
         emit line_edit->editingFinished();
         return;
@@ -1178,10 +1182,10 @@ void NewFlightDialog::onPilotNameLineEdit_editingFinished()
 {
     auto sender_object = sender();
     auto line_edit = this->findChild<QLineEdit*>(sender_object->objectName());
-    //DEB(line_edit->objectName() << "Editing Finished -" << line_edit->text());
+    //DEB << line_edit->objectName() << "Editing Finished -" << line_edit->text());
 
     if(line_edit->text().contains(SELF_RX)) {
-        DEB("self recognized.");
+        DEB << "self recognized.";
         line_edit->setText(pilotsIdMap.key(1));
         auto pilot = aDB()->getPilotEntry(1);
         ui->picCompanyLabel->setText(pilot.getData().value(DB_TAILS_COMPANY).toString());
@@ -1190,7 +1194,7 @@ void NewFlightDialog::onPilotNameLineEdit_editingFinished()
     }
 
     if(pilotsIdMap.value(line_edit->text()) != 0) {
-        DEB("Mapped: " << line_edit->text() << pilotsIdMap.value(line_edit->text()));
+        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());
         onGoodInputReceived(line_edit);
@@ -1202,7 +1206,7 @@ void NewFlightDialog::onPilotNameLineEdit_editingFinished()
     }
 
     if (!line_edit->completer()->currentCompletion().isEmpty()) {
-        DEB("Trying to fix input...");
+        DEB << "Trying to fix input...";
         line_edit->setText(line_edit->completer()->currentCompletion());
         emit line_edit->editingFinished();
         return;
@@ -1229,7 +1233,7 @@ void NewFlightDialog::on_restoreDefaultButton_clicked()
 
 void NewFlightDialog::on_PilotFlyingCheckBox_stateChanged(int)
 {
-    DEB("PF checkbox state changed.");
+    DEB << "PF checkbox state changed.";
     if(ui->PilotFlyingCheckBox->isChecked()){
         ui->TakeoffSpinBox->setValue(1);
         ui->TakeoffCheckBox->setCheckState(Qt::Checked);

+ 5 - 11
src/gui/dialogues/newflightdialog.h

@@ -31,15 +31,9 @@
 #include <QTabWidget>
 #include <QKeyEvent>
 
-#include "src/gui/dialogues/newtaildialog.h"
-#include "src/gui/dialogues/newpilotdialog.h"
-
-#include "src/experimental/adatabase.h"
-#include "src/experimental/aflightentry.h"
-#include "src/experimental/apilotentry.h"
-#include "src/experimental/atailentry.h"
-#include "src/functions/acalc.h"
-#include "src/testing/atimer.h"
+#include "src/classes/aflightentry.h"
+#include "src/classes/apilotentry.h"
+#include "src/classes/atailentry.h"
 
 namespace Ui {
 class NewFlight;
@@ -98,7 +92,7 @@ private:
      * from an old entry, is used to fill the form for editing an entry, or is
      * filled with new data for adding a new entry to the logbook.
      */
-    experimental::AFlightEntry flightEntry;
+    AFlightEntry flightEntry;
 
     QList<QLineEdit*> mandatoryLineEdits;
     QList<QLineEdit*> primaryTimeLineEdits;
@@ -151,7 +145,7 @@ private:
     void addNewTail(QLineEdit*);
     void addNewPilot(QLineEdit *);
 
-    experimental::TableData collectInput();
+    RowData collectInput();
 };
 
 

+ 15 - 14
src/gui/dialogues/newpilotdialog.cpp

@@ -17,6 +17,9 @@
  */
 #include "newpilotdialog.h"
 #include "ui_newpilot.h"
+
+#include "src/database/adatabase.h"
+#include "src/classes/aentry.h"
 #include "src/testing/adebug.h"
 
 /* Examples for names around the world:
@@ -59,14 +62,12 @@ static const auto LINE_EDIT_VALIDATORS = QVector{
         EMPLOYEENR_VALID
 };
 
-using namespace experimental;
-
 // For creating a new entry
 NewPilotDialog::NewPilotDialog(QWidget *parent) :
     QDialog(parent),
     ui(new Ui::NewPilot)
 {
-    DEB("New NewPilotDialog (newEntry)");
+    DEB << "New NewPilotDialog (newEntry)";
     setup();
 
     pilotEntry = APilotEntry();
@@ -77,18 +78,18 @@ NewPilotDialog::NewPilotDialog(int rowId, QWidget *parent) :
     QDialog(parent),
     ui(new Ui::NewPilot)
 {
-    DEB("New NewPilotDialog (editEntry)");
+    DEB << "New NewPilotDialog (editEntry)";
     setup();
 
     pilotEntry = aDB()->getPilotEntry(rowId);
-    DEB("Pilot Entry position: " << pilotEntry.getPosition());
+    DEB << "Pilot Entry position: " << pilotEntry.getPosition().tableName << pilotEntry.getPosition().rowId;
     formFiller();
     ui->lastnameLineEdit->setFocus();
 }
 
 NewPilotDialog::~NewPilotDialog()
 {
-    DEB("Deleting New NewPilotDialog");
+    DEB << "Deleting New NewPilotDialog";
     delete ui;
 }
 
@@ -96,18 +97,18 @@ void NewPilotDialog::setup()
 {
     ui->setupUi(this);
 
-    DEB("Setting up Validators...");
+    DEB << "Setting up Validators...";
     for (const auto& pair : LINE_EDIT_VALIDATORS) {
         auto line_edit = parent()->findChild<QLineEdit*>(pair.first);
         if (line_edit != nullptr) {
             auto validator = new QRegularExpressionValidator(pair.second,line_edit);
             line_edit->setValidator(validator);
         } else {
-            DEB("Error: Line Edit not found: "<< pair.first << " - skipping.");
+            DEB << "Error: Line Edit not found: "<< pair.first << " - skipping.";
         }
     }
 
-    DEB("Setting up completer...");
+    DEB << "Setting up completer...";
     auto completer = new QCompleter(aDB()->getCompletionList(ADatabaseTarget::companies), ui->companyLineEdit);
     completer->setCompletionMode(QCompleter::InlineCompletion);
     completer->setCaseSensitivity(Qt::CaseSensitive);
@@ -127,7 +128,7 @@ void NewPilotDialog::on_buttonBox_accepted()
 
 void NewPilotDialog::formFiller()
 {
-    DEB("Filling Form...");
+    DEB << "Filling Form...";
     auto line_edits = this->findChildren<QLineEdit *>();
 
     for (const auto &le : line_edits) {
@@ -138,9 +139,9 @@ void NewPilotDialog::formFiller()
 
 void NewPilotDialog::submitForm()
 {
-    DEB("Collecting User Input...");
+    DEB << "Collecting User Input...";
 
-    TableData new_data;
+    RowData new_data;
     auto line_edits = this->findChildren<QLineEdit *>();
     for(auto& le : line_edits) {
         auto key = le->objectName().remove("LineEdit");
@@ -149,8 +150,8 @@ void NewPilotDialog::submitForm()
     }
 
     pilotEntry.setData(new_data);
-    DEB("Pilot entry position: " << pilotEntry.getPosition());
-    DEB("Pilot entry data: " << pilotEntry.getData());
+    DEB << "Pilot entry position: " << pilotEntry.getPosition().tableName << pilotEntry.getPosition().rowId;
+    DEB << "Pilot entry data: " << pilotEntry.getData();
     if (!aDB()->commit(pilotEntry)) {
         auto message_box = QMessageBox(this);
         message_box.setText("The following error has ocurred:\n\n"

+ 2 - 7
src/gui/dialogues/newpilotdialog.h

@@ -23,12 +23,7 @@
 #include <QRegularExpression>
 #include <QRegularExpressionValidator>
 #include <QCompleter>
-#include "src/classes/pilot.h"
-
-#include "src/experimental/adatabase.h"
-#include "src/experimental/aentry.h"
-#include "src/experimental/apilotentry.h"
-#include "src/experimental/decl.h"
+#include "src/classes/apilotentry.h"
 
 namespace Ui {
 class NewPilot;
@@ -47,7 +42,7 @@ private slots:
 private:
     Ui::NewPilot *ui;
 
-    experimental::APilotEntry pilotEntry;
+    APilotEntry pilotEntry;
 
     inline void setup();
 

+ 17 - 22
src/gui/dialogues/newtaildialog.cpp

@@ -18,7 +18,6 @@
 #include "newtaildialog.h"
 #include "ui_newtail.h"
 #include "src/testing/adebug.h"
-#include "src/database/tablecolumnliterals.h"
 
 static const auto REG_VALID = QPair<QString, QRegularExpression> {
     "registrationLineEdit", QRegularExpression("\\w+-\\w+")};
@@ -35,7 +34,7 @@ NewTailDialog::NewTailDialog(QString new_registration, QWidget *parent) :
     QDialog(parent),
     ui(new Ui::NewTail)
 {
-    DEB("new NewTailDialog (experimental)");
+    DEB << "new NewTailDialog";
     ui->setupUi(this);
 
     setupCompleter();
@@ -45,15 +44,14 @@ NewTailDialog::NewTailDialog(QString new_registration, QWidget *parent) :
     ui->searchLineEdit->setStyleSheet("border: 1px solid blue");
     ui->searchLineEdit->setFocus();
 
-    entry = experimental::ATailEntry();
+    entry = ATailEntry();
 }
 
 NewTailDialog::NewTailDialog(int row_id, QWidget *parent) :
     QDialog(parent),
     ui(new Ui::NewTail)
 {
-    using namespace experimental;
-    DEB("New experimental New Pilot Dialog (edit existing)");
+    DEB << "New New Pilot Dialog (edit existing)";
     ui->setupUi(this);
 
     ui->searchLabel->hide();
@@ -67,7 +65,7 @@ NewTailDialog::NewTailDialog(int row_id, QWidget *parent) :
 
 NewTailDialog::~NewTailDialog()
 {
-    DEB("Deleting NewTailDialog\n");
+    DEB << "Deleting NewTailDialog\n";
     delete ui;
 }
 /// Functions
@@ -80,7 +78,6 @@ NewTailDialog::~NewTailDialog()
  */
 void NewTailDialog::setupCompleter()
 {
-    using namespace experimental;
     idMap = aDB()->getIdMap(ADatabaseTarget::aircraft);
     aircraftList = aDB()->getCompletionList(ADatabaseTarget::aircraft);
 
@@ -114,9 +111,9 @@ void NewTailDialog::setupValidators()
  * a tail (ATail, used when editing an existing entry)
  * \param entry
  */
-void NewTailDialog::fillForm(experimental::AEntry entry, bool is_template)
+void NewTailDialog::fillForm(AEntry entry, bool is_template)
 {
-    DEB("Filling Form for (experimental) a/c" << entry.getPosition());
+    DEB << "Filling Form for a/c" << entry.getPosition().tableName << entry.getPosition().rowId;
     //fill Line Edits
     auto line_edits = this->findChildren<QLineEdit *>();
 
@@ -152,12 +149,12 @@ bool NewTailDialog::verify()
 
     for (const auto &le : recommended_line_edits) {
         if (le->text() != "") {
-            DEB("Good: " << le);
+            DEB << "Good: " << le;
             recommended_line_edits.removeOne(le);
             le->setStyleSheet("");
         } else {
             le->setStyleSheet("border: 1px solid red");
-            DEB("Not Good: " << le);
+            DEB << "Not Good: " << le;
         }
     }
     for (const auto &cb : recommended_combo_boxes) {
@@ -167,7 +164,7 @@ bool NewTailDialog::verify()
             cb->setStyleSheet("");
         } else {
             cb->setStyleSheet("background: orange");
-            DEB("Not Good: " << cb);
+            DEB << "Not Good: " << cb;
         }
     }
 
@@ -184,9 +181,8 @@ bool NewTailDialog::verify()
  */
 void NewTailDialog::submitForm()
 {
-    DEB("Creating Database Object...");
-    using namespace experimental;
-    TableData new_data;
+    DEB << "Creating Database Object...";
+    RowData new_data;
     //retreive Line Edits
     auto line_edits = this->findChildren<QLineEdit *>();
     line_edits.removeOne(this->findChild<QLineEdit *>("searchLineEdit"));
@@ -220,8 +216,8 @@ void NewTailDialog::submitForm()
         message_box.exec();
         return;
     } else {
-        if (entry.getPosition().second != 0)
-            ACalc::updateAutoTimes(entry.getPosition().second);
+        if (entry.getPosition().rowId != 0)
+            ACalc::updateAutoTimes(entry.getPosition().rowId);
         QDialog::accept();
     }
 }
@@ -258,7 +254,7 @@ void NewTailDialog::on_weightComboBox_currentIndexChanged(int index)
 
 void NewTailDialog::on_buttonBox_accepted()
 {
-    DEB("Button Box Accepted.");
+    DEB << "Button Box Accepted.";
     if (ui->registrationLineEdit->text().isEmpty()) {
         auto nope = QMessageBox(this);
         nope.setText("Registration cannot be empty.");
@@ -289,19 +285,18 @@ void NewTailDialog::on_buttonBox_accepted()
             }
         }
     }
-    DEB("Form verified");
+    DEB << "Form verified";
     submitForm();
 }
 
 void NewTailDialog::onSearchCompleterActivated()
 {
-    DEB("Search completer activated!");
+    DEB << "Search completer activated!";
     const auto &text = ui->searchLineEdit->text();
     if (aircraftList.contains(text)) {
 
-            DEB("Template Selected. aircraft_id is: " << idMap.value(text));
+            DEB << "Template Selected. aircraft_id is: " << idMap.value(text);
             //call autofiller for dialog
-            using namespace experimental;
             fillForm(aDB()->getAircraftEntry(idMap.value(text)), true);
             ui->searchLineEdit->setStyleSheet("border: 1px solid green");
             ui->searchLabel->setText(text);

+ 7 - 8
src/gui/dialogues/newtaildialog.h

@@ -24,11 +24,10 @@
 #include <QRegularExpression>
 
 #include "src/classes/asettings.h"
-#include "src/classes/aircraft.h"
 #include "src/functions/acalc.h"
-#include "src/experimental/adatabase.h"
-#include "src/experimental/atailentry.h"
-#include "src/experimental/aaircraftentry.h"
+#include "src/database/adatabase.h"
+#include "src/classes/atailentry.h"
+#include "src/classes/aaircraftentry.h"
 
 namespace Ui {
 class NewTail;
@@ -45,9 +44,9 @@ class NewTailDialog : public QDialog
     Q_OBJECT
 
 public:
-    // experimental create new tail
+    //create new tail
     explicit NewTailDialog(QString new_registration, QWidget *parent = nullptr);
-    // experimental edit existing tail
+    //edit existing tail
     explicit NewTailDialog(int row_id, QWidget *parent = nullptr);
 
     ~NewTailDialog();
@@ -55,7 +54,7 @@ private:
 
     Ui::NewTail *ui;
 
-    experimental::ATailEntry entry;
+    ATailEntry entry;
 
     QStringList aircraftList;
 
@@ -63,7 +62,7 @@ private:
 
     void setupCompleter();
     void setupValidators();
-    void fillForm(experimental::AEntry entry, bool is_template);
+    void fillForm(AEntry entry, bool is_template);
     bool verify();
     void submitForm();
 

+ 10 - 10
src/gui/widgets/aircraftwidget.cpp

@@ -17,18 +17,18 @@
  */
 #include "aircraftwidget.h"
 #include "ui_aircraftwidget.h"
-
-// Debug Makro
-#define DEB(expr) \
-    qDebug() << __PRETTY_FUNCTION__ << "\t" << expr
-
-using namespace experimental;
+#include "src/gui/dialogues/newtaildialog.h"
+#include "src/classes/asettings.h"
+#include "src/database/adatabase.h"
+#include "src/classes/atailentry.h"
+#include "src/classes/aflightentry.h"
+#include "src/testing/adebug.h"
 
 AircraftWidget::AircraftWidget(QWidget *parent) :
     QWidget(parent),
     ui(new Ui::AircraftWidget)
 {
-    DEB("New AircraftWidet");
+    DEB << "New AircraftWidet";
     ui->setupUi(this);
     ui->stackedWidget->addWidget(this->findChild<QWidget*>("welcomePageTails"));
     ui->stackedWidget->setCurrentWidget(this->findChild<QWidget*>("welcomePageTails"));
@@ -38,7 +38,7 @@ AircraftWidget::AircraftWidget(QWidget *parent) :
 
 AircraftWidget::~AircraftWidget()
 {
-    DEB("Deleting NewAircraftWidget");
+    DEB << "Deleting NewAircraftWidget";
     delete ui;
 }
 
@@ -167,7 +167,7 @@ void AircraftWidget::onDisplayModel_dataBaseUpdated()
 void AircraftWidget::tableView_selectionChanged()
 {
     if (this->findChild<NewTailDialog*>() != nullptr) {
-        DEB("Selection changed. Deleting orphaned dialog.");
+        DEB << "Selection changed. Deleting orphaned dialog.";
         delete this->findChild<NewTailDialog*>();
         /// [F] if the user changes the selection without making any changes,
         /// if(selectedTails.length() == 1) spawns a new dialog without the
@@ -180,7 +180,7 @@ void AircraftWidget::tableView_selectionChanged()
 
     for (const auto& row : selection->selectedRows()) {
         selectedTails << row.data().toInt();
-        DEB("Selected Tails(s) with ID: " << selectedTails);
+        DEB << "Selected Tails(s) with ID: " << selectedTails;
     }
     if(selectedTails.length() == 1) {
         auto* nt = new NewTailDialog(selectedTails.first(), this);

+ 0 - 8
src/gui/widgets/aircraftwidget.h

@@ -24,14 +24,6 @@
 #include <QDebug>
 #include <QTableView>
 
-#include "src/classes/asettings.h"
-#include "src/gui/dialogues/newtaildialog.h"
-//#include "src/classes/aircraft.h"
-//#include "src/database/db.h"
-#include "src/experimental/adatabase.h"
-#include "src/experimental/atailentry.h"
-#include "src/experimental/aflightentry.h"
-
 
 namespace Ui {
 class AircraftWidget;

+ 16 - 43
src/gui/widgets/debugwidget.cpp

@@ -1,14 +1,13 @@
 #include "debugwidget.h"
 #include "ui_debugwidget.h"
-
-using namespace experimental;
+#include "src/astandardpaths.h"
 
 DebugWidget::DebugWidget(QWidget *parent) :
     QWidget(parent),
     ui(new Ui::DebugWidget)
 {
     ui->setupUi(this);
-    for (const auto& table : DbInfo().tables) {
+    for (const auto& table : aDB()->getTableNames()) {
         if( table != "sqlite_sequence") {
             ui->tableComboBox->addItem(table);
         }
@@ -41,7 +40,7 @@ void DebugWidget::on_resetDatabasePushButton_clicked()
     QMessageBox mb(this);
     //check if template dir exists and create if needed.
     QDir dir("data/templates");
-    DEB(dir.path());
+    DEB << dir.path();
     if (!dir.exists())
         dir.mkpath(".");
     // download latest csv
@@ -59,17 +58,20 @@ void DebugWidget::on_resetDatabasePushButton_clicked()
         loop.exec(); // event loop waits for download done signal before allowing loop to continue
         dl->deleteLater();
     }
+
     //close database connection
     aDB()->disconnect();
 
-    // back up old database
+    // back up and remove old database
     auto oldDatabase = QFile("data/logbook.db");
     if (oldDatabase.exists()) {
         auto dateString = QDateTime::currentDateTime().toString(Qt::ISODate);
-        DEB("Backing up old database as: " << "logbook-backup-" + dateString);
-        if (!oldDatabase.rename("data/logbook-backup-" + dateString + ".db")) {
-            DEB("Warning: Creating backup of old database has failed.");
+        DEB << "Backing up old database as: " << "logbook-backup-" + dateString + ".db";
+        if (oldDatabase.copy("data/logbook-backup-" + dateString + ".db")) {
+            oldDatabase.remove();
+            DEB << "Old Database removed.";
         }
+
     }
     // re-connct and create new database
     aDB()->connect();
@@ -95,7 +97,7 @@ void DebugWidget::on_fillUserDataPushButton_clicked()
     QMessageBox mb(this);
     //check if template dir exists and create if needed.
     QDir dir("data/templates");
-    DEB(dir.path());
+    DEB << dir.path();
     if (!dir.exists())
         dir.mkpath(".");
     // download latest csv
@@ -145,7 +147,7 @@ void DebugWidget::on_importCsvPushButton_clicked()
 {
     ATimer timer(this);
     auto file = QFileInfo(ui->importCsvLineEdit->text());
-    DEB("File exists/is file: " << file.exists() << file.isFile() << " Path: " << file.absoluteFilePath());
+    DEB << "File exists/is file: " << file.exists() << file.isFile() << " Path: " << file.absoluteFilePath();
 
     if (file.exists() && file.isFile()) {
 
@@ -167,41 +169,13 @@ void DebugWidget::on_importCsvPushButton_clicked()
 
 void DebugWidget::on_debugPushButton_clicked()
 {
-    qlonglong number_of_runs = 500;
-            long time1 = 0;
-            using namespace experimental;
-            {
-
-                ATimer timer;
-                for (int i = 0; i < number_of_runs; i++) {
-                    // first block, do stuff here...
-                    auto acft = aDB()->getTailEntry(5);
-                    auto pilot = aDB()->getPilotEntry(7);
-                    auto flight = aDB()->getFlightEntry(15);
-                    QList<AEntry> list = {acft, pilot, flight};
-                    for (auto entry : list) {
-                        for (auto column : entry.getData()) {
-                            QString value = column.toString();
-                        }
-                    }
-                }
-
-                time1 = timer.timeNow();
-            }
-
-            DEB("First block executed " << number_of_runs << " times for a total of " << time1 << " milliseconds.");
-            // 116 - 134 milliseconds with legacy exp db api
-            // 108 - 110 milliseconds with improved exp api
-            // to do: with string literals*/
-
-
+    DEB << AStandardPaths::getPaths()[QStandardPaths::AppDataLocation];
 }
 
 /* //Comparing two functions template
     qlonglong number_of_runs = 5000;
     long time1 = 0;
     long time2 = 0;
-    using namespace experimental;
     {
 
         ATimer timer;
@@ -219,8 +193,8 @@ void DebugWidget::on_debugPushButton_clicked()
         time2 = timer.timeNow();
     }
 
-    DEB("First block executed " << number_of_runs << " times for a total of " << time1 << " milliseconds.");
-    DEB("Second block executed " << number_of_runs << " times for a total of " << time2 << " milliseconds.");
+    DEB << "First block executed " << number_of_runs << " times for a total of " << time1 << " milliseconds.");
+    DEB << "Second block executed " << number_of_runs << " times for a total of " << time2 << " milliseconds.");
 */
 
 
@@ -228,7 +202,6 @@ void DebugWidget::on_debugPushButton_clicked()
 
 /*qlonglong number_of_runs = 500;
         long time1 = 0;
-        using namespace experimental;
         {
 
             ATimer timer;
@@ -248,7 +221,7 @@ void DebugWidget::on_debugPushButton_clicked()
             time1 = timer.timeNow();
         }
 
-        DEB("First block executed " << number_of_runs << " times for a total of " << time1 << " milliseconds.");
+        DEB << "First block executed " << number_of_runs << " times for a total of " << time1 << " milliseconds.");
         // 108 - 134 milliseconds with legacy exp db api
         // 108 - 110 milliseconds with improved exp api
         // to do: with string literals*/

+ 3 - 5
src/gui/widgets/debugwidget.h

@@ -8,15 +8,13 @@
 #include <QFileDialog>
 #include <QMessageBox>
 #include <QProcess>
-#include "src/database/db.h"
 #include "src/database/adatabasesetup.h"
-#include "src/database/dbinfo.h"
 #include "src/classes/adownload.h"
 #include "src/functions/areadcsv.h"
 
-#include "src/experimental/adatabase.h"
-#include "src/experimental/aentry.h"
-#include "src/experimental/apilotentry.h"
+#include "src/database/adatabase.h"
+#include "src/classes/aentry.h"
+#include "src/classes/apilotentry.h"
 
 #include "src/testing/abenchmark.h"
 #include "src/testing/atimer.h"

+ 1 - 5
src/gui/widgets/homewidget.h

@@ -22,19 +22,15 @@
 #include <QStackedLayout>
 #include <QLabel>
 #include <QLineEdit>
-#include "src/database/db.h"
 #include "src/functions/astat.h"
 #include "src/functions/acalc.h"
 #include "src/gui/dialogues/newtaildialog.h"
-#include "src/classes/aircraft.h"
 #include "src/gui/dialogues/newpilotdialog.h"
-#include "src/database/entry_deprecated.h"
 #include "src/gui/widgets/totalswidget.h"
 #include "src/gui/dialogues/firstrundialog.h"
 #include "src/gui/dialogues/newflightdialog.h"
 
-#include "src/experimental/adatabase.h"
-#include "src/experimental/decl.h"
+#include "src/database/adatabase.h"
 
 namespace Ui {
 class HomeWidget;

+ 13 - 10
src/gui/widgets/logbookwidget.cpp

@@ -17,9 +17,12 @@
  */
 #include "logbookwidget.h"
 #include "ui_logbookwidget.h"
-#include "src/testing/adebug.h"
 
-using namespace experimental;
+#include "src/classes/aflightentry.h"
+#include "src/database/adatabase.h"
+#include "src/classes/asettings.h"
+#include "src/gui/dialogues/newflightdialog.h"
+#include "src/testing/adebug.h"
 
 const QMap<int, QString> FILTER_MAP = {
     {0, "Date LIKE \"%"},
@@ -81,7 +84,7 @@ void LogbookWidget::connectSignalsAndSlots()
 
 void LogbookWidget::setupDefaultView()
 {
-    DEB("Loading Default View...");
+    DEB << "Loading Default View...";
     displayModel = new QSqlTableModel;
     displayModel->setTable("viewDefault");
     displayModel->select();
@@ -114,7 +117,7 @@ void LogbookWidget::setupDefaultView()
 
 void LogbookWidget::setupEasaView()
 {
-    DEB("Loading EASA View...");
+    DEB << "Loading EASA View...";
     displayModel = new QSqlTableModel;
     displayModel->setTable("viewEASA");
     displayModel->select();
@@ -165,7 +168,7 @@ void LogbookWidget::flightsTableView_selectionChanged()//
     selectedFlights.clear();
     for (const auto& row : selectionModel->selectedRows()) {
         selectedFlights.append(row.data().toInt());
-        DEB("Selected Flight(s) with ID: " << selectedFlights);
+        DEB << "Selected Flight(s) with ID: " << selectedFlights;
     }
 }
 
@@ -195,17 +198,17 @@ void LogbookWidget::on_editFlightButton_clicked()
 
 void LogbookWidget::on_deleteFlightPushButton_clicked()
 {
-    DEB("Flights selected: " << selectedFlights.length());
+    DEB << "Flights selected: " << selectedFlights.length();
     if (selectedFlights.length() == 0) {
         messageBox->setIcon(QMessageBox::Information);
         messageBox->setText("No Flight Selected.");
         messageBox->exec();
         return;
     } else if (selectedFlights.length() > 0 && selectedFlights.length() < 11) {
-        QList<experimental::AFlightEntry> flights_list;
+        QList<AFlightEntry> flights_list;
 
         for (const auto &flight_id : selectedFlights) {
-            flights_list.append(experimental::aDB()->getFlightEntry(flight_id));
+            flights_list.append(aDB()->getFlightEntry(flight_id));
         }
 
         QString warningMsg = "The following flight(s) will be deleted:<br><br><b><tt>";
@@ -226,7 +229,7 @@ void LogbookWidget::on_deleteFlightPushButton_clicked()
         int reply = confirm.exec();
         if (reply == QMessageBox::Yes) {
             for (auto& flight : flights_list) {
-                DEB("Deleting flight: " << flight.summary());
+                DEB << "Deleting flight: " << flight.summary();
                 if(!aDB()->remove(flight)) {
                     messageBox->setText(aDB()->lastError.text());
                     messageBox->exec();
@@ -238,7 +241,7 @@ void LogbookWidget::on_deleteFlightPushButton_clicked()
             displayModel->select();
         }
     } else if (selectedFlights.length() > 10) {
-        auto& warningMsg = "You have selected " + QString::number(selectedFlights.length())
+        auto warningMsg = "You have selected " + QString::number(selectedFlights.length())
                 + " flights.\n\n Deleting flights is irreversible.\n\n"
                   "Are you sure you want to proceed?";
         QMessageBox confirm;

+ 0 - 6
src/gui/widgets/logbookwidget.h

@@ -26,12 +26,6 @@
 #include <QMenu>
 #include <QTableView>
 
-#include "src/classes/asettings.h"
-#include "src/database/db.h"
-#include "src/classes/flight.h"
-#include "src/gui/dialogues/newflightdialog.h"
-#include "src/experimental/aflightentry.h"
-
 namespace Ui {
 class LogbookWidget;
 }

+ 4 - 3
src/gui/widgets/pilotswidget.cpp

@@ -18,8 +18,9 @@
 #include "pilotswidget.h"
 #include "ui_pilotswidget.h"
 #include "src/testing/adebug.h"
+#include "src/database/adatabase.h"
+#include "src/classes/apilotentry.h"
 
-using namespace experimental;
 PilotsWidget::PilotsWidget(QWidget *parent) :
     QWidget(parent),
     ui(new Ui::PilotsWidget)
@@ -80,7 +81,7 @@ void PilotsWidget::onDisplayModel_dataBaseUpdated()
 void PilotsWidget::tableView_selectionChanged()//const QItemSelection &index, const QItemSelection &
 {
     if (this->findChild<NewPilotDialog*>() != nullptr) {
-        DEB("Selection changed. Deleting orphaned dialog.");
+        DEB << "Selection changed. Deleting orphaned dialog.";
         delete this->findChild<NewPilotDialog*>();
         /// [F] if the user changes the selection without making any changes,
         /// if(selectedPilots.length() == 1) spawns a new dialog without the
@@ -94,7 +95,7 @@ void PilotsWidget::tableView_selectionChanged()//const QItemSelection &index, co
 
     for (const auto& row : selection->selectedRows()) {
         selectedPilots.append(row.data().toInt());
-        DEB("Selected Tails(s) with ID: " << selectedPilots);
+        DEB << "Selected Tails(s) with ID: " << selectedPilots;
     }
     if(selectedPilots.length() == 1) {
 

+ 0 - 1
src/gui/widgets/pilotswidget.h

@@ -24,7 +24,6 @@
 #include <QDebug>
 #include <QTableView>
 #include "src/classes/asettings.h"
-#include "src/classes/pilot.h"
 #include "src/gui/dialogues/newpilotdialog.h"
 
 namespace Ui {

+ 9 - 8
src/gui/widgets/settingswidget.cpp

@@ -17,9 +17,12 @@
  */
 #include "settingswidget.h"
 #include "ui_settingswidget.h"
-#include "src/database/dbinfo.h"
 #include "src/testing/adebug.h"
 
+#include "src/classes/asettings.h"
+#include "src/database/adatabase.h"
+#include "src/classes/apilotentry.h"
+
 static const auto FIRSTNAME_VALID = QPair<QString, QRegularExpression> {
     "firstnameLineEdit", QRegularExpression("[a-zA-Z]+")};
 static const auto LASTNAME_VALID = QPair<QString, QRegularExpression> {
@@ -41,8 +44,6 @@ static const auto LINE_EDIT_VALIDATORS = QVector({FIRSTNAME_VALID, LASTNAME_VALI
                                            COMPANY_VALID,     EMPLOYEENR_VALID,
                                            PREFIX_VALID});
 
-using namespace experimental;
-
 SettingsWidget::SettingsWidget(QWidget *parent) :
     QWidget(parent),
     ui(new Ui::SettingsWidget)
@@ -59,7 +60,7 @@ SettingsWidget::SettingsWidget(QWidget *parent) :
     setupValidators();
 
     QObject::connect(themeGroup, QOverload<int>::of(&QButtonGroup::buttonClicked),
-                     this, &SettingsWidget::on_themeGroup_buttonClicked);
+                     this, &SettingsWidget::onThemeGroup_buttonClicked);
 }
 
 SettingsWidget::~SettingsWidget()
@@ -111,14 +112,14 @@ void SettingsWidget::readSettings()
 
 void SettingsWidget::setupValidators()
 {
-    DEB("Setting up Validators...");
+    DEB << "Setting up Validators...";
     for(const auto& pair : LINE_EDIT_VALIDATORS){
         auto line_edit = parent()->findChild<QLineEdit*>(pair.first);
         if(line_edit != nullptr){
             auto validator = new QRegularExpressionValidator(pair.second,line_edit);
             line_edit->setValidator(validator);
         }else{
-            DEB("Error: Line Edit not found: "<< pair.first << " - skipping.");
+            DEB << "Error: Line Edit not found: "<< pair.first << " - skipping.";
         }
 
     }
@@ -263,7 +264,7 @@ void SettingsWidget::on_prefixLineEdit_textChanged(const QString &arg1)
 /*
  * Misc Tab
  */
-void SettingsWidget::on_themeGroup_buttonClicked(int theme_id)
+void SettingsWidget::onThemeGroup_buttonClicked(int theme_id)
 {
     ASettings::write("main/theme", theme_id);
 
@@ -325,7 +326,7 @@ void SettingsWidget::on_acAllowIncompleteComboBox_currentIndexChanged(int index)
 void SettingsWidget::on_aboutPushButton_clicked()
 {
     auto message_box = QMessageBox(this);
-    QString SQLITE_VERSION = DbInfo().version;
+    QString SQLITE_VERSION = aDB()->sqliteVersion();
     QString text = QMessageBox::tr(
 
                        "<h3><center>About openPilotLog</center></h3>"

+ 1 - 4
src/gui/widgets/settingswidget.h

@@ -24,9 +24,6 @@
 #include <QMessageBox>
 #include <QProcess>
 #include <QDebug>
-#include "src/classes/asettings.h"
-#include "src/experimental/adatabase.h"
-#include "src/experimental/apilotentry.h"
 
 namespace Ui {
 class SettingsWidget;
@@ -42,7 +39,7 @@ public:
 
 private slots:
 
-    void on_themeGroup_buttonClicked(int theme_id);
+    void onThemeGroup_buttonClicked(int theme_id);
     void on_aboutPushButton_clicked();
     void on_acSortComboBox_currentIndexChanged(int index);
     void on_acAllowIncompleteComboBox_currentIndexChanged(int index);

+ 2 - 2
src/gui/widgets/totalswidget.cpp

@@ -8,8 +8,8 @@ TotalsWidget::TotalsWidget(QWidget *parent) :
 {
     ui->setupUi(this);
     auto data = AStat::totals();
-    DEB("Filling Totals Line Edits...");
-    //DEB("data: " << data);
+    DEB << "Filling Totals Line Edits...";
+    //DEB << "data: " << data;
     for (const auto &field : data) {
         auto line_edit = parent->findChild<QLineEdit *>(field.first + "LineEdit");
         line_edit->setText(field.second);

+ 0 - 1
src/gui/widgets/totalswidget.h

@@ -6,7 +6,6 @@
 #include <QLabel>
 #include <QLineEdit>
 #include <QSettings>
-#include "src/database/db.h"
 #include "src/functions/astat.h"
 
 namespace Ui {

+ 12 - 12
src/testing/abenchmark.cpp

@@ -29,7 +29,7 @@ ABenchmark::ABenchmark(void (*function_one)(), void (*function_two)(), int numbe
             function_one();
         }
         auto stop1 = std::chrono::high_resolution_clock::now();
-        DEB("First Function execution finished (" << number_of_runs << " runs)");
+        DEB << "First Function execution finished (" << number_of_runs << " runs)";
 
 
         auto start2 = std::chrono::high_resolution_clock::now();
@@ -37,14 +37,14 @@ ABenchmark::ABenchmark(void (*function_one)(), void (*function_two)(), int numbe
             function_two();
         }
         auto stop2 = std::chrono::high_resolution_clock::now();
-        DEB("Second Function execution finished (" << number_of_runs << " runs)");
+        DEB << "Second Function execution finished (" << number_of_runs << " runs)";
 
-        DEB("Execution time for function 1: "
+        DEB << "Execution time for function 1: "
             << std::chrono::duration_cast<std::chrono::milliseconds>(stop1 - start1).count()
-            << "milliseconds.");
-        DEB("Execution time for function 2: "
+            << "milliseconds.";
+        DEB << "Execution time for function 2: "
             << std::chrono::duration_cast<std::chrono::milliseconds>(stop2 - start2).count()
-            << "milliseconds.");
+            << "milliseconds.";
 }
 
 ABenchmark::ABenchmark(bool (*function_one)(), bool (*function_two)(), int number_of_runs)
@@ -54,7 +54,7 @@ ABenchmark::ABenchmark(bool (*function_one)(), bool (*function_two)(), int numbe
         function_one();
     }
     auto stop1 = std::chrono::high_resolution_clock::now();
-    DEB("First Function execution finished (" << number_of_runs << " runs)");
+    DEB << "First Function execution finished (" << number_of_runs << " runs)";
 
 
     auto start2 = std::chrono::high_resolution_clock::now();
@@ -62,12 +62,12 @@ ABenchmark::ABenchmark(bool (*function_one)(), bool (*function_two)(), int numbe
         function_two();
     }
     auto stop2 = std::chrono::high_resolution_clock::now();
-    DEB("Second Function execution finished (" << number_of_runs << " runs)");
+    DEB << "Second Function execution finished (" << number_of_runs << " runs)";
 
-    DEB("Execution time for function 1: "
+    DEB << "Execution time for function 1: "
         << std::chrono::duration_cast<std::chrono::milliseconds>(stop1 - start1).count()
-        << "milliseconds.");
-    DEB("Execution time for function 2: "
+        << "milliseconds.";
+    DEB << "Execution time for function 2: "
         << std::chrono::duration_cast<std::chrono::milliseconds>(stop2 - start2).count()
-        << "milliseconds.");
+        << "milliseconds.";
 }

+ 0 - 5
src/testing/abenchmark.h

@@ -20,9 +20,6 @@
 
 #include <QObject>
 #include "src/testing/adebug.h"
-#include "src/experimental/adatabase.h"
-#include "src/experimental/aentry.h"
-#include "src/experimental/decl.h"
 
 /*!
  * \brief The ABenchmark class provides quick access to benchmarking two functions for
@@ -38,8 +35,6 @@ public:
 
     ABenchmark(bool (*function_one)(), bool (*function_two)(), int number_of_runs);
 
-    //ABenchmark(experimental::AEntry (*function_one)(experimental::DataPosition), experimental::AEntry (*function_two)(int), int number_of_runs);
-
 };
 
 #endif // ABENCHMARK_H

+ 28 - 2
src/testing/adebug.h

@@ -3,7 +3,33 @@
 
 #include <QDebug>
 
-#define DEB(expr) \
-    qDebug() << __PRETTY_FUNCTION__ << "\t" << expr
+#define DEB qDebug() << __PRETTY_FUNCTION__ << "\t"
+
+/*!
+ * Representation macro for custom classes.
+ *
+ * Usage
+ * -----
+ * class Myclass {
+ *  ...
+ * 	REPR(MyClass,
+ *       "member1=" + object.member1 + ", "
+ *       "something2" + object.calculate()
+ *      )
+ * };
+ *
+ * MyClass mc;
+ * DEB << mc;
+ *
+ * output:
+ * MyClass(member1=3000, something2="A320")
+ */
+#define REPR(cls, str) \
+friend \
+QDebug operator<<(QDebug qdb, const cls& object) \
+{ \
+    qdb << QString(#cls) + '(' + str + ')'; \
+    return qdb; \
+}
 
 #endif

+ 10 - 10
src/testing/atimer.cpp

@@ -22,9 +22,9 @@ ATimer::ATimer(QObject *parent) : QObject(parent)
 {
      start = std::chrono::high_resolution_clock::now();
      if(parent == nullptr) {
-         DEB("Starting Timer... ");
+         DEB << "Starting Timer... ";
      } else {
-         DEB("Starting Timer for: " << parent->objectName());
+         DEB << "Starting Timer for: " << parent->objectName();
      }
 
 }
@@ -33,13 +33,13 @@ ATimer::~ATimer()
 {
     stop = std::chrono::high_resolution_clock::now();
     if(parent() == nullptr) {
-        DEB("Execution time: "
+        DEB << "Execution time: "
                  << std::chrono::duration_cast<std::chrono::milliseconds>(stop - start).count()
-                 << "milliseconds.");
+                 << "milliseconds.";
     } else {
-        DEB("Execution time for: " << parent()->objectName() << ": "
+        DEB << "Execution time for: " << parent()->objectName() << ": "
                  << std::chrono::duration_cast<std::chrono::milliseconds>(stop - start).count()
-                 << "milliseconds.");
+                 << "milliseconds.";
     }
 }
 
@@ -47,13 +47,13 @@ long ATimer::timeNow()
 {
     intermediate_point = std::chrono::high_resolution_clock::now();
     if(parent() == nullptr) {
-        DEB("Intermediate time: "
+        DEB << "Intermediate time: "
                  << std::chrono::duration_cast<std::chrono::milliseconds>(intermediate_point - start).count()
-                 << "milliseconds.");
+                 << "milliseconds.";
     } else {
-        DEB("Intermediate time for: " << parent()->objectName() << ": "
+        DEB << "Intermediate time for: " << parent()->objectName() << ": "
                  << std::chrono::duration_cast<std::chrono::milliseconds>(intermediate_point - start).count()
-                 << "milliseconds.");
+                 << "milliseconds.";
     }
     return std::chrono::duration_cast<std::chrono::milliseconds>(intermediate_point - start).count();
 }