Browse Source

preliminary work on flight class

fiffty-50 4 years ago
parent
commit
bb9cb21139
2 changed files with 186 additions and 0 deletions
  1. 117 0
      flight.cpp
  2. 69 0
      flight.h

+ 117 - 0
flight.cpp

@@ -0,0 +1,117 @@
+#include "flight.h"
+
+/*!
+ * \brief flight::printFlight Displays basic data for debugging
+ */
+void flight::printFlight()
+{
+    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";
+    }
+}
+/*!
+ * \brief flight::debug Provides compatibility with qDebug
+ * \return
+ */
+QString flight::debug()
+{
+    printFlight();
+    return QString();
+}
+
+flight flight::fromVector(QVector<QString> details)
+{
+    if(details.length() != 31){
+        qWarning() << __PRETTY_FUNCTION__ << "Invalid Input. Aborting.";
+        return flight();
+    }
+    flight flightobject;
+    flightobject.id      = details[1].toInt();
+    flightobject.doft    = QDate::fromString(details[2],Qt::ISODate);
+    flightobject.dept    = details[3];
+    flightobject.dest    = details[4];
+    flightobject.tofb    = QTime::fromString(details[5],"hh:mm");
+    flightobject.tonb    = QTime::fromString(details[6],"hh:mm");
+    flightobject.pic     = details[7];
+    flightobject.acft    = details[8];
+    flightobject.tblk    = QTime::fromString(details[9],"hh:mm");
+    flightobject.tSPSE = details[10].toInt();
+    flightobject.tSPME = details[11].toInt();
+    flightobject.tMP = details[12].toInt();
+    flightobject.tNIGHT = details[13].toInt();
+    flightobject.tIFR = details[14].toInt();
+
+    flightobject.tPIC = details[15].toInt();
+    flightobject.tSIC = details[16].toInt();
+    flightobject.tDUAL = details[17].toInt();
+    flightobject.tFI = details[18].toInt();
+
+    flightobject.tSIM = details[19].toInt();
+
+    flightobject.pilotFlying = details[20].toInt();
+    flightobject.toDay = details[21].toInt();
+    flightobject.toNight = details[22].toInt();
+    flightobject.ldgDay = details[23].toInt();
+    flightobject.ldgNight = details[24].toInt();
+    flightobject.autoland = details[25].toInt();
+
+    flightobject.secondPilot = details[26];
+    flightobject.thirdPilot = details[27];
+    flightobject.approachType = details[28];
+    flightobject.flightNumber = details[29];
+    flightobject.remarks = details[30];
+
+    return flightobject;
+}

+ 69 - 0
flight.h

@@ -0,0 +1,69 @@
+#ifndef FLIGHT_H
+#define FLIGHT_H
+
+#include <QCoreApplication>
+#include <QDateTime>
+#include <QDebug>
+
+/*!
+ * \brief The flight class is a container 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.
+ */
+class flight
+{
+public:
+    bool        isValid = false;
+    QStringList invalidItems = {
+        "doft", "dept", "dest", "tofb",
+        "tonb", "pic",  "acft", "tblk"
+    };
+
+    int         id      = -1;                             // Primary Key in Database, needed for retreival but not for commiting (sqlite autoincrement)
+    QDate       doft    = QDate();                        // Date of Flight
+    QString     dept    = "INVA";                         // Departure
+    QString     dest    = "INVA";                         // Destination
+    QTime       tofb    = QTime();                        // Time off blocks (UTC), initialised invalid
+    QTime       tonb    = QTime();                        // Time on blocks (UTC), initialised invalid
+    QString     pic     = "INVA";                         // Pilot in command (ID)
+    QString     acft    = "INVA";                         // Aircraft Registration (ID)
+
+    QTime       tblk    = QTime();                        // Total Blocktime, initialised invalid
+    QTime       tSPSE   = QTime(0,0);                     // optional times initialised as 0
+    QTime       tSPME   = QTime(0,0);
+    QTime       tMP     = QTime(0,0);
+    QTime       tNIGHT  = QTime(0,0);
+    QTime       tIFR    = QTime(0,0);
+
+    QTime       tPIC    = QTime(0,0);
+    QTime       tSIC    = QTime(0,0);
+    QTime       tDUAL   = QTime(0,0);
+    QTime       tFI     = QTime(0,0);
+
+    QTime       tSIM    = QTime(0,0);
+
+    int         pilotFlying;
+    int         toDay;
+    int         toNight;
+    int         ldgDay;
+    int         ldgNight;
+    int         autoland;
+
+    QString     secondPilot;
+    QString     thirdPilot;
+    QString     approachType;
+    QString     flightNumber;
+    QString     remarks;
+
+    // Functions
+    static flight           fromVector(QVector<QString>);
+    static QVector<QString> toVector(flight);
+
+    // Debug functionality
+    void printFlight();
+    QString debug();
+    operator QString() { return debug(); }
+};
+
+#endif // FLIGHT_H