Browse Source

Refactored DataBase to ADataBase

name of class and files changed, includes adjusted.
Felix Turo 4 years ago
parent
commit
a8bf356035

+ 2 - 2
main.cpp

@@ -22,7 +22,7 @@
 #include <QProcess>
 #include <QSettings>
 #include <QFileInfo>
-#include "src/experimental/DataBase.h"
+#include "src/experimental/adatabase.h"
 
 const auto DATA_DIR = QLatin1String("data");
 /*!
@@ -52,7 +52,7 @@ int main(int argc, char *argv[])
     QSettings settings;
 
 //    Db::connect();
-    experimental::DB()->connect();
+    experimental::aDB()->connect();
 
     QApplication openPilotLog(argc, argv);
     if(!setup()){

+ 1 - 1
mainwindow.h

@@ -36,7 +36,7 @@
 #include "src/gui/dialogues/newtaildialog.h"
 #include "src/gui/dialogues/newpilotdialog.h"
 #include "src/classes/runguard.h"
-#include "src/experimental/DataBase.h"
+#include "src/experimental/adatabase.h"
 
 QT_BEGIN_NAMESPACE
 namespace Ui {

+ 2 - 2
openPilotLog.pro

@@ -32,8 +32,8 @@ SOURCES += \
     src/database/dbinfo.cpp \
     src/database/dbsetup.cpp \
     src/database/entry.cpp \
-    src/experimental/DataBase.cpp \
     src/experimental/Entry.cpp \
+    src/experimental/adatabase.cpp \
     src/gui/dialogues/firstrundialog.cpp \
     src/gui/dialogues/newflightdialog.cpp \
     src/gui/dialogues/newpilotdialog.cpp \
@@ -63,10 +63,10 @@ HEADERS += \
     src/database/dbinfo.h \
     src/database/dbsetup.h \
     src/database/entry.h \
-    src/experimental/DataBase.h \
     src/experimental/Decl.h \
     src/experimental/Entry.h \
     src/experimental/UserInput.h \
+    src/experimental/adatabase.h \
     src/gui/dialogues/firstrundialog.h \
     src/gui/dialogues/newflightdialog.h \
     src/gui/dialogues/newpilotdialog.h \

+ 18 - 18
src/experimental/DataBase.cpp → src/experimental/adatabase.cpp

@@ -1,17 +1,17 @@
-#include "DataBase.h"
+#include "adatabase.h"
 
 namespace experimental {
 
-DataBase* DataBase::instance = nullptr;
+ADataBase* ADataBase::instance = nullptr;
 
-DataBase* DataBase::getInstance()
+ADataBase* ADataBase::getInstance()
 {
     if(!instance)
-        instance = new DataBase();
+        instance = new ADataBase();
     return instance;
 }
 
-bool DataBase::connect()
+bool ADataBase::connect()
 {
     const QString driver("QSQLITE");
 
@@ -44,20 +44,20 @@ bool DataBase::connect()
     return true;
 }
 
-void DataBase::disconnect()
+void ADataBase::disconnect()
 {
-    auto db = DataBase::database();
+    auto db = ADataBase::database();
     db.close();
     db.removeDatabase(db.connectionName());
     DEB("Database connection closed.");
 }
 
-QSqlDatabase DataBase::database()
+QSqlDatabase ADataBase::database()
 {
     return QSqlDatabase::database("qt_sql_default_connection");
 }
 
-bool DataBase::commit(Entry entry)
+bool ADataBase::commit(Entry entry)
 {
     if (exists(entry)) {
         return update(entry);
@@ -66,7 +66,7 @@ bool DataBase::commit(Entry entry)
     }
 }
 
-bool DataBase::remove(Entry entry)
+bool ADataBase::remove(Entry entry)
 {
     if (!exists(entry)) {
         DEB("Error: Entry does not exist.");
@@ -91,7 +91,7 @@ bool DataBase::remove(Entry entry)
     }
 }
 
-bool DataBase::exists(Entry entry)
+bool ADataBase::exists(Entry entry)
 {
     if(entry.getPosition() == DEFAULT_PILOT_POSITION)
         return false;
@@ -113,7 +113,7 @@ bool DataBase::exists(Entry entry)
 }
 
 
-bool DataBase::update(Entry updated_entry)
+bool ADataBase::update(Entry updated_entry)
 {
     auto data = updated_entry.getData();
     QString statement = "UPDATE " + updated_entry.getPosition().tableName + " SET ";
@@ -144,7 +144,7 @@ bool DataBase::update(Entry updated_entry)
     }
 }
 
-bool DataBase::insert(Entry new_entry)
+bool ADataBase::insert(Entry new_entry)
 {
     auto data = new_entry.getData();
     DEB("Inserting...");
@@ -178,7 +178,7 @@ bool DataBase::insert(Entry new_entry)
 
 }
 
-TableData DataBase::getEntryData(DataPosition data_position)
+TableData ADataBase::getEntryData(DataPosition data_position)
 {
     // check table exists
     if (!tableNames.contains(data_position.first)) {
@@ -224,21 +224,21 @@ TableData DataBase::getEntryData(DataPosition data_position)
     return entry_data;
 }
 
-Entry DataBase::getEntry(DataPosition data_position)
+Entry ADataBase::getEntry(DataPosition data_position)
 {
     Entry entry(data_position);
     entry.setData(getEntryData(data_position));
     return entry;
 }
 
-PilotEntry DataBase::getPilotEntry(RowId row_id)
+PilotEntry ADataBase::getPilotEntry(RowId row_id)
 {
     PilotEntry pilotEntry(row_id);
     pilotEntry.setData(getEntryData(pilotEntry.getPosition()));
     return pilotEntry;
 }
 
-QStringList DataBase::getCompletionList(DataBase::CompleterTarget target)
+QStringList ADataBase::getCompletionList(ADataBase::CompleterTarget target)
 {
     QString statement;
 
@@ -278,6 +278,6 @@ QStringList DataBase::getCompletionList(DataBase::CompleterTarget target)
     return completer_list;
 }
 
-DataBase* DB() { return DataBase::getInstance(); }
+ADataBase* aDB() { return ADataBase::getInstance(); }
 
 }

+ 8 - 8
src/experimental/DataBase.h → src/experimental/adatabase.h

@@ -18,18 +18,18 @@ namespace experimental {
  * \brief The DB class encapsulates the SQL database by providing fast access
  * to hot database data.
  */
-class DataBase : public QObject {
+class ADataBase : public QObject {
     Q_OBJECT
 private:
     TableNames tableNames;
     TableColumns tableColumns;
-    static DataBase* instance;
-    DataBase() = default;
+    static ADataBase* instance;
+    ADataBase() = default;
 public:
     // Ensure DB is not copiable or assignable
-    DataBase(const DataBase&) = delete;
-    void operator=(const DataBase&) = delete;
-    static DataBase* getInstance();
+    ADataBase(const ADataBase&) = delete;
+    void operator=(const ADataBase&) = delete;
+    static ADataBase* getInstance();
 
     /*!
      * \brief The CompleterTarget enum provides the items for which QCompleter
@@ -120,9 +120,9 @@ signals:
  * Instead of this:
  * DataBase::getInstance().commit(...)
  * Write this:
- * DB()->commit(...)
+ * aDB()->commit(...)
  */
-DataBase* DB();
+ADataBase* aDB();
 
 }  // namespace experimental
 

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

@@ -183,9 +183,9 @@ void NewFlightDialog::setup(){
         }
     }
     //fill Lists
-    pilots   = experimental::DB()->getCompletionList(experimental::DataBase::pilots);
-    tails    = experimental::DB()->getCompletionList(experimental::DataBase::registrations);
-    airports = experimental::DB()->getCompletionList(experimental::DataBase::airports);
+    pilots   = experimental::aDB()->getCompletionList(experimental::ADataBase::pilots);
+    tails    = experimental::aDB()->getCompletionList(experimental::ADataBase::registrations);
+    airports = experimental::aDB()->getCompletionList(experimental::ADataBase::airports);
 
     QString statement = "SELECT iata, icao FROM airports";
     auto result = Db::customQuery(statement,2);
@@ -1210,7 +1210,7 @@ void NewFlightDialog::on_acftLineEdit_inputRejected()
 
 void NewFlightDialog::on_acftLineEdit_editingFinished()
 {
-    auto registrationList = experimental::DB()->getCompletionList(experimental::DataBase::registrations);
+    auto registrationList = experimental::aDB()->getCompletionList(experimental::ADataBase::registrations);
     auto line_edit = ui->acftLineEdit;
     auto text = ui->acftLineEdit->text();
 
@@ -1250,7 +1250,7 @@ void NewFlightDialog::on_picNameLineEdit_editingFinished()
         return;
     }else //check if entry is in pilotList
     {
-        QStringList pilotList = experimental::DB()->getCompletionList(experimental::DataBase::pilots);
+        QStringList pilotList = experimental::aDB()->getCompletionList(experimental::ADataBase::pilots);
         QStringList match = pilotList.filter(line_edit->text().remove(" "), Qt::CaseInsensitive);
 
         if(match.length()!= 0)
@@ -1295,7 +1295,7 @@ void NewFlightDialog::on_secondPilotNameLineEdit_editingFinished()
         return;
     }else //check if entry is in pilotList
     {
-        QStringList pilotList = experimental::DB()->getCompletionList(experimental::DataBase::pilots);
+        QStringList pilotList = experimental::aDB()->getCompletionList(experimental::ADataBase::pilots);
         QStringList match = pilotList.filter(line_edit->text().remove(" "), Qt::CaseInsensitive);
 
         if(match.length()!= 0)
@@ -1329,7 +1329,7 @@ void NewFlightDialog::on_thirdPilotNameLineEdit_editingFinished()
         return;
     }else //check if entry is in pilotList
     {
-        QStringList pilotList = experimental::DB()->getCompletionList(experimental::DataBase::pilots);
+        QStringList pilotList = experimental::aDB()->getCompletionList(experimental::ADataBase::pilots);
         QStringList match = pilotList.filter(line_edit->text().remove(" "), Qt::CaseInsensitive);
 
         if(match.length()!= 0)

+ 1 - 1
src/gui/dialogues/newflightdialog.h

@@ -41,7 +41,7 @@
 #include "src/classes/strictrxvalidator.h"
 #include "src/classes/settings.h"
 #include "src/classes/acalc.h"
-#include "src/experimental/DataBase.h"
+#include "src/experimental/adatabase.h"
 
 #include "src/gui/dialogues/newpilotdialog.h"
 #include "src/gui/dialogues/newtaildialog.h"

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

@@ -80,7 +80,7 @@ NewPilotDialog::NewPilotDialog(int rowId, QWidget *parent) :
     DEB("New NewPilotDialog (editEntry)");
     setup();
 
-    pilotEntry = DB()->getPilotEntry(rowId);
+    pilotEntry = aDB()->getPilotEntry(rowId);
     DEB("Pilot Entry position: " << pilotEntry.getPosition());
     formFiller();
     ui->piclastnameLineEdit->setFocus();
@@ -108,7 +108,7 @@ void NewPilotDialog::setup()
     }
 
     DEB("Setting up completer...");
-    auto completer = new QCompleter(DB()->getCompletionList(DataBase::companies), ui->companyLineEdit);
+    auto completer = new QCompleter(aDB()->getCompletionList(ADataBase::companies), ui->companyLineEdit);
     completer->setCompletionMode(QCompleter::InlineCompletion);
     completer->setCaseSensitivity(Qt::CaseSensitive);
     ui->companyLineEdit->setCompleter(completer);
@@ -119,9 +119,9 @@ void NewPilotDialog::setup()
     ///   makes it easier to maintain.
     /// - these signals and slots are specific to this dialog, for communication with
     ///   other widgets we have the QDialog::accepted() and QDialog::rejected signals.
-    QObject::connect(DB(), &DataBase::commitSuccessful,
+    QObject::connect(aDB(), &ADataBase::commitSuccessful,
                      this, &NewPilotDialog::onCommitSuccessful);
-    QObject::connect(DB(), &DataBase::sqlError,
+    QObject::connect(aDB(), &ADataBase::sqlError,
                      this, &NewPilotDialog::onCommitUnsuccessful);
 }
 
@@ -178,5 +178,5 @@ void NewPilotDialog::submitForm()
     pilotEntry.setData(new_data);
     DEB("Pilot entry position: " << pilotEntry.getPosition());
     DEB("Pilot entry data: " << pilotEntry.getData());
-    DB()->commit(pilotEntry);
+    aDB()->commit(pilotEntry);
 }

+ 1 - 1
src/gui/dialogues/newpilotdialog.h

@@ -25,7 +25,7 @@
 #include <QCompleter>
 #include "src/classes/pilot.h"
 
-#include "src/experimental/DataBase.h"
+#include "src/experimental/adatabase.h"
 #include "src/experimental/Entry.h"
 #include "src/experimental/Decl.h"
 

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

@@ -90,7 +90,7 @@ void NewTailDialog::setupCompleter()
     //but creating it like this is faster.
 
 
-    auto aircraftlist = experimental::DB()->getCompletionList(experimental::DataBase::aircraft);
+    auto aircraftlist = experimental::aDB()->getCompletionList(experimental::ADataBase::aircraft);
     idMap = map;
     QCompleter *completer = new QCompleter(aircraftlist, ui->searchLineEdit);
     completer->setCaseSensitivity(Qt::CaseInsensitive);

+ 1 - 1
src/gui/dialogues/newtaildialog.h

@@ -28,7 +28,7 @@
 #include "src/classes/strictrxvalidator.h"
 #include "src/classes/acalc.h"
 #include "src/database/entry.h"
-#include "src/experimental/DataBase.h"
+#include "src/experimental/adatabase.h"
 
 namespace Ui {
 class NewTail;

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

@@ -33,7 +33,7 @@
 #include "src/gui/dialogues/firstrundialog.h"
 #include "src/gui/dialogues/newflightdialog.h"
 
-#include "src/experimental/DataBase.h"
+#include "src/experimental/adatabase.h"
 #include "src/experimental/Decl.h"
 
 namespace Ui {

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

@@ -142,8 +142,8 @@ void PilotsWidget::on_deletePushButton_clicked()
         /// flights table (see on_delete_unsuccessful) below
 
     } else if (selectedPilots.length() == 1) {
-        auto entry = DB()->getPilotEntry(selectedPilots.first());
-        DB()->remove(entry);
+        auto entry = aDB()->getPilotEntry(selectedPilots.first());
+        aDB()->remove(entry);
         }
     refreshModelAndView();