ソースを参照

Merge pull request #9 from fiffty-50/devel-flightclass

Devel flightclass
Felix Turowsky 4 年 前
コミット
db1ce6156b
15 ファイル変更682 行追加83 行削除
  1. 1 1
      dbaircraft.cpp
  2. 3 6
      dbairport.cpp
  3. 218 27
      dbflight.cpp
  4. 10 1
      dbflight.h
  5. 43 0
      dbpilots.cpp
  6. 2 0
      dbpilots.h
  7. 62 42
      dbsetup.cpp
  8. 5 0
      dbsetup.h
  9. 253 0
      flight.cpp
  10. 76 0
      flight.h
  11. 0 1
      homewidget.cpp
  12. BIN
      logbook.db
  13. 4 5
      main.cpp
  14. 3 0
      mainwindow.cpp
  15. 2 0
      openLog.pro

+ 1 - 1
dbaircraft.cpp

@@ -84,7 +84,7 @@ QStringList dbAircraft::newAcftGetString(QString searchstring)
 /*!
  * \brief dbAircraft::newAcftGetId Looks up a registration in the databse
  * \param registration Aircraft Registration
- * \return tail_id
+ * \return tail_id or empty string
  */
 QString dbAircraft::retreiveTailId(QString registration)
 {

+ 3 - 6
dbairport.cpp

@@ -112,17 +112,14 @@ bool dbAirport::checkICAOValid(QString identifier)
         QString check = retreiveAirportIdFromIcao(identifier);
         if(check.length() > 0)
         {
-            //qDebug() << "db::CheckICAOValid says: Check passed!";
-            return 1;
+            return true;
         }else
         {
-            //qDebug() << "db::CheckICAOValid says: Check NOT passed! Lookup unsuccessful";
-            return 0;
+            return false;
         }
     }else
     {
-        //qDebug() << "db::CheckICAOValid says: Check NOT passed! Empty String NOT epico!";
-        return 0;
+        return false;
     }
 }
 

+ 218 - 27
dbflight.cpp

@@ -16,7 +16,224 @@
  *along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 #include "dbflight.h"
-#include "calc.h"
+#include "dbpilots.h"
+#include "dbaircraft.h"
+
+
+/*!
+ * \brief dbFlight::verifyInput Checks the validity of the data in a
+ * flight object against the database and sets its verified flag
+ * accordingly. Information about partial validity can be obtained
+ * by querying the flight objects invalidItems member.
+ */
+flight dbFlight::verifyInput(flight object)
+{
+
+    if (object.doft.isValid()){
+        object.invalidItems.removeOne("doft");
+        qDebug() << "doft verified.";
+    }else{
+        qWarning() << "Invalid entry: doft";
+    }
+
+    if(dbAirport::checkICAOValid(object.dept)){
+        object.invalidItems.removeOne("dept");
+        qDebug() << "dept verified.";
+    }else{
+        qWarning() << "Invalid entry: dept";
+    }
+
+    if(dbAirport::checkICAOValid(object.dest)){
+        object.invalidItems.removeOne("dest");
+        qDebug() << "dest verified.";
+    }else{
+        qWarning() << "Invalid entry: dest";
+    }
+
+    if(object.tofb.isValid()){
+        object.invalidItems.removeOne("tofb");
+        qDebug() << "tofb verified.";
+    }else{
+        qWarning() << "Invalid entry: tofb";
+    }
+
+    if(object.tonb.isValid()){
+        object.invalidItems.removeOne("tonb");
+        qDebug() << "tonb verified.";
+    }else{
+        qWarning() << "Invalid entry: tonb";
+    }
+
+    if(dbPilots::verifyPilotExists(object.pic.split(QLatin1Char(',')))){
+        object.invalidItems.removeOne("pic");
+        qDebug() << "pic verified.";
+    }else{
+        qWarning() << "Invalid entry: pic";
+    }
+
+    //acft
+
+    QTime tblkcheck = calc::blocktime(object.tofb, object.tonb);
+    if(object.tblk.isValid() && !object.tblk.isNull() && tblkcheck == object.tblk){
+        object.invalidItems.removeOne("tblk");
+        qDebug() << "tblk verified.";
+    }else{
+        qWarning() << "Invalid entry: tblk";
+    }
+
+    if(!dbAircraft::retreiveTailId(object.acft).isEmpty()){
+        object.invalidItems.removeOne("acft");
+        qDebug() << "acft verified.";
+    }else{
+        qWarning() << "Invalid entry: acft";
+    }
+
+    if(object.invalidItems.isEmpty()){
+        object.isValid = true;
+        qDebug() << "All checks passed. Object is now verified.";
+    }else{
+        qDebug() << "Not all checks have been passed.";
+        qDebug() << "Invalid items: " << object.invalidItems;
+    }
+
+    return object;
+
+    /* To Do: Checks on internal logic, i.e. times <= tblk,
+     * restrict what strings are allowed in remarks etc.
+
+    object.pic     = details[7];
+    object.acft    = details[8];
+    object.tblk    = QTime::fromString(details[9],"hh:mm");*/
+
+    /*object.tSPSE   = QTime::fromString(details[10],"hh:mm");
+    object.tSPME   = QTime::fromString(details[11],"hh:mm");
+    object.tMP     = QTime::fromString(details[12],"hh:mm");
+    object.tNIGHT  = QTime::fromString(details[13],"hh:mm");
+    object.tIFR    = QTime::fromString(details[14],"hh:mm");
+
+    object.tPIC    = QTime::fromString(details[15],"hh:mm");
+    object.tPICUS  = QTime::fromString(details[16],"hh:mm");
+    object.tSIC    = QTime::fromString(details[17],"hh:mm");
+    object.tDUAL   = QTime::fromString(details[18],"hh:mm");
+    object.tFI     = QTime::fromString(details[19],"hh:mm");
+    object.tSIM    = QTime::fromString(details[20],"hh:mm");
+
+    object.pilotFlying  = details[21].toInt();
+    object.toDay        = details[22].toInt();
+    object.toNight      = details[23].toInt();
+    object.ldgDay       = details[24].toInt();
+    object.ldgNight     = details[25].toInt();
+    object.autoland     = details[26].toInt();
+
+    object.secondPilot  = details[27];
+    object.thirdPilot   = details[28];
+    object.approachType = details[29];
+    object.flightNumber = details[30];
+    object.remarks      = details[31];*/
+}
+
+/*!
+ * \brief dbFlight::retreiveFlight Runs a select statement on the database
+ * for a given flight_id and returns a flight object containing the details
+ * for the given ID. If no matching ID is found, an empty flight object is
+ * returned
+ * \param flight_id Primary Key of flight database
+ */
+flight dbFlight::retreiveFlight(QString flight_id)
+{
+    QSqlQuery query;
+    query.prepare("SELECT * FROM flights WHERE id = ?");
+    query.addBindValue(flight_id);
+    query.exec();
+
+    if(query.first());
+    else
+    {
+        qWarning() << __func__ << "No Flight with this ID found";
+        return flight(); //return empty
+
+    }
+    flight object;
+
+    object.id      = query.value(0).toInt();
+    object.doft    = QDate::fromString(query.value(1).toString(),Qt::ISODate);
+    object.dept    = query.value(2).toString();
+    object.dest    = query.value(3).toString();
+    object.tofb    = QTime::fromString(
+                     calc::minutes_to_string(
+                     query.value(4).toString()),"hh:mm");
+    object.tonb    = QTime::fromString(
+                     calc::minutes_to_string(
+                     query.value(5).toString()),"hh:mm");
+    object.pic     = dbPilots::retreivePilotNameFromID(
+                     query.value(6).toString());
+    object.acft    = dbAircraft::retreiveRegistration(
+                     query.value(7).toString());
+    object.tblk    = QTime::fromString(
+                     calc::minutes_to_string(
+                     query.value(8).toString()),"hh:mm");
+    object.tSPSE   = QTime::fromString(
+                     calc::minutes_to_string(
+                     query.value(9).toString()),"hh:mm");
+    object.tSPME   = QTime::fromString(
+                     calc::minutes_to_string(
+                     query.value(10).toString()),"hh:mm");
+    object.tMP     = QTime::fromString(
+                     calc::minutes_to_string(
+                     query.value(11).toString()),"hh:mm");
+    object.tNIGHT  = QTime::fromString(
+                     calc::minutes_to_string(
+                     query.value(12).toString()),"hh:mm");
+    object.tIFR    = QTime::fromString(
+                     calc::minutes_to_string(
+                     query.value(13).toString()),"hh:mm");
+
+    object.tPIC    = QTime::fromString(
+                     calc::minutes_to_string(
+                     query.value(14).toString()),"hh:mm");
+    object.tPICUS  = QTime::fromString(
+                     calc::minutes_to_string(
+                     query.value(15).toString()),"hh:mm");
+    object.tSIC    = QTime::fromString(
+                     calc::minutes_to_string(
+                     query.value(16).toString()),"hh:mm");
+    object.tDUAL   = QTime::fromString(
+                     calc::minutes_to_string(
+                     query.value(17).toString()),"hh:mm");
+    object.tFI     = QTime::fromString(
+                     calc::minutes_to_string(
+                     query.value(18).toString()),"hh:mm");
+    object.tSIM    = QTime::fromString(
+                     calc::minutes_to_string(
+                     query.value(19).toString()),"hh:mm");
+
+    object.pilotFlying  = query.value(20).toInt();
+    object.toDay        = query.value(21).toInt();
+    object.toNight      = query.value(22).toInt();
+    object.ldgDay       = query.value(23).toInt();
+    object.ldgNight     = query.value(24).toInt();
+    object.autoland     = query.value(25).toInt();
+
+    object.secondPilot  = query.value(26).toInt();
+    object.thirdPilot   = query.value(27).toInt();
+    object.approachType = query.value(28).toString();
+    object.flightNumber = query.value(29).toString();
+    object.remarks      = query.value(30).toString();
+
+    //Database entries are assumed to be valid
+    object.isValid      = true;
+    object.invalidItems.clear();
+
+    return object;
+}
+
+
+bool dbFlight::commitFlight(flight object)
+{
+    //To Do
+    qDebug() << object;
+    return false;
+}
 
 /*!
  * \brief SelectFlightById Retreives a single flight from the database.
@@ -112,33 +329,7 @@ QVector<QString> dbFlight::createFlightVectorFromInput(QString doft, QString dep
     //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.

+ 10 - 1
dbflight.h

@@ -22,6 +22,8 @@
 #include <QSqlQuery>
 #include <QSqlError>
 #include <QDebug>
+#include "flight.h"
+#include "calc.h"
 
 /*!
  * \brief The dbFlight class provides a databank interface for actions related to the
@@ -31,13 +33,20 @@ class dbFlight
 {
 public:
 
+    static flight verifyInput(flight object);
+
+    static flight retreiveFlight(QString flight_id);
+
+    static bool commitFlight(flight object);
+
+
+
     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);
 

+ 43 - 0
dbpilots.cpp

@@ -298,3 +298,46 @@ QString dbPilots::newPicGetId(QString name)
     qDebug() << "newPicGetId: result = " << result;
     return result;
 }
+
+bool dbPilots::verifyPilotExists(QStringList names)
+{
+    QString name0;
+    QString name1;
+    if (!names.isEmpty()){
+        if(names.length() == 1){                 //only lastname
+            name0 = names[0].trimmed();
+        }else if (names.length() == 2){     //firstname and lastname
+            name0 = names[0].trimmed();
+            name1 = names[1].trimmed();
+        }
+    }else{
+        qWarning() << __func__ << "Invalid Input. Aborting.";
+        return false;
+    }
+
+    QSqlQuery query;
+
+    if(names.length() == 1){                 //only lastname
+        query.prepare("SELECT pilot_id FROM pilots "
+                      "WHERE piclastname = ?");
+        query.addBindValue(name0);
+    }else if (names.length() == 2){     //firstname and lastname
+        query.prepare("SELECT pilot_id FROM pilots "
+                      "WHERE piclastname = ?  AND picfirstname = ? "
+                      "OR picfirstname = ? AND piclastname = ? ");
+        query.addBindValue(name0);
+        query.addBindValue(name1);
+        query.addBindValue(name0);
+        query.addBindValue(name1);
+    }
+
+    query.exec();
+
+    if(query.first()){
+        qDebug() << __func__ << "Pilot found: " << name0;
+        return true;
+    }else{
+        qDebug() << __func__ << "No Pilot found";
+        return false;
+    }
+}

+ 2 - 0
dbpilots.h

@@ -42,6 +42,8 @@ public:
     static QStringList retreivePilotList();
 
     static QString newPicGetId(QString name);
+
+    static bool verifyPilotExists(QStringList);
 };
 
 #endif // DBPILOTS_H

+ 62 - 42
dbsetup.cpp

@@ -17,8 +17,7 @@
  */
 #include "dbsetup.h"
 
-
-// Pragmas for creation of database table
+// Statements for creation of database table
 const QString createTablePilots = "CREATE TABLE pilots ( "
                             "pilot_id       INTEGER, "
                             "picfirstname	TEXT, "
@@ -58,43 +57,48 @@ const QString createTableTails = "CREATE TABLE tails ( "
                              ")";
 
 const QString createTableFlights = "CREATE TABLE flights  ( "
-                             "id	INTEGER, "
-                             "doft	NUMERIC NOT NULL, "
-                             "dept	TEXT    NOT NULL, "
-                             "tofb	INTEGER NOT NULL, "
-                             "dest	TEXT    NOT NULL, "
-                             "tonb	INTEGER NOT NULL, "
-                             "tblk	INTEGER NOT NULL, "
-                             "pic	INTEGER, "
-                             "acft	INTEGER, "
-                             "PRIMARY KEY(id), "
-                             "FOREIGN KEY(pic)  REFERENCES pilots(pilot_id), "
-                             "FOREIGN KEY(acft) REFERENCES tails(tail_id) "
-                             ")";
-//extras table might eventually be merged into flights table.
-const QString createTableExtras = "CREATE TABLE extras ( "
-                            "extras_id      INTEGER NOT NULL, "
-                            "PilotFlying	INTEGER, "
-                            "TOday          INTEGER, "
-                            "TOnight        INTEGER, "
-                            "LDGday         INTEGER, "
-                            "LDGnight       INTEGER, "
-                            "autoland       INTEGER, "
-                            "tSPSE          INTEGER, "
-                            "tSPME          INTEGER, "
-                            "tMPME          INTEGER, "
-                            "tNight         INTEGER, "
-                            "tIFR           INTEGER, "
-                            "tPIC           INTEGER, "
-                            "tSIC           INTEGER, "
-                            "tDual          INTEGER, "
-                            "tInstructor	INTEGER, "
-                            "tSIM           INTEGER, "
-                            "ApproachType	TEXT, "
-                            "FlightNumber	TEXT, "
-                            "Remarks        TEXT, "
-                            "PRIMARY KEY(extras_id) "
-                            ")";
+                                   "id              INTEGER, "
+                                   "doft        	NUMERIC NOT NULL, "
+                                   "dept            TEXT    NOT NULL, "
+                                   "dest            TEXT    NOT NULL, "
+                                   "tofb            INTEGER NOT NULL, "
+                                   "tonb            INTEGER NOT NULL, "
+
+                                   "pic             INTEGER NOT NULL, "
+                                   "acft        	INTEGER NOT NULL, "
+                                   "tblk        	INTEGER NOT NULL, "
+
+
+                                   "tSPSE           INTEGER, "
+                                   "tSPME           INTEGER, "
+                                   "tMP             INTEGER, "
+                                   "tNIGHT          INTEGER, "
+                                   "tIFR            INTEGER, "
+
+                                   "tPIC            INTEGER, "
+                                   "tPICUS          INTEGER, "
+                                   "tSIC            INTEGER, "
+                                   "tDual           INTEGER, "
+                                   "tFI        	    INTEGER, "
+                                   "tSIM            INTEGER, "
+
+                                   "pilotFlying     INTEGER, "
+                                   "toDay           INTEGER, "
+                                   "toNight         INTEGER, "
+                                   "ldgDay          INTEGER, "
+                                   "ldgNight        INTEGER, "
+                                   "autoland        INTEGER, "
+
+                                   "secondPilot     INTEGER, "
+                                   "thirdPilot      INTEGER"
+                                   "ApproachType	TEXT, "
+                                   "FlightNumber	TEXT, "
+                                   "Remarks         TEXT, "
+
+                                   "PRIMARY KEY(id), "
+                                   "FOREIGN KEY(pic)  REFERENCES pilots(pilot_id), "
+                                   "FOREIGN KEY(acft) REFERENCES tails(tail_id) "
+                                   ")";
 
 const QString createTableAirports = "CREATE TABLE airports ( "
                             "airport_id INTEGER primary key, "
@@ -127,7 +131,7 @@ const QString createTableSettings = "CREATE TABLE settings ( "
                              "description	TEXT "
                              ")";
 
-// Pragmas for creation of views in the database
+// Statements for creation of views in the database
 
 const QString createViewQCompleterView = "CREATE VIEW QCompleterView AS "
                               "SELECT airport_id, icao, iata, "
@@ -159,7 +163,6 @@ const QString createViewLogbook = "CREATE VIEW Logbook AS "
                               "INNER JOIN pilots on flights.pic = pilots.pilot_id "
                               "INNER JOIN tails on flights.acft = tails.tail_id "
                               "INNER JOIN aircraft on tails.aircraft_id = aircraft.aircraft_id "
-                              "INNER JOIN extras on extras.extras_id = flights.id "
                               "ORDER BY date DESC ";
 
 //Displays Single Engine, Multi Engine and Multi Pilot Time
@@ -176,7 +179,6 @@ QStringList tables = {
     createTableAircraft,
     createTableTails,
     createTableFlights,
-    createTableExtras,
     createTableScratchpad,
     createTableAirports,
     createTableSettings
@@ -314,3 +316,21 @@ void dbSetup::commitAirportData(QVector<QStringList> airportData)
     query.exec("COMMIT;"); //commit transaction
     qDebug() << "Airport Database updated!";
 }
+//dbSetup::commitAirportData(dbSetup::importCSV("airports.csv")); //import airports and write to db
+
+/*!
+ * \brief dbSetup::getColumnNames Looks up column names of a given table
+ * \param table name of the table in the database
+ */
+QVector<QString> dbSetup::getColumnNames(QString table)
+{
+    QSqlDatabase db = QSqlDatabase::database("qt_sql_default_connection");
+    QVector<QString> columnNames;
+
+    QSqlRecord fields = db.driver()->record(table);
+    for(int i = 0; i < fields.count(); i++){
+        columnNames << fields.field(i).name();
+    }
+    return columnNames;
+}
+

+ 5 - 0
dbsetup.h

@@ -21,6 +21,9 @@
 #include <QCoreApplication>
 #include <QSqlQuery>
 #include <QSqlError>
+#include <QSqlRecord>
+#include <QSqlField>
+#include <QSqlDriver>
 #include <QDebug>
 #include <QFile>
 
@@ -42,6 +45,8 @@ public:
     static QVector<QStringList> importCSV(QString);
 
     static void commitAirportData(QVector<QStringList>);
+
+    static QVector<QString> getColumnNames(QString table);
 };
 
 #endif // DBSETUP_H

+ 253 - 0
flight.cpp

@@ -0,0 +1,253 @@
+#include "flight.h"
+
+flight::flight()
+{
+    isValid = false;
+    invalidItems.append( {                      // Upon verification, verified entries are removed from the list
+        "doft", "dept", "dest", "tofb",
+        "tonb", "pic",  "acft", "tblk"
+    });
+
+    id      = -1;                         //[1] Primary Key in Database, needed for retreival but not for commiting (sqlite autoincrement)
+    doft    = QDate();                    //[2] Date of Flight, initialised invalid
+    dept    = "INVA";                     //[3] Departure, initialised invalid
+    dest    = "INVA";                     //[4] Destination, initialised invalid
+    tofb    = QTime();                    //[5] Time off blocks (UTC), initialised invalid
+    tonb    = QTime();                    //[6] Time on blocks (UTC), initialised invalid
+    pic     = "INVA";                     //[7] Pilot in command (ID), initialised invalid
+    acft    = "INVA";                     //[8] Aircraft Registration (ID), initialised invalid
+
+    tblk    = QTime();                    //[9] Total Blocktime, initialised invalid
+    tSPSE   = QTime(0,0);                 //[10] optional times initialised as 0
+    tSPME   = QTime(0,0);                 //[11]
+    tMP     = QTime(0,0);                 //[12]
+    tNIGHT  = QTime(0,0);                 //[13]
+    tIFR    = QTime(0,0);                 //[14]
+
+    tPIC    = QTime(0,0);                 //[15]
+    tPICUS  = QTime(0,0);                 //[16]
+    tSIC    = QTime(0,0);                 //[17]
+    tDUAL   = QTime(0,0);                 //[18]
+    tFI     = QTime(0,0);                 //[19]
+
+    tSIM    = QTime(0,0);                 //[20]
+}
+
+flight::flight(QVector<QString> details)
+{
+    isValid = false;
+    invalidItems.append({                      // Upon verification, verified entries are removed from the list
+        "doft", "dept", "dest", "tofb",
+        "tonb", "pic",  "acft", "tblk"
+    });
+    if(details.length() != 32){
+        qWarning() << __PRETTY_FUNCTION__ << "Vector needs to be of size 32.";
+        qWarning() << __PRETTY_FUNCTION__ << "Unable to create object.";
+        details = QVector<QString>(32);
+    }
+
+    id      = details[1].toInt();
+    doft    = QDate::fromString(details[2],Qt::ISODate);
+    dept    = details[3];
+    dest    = details[4];
+    tofb    = QTime::fromString(details[5],"hh:mm");
+    tonb    = QTime::fromString(details[6],"hh:mm");
+    pic     = details[7];
+    acft    = details[8];
+    tblk    = QTime::fromString(details[9],"hh:mm");
+    tSPSE   = QTime::fromString(details[10],"hh:mm");
+    tSPME   = QTime::fromString(details[11],"hh:mm");
+    tMP     = QTime::fromString(details[12],"hh:mm");
+    tNIGHT  = QTime::fromString(details[13],"hh:mm");
+    tIFR    = QTime::fromString(details[14],"hh:mm");
+
+    tPIC    = QTime::fromString(details[15],"hh:mm");
+    tPICUS  = QTime::fromString(details[16],"hh:mm");
+    tSIC    = QTime::fromString(details[17],"hh:mm");
+    tDUAL   = QTime::fromString(details[18],"hh:mm");
+    tFI     = QTime::fromString(details[19],"hh:mm");
+    tSIM    = QTime::fromString(details[20],"hh:mm");
+
+    pilotFlying  = details[21].toInt();
+    toDay        = details[22].toInt();
+    toNight      = details[23].toInt();
+    ldgDay       = details[24].toInt();
+    ldgNight     = details[25].toInt();
+    autoland     = details[26].toInt();
+
+    secondPilot  = details[27];
+    thirdPilot   = details[28];
+    approachType = details[29];
+    flightNumber = details[30];
+    remarks      = details[31];
+}
+
+/*!
+ * \brief flight::printFlight Displays basic data for debugging
+ */
+void flight::print()
+{
+    QTextStream cout(stdout, QIODevice::WriteOnly);
+
+    if(id != -1){
+        cout << "Flight ID:\t\t" + QString::number(id) + "\n";
+    }else{
+        cout << "Flight ID:\t\tnot set\n";
+    }
+
+    if(doft.toString(Qt::ISODate).length()){
+        cout << "Date of Flight:\t" + doft.toString(Qt::ISODate) + "\n";
+    }else{
+        cout << "Date of Flight:\tnot set\n";
+    }
+
+   if(dept != QStringLiteral("INVA")){
+       cout << "Departure:\t\t" + dept  + "\n";
+    }else{
+       cout << "Departure:\t\tnot set\n";
+    }
+
+   if(dest != QStringLiteral("INVA")){
+       cout << "Destination:\t\t" + dest  + "\n";
+    }else{
+       cout << "Destination:\t\tnot set\n";
+    }
+
+   if(tofb.toString("hh:mm").length()){
+       cout << "Departure Time:\t" + tofb.toString("hh:mm") + "\n";
+   }else{
+       cout << "Departure Time:\tnot set\n";
+   }
+
+   if(tonb.toString("hh:mm").length()){
+       cout << "Arrival Time:\t" + tonb.toString("hh:mm") + "\n";
+   }else{
+       cout << "Arrival Time:\tnot set\n";
+   }
+
+    if(pic != QStringLiteral("INVA")){
+        cout << "Pilot in Command:\t" + pic + "\n";
+    }else{
+       cout << "Pilot in Command:\tnot set\n";
+    }
+
+    if(acft != QStringLiteral("INVA")){
+        cout << "Aircraft:\t\t" + acft + "\n";
+    }else{
+       cout << "Aircraft:\t\tnot set\n";
+    }
+
+    if(tblk.isValid()){
+        cout << "Blocktime:\t\t" + tblk.toString("hh:mm") + "\n";
+    }else{
+       cout << "Blocktime:\t\tnot set\n";
+    }
+
+    if(isValid){
+        cout << "Object status:\t\033[38;2;0;255;0;48;2;0;0;0m VERIFIED \033[0m\n";
+    }else{
+        cout << "Object status:\t\033[38;2;255;0;0;48;2;0;0;0m UNVERIFIED \033[0m\n";
+    }
+    if(!invalidItems.isEmpty()){
+        cout << "Invalid items:\t";
+        for(auto const& item : invalidItems){
+            cout << item + QLatin1Char(' ');
+        }
+        cout << "\n";
+    }
+}
+/*!
+ * \brief flight::debug Provides compatibility with qDebug
+ * \return
+ */
+QString flight::debug()
+{
+    print();
+    return QString();
+}
+
+flight flight::fromVector(QVector<QString> details)
+{
+    if(details.length() != 32){
+        qWarning() << __PRETTY_FUNCTION__ << "Invalid Input. Aborting.";
+        return flight();
+    }
+    flight object;
+    object.id      = details[1].toInt();
+    object.doft    = QDate::fromString(details[2],Qt::ISODate);
+    object.dept    = details[3];
+    object.dest    = details[4];
+    object.tofb    = QTime::fromString(details[5],"hh:mm");
+    object.tonb    = QTime::fromString(details[6],"hh:mm");
+    object.pic     = details[7];
+    object.acft    = details[8];
+    object.tblk    = QTime::fromString(details[9],"hh:mm");
+    object.tSPSE   = QTime::fromString(details[10],"hh:mm");
+    object.tSPME   = QTime::fromString(details[11],"hh:mm");
+    object.tMP     = QTime::fromString(details[12],"hh:mm");
+    object.tNIGHT  = QTime::fromString(details[13],"hh:mm");
+    object.tIFR    = QTime::fromString(details[14],"hh:mm");
+
+    object.tPIC    = QTime::fromString(details[15],"hh:mm");
+    object.tPICUS  = QTime::fromString(details[16],"hh:mm");
+    object.tSIC    = QTime::fromString(details[17],"hh:mm");
+    object.tDUAL   = QTime::fromString(details[18],"hh:mm");
+    object.tFI     = QTime::fromString(details[19],"hh:mm");
+    object.tSIM    = QTime::fromString(details[20],"hh:mm");
+
+    object.pilotFlying  = details[21].toInt();
+    object.toDay        = details[22].toInt();
+    object.toNight      = details[23].toInt();
+    object.ldgDay       = details[24].toInt();
+    object.ldgNight     = details[25].toInt();
+    object.autoland     = details[26].toInt();
+
+    object.secondPilot  = details[27];
+    object.thirdPilot   = details[28];
+    object.approachType = details[29];
+    object.flightNumber = details[30];
+    object.remarks      = details[31];
+
+    return object;
+}
+
+QVector<QString> flight::toVector(flight object)
+{
+    QVector<QString> vecOut(32);
+
+    vecOut [1]  = QString::number(object.id);
+    vecOut [2]  = object.doft.toString(Qt::ISODate);
+    vecOut [3]  = object.dept;
+    vecOut [4]  = object.dest;
+    vecOut [5]  = object.tofb.toString("hh:mm");
+    vecOut [6]  = object.tonb.toString("hh:mm");
+    vecOut [7]  = object.pic;
+    vecOut [8]  = object.acft;
+    vecOut [9]  = object.tblk.toString("hh:mm");
+
+    vecOut [10] = object.tSPSE.toString("hh:mm");
+    vecOut [11] = object.tSPME.toString("hh:mm");
+    vecOut [12] = object.tMP.toString("hh:mm");
+    vecOut [13] = object.tNIGHT.toString("hh:mm");
+    vecOut [14] = object.tIFR.toString("hh:mm");
+    vecOut [15] = object.tPIC.toString("hh:mm");
+    vecOut [16] = object.tPICUS.toString("hh:mm");
+    vecOut [17] = object.tSIC.toString("hh:mm");
+    vecOut [18] = object.tDUAL.toString("hh:mm");
+    vecOut [19] = object.tFI.toString("hh:mm");
+    vecOut [20] = object.tSIM.toString("hh:mm");
+
+    vecOut [21] = QString::number(object.pilotFlying);
+    vecOut [22] = QString::number(object.toDay);
+    vecOut [23] = QString::number(object.toNight);
+    vecOut [24] = QString::number(object.ldgDay);
+    vecOut [25] = QString::number(object.ldgNight);
+    vecOut [26] = QString::number(object.autoland);
+    vecOut [27] = object.secondPilot;
+    vecOut [28] = object.thirdPilot;
+    vecOut [29] = object.approachType;
+    vecOut [30] = object.flightNumber;
+    vecOut [31] = object.remarks;
+
+    return vecOut;
+}

+ 76 - 0
flight.h

@@ -0,0 +1,76 @@
+#ifndef FLIGHT_H
+#define FLIGHT_H
+
+#include <QCoreApplication>
+#include <QDateTime>
+#include <QDebug>
+
+/*!
+ * \brief The flight class is a container class for a logbook entry. It contains all the
+ * entries relevant to a flight. There are 8 mandatory entries which are initalized
+ * invalid and need to be set before the flight can be committed. The other entries
+ * are optional and can be empty, null or any other value.
+ * All time entries in a flight object shall be UTC.
+ */
+class flight
+{
+public:
+
+    bool        isValid;
+    QStringList invalidItems;/* = {                      // Upon verification, verified entries are removed from the list
+        "doft", "dept", "dest", "tofb",
+        "tonb", "pic",  "acft", "tblk"
+    };*/
+
+    int         id;//      = -1;                         //[1] Primary Key in Database, needed for retreival but not for commiting (sqlite autoincrement)
+    QDate       doft;//   = QDate();                    //[2] Date of Flight, initialised invalid
+    QString     dept;//    = "INVA";                     //[3] Departure, initialised invalid
+    QString     dest;//    = "INVA";                     //[4] Destination, initialised invalid
+    QTime       tofb;// = QTime();                    //[5] Time off blocks (UTC), initialised invalid
+    QTime       tonb;//    = QTime();                    //[6] Time on blocks (UTC), initialised invalid
+    QString     pic;//     = "INVA";                     //[7] Pilot in command (ID), initialised invalid
+    QString     acft;//    = "INVA";                     //[8] Aircraft Registration (ID), initialised invalid
+
+    QTime       tblk;//    = QTime();                    //[9] Total Blocktime, initialised invalid
+    QTime       tSPSE;//   = QTime(0,0);                 //[10] optional times initialised as 0
+    QTime       tSPME;//   = QTime(0,0);                 //[11]
+    QTime       tMP;//     = QTime(0,0);                 //[12]
+    QTime       tNIGHT;//  = QTime(0,0);                 //[13]
+    QTime       tIFR;//    = QTime(0,0);                 //[14]
+
+    QTime       tPIC;//    = QTime(0,0);                 //[15]
+    QTime       tPICUS;//  = QTime(0,0);                 //[16]
+    QTime       tSIC;//    = QTime(0,0);                 //[17]
+    QTime       tDUAL;//   = QTime(0,0);                 //[18]
+    QTime       tFI;//     = QTime(0,0);                 //[19]
+
+    QTime       tSIM;//    = QTime(0,0);                 //[20]
+
+    int         pilotFlying;                          //[21]
+    int         toDay;                                //[22]
+    int         toNight;                              //[23]
+    int         ldgDay;                               //[24]
+    int         ldgNight;                             //[25]
+    int         autoland;                             //[26]
+
+    QString     secondPilot;                          //[27]
+    QString     thirdPilot;                           //[28]
+    QString     approachType;                         //[29]
+    QString     flightNumber;                         //[30]
+    QString     remarks;                              //[31]
+
+    flight();
+    flight(QVector<QString>);
+
+
+    // Functions
+    static flight           fromVector(QVector<QString>);
+    static QVector<QString> toVector(flight);
+
+    // Debug functionality
+    void print();
+    QString debug();
+    operator QString() { return debug(); }
+};
+
+#endif // FLIGHT_H

+ 0 - 1
homewidget.cpp

@@ -30,7 +30,6 @@ homeWidget::homeWidget(QWidget *parent) :
     ui->setupUi(this);
     qDebug() << "homeWidget: Activated";
 
-
     /*
      * To Do: Functions to retreive values from DB
      */

BIN
logbook.db


+ 4 - 5
main.cpp

@@ -28,9 +28,9 @@
 #include <QSqlError>
 #include <QSqlQuery>
 #include "dbsettings.h"
+#include "dbsetup.h"
 #include <QDebug>
 
-int selectedtheme = 1; //Variable to store theming information
 
 void connectToDatabase()
 {
@@ -58,16 +58,16 @@ void connectToDatabase()
 
 int main(int argc, char *argv[])
 {
+    connectToDatabase();
+
     QCoreApplication::setOrganizationName("Fiffty50");
     QCoreApplication::setOrganizationDomain("https://github.com/fiffty-50/openpilotlog");
     QCoreApplication::setApplicationName("openLog");
     QApplication openLog(argc, argv);
 
-    connectToDatabase();
-
     //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 = dbSettings::retreiveSetting(10).toInt();
+    int selectedtheme = dbSettings::retreiveSetting(10).toInt();
     QDir::setCurrent("/themes");
     if (selectedtheme == 1){
         qDebug() << "Loading light theme";
@@ -82,7 +82,6 @@ int main(int argc, char *argv[])
         QTextStream stream(&file);
         openLog.setStyleSheet(stream.readAll());
     }
-
     MainWindow w;
     w.show();
     return openLog.exec();

+ 3 - 0
mainwindow.cpp

@@ -25,6 +25,9 @@
 #include "homewidget.h"
 #include "logbookwidget.h"
 #include "settingswidget.h"
+#include "dbsetup.h"
+
+
 
 MainWindow::MainWindow(QWidget *parent)
     : QMainWindow(parent)

+ 2 - 0
openLog.pro

@@ -32,6 +32,7 @@ SOURCES += \
     dbstat.cpp \
     easaview.cpp \
     editflight.cpp \
+    flight.cpp \
     homewidget.cpp \
     logbookwidget.cpp \
     main.cpp \
@@ -53,6 +54,7 @@ HEADERS += \
     dbstat.h \
     easaview.h \
     editflight.h \
+    flight.h \
     homewidget.h \
     logbookwidget.h \
     mainwindow.h \