Browse Source

added dbFlights class

fiffty-50 4 years ago
parent
commit
05596a87ed
15 changed files with 401 additions and 318 deletions
  1. 11 0
      calc.h
  2. 222 0
      dbflight.cpp
  3. 33 0
      dbflight.h
  4. 0 273
      dbman.cpp
  5. 63 0
      dbsettings.cpp
  6. 22 0
      dbsettings.h
  7. 1 5
      dbstat.h
  8. 5 4
      editflight.cpp
  9. 2 2
      logbookwidget.cpp
  10. 2 1
      main.cpp
  11. 33 32
      newflight.cpp
  12. 1 0
      newflight.h
  13. 4 0
      openLog.pro
  14. 1 1
      settingswidget.cpp
  15. 1 0
      settingswidget.h

+ 11 - 0
calc.h

@@ -29,16 +29,27 @@
 class calc
 {
 public:
+
     static QTime blocktime(QTime tofb, QTime tonb);
+
     static QString minutes_to_string(QString blockminutes);
+
     static int string_to_minutes(QString time);
+
     static int time_to_minutes(QTime time);
+
     static double radToDeg(double rad);
+
     static double degToRad(double deg);
+
     static double radToNauticalMiles(double rad);
+
     static double greatCircleDistance(double lat1, double lon1, double lat2, double lon2);
+
     static QVector<QVector<double>> intermediatePointsOnGreatCircle(double lat1, double lon1, double lat2, double lon2, int tblk);
+
     static double solarElevation(QDateTime utc_time_point, double lat, double lon);
+
     static int calculateNightTime(QString dept, QString dest, QDateTime departureTime, int tblk);
 };
 

+ 222 - 0
dbflight.cpp

@@ -0,0 +1,222 @@
+#include "dbflight.h"
+#include "dbman.cpp"
+
+dbFlight::dbFlight()
+{
+
+}
+
+/*!
+ * \brief SelectFlightById Retreives a single flight from the database.
+ * \param flight_id Primary Key of flights database
+ * \return Flight details of selected flight.
+ */
+QVector<QString> dbFlight::selectFlightById(QString flight_id)
+{
+    QSqlQuery query;
+    query.prepare("SELECT * FROM flights WHERE id = ?");
+    query.addBindValue(flight_id);
+    query.exec();
+
+    if(query.first());
+    else
+    {
+        qDebug() << "db::SelectFlightById - No Flight with this ID found";
+        QVector<QString> flight; //return empty
+        return flight;
+    }
+
+    QVector<QString> flight;
+    flight.append(query.value(0).toString());
+    flight.append(query.value(1).toString());
+    flight.append(query.value(2).toString());
+    flight.append(query.value(3).toString());
+    flight.append(query.value(4).toString());
+    flight.append(query.value(5).toString());
+    flight.append(query.value(6).toString());
+    flight.append(query.value(7).toString());
+    flight.append(query.value(8).toString());
+
+    qDebug() << "db::SelectFlightById - retreived flight: " << flight;
+    return flight;
+}
+
+/*!
+ * \brief deleteFlightById Deletes a Flight from the database.
+ * Entries in the basic flights table as well as in the extras table are deleted.
+ * \param flight_id The primary key of the entry in the database
+ * \return True if no errors, otherwise false
+ */
+bool dbFlight::deleteFlightById(QString flight_id)
+{
+    QSqlQuery query;
+    query.prepare("DELETE FROM flights WHERE id = ?");
+    query.addBindValue(flight_id);
+    query.exec();
+    QString error = query.lastError().text();
+
+    QSqlQuery query2;
+    query2.prepare("DELETE FROM extras WHERE extras_id = ?");
+    query2.addBindValue(flight_id);
+    query2.exec();
+    QString error2 = query2.lastError().text();
+
+    qDebug() << "db::deleteFlightById: Removing flight with ID#: " << flight_id;
+    if(error.length() > 0 || error2.length() > 0)
+    {
+        qWarning() << "db::deleteFlightsById: Errors have occured: " << error << " " << error2;
+        return false;
+    }else
+    {
+        return true;
+    }
+}
+
+/*!
+ * \brief CreateFlightVectorFromInput Converts input from NewFlight Window into database format
+ * \param doft Date of flight
+ * \param dept Place of Departure
+ * \param tofb Time Off Blocks (UTC)
+ * \param dest Place of Destination
+ * \param tonb Time On Blocks (UTC)
+ * \param tblk Total Block Time
+ * \param pic Pilot in command
+ * \param acft Aircraft
+ * \return Vector of values ready for committing
+ */
+QVector<QString> dbFlight::createFlightVectorFromInput(QString doft, QString dept, QTime tofb, QString dest,
+                                             QTime tonb, QTime tblk, QString pic, QString acft)
+{
+    QVector<QString> flight;
+    flight.insert(0, ""); // ID, created as primary key during commit
+    flight.insert(1, doft);
+    flight.insert(2, dept);
+    flight.insert(3, QString::number(calc::time_to_minutes(tofb)));
+    flight.insert(4, dest);
+    flight.insert(5, QString::number(calc::time_to_minutes(tonb)));
+    flight.insert(6, QString::number(calc::time_to_minutes(tblk)));
+    flight.insert(7, pic); // lookup and matching tbd
+    flight.insert(8, acft);// lookup and matching tbd
+    //qDebug() << flight;
+    return flight;
+}
+/*!
+ * \brief CommitFlight Inserts prepared flight vector into database. Also creates
+ * a corresponding entry in the extras database to ensure matching IDs.
+ * \param flight a Vector of values in database format
+ */
+void dbFlight::commitFlight(QVector<QString> flight)// flight vector shall always have length 9
+{
+    QSqlQuery query;
+    query.prepare("INSERT INTO flights (doft, dept, tofb, dest, tonb, tblk, pic, acft) "
+                  "VALUES (:doft, :dept, :tofb, :dest, :tonb, :tblk, :pic, :acft)");
+    //flight[0] is primary key, not required for commit
+    query.bindValue(":doft", flight[1]); //string
+    query.bindValue(":dept", flight[2]);
+    query.bindValue(":tofb", flight[3].toInt()); //int
+    query.bindValue(":dest", flight[4]);
+    query.bindValue(":tonb", flight[5].toInt());
+    query.bindValue(":tblk", flight[6].toInt());
+    query.bindValue(":pic", flight[7].toInt());
+    query.bindValue(":acft", flight[8].toInt());
+    query.exec();
+    qDebug() << "Error message for commiting flight: " << query.lastError().text();
+
+    QSqlQuery query2;
+    query2.prepare("INSERT INTO extras DEFAULT VALUES");
+    query2.exec();
+    qDebug() << "Creating extras entry" << query2.lastError().text();
+}
+/*!
+ * \brief CommitToScratchpad Commits the inputs of the NewFlight window to a scratchpad
+ * to make them available for restoring entries when the input fields are being reloaded.
+ * \param flight The input data, which was not accepted for commiting to the flights table.
+ */
+void dbFlight::commitToScratchpad(QVector<QString> flight)// to store input mask
+{
+    //qDebug() << "Saving invalid flight to scratchpad";
+    QSqlQuery query;
+    query.prepare("INSERT INTO scratchpad (doft, dept, tofb, dest, tonb, tblk, pic, acft) "
+                  "VALUES (:doft, :dept, :tofb, :dest, :tonb, :tblk, :pic, :acft)");
+    //flight[0] is primary key, not required for commit
+    query.bindValue(":doft", flight[1]); //string
+    query.bindValue(":dept", flight[2]);
+    query.bindValue(":tofb", flight[3].toInt()); //int
+    query.bindValue(":dest", flight[4]);
+    query.bindValue(":tonb", flight[5].toInt());
+    query.bindValue(":tblk", flight[6].toInt());
+    query.bindValue(":pic", flight[7].toInt());
+    query.bindValue(":acft", flight[8].toInt());
+    query.exec();
+    qDebug() << query.lastError().text();
+}
+
+/*!
+ * \brief RetreiveScratchpad Selects data from scratchpad
+ * \return Vector of data contained in scratchpad
+ */
+QVector<QString> dbFlight::retreiveScratchpad()
+{
+    //qDebug() << "Retreiving invalid flight from scratchpad";
+    QSqlQuery query;
+    query.prepare("SELECT * FROM scratchpad");
+    query.exec();
+
+    if(query.first());
+    else
+    {
+        //qDebug() << ("scratchpad empty");
+        QVector<QString> flight; //return empty
+        return flight;
+    }
+
+    query.previous();
+    QVector<QString> flight;
+    while (query.next()) {
+        flight.append(query.value(0).toString());
+        flight.append(query.value(1).toString());
+        flight.append(query.value(2).toString());
+        flight.append(calc::minutes_to_string((query.value(3).toString())));
+        flight.append(query.value(4).toString());
+        flight.append(calc::minutes_to_string((query.value(5).toString())));
+        flight.append(calc::minutes_to_string((query.value(6).toString())));
+        flight.append(query.value(7).toString());
+        flight.append(query.value(8).toString());
+    }
+    clearScratchpad();
+    return flight;
+}
+
+/*!
+ * \brief CheckScratchpad Verifies if the scratchpad contains data
+ * \return true if scratchpad contains data
+ */
+bool dbFlight::checkScratchpad() // see if scratchpad is empty
+{
+    //qDebug() << "Checking if scratchpad contains data";
+    QSqlQuery query;
+    query.prepare("SELECT * FROM scratchpad");
+    query.exec();
+
+    if(query.first())
+    {
+        //qDebug() << "Scratchpad contains data";
+        return 1;
+    }
+    else
+    {
+        //qDebug() << ("Scratchpad contains NO data");
+        return 0;
+    }
+}
+/*!
+ * \brief ClearScratchpad Deletes data contained in the scratchpad
+ */
+void dbFlight::clearScratchpad()
+{
+    qDebug() << "Deleting scratchpad";
+    QSqlQuery query;
+    query.prepare("DELETE FROM scratchpad;");
+    query.exec();
+}
+

+ 33 - 0
dbflight.h

@@ -0,0 +1,33 @@
+#ifndef DBFLIGHT_H
+#define DBFLIGHT_H
+
+#include <QCoreApplication>
+
+/*!
+ * \brief The dbFlight class provides a databank interface for actions related to the
+ * flights, extras and scratchpad tables, i.e. all tables that are related to a flight entry.
+ */
+class dbFlight
+{
+public:
+    dbFlight();
+
+    static QVector<QString> selectFlightById(QString flight_id);
+
+    static bool deleteFlightById(QString flight_id);
+
+    static QVector<QString> createFlightVectorFromInput(QString doft, QString dept, QTime tofb, QString dest,
+                                                        QTime tonb, QTime tblk, QString pic, QString acft);
+    static void commitFlight(QVector<QString> flight);
+
+    static void commitToScratchpad(QVector<QString> flight);
+
+    static QVector<QString> retreiveScratchpad();
+
+    static bool checkScratchpad();
+
+    static void clearScratchpad();
+
+};
+
+#endif // DBFLIGHT_H

+ 0 - 273
dbman.cpp

@@ -95,221 +95,6 @@ public:
          * QVariant::toString() and QVariant::toInt() to convert variants to QString and int.
          */
     }
-
-    /*
-     * Flights Database Related Functions
-     */
-    /*!
-     * \brief SelectFlightById Retreives a single flight from the database.
-     * \param flight_id Primary Key of flights database
-     * \return Flight details of selected flight.
-     */
-    static QVector<QString> SelectFlightById(QString flight_id)
-    {
-        QSqlQuery query;
-        query.prepare("SELECT * FROM flights WHERE id = ?");
-        query.addBindValue(flight_id);
-        query.exec();
-
-        if(query.first());
-        else
-        {
-            qDebug() << "db::SelectFlightById - No Flight with this ID found";
-            QVector<QString> flight; //return empty
-            return flight;
-        }
-
-        QVector<QString> flight;
-        flight.append(query.value(0).toString());
-        flight.append(query.value(1).toString());
-        flight.append(query.value(2).toString());
-        flight.append(query.value(3).toString());
-        flight.append(query.value(4).toString());
-        flight.append(query.value(5).toString());
-        flight.append(query.value(6).toString());
-        flight.append(query.value(7).toString());
-        flight.append(query.value(8).toString());
-
-        qDebug() << "db::SelectFlightById - retreived flight: " << flight;
-        return flight;
-    }
-
-    /*!
-     * \brief CreateFlightVectorFromInput Converts input from NewFlight Window into database format
-     * \param doft Date of flight
-     * \param dept Place of Departure
-     * \param tofb Time Off Blocks (UTC)
-     * \param dest Place of Destination
-     * \param tonb Time On Blocks (UTC)
-     * \param tblk Total Block Time
-     * \param pic Pilot in command
-     * \param acft Aircraft
-     * \return Vector of values ready for committing
-     */
-    static QVector<QString> CreateFlightVectorFromInput(QString doft, QString dept, QTime tofb, QString dest, QTime tonb, QTime tblk, QString pic, QString acft)
-    {
-
-        QVector<QString> flight;
-        flight.insert(0, ""); // ID, created as primary key during commit
-        flight.insert(1, doft);
-        flight.insert(2, dept);
-        flight.insert(3, QString::number(calc::time_to_minutes(tofb)));
-        flight.insert(4, dest);
-        flight.insert(5, QString::number(calc::time_to_minutes(tonb)));
-        flight.insert(6, QString::number(calc::time_to_minutes(tblk)));
-        flight.insert(7, pic); // lookup and matching tbd
-        flight.insert(8, acft);// lookup and matching tbd
-        //qDebug() << flight;
-        return flight;
-    }
-    /*!
-     * \brief CommitFlight Inserts prepared flight vector into database. Also creates
-     * a corresponding entry in the extras database to ensure matching IDs.
-     * \param flight a Vector of values in database format
-     */
-    static void CommitFlight(QVector<QString> flight)// flight vector shall always have length 9
-    {
-        QSqlQuery query;
-        query.prepare("INSERT INTO flights (doft, dept, tofb, dest, tonb, tblk, pic, acft) "
-                      "VALUES (:doft, :dept, :tofb, :dest, :tonb, :tblk, :pic, :acft)");
-        //flight[0] is primary key, not required for commit
-        query.bindValue(":doft", flight[1]); //string
-        query.bindValue(":dept", flight[2]);
-        query.bindValue(":tofb", flight[3].toInt()); //int
-        query.bindValue(":dest", flight[4]);
-        query.bindValue(":tonb", flight[5].toInt());
-        query.bindValue(":tblk", flight[6].toInt());
-        query.bindValue(":pic", flight[7].toInt());
-        query.bindValue(":acft", flight[8].toInt());
-        query.exec();
-        qDebug() << "Error message for commiting flight: " << query.lastError().text();
-
-        QSqlQuery query2;
-        query2.prepare("INSERT INTO extras DEFAULT VALUES");
-        query2.exec();
-        qDebug() << "Creating extras entry" << query2.lastError().text();
-    }
-    /*!
-     * \brief CommitToScratchpad Commits the inputs of the NewFlight window to a scratchpad
-     * to make them available for restoring entries when the input fields are being reloaded.
-     * \param flight The input data, which was not accepted for commiting to the flights table.
-     */
-    static void CommitToScratchpad(QVector<QString> flight)// to store input mask
-    {
-        //qDebug() << "Saving invalid flight to scratchpad";
-        QSqlQuery query;
-        query.prepare("INSERT INTO scratchpad (doft, dept, tofb, dest, tonb, tblk, pic, acft) "
-                      "VALUES (:doft, :dept, :tofb, :dest, :tonb, :tblk, :pic, :acft)");
-        //flight[0] is primary key, not required for commit
-        query.bindValue(":doft", flight[1]); //string
-        query.bindValue(":dept", flight[2]);
-        query.bindValue(":tofb", flight[3].toInt()); //int
-        query.bindValue(":dest", flight[4]);
-        query.bindValue(":tonb", flight[5].toInt());
-        query.bindValue(":tblk", flight[6].toInt());
-        query.bindValue(":pic", flight[7].toInt());
-        query.bindValue(":acft", flight[8].toInt());
-        query.exec();
-        qDebug() << query.lastError().text();
-    }
-    /*!
-     * \brief CheckScratchpad Verifies if the scratchpad contains data
-     * \return true if scratchpad contains data
-     */
-    static bool CheckScratchpad() // see if scratchpad is empty
-    {
-        //qDebug() << "Checking if scratchpad contains data";
-        QSqlQuery query;
-        query.prepare("SELECT * FROM scratchpad");
-        query.exec();
-
-        if(query.first())
-        {
-            //qDebug() << "Scratchpad contains data";
-            return 1;
-        }
-        else
-        {
-            //qDebug() << ("Scratchpad contains NO data");
-            return 0;
-        }
-    }
-    /*!
-     * \brief ClearScratchpad Deletes data contained in the scratchpad
-     */
-    static void ClearScratchpad()
-    {
-        qDebug() << "Deleting scratchpad";
-        QSqlQuery query;
-        query.prepare("DELETE FROM scratchpad;");
-        query.exec();
-    }
-    /*!
-     * \brief RetreiveScratchpad Selects data from scratchpad
-     * \return Vector of data contained in scratchpad
-     */
-    static QVector<QString> RetreiveScratchpad()
-    {
-        //qDebug() << "Retreiving invalid flight from scratchpad";
-        QSqlQuery query;
-        query.prepare("SELECT * FROM scratchpad");
-        query.exec();
-
-        if(query.first());
-        else
-        {
-            //qDebug() << ("scratchpad empty");
-            QVector<QString> flight; //return empty
-            return flight;
-        }
-
-        query.previous();
-        QVector<QString> flight;
-        while (query.next()) {
-            flight.append(query.value(0).toString());
-            flight.append(query.value(1).toString());
-            flight.append(query.value(2).toString());
-            flight.append(calc::minutes_to_string((query.value(3).toString())));
-            flight.append(query.value(4).toString());
-            flight.append(calc::minutes_to_string((query.value(5).toString())));
-            flight.append(calc::minutes_to_string((query.value(6).toString())));
-            flight.append(query.value(7).toString());
-            flight.append(query.value(8).toString());
-        }
-        ClearScratchpad();
-        return flight;
-    }
-
-    /*!
-     * \brief deleteFlightById Deletes a Flight from the database.
-     * Entries in the basic flights table as well as in the extras table are deleted.
-     * \param flight_id The primary key of the entry in the database
-     * \return True if no errors, otherwise false
-     */
-    static bool deleteFlightById(QString flight_id)
-    {
-        QSqlQuery query;
-        query.prepare("DELETE FROM flights WHERE id = ?");
-        query.addBindValue(flight_id);
-        query.exec();
-        QString error = query.lastError().text();
-
-        QSqlQuery query2;
-        query2.prepare("DELETE FROM extras WHERE extras_id = ?");
-        query2.addBindValue(flight_id);
-        query2.exec();
-        QString error2 = query2.lastError().text();
-
-        qDebug() << "db::deleteFlightById: Removing flight with ID#: " << flight_id;
-        if(error.length() > 0 || error2.length() > 0)
-        {
-            qWarning() << "db::deleteFlightsById: Errors have occured: " << error << " " << error2;
-            return false;
-        }else
-        {
-            return true;
-        }
-    }
     /*
      * Pilots Database Related Functions
      */
@@ -906,65 +691,7 @@ public:
         }
     }
 
-    /*
-     * Settings Database Related Functions
-     */
 
-    /*!
-     * \brief retreiveSetting Looks up a setting in the database and returns its value
-     * \param setting_id
-     * \return setting value
-     */
-    static QString retreiveSetting(QString setting_id)
-    {
-        QSqlQuery query;
-        query.prepare("SELECT setting FROM settings WHERE setting_id = ?");
-        query.addBindValue(setting_id);
-        query.exec();
-
-        QString setting = "-1";
-
-        while(query.next()){
-            setting = query.value(0).toString();
-        }
-        return setting;
-    }
-    /*!
-     * \brief retreiveSettingInfo Looks up a setting in the database and returns its value and description
-     * \param setting_id
-     * \return {setting_id, setting, description}
-     */
-    static QVector<QString> retreiveSettingInfo(QString setting_id)
-    {
-        QSqlQuery query;
-        query.prepare("SELECT * FROM settings WHERE setting_id = ?");
-        query.addBindValue(setting_id);
-        query.exec();
-
-        QVector<QString> setting;
-
-        while(query.next()){
-            setting.append(query.value(0).toString());
-            setting.append(query.value(1).toString());
-            setting.append(query.value(2).toString());
-        }
-        return setting;
-    }
-    /*!
-     * \brief storesetting Updates a stored setting in the database
-     * \param setting_id
-     * \param setting_value
-     */
-    static void storesetting(int setting_id, QString setting_value)
-    {
-        QSqlQuery query;
-        query.prepare("UPDATE settings "
-                      "SET  setting = ? "
-                      "WHERE setting_id = ?");
-        query.addBindValue(setting_value);
-        query.addBindValue(setting_id);
-        query.exec();
-    }
 /*
  *  Obsolete Functions
  */

+ 63 - 0
dbsettings.cpp

@@ -0,0 +1,63 @@
+#include "dbsettings.h"
+#include "dbman.cpp"
+
+/*
+ * Settings Database Related Functions
+ */
+/*!
+ * \brief storesetting Updates a stored setting in the database
+ * \param setting_id
+ * \param setting_value
+ */
+void dbSettings::storeSetting(int setting_id, QString setting_value)
+{
+    QSqlQuery query;
+    query.prepare("UPDATE settings "
+                  "SET  setting = ? "
+                  "WHERE setting_id = ?");
+    query.addBindValue(setting_value);
+    query.addBindValue(setting_id);
+    query.exec();
+}
+
+/*!
+ * \brief retreiveSetting Looks up a setting in the database and returns its value
+ * \param setting_id
+ * \return setting value
+ */
+QString dbSettings::retreiveSetting(QString setting_id)
+{
+    QSqlQuery query;
+    query.prepare("SELECT setting FROM settings WHERE setting_id = ?");
+    query.addBindValue(setting_id);
+    query.exec();
+
+    QString setting = "-1";
+
+    while(query.next()){
+        setting = query.value(0).toString();
+    }
+    return setting;
+}
+
+/*!
+ * \brief retreiveSettingInfo Looks up a setting in the database and returns its value and description
+ * \param setting_id
+ * \return {setting_id, setting, description}
+ */
+QVector<QString> dbSettings::retreiveSettingInfo(QString setting_id)
+{
+    QSqlQuery query;
+    query.prepare("SELECT * FROM settings WHERE setting_id = ?");
+    query.addBindValue(setting_id);
+    query.exec();
+
+    QVector<QString> setting;
+
+    while(query.next()){
+        setting.append(query.value(0).toString());
+        setting.append(query.value(1).toString());
+        setting.append(query.value(2).toString());
+    }
+    return setting;
+}

+ 22 - 0
dbsettings.h

@@ -0,0 +1,22 @@
+#ifndef DBSETTINGS_H
+#define DBSETTINGS_H
+
+#include <QCoreApplication>
+
+/*!
+ * \brief The dbSettings class provides functionality for retreiving settings
+ * from the database. In general, most values are provided as either QString or
+ * QVector<QString>.
+ */
+class dbSettings
+{
+public:
+
+    static void storeSetting(int setting_id, QString setting_value);
+
+    static QString retreiveSetting(QString setting_id);
+
+    static QVector<QString> retreiveSettingInfo(QString setting_id);
+};
+
+#endif // DBSETTINGS_H

+ 1 - 5
dbstat.h

@@ -2,11 +2,7 @@
 #define DBSTAT_H
 
 #include <QCoreApplication>
-#include <QDebug>
-#include <QSqlDatabase>
-#include <QSqlDriver>
-#include <QSqlError>
-#include <QSqlQuery>
+
 
 /*!
  * \brief The dbStat class provides functionality for retreiving various statistics

+ 5 - 4
editflight.cpp

@@ -19,6 +19,7 @@
 #include "ui_editflight.h"
 #include "calc.h"
 #include "dbman.cpp"
+#include "dbflight.h"
 #include <QMessageBox>
 #include <QDebug>
 
@@ -51,7 +52,7 @@ EditFlight::EditFlight(QWidget *parent) :
 {
     ui->setupUi(this);
 
-    editflight = db::RetreiveScratchpad();
+    editflight = dbFlight::retreiveScratchpad();
     qDebug() << "EditFlight: Re-assigning variables from vector " << editflight;
 
     editdate = QDate::fromString(editflight[1],Qt::ISODate);
@@ -114,7 +115,7 @@ QVector<QString> EditFlight::collectInput()
 
 
     // Prepare Vector for commit to database
-    editflight = db::CreateFlightVectorFromInput(editdoft, editdept, edittofb, editdest, edittonb, tblk, editpic, editacft);
+    editflight = dbFlight::createFlightVectorFromInput(editdoft, editdept, edittofb, editdest, edittonb, tblk, editpic, editacft);
     qDebug() << "Created flight vector:" << editflight;
 
     return editflight;
@@ -431,7 +432,7 @@ void EditFlight::on_buttonBox_accepted()
     }else
     {
         qDebug() << "Invalid Input. No entry has been made in the database.";
-        db::CommitToScratchpad(flight);
+        dbFlight::commitToScratchpad(flight);
         QMessageBox msgBox;
         msgBox.setText("La Base de datos se niega a ser violada!");
         msgBox.exec();
@@ -443,7 +444,7 @@ void EditFlight::on_buttonBox_accepted()
 
 void EditFlight::on_buttonBox_rejected()
 {
-    db::ClearScratchpad();
+    dbFlight::clearScratchpad();
 }
 
 void EditFlight::on_verifyButton_clicked()

+ 2 - 2
logbookwidget.cpp

@@ -3,6 +3,7 @@
 #include <QSqlTableModel>
 #include <QMessageBox>
 #include "dbman.cpp"
+#include "dbflight.h"
 #include "newflight.h"
 #include "editflight.h"
 
@@ -33,7 +34,6 @@ logbookWidget::logbookWidget(QWidget *parent) :
     view->setSelectionMode(QAbstractItemView::SingleSelection);
     view->setEditTriggers(QAbstractItemView::NoEditTriggers);
 
-
     view->setColumnWidth(1,120);
     view->setColumnWidth(2,60);
     view->setColumnWidth(3,60);
@@ -87,7 +87,7 @@ void logbookWidget::on_deleteFlightPushButton_clicked()
         if (reply == QMessageBox::Yes)
         {
             qDebug() << "Deleting Flight with ID# " << SelectedFlight;
-            db::deleteFlightById(QString::number(SelectedFlight));
+            dbFlight::deleteFlightById(QString::number(SelectedFlight));
 
             QSqlTableModel *ShowAllModel = new QSqlTableModel; //refresh view
             ShowAllModel->setTable("Logbook");

+ 2 - 1
main.cpp

@@ -24,6 +24,7 @@
 #include <QPalette>
 #include <QColor>
 #include "dbman.cpp"
+#include "dbsettings.h"
 #include <QDebug>
 
 int selectedtheme = 1; //Variable to store theming information
@@ -38,7 +39,7 @@ int main(int argc, char *argv[])
 
     //Theming with CSS inlcues QFile,QTextStream, QDir, themes folder and TARGET = flog, RESOURCES = themes/breeze.qrc in pro
     // credit: https://github.com/Alexhuszagh/BreezeStyleSheets
-    selectedtheme = db::retreiveSetting("10").toInt();
+    selectedtheme = dbSettings::retreiveSetting("10").toInt();
     QDir::setCurrent("/themes");
     if (selectedtheme == 1){
         qDebug() << "Loading light theme";

+ 33 - 32
newflight.cpp

@@ -20,6 +20,7 @@
 #include "newacft.h"
 #include "calc.h"
 #include "dbman.cpp"
+#include "dbflight.h"
 #include <QMessageBox>
 #include <QDebug>
 #include <QCompleter>
@@ -86,11 +87,11 @@ NewFlight::NewFlight(QWidget *parent) :
     ui->setupUi(this);
     ui->newDoft->setDate(QDate::currentDate());
 
-    bool hasoldinput = db::CheckScratchpad();
+    bool hasoldinput = dbFlight::checkScratchpad();
     qDebug() << "Hasoldinput? = " << hasoldinput;
     if(hasoldinput) // Re-populate the Form
     {
-        flight = db::RetreiveScratchpad();
+        flight = dbFlight::retreiveScratchpad();
         qDebug() << "Re-Filling Form from Scratchpad";
         returnInput(flight);
     }
@@ -239,7 +240,7 @@ QVector<QString> NewFlight::collectInput()
 
 
     // Prepare Vector for commit to database
-    flight = db::CreateFlightVectorFromInput(doft, dept, tofb, dest, tonb, tblk, pic, acft);
+    flight = dbFlight::createFlightVectorFromInput(doft, dept, tofb, dest, tonb, tblk, pic, acft);
     qDebug() << "Created flight vector:" << flight;
 
     return flight;
@@ -333,37 +334,37 @@ void NewFlight::returnInput(QVector<QString> flight)
 void NewFlight::storeSettings()
 {
     qDebug() << "Storing Settings...";
-    db::storesetting(100, ui->FunctionComboBox->currentText());
-    db::storesetting(101, ui->ApproachComboBox->currentText());
-    db::storesetting(102, QString::number(ui->PilotFlyingCheckBox->isChecked()));
-    db::storesetting(103, QString::number(ui->PilotMonitoringCheckBox->isChecked()));
-    db::storesetting(104, QString::number(ui->TakeoffSpinBox->value()));
-    db::storesetting(105, QString::number(ui->TakeoffCheckBox->isChecked()));
-    db::storesetting(106, QString::number(ui->LandingSpinBox->value()));
-    db::storesetting(107, QString::number(ui->LandingCheckBox->isChecked()));
-    db::storesetting(108, QString::number(ui->AutolandSpinBox->value()));
-    db::storesetting(109, QString::number(ui->AutolandCheckBox->isChecked()));
-    db::storesetting(110, QString::number(ui->IfrCheckBox->isChecked()));
-    db::storesetting(111, QString::number(ui->VfrCheckBox->isChecked()));
-    //db::storesetting(112, QString::number(ui->autoNightCheckBox->isChecked()));
+    dbSettings::storeSetting(100, ui->FunctionComboBox->currentText());
+    dbSettings::storeSetting(101, ui->ApproachComboBox->currentText());
+    dbSettings::storeSetting(102, QString::number(ui->PilotFlyingCheckBox->isChecked()));
+    dbSettings::storeSetting(103, QString::number(ui->PilotMonitoringCheckBox->isChecked()));
+    dbSettings::storeSetting(104, QString::number(ui->TakeoffSpinBox->value()));
+    dbSettings::storeSetting(105, QString::number(ui->TakeoffCheckBox->isChecked()));
+    dbSettings::storeSetting(106, QString::number(ui->LandingSpinBox->value()));
+    dbSettings::storeSetting(107, QString::number(ui->LandingCheckBox->isChecked()));
+    dbSettings::storeSetting(108, QString::number(ui->AutolandSpinBox->value()));
+    dbSettings::storeSetting(109, QString::number(ui->AutolandCheckBox->isChecked()));
+    dbSettings::storeSetting(110, QString::number(ui->IfrCheckBox->isChecked()));
+    dbSettings::storeSetting(111, QString::number(ui->VfrCheckBox->isChecked()));
+    //dbSettings::storesetting(112, QString::number(ui->autoNightCheckBox->isChecked()));
 }
 void NewFlight::restoreSettings()
 {
     qDebug() << "Restoring Settings...";//crashes if db is empty due to QVector index out of range.
-    ui->FunctionComboBox->setCurrentText(db::retreiveSetting("100"));
-    ui->ApproachComboBox->setCurrentText(db::retreiveSetting("101"));
-    ui->PilotFlyingCheckBox->setChecked(db::retreiveSetting("102").toInt());
-    ui->PilotMonitoringCheckBox->setChecked(db::retreiveSetting("103").toInt());
-    ui->TakeoffSpinBox->setValue(db::retreiveSetting("104").toInt());
-    ui->TakeoffCheckBox->setChecked(db::retreiveSetting("105").toInt());
-    ui->LandingSpinBox->setValue(db::retreiveSetting("106").toInt());
-    ui->LandingCheckBox->setChecked(db::retreiveSetting("107").toInt());
-    ui->AutolandSpinBox->setValue(db::retreiveSetting("108").toInt());
-    ui->AutolandCheckBox->setChecked(db::retreiveSetting("109").toInt());
-    ui->IfrCheckBox->setChecked(db::retreiveSetting("110").toInt());
-    ui->VfrCheckBox->setChecked(db::retreiveSetting("111").toInt());
-    //ui->autoNightCheckBox->setChecked(db::retreiveSetting("112")[1].toInt());
-    //qDebug() << "restore Settings ifr to int: " << db::retreiveSetting("110")[1].toInt();
+    ui->FunctionComboBox->setCurrentText(dbSettings::retreiveSetting("100"));
+    ui->ApproachComboBox->setCurrentText(dbSettings::retreiveSetting("101"));
+    ui->PilotFlyingCheckBox->setChecked(dbSettings::retreiveSetting("102").toInt());
+    ui->PilotMonitoringCheckBox->setChecked(dbSettings::retreiveSetting("103").toInt());
+    ui->TakeoffSpinBox->setValue(dbSettings::retreiveSetting("104").toInt());
+    ui->TakeoffCheckBox->setChecked(dbSettings::retreiveSetting("105").toInt());
+    ui->LandingSpinBox->setValue(dbSettings::retreiveSetting("106").toInt());
+    ui->LandingCheckBox->setChecked(dbSettings::retreiveSetting("107").toInt());
+    ui->AutolandSpinBox->setValue(dbSettings::retreiveSetting("108").toInt());
+    ui->AutolandCheckBox->setChecked(dbSettings::retreiveSetting("109").toInt());
+    ui->IfrCheckBox->setChecked(dbSettings::retreiveSetting("110").toInt());
+    ui->VfrCheckBox->setChecked(dbSettings::retreiveSetting("111").toInt());
+    //ui->autoNightCheckBox->setChecked(dbSettings::retreiveSetting("112")[1].toInt());
+    //qDebug() << "restore Settings ifr to int: " << dbSettings::retreiveSetting("110")[1].toInt();
 
 /*
  *
@@ -693,7 +694,7 @@ void NewFlight::on_buttonBox_accepted()
         flight = collectInput();
         if(verifyInput())
         {
-            db::CommitFlight(flight);
+            dbFlight::commitFlight(flight);
             qDebug() << flight << "Has been commited.";
             QMessageBox msgBox(this);
             msgBox.setText("Flight has been commited.");
@@ -701,7 +702,7 @@ void NewFlight::on_buttonBox_accepted()
         }else
         {
             qDebug() << "Invalid Input. No entry has been made in the database.";
-            db::CommitToScratchpad(flight);
+            dbFlight::commitToScratchpad(flight);
             QMessageBox msgBox(this);
             msgBox.setText("Invalid entries detected. Please check your input.");
             msgBox.exec();

+ 1 - 0
newflight.h

@@ -19,6 +19,7 @@
 #define NEWFLIGHT_H
 
 #include <QDialog>
+#include "dbsettings.h"
 
 namespace Ui {
 class NewFlight;

+ 4 - 0
openLog.pro

@@ -23,7 +23,9 @@ DEFINES += QT_DEPRECATED_WARNINGS
 
 SOURCES += \
     calc.cpp \
+    dbflight.cpp \
     dbman.cpp \
+    dbsettings.cpp \
     dbstat.cpp \
     easaview.cpp \
     editflight.cpp \
@@ -38,6 +40,8 @@ SOURCES += \
 
 HEADERS += \
     calc.h \
+    dbflight.h \
+    dbsettings.h \
     dbstat.h \
     easaview.h \
     editflight.h \

+ 1 - 1
settingswidget.cpp

@@ -17,7 +17,7 @@ settingsWidget::settingsWidget(QWidget *parent) :
     themeGroup->addButton(ui->lightThemeCheckBox);
     themeGroup->addButton(ui->darkThemeCheckBox);
 
-    switch (db::retreiveSetting("10").toInt()) {
+    switch (dbSettings::retreiveSetting("10").toInt()) {
       case 0:
         qDebug() << "System Theme";
         ui->systemThemeCheckBox->setChecked(true);

+ 1 - 0
settingswidget.h

@@ -2,6 +2,7 @@
 #define SETTINGSWIDGET_H
 
 #include <QWidget>
+#include "dbsettings.h"
 
 namespace Ui {
 class settingsWidget;