Browse Source

Refactored aDB() to aDB

George 4 years ago
parent
commit
41dd5fd16c

+ 1 - 1
main.cpp

@@ -51,7 +51,7 @@ int main(int argc, char *argv[])
     ASettings::setup();
 
     AStyle::setup();
-    aDB()->connect();
+    aDB->connect();
     if (!ASettings::read(ASettings::Setup::SetupComplete).toBool()) {
         if(FirstRunDialog().exec() == QDialog::Rejected){
             DEB "First run not accepted. Exiting.";

+ 3 - 3
mainwindow.cpp

@@ -130,11 +130,11 @@ void MainWindow::on_actionDebug_triggered()
 
 void MainWindow::connectWidgets()
 {
-    QObject::connect(aDB(), &ADatabase::dataBaseUpdated,
+    QObject::connect(aDB, &ADatabase::dataBaseUpdated,
                      logbookWidget, &LogbookWidget::onDisplayModel_dataBaseUpdated);
-    QObject::connect(aDB(), &ADatabase::dataBaseUpdated,
+    QObject::connect(aDB, &ADatabase::dataBaseUpdated,
                      pilotsWidget, &PilotsWidget::onDisplayModel_dataBaseUpdated);
-    QObject::connect(aDB(), &ADatabase::dataBaseUpdated,
+    QObject::connect(aDB, &ADatabase::dataBaseUpdated,
                      aircraftWidget, &AircraftWidget::onDisplayModel_dataBaseUpdated);
 
     QObject::connect(settingsWidget, &SettingsWidget::viewSelectionChanged,

+ 4 - 4
src/classes/aflightentry.cpp

@@ -47,7 +47,7 @@ const QString AFlightEntry::summary()
 
 const QString AFlightEntry::getRegistration()
 {
-    ATailEntry acft = aDB()->resolveForeignTail(tableData.value(DB_FLIGHTS_ACFT).toInt());
+    ATailEntry acft = aDB->resolveForeignTail(tableData.value(DB_FLIGHTS_ACFT).toInt());
     return acft.registration();
 }
 
@@ -55,16 +55,16 @@ const QString AFlightEntry::getPilotName(pilotPosition pilot_)
 {
     switch (pilot_) {
     case pilotPosition::pic: {
-        auto foreign_pilot = aDB()->resolveForeignPilot(tableData.value(DB_FLIGHTS_PIC).toInt());
+        auto foreign_pilot = aDB->resolveForeignPilot(tableData.value(DB_FLIGHTS_PIC).toInt());
         return foreign_pilot.name();
         break;
     }
     case pilotPosition::secondPilot: {
-        auto foreign_pilot = aDB()->resolveForeignPilot(tableData.value(DB_FLIGHTS_SECONDPILOT).toInt());
+        auto foreign_pilot = aDB->resolveForeignPilot(tableData.value(DB_FLIGHTS_SECONDPILOT).toInt());
         return foreign_pilot.name();
     }
     case pilotPosition::thirdPilot: {
-        auto foreign_pilot = aDB()->resolveForeignPilot(tableData.value(DB_FLIGHTS_THIRDPILOT).toInt());
+        auto foreign_pilot = aDB->resolveForeignPilot(tableData.value(DB_FLIGHTS_THIRDPILOT).toInt());
         return foreign_pilot.name();
         break;
     } // case scope

+ 14 - 10
src/database/adatabase.cpp

@@ -19,7 +19,9 @@
 #include "src/testing/adebug.h"
 #include "src/classes/astandardpaths.h"
 
-#define DATABASE_VERSION 15
+// [G]: this is something that should be declared in adatabase.h
+// it can also be a define because i think we can fetch the driver
+// from the ADatabase::database() (?)
 const auto SQL_DRIVER = QStringLiteral("QSQLITE");
 
 ADatabaseError::ADatabaseError(QString msg_)
@@ -31,7 +33,7 @@ QString ADatabaseError::text() const
     return "Database Error: " + QSqlError::text();
 }
 
-ADatabase* ADatabase::instance = nullptr;
+ADatabase* ADatabase::self = nullptr;
 
 /*!
  * \brief Return the names of a given table in the database.
@@ -70,11 +72,15 @@ void ADatabase::updateLayout()
     emit dataBaseUpdated();
 }
 
-ADatabase* ADatabase::getInstance()
+ADatabase* ADatabase::instance()
 {
-    if(!instance)
-        instance = new ADatabase();
-    return instance;
+#ifdef __GNUC__
+    return self ?: self = new ADatabase();
+#else
+    if(!self)
+        self = new ADatabase();
+    return self;
+#endif
 }
 
 ADatabase::ADatabase()
@@ -603,12 +609,12 @@ QList<int> ADatabase::getForeignKeyConstraints(int foreign_row_id, ADatabaseTarg
 
 APilotEntry ADatabase::resolveForeignPilot(int foreign_key)
 {
-    return aDB()->getPilotEntry(foreign_key);
+    return aDB->getPilotEntry(foreign_key);
 }
 
 ATailEntry ADatabase::resolveForeignTail(int foreign_key)
 {
-    return aDB()->getTailEntry(foreign_key);
+    return aDB->getTailEntry(foreign_key);
 }
 
 QVector<QString> ADatabase::customQuery(QString statement, int return_values)
@@ -636,5 +642,3 @@ QVector<QString> ADatabase::customQuery(QString statement, int return_values)
         return result;
     }
 }
-
-ADatabase* aDB() { return ADatabase::getInstance(); }

+ 14 - 11
src/database/adatabase.h

@@ -39,6 +39,17 @@
 #include "src/classes/aflightentry.h"
 #include "src/classes/astandardpaths.h"
 
+#define DATABASE_VERSION 15
+
+/*!
+ * \brief Convinience macro that returns instance of DataBase.
+ * Instead of this:
+ * DataBase::getInstance().commit(...)
+ * Write this:
+ * aDB->commit(...)
+ */
+#define aDB ADatabase::instance()
+
 /*!
  * \brief The DBTarget enum lists database items that are
  * used by completers, for content matching or need to be accessed programatically.
@@ -77,15 +88,16 @@ public:
 class ADatabase : public QObject {
     Q_OBJECT
 private:
-    static ADatabase* instance;
     ADatabase();
+
+    static ADatabase* self;
     TableNames tableNames;
     TableColumns tableColumns;
 public:
     // Ensure DB is not copiable or assignable
     ADatabase(const ADatabase&) = delete;
     void operator=(const ADatabase&) = delete;
-    static ADatabase* getInstance();
+    static ADatabase* instance();
     TableNames getTableNames() const;
     ColumnNames getTableColumns(TableName table_name) const;
     void updateLayout();
@@ -250,13 +262,4 @@ signals:
     void dataBaseUpdated();
 };
 
-/*!
- * \brief Convinience function that returns instance of DataBase.
- * Instead of this:
- * DataBase::getInstance().commit(...)
- * Write this:
- * aDB()->commit(...)
- */
-ADatabase* aDB();
-
 #endif // ADATABASE_H

+ 6 - 6
src/database/adatabasesetup.cpp

@@ -266,7 +266,7 @@ bool ADataBaseSetup::createDatabase()
         return false;
     }
 
-    aDB()->updateLayout();
+    aDB->updateLayout();
 
     DEB << "Populating tables...";
     if (!importDefaultData()) {
@@ -296,7 +296,7 @@ bool ADataBaseSetup::downloadTemplates()
 }
 bool ADataBaseSetup::backupOldData()
 {
-    auto database_file = aDB()->databaseFile;
+    auto database_file = aDB->databaseFile;
     if(!database_file.exists()) {
         DEB << "No Database to backup, returning.";
         return true;
@@ -305,7 +305,7 @@ bool ADataBaseSetup::backupOldData()
     auto date_string = QDateTime::currentDateTime().toString(Qt::ISODate);
     auto backup_dir = QDir(AStandardPaths::absPathOf(AStandardPaths::DatabaseBackup));
     auto backup_name = database_file.baseName() + "_bak_" + date_string + ".db";
-    auto file = QFile(aDB()->databaseFile.absoluteFilePath());
+    auto file = QFile(aDB->databaseFile.absoluteFilePath());
 
     if (!file.rename(backup_dir.absolutePath() + '/' + backup_name)) {
         DEB << "Unable to backup old database.";
@@ -416,9 +416,9 @@ bool ADataBaseSetup::createSchemata(const QStringList &statements)
  */
 bool ADataBaseSetup::commitData(QVector<QStringList> from_csv, const QString &table_name)
 {
-    DEB << "Table names: " << aDB()->getTableNames();
+    DEB << "Table names: " << aDB->getTableNames();
     DEB << "Importing Data to" << table_name;
-    if (!aDB()->getTableNames().contains(table_name)){
+    if (!aDB->getTableNames().contains(table_name)){
         DEB << table_name << "is not a table in the database. Aborting.";
         DEB << "Please check input data.";
         return false;
@@ -427,7 +427,7 @@ bool ADataBaseSetup::commitData(QVector<QStringList> from_csv, const QString &ta
     QString statement = "INSERT INTO " + table_name + " (";
     QString placeholder = ") VALUES (";
     for (auto& csvColumn : from_csv) {
-        if(aDB()->getTableColumns(table_name).contains(csvColumn.first())) {
+        if(aDB->getTableColumns(table_name).contains(csvColumn.first())) {
             statement += csvColumn.first() + ',';
             csvColumn.removeFirst();
             placeholder.append("?,");

+ 10 - 10
src/functions/acalc.cpp

@@ -88,7 +88,7 @@ double ACalc::greatCircleDistanceBetweenAirports(const QString &dept, const QStr
 {
     auto statement = "SELECT lat, long FROM airports WHERE icao = '"
             + dept + "' OR icao = '" + dest + "'";
-    auto lat_lon = aDB()->customQuery(statement, 2);
+    auto lat_lon = aDB->customQuery(statement, 2);
 
     if (lat_lon.length() != 4) {
         DEB << "Invalid input. Aborting.";
@@ -206,7 +206,7 @@ int ACalc::calculateNightTime(const QString &dept, const QString &dest, QDateTim
 {
 
     auto statement = "SELECT lat, long FROM airports WHERE icao = '" + dept + "' OR icao = '" + dest + "'";
-    auto lat_lon = aDB()->customQuery(statement, 2);
+    auto lat_lon = aDB->customQuery(statement, 2);
 
     if (lat_lon.length() != 4) {
         DEB << "Invalid input. Aborting.";
@@ -234,7 +234,7 @@ int ACalc::calculateNightTime(const QString &dept, const QString &dest, QDateTim
 bool ACalc::isNight(const QString &icao, QDateTime event_time, int night_angle)
 {
     auto statement = "SELECT lat, long FROM airports WHERE icao = '" + icao + "'";
-    auto lat_lon = aDB()->customQuery(statement, 2);
+    auto lat_lon = aDB->customQuery(statement, 2);
 
     if (lat_lon.length() != 2) {
         DEB << "Invalid input. Aborting.";
@@ -262,17 +262,17 @@ void ACalc::updateAutoTimes(int acft_id)
 {
     //find all flights for aircraft
     const QString statement = QStringLiteral("SELECT flight_id FROM flights WHERE acft = ") + QString::number(acft_id);
-    auto flight_list = aDB()->customQuery(statement, 1);
+    auto flight_list = aDB->customQuery(statement, 1);
     if (flight_list.isEmpty()) {
         DEB << "No flights for this tail found.";
         return;
     }
     DEB << "Updating " << flight_list.length() << " flights with this aircraft.";
 
-    auto acft = aDB()->getTailEntry(acft_id);
+    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 = aDB->getFlightEntry(item.toInt());
         auto flight_data = flight.getData();
 
         if(acft_data.value(DB_TAILS_MULTIPILOT).toInt() == 0
@@ -294,7 +294,7 @@ void ACalc::updateAutoTimes(int acft_id)
             flight_data.insert(DB_FLIGHTS_TSPME, DB_NULL);
         }
         flight.setData(flight_data);
-        aDB()->commit(flight);
+        aDB->commit(flight);
     }
 }
 /*!
@@ -307,7 +307,7 @@ void ACalc::updateNightTimes()
 
     //find all flights for aircraft
     auto statement = "SELECT ROWID FROM flights";
-    auto flight_list = aDB()->customQuery(statement, 1);
+    auto flight_list = aDB->customQuery(statement, 1);
 
     if (flight_list.isEmpty()) {
         DEB << "No flights found.";
@@ -317,7 +317,7 @@ void ACalc::updateNightTimes()
 
     for (const auto& item : flight_list) {
 
-        auto flt = aDB()->getFlightEntry(item.toInt());
+        auto flt = aDB->getFlightEntry(item.toInt());
         auto data = flt.getData();
         auto dateTime = QDateTime(QDate::fromString(data.value(DB_FLIGHTS_DOFT).toString(), Qt::ISODate),
                                   QTime().addSecs(data.value(DB_FLIGHTS_TOFB).toInt() * 60),
@@ -329,7 +329,7 @@ void ACalc::updateNightTimes()
                                        data.value(DB_FLIGHTS_TBLK).toInt(),
                                        night_angle));
         flt.setData(data);
-        aDB()->commit(flt);
+        aDB->commit(flt);
     }
 }
 

+ 1 - 1
src/functions/astat.cpp

@@ -84,7 +84,7 @@ QVector<QString> AStat::currencyTakeOffLanding(int days)
             "FROM flights "
             "WHERE doft >= \"" + startdate + "\"";
 
-    QVector<QString> result = aDB()->customQuery(statement, 2);
+    QVector<QString> result = aDB->customQuery(statement, 2);
 
     if (!result.isEmpty()) {
         return result;

+ 5 - 5
src/gui/dialogues/firstrundialog.cpp

@@ -114,11 +114,11 @@ bool FirstRunDialog::finish()
         return false;
     }
 
-    aDB()->updateLayout();
+    aDB->updateLayout();
 
     auto pilot = APilotEntry(1);
     pilot.setData(data);
-    if(!aDB()->commit(pilot)){
+    if(!aDB->commit(pilot)){
         db_fail_msg_box.exec();
         return false;
     }
@@ -137,15 +137,15 @@ bool FirstRunDialog::setupDatabase()
     if (confirm.exec() == QMessageBox::Yes)
         ADataBaseSetup::downloadTemplates();
 
-    aDB()->disconnect();
+    aDB->disconnect();
     ADataBaseSetup::backupOldData();
-    aDB()->connect();
+    aDB->connect();
 
     // [F]: todo: handle unsuccessful steps
     if(!ADataBaseSetup::createDatabase())
         return false;
 
-    aDB()->updateLayout();
+    aDB->updateLayout();
 
     if(!ADataBaseSetup::importDefaultData())
         return false;

+ 23 - 23
src/gui/dialogues/newflightdialog.cpp

@@ -122,7 +122,7 @@ NewFlightDialog::NewFlightDialog(int row_id, QWidget *parent) :
     ui(new Ui::NewFlight)
 {
     ui->setupUi(this);
-    flightEntry = aDB()->getFlightEntry(row_id);
+    flightEntry = aDB->getFlightEntry(row_id);
     setup();
     formFiller();
 }
@@ -210,15 +210,15 @@ void NewFlightDialog::setupButtonGroups()
 void NewFlightDialog::setupRawInputValidation()
 {
     // get Maps
-    pilotsIdMap      = aDB()->getIdMap(ADatabaseTarget::pilots);
-    tailsIdMap       = aDB()->getIdMap(ADatabaseTarget::tails);
-    airportIcaoIdMap = aDB()->getIdMap(ADatabaseTarget::airport_identifier_icao);
-    airportIataIdMap = aDB()->getIdMap(ADatabaseTarget::airport_identifier_iata);
-    airportNameIdMap = aDB()->getIdMap(ADatabaseTarget::airport_names);
+    pilotsIdMap      = aDB->getIdMap(ADatabaseTarget::pilots);
+    tailsIdMap       = aDB->getIdMap(ADatabaseTarget::tails);
+    airportIcaoIdMap = aDB->getIdMap(ADatabaseTarget::airport_identifier_icao);
+    airportIataIdMap = aDB->getIdMap(ADatabaseTarget::airport_identifier_iata);
+    airportNameIdMap = aDB->getIdMap(ADatabaseTarget::airport_names);
     //get Completer Lists
-    pilotList   = aDB()->getCompletionList(ADatabaseTarget::pilots);
-    tailsList   = aDB()->getCompletionList(ADatabaseTarget::registrations);
-    airportList = aDB()->getCompletionList(ADatabaseTarget::airport_identifier_all);
+    pilotList   = aDB->getCompletionList(ADatabaseTarget::pilots);
+    tailsList   = aDB->getCompletionList(ADatabaseTarget::registrations);
+    airportList = aDB->getCompletionList(ADatabaseTarget::airport_identifier_all);
     auto tempList = QStringList();
     // define tuples
     const std::tuple<QString, QStringList*, QRegularExpression>
@@ -406,7 +406,7 @@ void NewFlightDialog::fillDeductibleData()
     QString block_minutes = QString::number(ACalc::stringToMinutes(block_time));
     ui->tblkTimeLineEdit->setText(block_time);
     // get acft data and fill deductible entries
-    auto acft = aDB()->getTailEntry(tailsIdMap.value(ui->acftLineEdit->text()));
+    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.";
 
@@ -806,13 +806,13 @@ void NewFlightDialog::addNewTail(QLineEdit *parent_line_edit)
         auto na = NewTailDialog(ui->acftLineEdit->text(), this);
         na.exec();
         // update map and list, set line edit
-        tailsIdMap  = aDB()->getIdMap(ADatabaseTarget::tails);
-        tailsList   = aDB()->getCompletionList(ADatabaseTarget::registrations);
+        tailsIdMap  = aDB->getIdMap(ADatabaseTarget::tails);
+        tailsList   = aDB->getCompletionList(ADatabaseTarget::registrations);
 
-        DEB << "New Entry added. Id:" << aDB()->getLastEntry(ADatabaseTarget::tails);
+        DEB << "New Entry added. Id:" << aDB->getLastEntry(ADatabaseTarget::tails);
         DEB << "AC Map: " << tailsIdMap;
 
-        parent_line_edit->setText(tailsIdMap.key(aDB()->getLastEntry(ADatabaseTarget::tails)));
+        parent_line_edit->setText(tailsIdMap.key(aDB->getLastEntry(ADatabaseTarget::tails)));
         emit parent_line_edit->editingFinished();
     } else {
         parent_line_edit->setText(DB_NULL);
@@ -838,10 +838,10 @@ void NewFlightDialog::addNewPilot(QLineEdit *parent_line_edit)
         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));
-        parent_line_edit->setText(pilotsIdMap.key(aDB()->getLastEntry(ADatabaseTarget::pilots)));
+        pilotsIdMap  = aDB->getIdMap(ADatabaseTarget::pilots);
+        pilotList    = aDB->getCompletionList(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 {
         parent_line_edit->setText(DB_NULL);
@@ -886,10 +886,10 @@ void NewFlightDialog::on_submitButton_clicked()
     DEB << "Setting Data for flightEntry...";
     flightEntry.setData(newData);
     DEB << "Committing...";
-    if (!aDB()->commit(flightEntry)) {
+    if (!aDB->commit(flightEntry)) {
         auto message_box = QMessageBox(this);
         message_box.setText("The following error has ocurred:\n\n"
-                            + aDB()->lastError.text()
+                            + aDB->lastError.text()
                             + "\n\nYour entry has not been saved.");
         message_box.setIcon(QMessageBox::Warning);
         message_box.exec();
@@ -1153,7 +1153,7 @@ void NewFlightDialog::on_acftLineEdit_editingFinished()
 
     if (tailsIdMap.value(line_edit->text()) != 0) {
         DEB << "Mapped: " << line_edit->text() << tailsIdMap.value(line_edit->text());
-        auto acft = aDB()->getTailEntry(tailsIdMap.value(line_edit->text()));
+        auto acft = aDB->getTailEntry(tailsIdMap.value(line_edit->text()));
         ui->acftTypeLabel->setText(acft.type());
         onGoodInputReceived(line_edit);
         return;
@@ -1187,7 +1187,7 @@ void NewFlightDialog::onPilotNameLineEdit_editingFinished()
     if(line_edit->text().contains(SELF_RX)) {
         DEB << "self recognized.";
         line_edit->setText(pilotsIdMap.key(1));
-        auto pilot = aDB()->getPilotEntry(1);
+        auto pilot = aDB->getPilotEntry(1);
         ui->picCompanyLabel->setText(pilot.getData().value(DB_TAILS_COMPANY).toString());
         onGoodInputReceived(line_edit);
         return;
@@ -1195,7 +1195,7 @@ void NewFlightDialog::onPilotNameLineEdit_editingFinished()
 
     if(pilotsIdMap.value(line_edit->text()) != 0) {
         DEB << "Mapped: " << line_edit->text() << pilotsIdMap.value(line_edit->text());
-        auto pilot = aDB()->getPilotEntry(pilotsIdMap.value(line_edit->text()));
+        auto pilot = aDB->getPilotEntry(pilotsIdMap.value(line_edit->text()));
         ui->picCompanyLabel->setText(pilot.getData().value(DB_TAILS_COMPANY).toString());
         onGoodInputReceived(line_edit);
         return;

+ 4 - 4
src/gui/dialogues/newpilotdialog.cpp

@@ -81,7 +81,7 @@ NewPilotDialog::NewPilotDialog(int rowId, QWidget *parent) :
     DEB << "New NewPilotDialog (editEntry)";
     setup();
 
-    pilotEntry = aDB()->getPilotEntry(rowId);
+    pilotEntry = aDB->getPilotEntry(rowId);
     DEB << "Pilot Entry position: " << pilotEntry.getPosition().tableName << pilotEntry.getPosition().rowId;
     formFiller();
     ui->lastnameLineEdit->setFocus();
@@ -109,7 +109,7 @@ void NewPilotDialog::setup()
     }
 
     DEB << "Setting up completer...";
-    auto completer = new QCompleter(aDB()->getCompletionList(ADatabaseTarget::companies), ui->companyLineEdit);
+    auto completer = new QCompleter(aDB->getCompletionList(ADatabaseTarget::companies), ui->companyLineEdit);
     completer->setCompletionMode(QCompleter::InlineCompletion);
     completer->setCaseSensitivity(Qt::CaseSensitive);
     ui->companyLineEdit->setCompleter(completer);
@@ -152,10 +152,10 @@ void NewPilotDialog::submitForm()
     pilotEntry.setData(new_data);
     DEB << "Pilot entry position: " << pilotEntry.getPosition().tableName << pilotEntry.getPosition().rowId;
     DEB << "Pilot entry data: " << pilotEntry.getData();
-    if (!aDB()->commit(pilotEntry)) {
+    if (!aDB->commit(pilotEntry)) {
         auto message_box = QMessageBox(this);
         message_box.setText("The following error has ocurred:\n\n"
-                            + aDB()->lastError.text()
+                            + aDB->lastError.text()
                             + "\n\nThe entry has not been saved.");
         message_box.exec();
         return;

+ 6 - 6
src/gui/dialogues/newtaildialog.cpp

@@ -59,7 +59,7 @@ NewTailDialog::NewTailDialog(int row_id, QWidget *parent) :
     ui->line->hide();
 
     setupValidators();
-    entry = aDB()->getTailEntry(row_id);
+    entry = aDB->getTailEntry(row_id);
     fillForm(entry, false);
 }
 
@@ -78,8 +78,8 @@ NewTailDialog::~NewTailDialog()
  */
 void NewTailDialog::setupCompleter()
 {
-    idMap = aDB()->getIdMap(ADatabaseTarget::aircraft);
-    aircraftList = aDB()->getCompletionList(ADatabaseTarget::aircraft);
+    idMap = aDB->getIdMap(ADatabaseTarget::aircraft);
+    aircraftList = aDB->getCompletionList(ADatabaseTarget::aircraft);
 
     QCompleter *completer = new QCompleter(aircraftList, ui->searchLineEdit);
     completer->setCaseSensitivity(Qt::CaseInsensitive);
@@ -208,10 +208,10 @@ void NewTailDialog::submitForm()
     //create db object
 
     entry.setData(new_data);
-    if (!aDB()->commit(entry)) {
+    if (!aDB->commit(entry)) {
         auto message_box = QMessageBox(this);
         message_box.setText("The following error has ocurred:\n\n"
-                            + aDB()->lastError.text()
+                            + aDB->lastError.text()
                             + "\n\nThe entry has not been saved.");
         message_box.exec();
         return;
@@ -297,7 +297,7 @@ void NewTailDialog::onSearchCompleterActivated()
 
             DEB << "Template Selected. aircraft_id is: " << idMap.value(text);
             //call autofiller for dialog
-            fillForm(aDB()->getAircraftEntry(idMap.value(text)), true);
+            fillForm(aDB->getAircraftEntry(idMap.value(text)), true);
             ui->searchLineEdit->setStyleSheet("border: 1px solid green");
             ui->searchLabel->setText(text);
         } else {

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

@@ -102,14 +102,14 @@ void AircraftWidget::on_deleteButton_clicked()
         /// I think batch-editing should be implemented at some point, but batch-deleting should not.
 
     } else if (selectedTails.length() == 1) {
-        auto entry = aDB()->getTailEntry(selectedTails.first());
+        auto entry = aDB->getTailEntry(selectedTails.first());
         auto message_box = QMessageBox(this);
         QString message = "You are deleting the following aircraft:<br><br><b><tt>";
         message.append(entry.registration() + QStringLiteral(" - (") + entry.type() + ')');
         message.append(QStringLiteral("</b></tt><br><br>Are you sure?"));
         message_box.setText(message);
         message_box.exec();
-        if(!aDB()->remove(entry))
+        if(!aDB->remove(entry))
             onDeleteUnsuccessful();
         }
     model->select();
@@ -119,10 +119,10 @@ void AircraftWidget::onDeleteUnsuccessful()
 {
     /// [F]: To do: Some logic to display a warning if too many entries exists, so that
     /// the messagebox doesn't grow too tall.
-    QList<int> foreign_key_constraints = aDB()->getForeignKeyConstraints(selectedTails.first(), ADatabaseTarget::tails);
+    QList<int> foreign_key_constraints = aDB->getForeignKeyConstraints(selectedTails.first(), ADatabaseTarget::tails);
     QList<AFlightEntry> constrained_flights;
     for (const auto &row_id : foreign_key_constraints) {
-        constrained_flights.append(aDB()->getFlightEntry(row_id));
+        constrained_flights.append(aDB->getFlightEntry(row_id));
     }
 
     QString message = "<br>Unable to delete.<br><br>";

+ 9 - 9
src/gui/widgets/debugwidget.cpp

@@ -10,7 +10,7 @@ DebugWidget::DebugWidget(QWidget *parent) :
     ui(new Ui::DebugWidget)
 {
     ui->setupUi(this);
-    for (const auto& table : aDB()->getTableNames()) {
+    for (const auto& table : aDB->getTableNames()) {
         if( table != "sqlite_sequence") {
             ui->tableComboBox->addItem(table);
         }
@@ -29,7 +29,7 @@ void DebugWidget::on_resetUserTablesPushButton_clicked()
     if (ADataBaseSetup::resetToDefault()){
         result.setText("Database successfully reset");
         result.exec();
-        emit aDB()->dataBaseUpdated();
+        emit aDB->dataBaseUpdated();
     } else {
         result.setText("Errors have occurred. Check console for Debug output. ");
         result.exec();
@@ -60,11 +60,11 @@ void DebugWidget::on_resetDatabasePushButton_clicked()
     }
 
     // back up old db
-    aDB()->disconnect();
+    aDB->disconnect();
     ADataBaseSetup::backupOldData();
 
     // re-connct and create new database
-    aDB()->connect();
+    aDB->connect();
     if (ADataBaseSetup::createDatabase()) {
         DEB << "Database has been successfully created.";
     } else {
@@ -74,7 +74,7 @@ void DebugWidget::on_resetDatabasePushButton_clicked()
     }
     if (ADataBaseSetup::importDefaultData()) {
         message_box.setText("Database has been successfully reset.");
-        emit aDB()->dataBaseUpdated();
+        emit aDB->dataBaseUpdated();
         message_box.exec();
     } else {
         message_box.setText("Errors have ocurred while importing templates.<br>"
@@ -127,7 +127,7 @@ void DebugWidget::on_fillUserDataPushButton_clicked()
 
     message_box.setText("User tables successfully populated.");
     message_box.exec();
-    emit aDB()->dataBaseUpdated();
+    emit aDB->dataBaseUpdated();
 }
 
 void DebugWidget::on_selectCsvPushButton_clicked()
@@ -203,9 +203,9 @@ void DebugWidget::on_debugPushButton_clicked()
             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);
+                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()) {

+ 5 - 5
src/gui/widgets/logbookwidget.cpp

@@ -208,7 +208,7 @@ void LogbookWidget::on_deleteFlightPushButton_clicked()
         QList<AFlightEntry> flights_list;
 
         for (const auto &flight_id : selectedFlights) {
-            flights_list.append(aDB()->getFlightEntry(flight_id));
+            flights_list.append(aDB->getFlightEntry(flight_id));
         }
 
         QString warningMsg = "The following flight(s) will be deleted:<br><br><b><tt>";
@@ -230,8 +230,8 @@ void LogbookWidget::on_deleteFlightPushButton_clicked()
         if (reply == QMessageBox::Yes) {
             for (auto& flight : flights_list) {
                 DEB << "Deleting flight: " << flight.summary();
-                if(!aDB()->remove(flight)) {
-                    messageBox->setText(aDB()->lastError.text());
+                if(!aDB->remove(flight)) {
+                    messageBox->setText(aDB->lastError.text());
                     messageBox->exec();
                     return;
                 }
@@ -256,9 +256,9 @@ void LogbookWidget::on_deleteFlightPushButton_clicked()
             for (const auto& flight_id : selectedFlights) {
                 selected_flights.append({QLatin1String("flights"), flight_id});
             }
-            if (!aDB()->removeMany(selected_flights)) {
+            if (!aDB->removeMany(selected_flights)) {
 
-                messageBox->setText(aDB()->lastError.text()); // [F]: To Do: error info
+                messageBox->setText(aDB->lastError.text()); // [F]: To Do: error info
                 messageBox->exec();
                 return;
             }

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

@@ -150,14 +150,14 @@ void PilotsWidget::on_deletePilotButton_clicked()
         /// I think batch-editing should be implemented at some point, but batch-deleting should not.
 
     } else if (selectedPilots.length() == 1) {
-        auto entry = aDB()->getPilotEntry(selectedPilots.first());
+        auto entry = aDB->getPilotEntry(selectedPilots.first());
         auto message_box = QMessageBox(this);
         QString message = "You are deleting the following pilot:<br><br><b><tt>";
         message.append(entry.name());
         message.append(QStringLiteral("</b></tt><br><br>Are you sure?"));
         message_box.setText(message);
         message_box.exec();
-        if(!aDB()->remove(entry))
+        if(!aDB->remove(entry))
             onDeleteUnsuccessful();
         }
     model->select();
@@ -167,10 +167,10 @@ void PilotsWidget::onDeleteUnsuccessful()
 {
     /// [F]: To do: Some logic to display a warning if too many entries exists, so that
     /// the messagebox doesn't grow too tall.
-    QList<int> foreign_key_constraints = aDB()->getForeignKeyConstraints(selectedPilots.first(), ADatabaseTarget::pilots);
+    QList<int> foreign_key_constraints = aDB->getForeignKeyConstraints(selectedPilots.first(), ADatabaseTarget::pilots);
     QList<AFlightEntry> constrained_flights;
     for (const auto &row_id : foreign_key_constraints) {
-        constrained_flights.append(aDB()->getFlightEntry(row_id));
+        constrained_flights.append(aDB->getFlightEntry(row_id));
     }
 
     QString message = "<br>Unable to delete.<br><br>";

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

@@ -83,7 +83,7 @@ void SettingsWidget::readSettings()
      */
     {
         const QSignalBlocker blocker(this); // don't emit editing finished for setting these values
-        auto user_data = aDB()->getPilotEntry(1).getData();
+        auto user_data = aDB->getPilotEntry(1).getData();
         ui->lastnameLineEdit->setText(user_data.value(DB_PILOTS_LASTNAME).toString());
         ui->firstnameLineEdit->setText(user_data.value(DB_PILOTS_FIRSTNAME).toString());
         ui->companyLineEdit->setText(user_data.value(DB_PILOTS_COMPANY).toString());
@@ -158,7 +158,7 @@ void SettingsWidget::updatePersonalDetails()
     auto user = APilotEntry(1);
     user.setData(user_data);
 
-    aDB()->commit(user);
+    aDB->commit(user);
 }
 
 /*
@@ -294,7 +294,7 @@ void SettingsWidget::on_acAllowIncompleteComboBox_currentIndexChanged(int index)
 void SettingsWidget::on_aboutPushButton_clicked()
 {
     auto message_box = QMessageBox(this);
-    QString SQLITE_VERSION = aDB()->sqliteVersion();
+    QString SQLITE_VERSION = aDB->sqliteVersion();
     QString text = QMessageBox::tr(
 
                        "<h3><center>About openPilotLog</center></h3>"