Browse Source

Consolidation of date and time usage

Consolidated interfacing with Dates, Times and Datetimes into the opl and ATime/ADateTime namespaces.

ADate namespace is missing, but at the moment, all dates are handled as Qt::ISOdate or Qt::Textdate, so no need at the moment for that. Might be implemented later.

Tweaked NewFlightDialog to use the new namespace exclusivly and marked duplicate old functions in ACalc namespace as deprecated for removal after new functionality has been tested.
Felix 4 years ago
parent
commit
8965c512b1

+ 2 - 0
openPilotLog.pro

@@ -65,8 +65,10 @@ HEADERS += \
     src/database/adatabasesetup.h \
     src/database/declarations.h \
     src/functions/acalc.h \
+    src/functions/adatetime.h \
     src/functions/areadcsv.h \
     src/functions/astat.h \
+    src/functions/atime.h \
     src/gui/dialogues/firstrundialog.h \
     src/gui/dialogues/newflightdialog.h \
     src/gui/dialogues/newpilotdialog.h \

+ 3 - 1
src/database/adatabasesetup.cpp

@@ -22,6 +22,7 @@
 #include "src/classes/astandardpaths.h"
 #include "src/classes/adownload.h"
 #include "src/oplconstants.h"
+#include "src/functions/adatetime.h"
 
 // Statements for creation of database tables, Revision 15
 
@@ -303,7 +304,8 @@ bool ADataBaseSetup::backupOldData()
         return true;
     }
 
-    auto date_string = QDateTime::currentDateTime().toString(opl::datetime::DATETIME_BACKUP_FORMAT);
+    auto date_string = ADateTime::toString(QDateTime::currentDateTime(),
+                                           opl::datetime::Backup);
     auto backup_dir = QDir(AStandardPaths::absPathOf(AStandardPaths::DatabaseBackup));
     auto backup_name = database_file.baseName() + "_bak_" + date_string + ".db";
     QFile file(aDB->databaseFile.absoluteFilePath());

+ 5 - 2
src/functions/acalc.cpp

@@ -12,9 +12,12 @@ using namespace ACalc;
  * input as hh:mm, h:mm, hhmm or hmm.
  * \param userinput from a QLineEdit
  * \return formatted QString "hh:mm" or Empty String
- */
+ *
 QString ACalc::formatTimeInput(QString user_input)
 {
+    DEB << "#######################################";
+    DEB << "# WARNING: USE OF DEPRECATED FUNCTION #";
+    DEB << "#######################################";
     QString output; //
     QTime temp_time; //empty time object is invalid by default
 
@@ -39,7 +42,7 @@ QString ACalc::formatTimeInput(QString user_input)
         DEB << "Time input is invalid.";
     }
     return output;
-}
+}*/
 
 /*!
  * The purpose of the following functions is to provide functionality enabling the Calculation of

+ 18 - 1
src/functions/acalc.h

@@ -1,12 +1,13 @@
 #ifndef ACALC_H
 #define ACALC_H
 
-#include <QDateTime>
 #ifdef _MSC_VER
 #define _USE_MATH_DEFINES
 #endif
 #include <cmath>
+#include <QDateTime>
 #include <QDebug>
+#include "src/testing/adebug.h"
 /*!
  * \brief The ACalc namespace provides various functions for calculations that are performed
  * outside of the database. This includes tasks like converting different units and formats,
@@ -23,6 +24,10 @@ namespace ACalc {
  */
 inline QTime blocktime(QTime tofb, QTime tonb)
 {
+    DEB << "#######################################";
+    DEB << "# WARNING: USE OF DEPRECATED FUNCTION #";
+    DEB << "#######################################";
+
     QTime blocktime_out(0, 0); // initialise return value at midnight
 
     if (tonb > tofb) { // landing same day
@@ -44,6 +49,9 @@ inline QTime blocktime(QTime tofb, QTime tonb)
  */
 inline QString minutesToString(QString block_minutes)
 {
+    DEB << "#######################################";
+    DEB << "# WARNING: USE OF DEPRECATED FUNCTION #";
+    DEB << "#######################################";
     int minutes = block_minutes.toInt();
     QString hour = QString::number(minutes / 60);
     if (hour.size() < 2) {
@@ -59,6 +67,9 @@ inline QString minutesToString(QString block_minutes)
 
 inline QString minutesToString(int block_minutes)
 {
+    DEB << "#######################################";
+    DEB << "# WARNING: USE OF DEPRECATED FUNCTION #";
+    DEB << "#######################################";
     QString hour = QString::number(block_minutes / 60);
     if (hour.size() < 2) {
         hour.prepend("0");
@@ -78,6 +89,9 @@ inline QString minutesToString(int block_minutes)
  */
 inline int QTimeToMinutes(QTime time)
 {
+    DEB << "#######################################";
+    DEB << "# WARNING: USE OF DEPRECATED FUNCTION #";
+    DEB << "#######################################";
     QString timestring = time.toString("hh:mm");
     int minutes = (timestring.left(2).toInt()) * 60;
     minutes += timestring.right(2).toInt();
@@ -91,6 +105,9 @@ inline int QTimeToMinutes(QTime time)
  */
 inline int stringToMinutes(QString timestring)
 {
+    DEB << "#######################################";
+    DEB << "# WARNING: USE OF DEPRECATED FUNCTION #";
+    DEB << "#######################################";
     int minutes = (timestring.left(2).toInt()) * 60;
     minutes += timestring.right(2).toInt();
     timestring = QString::number(minutes);

+ 24 - 0
src/functions/adatetime.h

@@ -0,0 +1,24 @@
+#ifndef ADATETIME_H
+#define ADATETIME_H
+#include <QtCore>
+#include "src/oplconstants.h"
+
+namespace ADateTime {
+
+/*!
+ * \brief toString formats a QDateTime object into a string in a uniform way.
+ * \return
+ */
+inline const QString toString (const QDateTime date_time, opl::datetime::DateTimeFormat format) {
+    switch (format) {
+    case opl::datetime::Default:
+        return date_time.toString(Qt::ISODate);
+    case opl::datetime::Backup:
+        return date_time.toString(QStringLiteral("yyyy_MM_dd_T_hh_mm"));
+        break;
+    }
+}
+
+}
+
+#endif // ADATETIME_H

+ 131 - 0
src/functions/atime.h

@@ -0,0 +1,131 @@
+#ifndef ATIME_H
+#define ATIME_H
+
+#include <QtCore>
+#include <QTime>
+#include "src/oplconstants.h"
+#include "src/testing/adebug.h"
+
+namespace ATime {
+
+inline const QString toString(const QTime &time, opl::time::FlightTimeFormat format)
+{
+    switch (format) {
+    case opl::time::Default:
+        return time.toString(QStringLiteral("hh:mm"));
+        break;
+    case opl::time::Decimal:
+        return QString::asprintf("%.2f", (time.hour() * 60 + time.minute() )/60.0);
+        break;
+    default:
+        return QString();
+    }
+}
+
+inline double toDecimalHours(const QTime &time){
+    return (time.hour() * 60 + time.minute()) / 60.0;
+}
+
+inline int toMinutes(const QTime &time) {return time.hour() * 60 + time.minute();}
+
+inline QTime fromMinutes(int total_minutes)
+{
+    int minute = total_minutes % 60;
+    int hour = total_minutes / 60;
+
+    return QTime(hour, minute, 0);
+}
+
+inline const QTime fromString(QString time_string, opl::time::FlightTimeFormat format)
+{
+    switch (format) {
+    case opl::time::Default:
+        return QTime::fromString(time_string, QStringLiteral("hh:mm"));
+        break;
+    case opl::time::Decimal:
+    {
+        double decimal_time = time_string.toDouble();
+        int hour = decimal_time;
+        int minute = round((decimal_time - hour) * 60);
+        return QTime(hour, minute, 0);
+        break;
+    }
+    default:
+        return QTime();
+    }
+}
+
+inline const QTime fromString(const char* time_string, opl::time::FlightTimeFormat format)
+{
+    switch (format) {
+    case opl::time::Default:
+        return QTime::fromString(time_string, QStringLiteral("hh:mm"));
+        break;
+    case opl::time::Decimal:
+    {
+        double decimal_time = QString(time_string).toDouble();
+        int hour = decimal_time;
+        int minute = round((decimal_time - hour) * 60);
+        return QTime(hour, minute, 0);
+        break;
+    }
+    default:
+        return QTime();
+    }
+}
+
+inline QTime blocktime(const QTime &tofb, const QTime &tonb)
+{
+    QTime blocktime_out(0, 0); // initialise return value at midnight
+
+    if (tonb > tofb) { // landing same day
+        int block_seconds = tofb.secsTo(tonb);
+        blocktime_out = blocktime_out.addSecs(block_seconds);
+    } else { // landing next day
+        QTime midnight(0, 0);
+        int seconds = tofb.secsTo(midnight);
+        blocktime_out = blocktime_out.addSecs(seconds);
+        seconds = midnight.secsTo(tonb);
+        blocktime_out = blocktime_out.addSecs(seconds);
+    }
+    return blocktime_out;
+}
+
+/*!
+ * \brief verifies user input and formats to hh:mm
+ * if the output is not a valid time, an empty string is returned. Accepts
+ * input as hh:mm, h:mm, hhmm or hmm.
+ * \param userinput from a QLineEdit
+ * \return formatted QString "hh:mm" or Empty String
+ */
+inline const QString formatTimeInput(QString user_input)
+{
+    QTime temp_time; //empty time object is invalid by default
+
+    bool contains_seperator = user_input.contains(':');
+    if (user_input.length() == 4 && !contains_seperator) {
+        temp_time = QTime::fromString(user_input, QStringLiteral("hhmm"));
+    } else if (user_input.length() == 3 && !contains_seperator) {
+        if (user_input.toInt() < 240) { //Qtime is invalid if time is between 000 and 240 for this case
+            QString tempstring = user_input.prepend(QStringLiteral("0"));
+            temp_time = QTime::fromString(tempstring, QStringLiteral("hhmm"));
+        } else {
+            temp_time = QTime::fromString(user_input, QStringLiteral("Hmm"));
+        }
+    } else if (user_input.length() == 4 && contains_seperator) {
+        temp_time = QTime::fromString(user_input, QStringLiteral("h:mm"));
+    } else if (user_input.length() == 5 && contains_seperator) {
+        temp_time = QTime::fromString(user_input, QStringLiteral("hh:mm"));
+    }
+
+    auto output = temp_time.toString(QStringLiteral("hh:mm"));
+
+    if (output.isEmpty()) {
+        DEB << "Time input is invalid.";
+    }
+    return output;
+}
+
+} // namespace ATime
+
+#endif // ATIME_H

+ 3 - 28
src/gui/dialogues/newflight.ui

@@ -790,7 +790,8 @@
          </property>
          <property name="font">
           <font>
-           <pointsize>16</pointsize>
+           <family>DejaVu Sans</family>
+           <pointsize>10</pointsize>
            <weight>75</weight>
            <bold>true</bold>
           </font>
@@ -799,7 +800,7 @@
           <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Once all the required items are filled out, the total time of flight will be displayed here.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
          </property>
          <property name="styleSheet">
-          <string notr="true">color: rgb(237, 212, 0);</string>
+          <string notr="true"/>
          </property>
          <property name="frameShape">
           <enum>QFrame::NoFrame</enum>
@@ -840,30 +841,6 @@
          </property>
         </widget>
        </item>
-       <item row="10" column="3">
-        <widget class="QLabel" name="submissionReadyTextLabel">
-         <property name="text">
-          <string>Status:</string>
-         </property>
-        </widget>
-       </item>
-       <item row="10" column="4">
-        <widget class="QLabel" name="submissonReadyLabel">
-         <property name="font">
-          <font>
-           <pointsize>16</pointsize>
-           <weight>75</weight>
-           <bold>true</bold>
-          </font>
-         </property>
-         <property name="styleSheet">
-          <string notr="true">color: rgb(237, 212, 0);</string>
-         </property>
-         <property name="text">
-          <string>INCOMPLETE</string>
-         </property>
-        </widget>
-       </item>
       </layout>
       <zorder>placeLabel2</zorder>
       <zorder>deptLocLineEdit</zorder>
@@ -920,8 +897,6 @@
       <zorder>placeLabel1</zorder>
       <zorder>calendarCheckBox</zorder>
       <zorder>picCompanyLabel</zorder>
-      <zorder>submissionReadyTextLabel</zorder>
-      <zorder>submissonReadyLabel</zorder>
      </widget>
      <widget class="QWidget" name="autoLoggingTab">
       <attribute name="title">

+ 98 - 92
src/gui/dialogues/newflightdialog.cpp

@@ -173,6 +173,8 @@ void NewFlightDialog::readSettings()
     ui->FlightNumberLineEdit->setText(ASettings::read(ASettings::FlightLogging::FlightNumberPrefix).toString());
     ui->calendarCheckBox->setChecked(ASettings::read(ASettings::FlightLogging::PopupCalendar).toBool());
 
+    flightTimeFormat = opl::time::Default; // No support for Decimal Time implemented yet.
+
 }
 
 void NewFlightDialog::writeSettings()
@@ -214,13 +216,13 @@ void NewFlightDialog::setupRawInputValidation()
     auto tempList = QStringList();
     // define tuples
     const std::tuple<QString, QStringList*, QRegularExpression>
-            location_line_edit_settings = {"Loc", &airportList, LOC_VALID_RGX};
+            location_line_edit_settings = {QStringLiteral("Loc"), &airportList, LOC_VALID_RGX};
     const std::tuple<QString, QStringList*, QRegularExpression>
-            name_line_edit_settings = {"Name", &pilotList, NAME_VALID_RGX};
+            name_line_edit_settings = {QStringLiteral("Name"), &pilotList, NAME_VALID_RGX};
     const std::tuple<QString, QStringList*, QRegularExpression>
-            acft_line_edit_settings = {"acft", &tailsList, AIRCRAFT_VALID_RGX};
+            acft_line_edit_settings = {QStringLiteral("acft"), &tailsList, AIRCRAFT_VALID_RGX};
     const std::tuple<QString, QStringList*, QRegularExpression>
-            time_line_edit_settings = {"Time", &tempList, TIME_VALID_RGX};
+            time_line_edit_settings = {QStringLiteral("Time"), &tempList, TIME_VALID_RGX};
     const QList<std::tuple<QString, QStringList*, QRegularExpression>> line_edit_settings = {
         location_line_edit_settings,
         name_line_edit_settings,
@@ -275,31 +277,33 @@ void NewFlightDialog::setupSignalsAndSlots()
 
     for (const auto &line_edit : line_edits){
         line_edit->installEventFilter(this);
-        if(line_edit->objectName().contains("Loc")){
+        if(line_edit->objectName().contains(QStringLiteral("Loc"))){
             QObject::connect(line_edit, &QLineEdit::textChanged,
                              this, &NewFlightDialog::onToUpperTriggered_textChanged);
         }
-        if(line_edit->objectName().contains("acft")){
+        if(line_edit->objectName().contains(QStringLiteral("acft"))){
             QObject::connect(line_edit, &QLineEdit::textChanged,
                              this, &NewFlightDialog::onToUpperTriggered_textChanged);
         }
-        if(line_edit->objectName().contains("Name")){
+        if(line_edit->objectName().contains(QStringLiteral("Name"))){
             QObject::connect(line_edit, &QLineEdit::editingFinished,
                              this, &NewFlightDialog::onPilotNameLineEdit_editingFinished);
         }
-        if(line_edit->objectName().contains("Time")){
+        if(line_edit->objectName().contains(QStringLiteral("Time"))){
             QObject::connect(line_edit, &QLineEdit::editingFinished,
                              this, &NewFlightDialog::onTimeLineEdit_editingFinished);
         }
     }
+#if QT_VERSION >= QT_VERSION_CHECK(5, 9, 0)
     for (const auto &line_edit : qAsConst(mandatoryLineEdits)) {
-        if(line_edit->objectName().contains("doft"))
+        if(line_edit->objectName().contains(QStringLiteral("doft")))
             break;
         QObject::connect(line_edit->completer(), QOverload<const QString &>::of(&QCompleter::highlighted),
                          this, &NewFlightDialog::onCompleter_highlighted);
         QObject::connect(line_edit->completer(), QOverload<const QString &>::of(&QCompleter::activated),
                          this, &NewFlightDialog::onCompleter_activated);
     }
+#endif
 }
 
 
@@ -388,11 +392,13 @@ void NewFlightDialog::fillDeductibleData()
     for(const auto& widget : LE) {widget->setText(EMPTY_STRING);}
     for(const auto& widget : LB) {widget->setText(opl::db::NULL_TIME_hhmm);}
     //Calculate block time
-    auto tofb = QTime::fromString(ui->tofbTimeLineEdit->text(), opl::datetime::TIME_DEFAULT_FORMAT);
-    auto tonb = QTime::fromString(ui->tonbTimeLineEdit->text(), opl::datetime::TIME_DEFAULT_FORMAT);
-    QString block_time = ACalc::blocktime(tofb, tonb).toString(opl::datetime::FLIGHT_TIME_DEFAULT_FORMAT);
-    QString block_minutes = QString::number(ACalc::stringToMinutes(block_time));
-    ui->tblkTimeLineEdit->setText(block_time);
+    const auto tofb = ATime::fromString(ui->tofbTimeLineEdit->text(), opl::time::Default);
+    const auto tonb = ATime::fromString(ui->tonbTimeLineEdit->text(), opl::time::Default);
+    const auto tblk = ATime::blocktime(tofb, tonb);
+    const auto block_time_string = ATime::toString(tblk, flightTimeFormat);
+    const auto block_minutes = ATime::toMinutes(tblk);
+
+    ui->tblkTimeLineEdit->setText(block_time_string);
     // get acft data and fill deductible entries
     auto acft = aDB->getTailEntry(tailsIdMap.value(ui->acftLineEdit->text()));
     if (acft.getData().isEmpty())
@@ -402,70 +408,67 @@ void NewFlightDialog::fillDeductibleData()
     // SP SE
     if(acft.getData().value(opl::db::TAILS_MULTIPILOT).toInt() == 0
             && acft.getData().value(opl::db::TAILS_MULTIENGINE).toInt() == 0){
-        ui->tSPSETimeLineEdit->setText(block_time);
-        ui->tSPSELabel->setText(block_time);
+        ui->tSPSETimeLineEdit->setText(block_time_string);
+        ui->tSPSELabel->setText(block_time_string);
     }
     // SP ME
     if(acft.getData().value(opl::db::TAILS_MULTIPILOT).toInt() == 0
             && acft.getData().value(opl::db::TAILS_MULTIENGINE).toInt() == 1){
-        ui->tSPMETimeLineEdit->setText(block_time);
-        ui->tSPMELabel->setText(block_time);
+        ui->tSPMETimeLineEdit->setText(block_time_string);
+        ui->tSPMELabel->setText(block_time_string);
     }
     // MP
     if(acft.getData().value(opl::db::TAILS_MULTIPILOT).toInt() == 1){
-        ui->tMPTimeLineEdit->setText(block_time);
-        ui->tMPLabel->setText(block_time);
+        ui->tMPTimeLineEdit->setText(block_time_string);
+        ui->tMPLabel->setText(block_time_string);
     }
     // TOTAL
-    ui->tblkLabel->setText("<b>" + block_time + "</b>");
-    ui->tblkLabel->setStyleSheet("color: green;");
-    ui->submissonReadyLabel->setText("Ready for Submission");
-    ui->submissonReadyLabel->setStyleSheet("color: green;");
+    ui->tblkLabel->setText("<b>" + block_time_string + "</b>");
     // IFR
     if(ui->IfrCheckBox->isChecked()){
-        ui->tIFRTimeLineEdit->setText(block_time);
-        ui->tIFRLabel->setText(block_time);
+        ui->tIFRTimeLineEdit->setText(block_time_string);
+        ui->tIFRLabel->setText(block_time_string);
     }
     // Night
-    QString dept_date = ui->doftLineEdit->text() + 'T' + tofb.toString(opl::datetime::TIME_DEFAULT_FORMAT);
-    QDateTime dept_date_time = QDateTime::fromString(dept_date,"yyyy-MM-ddThh:mm");
-    int tblk = block_minutes.toInt();
+    auto dept_date = ui->doftLineEdit->text() + 'T'
+            + ATime::toString(tofb, opl::time::Default);
+    auto dept_date_time = QDateTime::fromString(dept_date, QStringLiteral("yyyy-MM-ddThh:mm"));
     const int night_angle = ASettings::read(ASettings::FlightLogging::NightAngle).toInt();
-    QString night_minutes = QString::number(
-                ACalc::calculateNightTime(
-                    ui->deptLocLineEdit->text(),
-                    ui->destLocLineEdit->text(),
-                    dept_date_time,
-                    tblk,
-                    night_angle));
-
-    ui->tNIGHTTimeLineEdit->setText(ACalc::minutesToString(night_minutes));
-    ui->tNIGHTLabel->setText(ACalc::minutesToString(night_minutes));
+    auto night_time = ATime::fromMinutes(ACalc::calculateNightTime(
+                                             ui->deptLocLineEdit->text(),
+                                             ui->destLocLineEdit->text(),
+                                             dept_date_time,
+                                             block_minutes,
+                                             night_angle));
+
+    ui->tNIGHTTimeLineEdit->setText(ATime::toString(night_time, flightTimeFormat));
+    ui->tNIGHTLabel->setText(ATime::toString(night_time, flightTimeFormat));
     // Function times
     switch (ui->FunctionComboBox->currentIndex()) {
     case 0://PIC
-        ui->tPICTimeLineEdit->setText(block_time);
-        ui->tPICLabel->setText(block_time);
+        ui->tPICTimeLineEdit->setText(block_time_string);
+        ui->tPICLabel->setText(block_time_string);
         break;
     case 1://PICus
-        ui->tPICUSTimeLineEdit->setText(block_time);
-        ui->tPICUSLabel->setText(block_time);
+        ui->tPICUSTimeLineEdit->setText(block_time_string);
+        ui->tPICUSLabel->setText(block_time_string);
         break;
     case 2://Co-Pilot
-        ui->tSICTimeLineEdit->setText(block_time);
-        ui->tSICLabel->setText(block_time);
+        ui->tSICTimeLineEdit->setText(block_time_string);
+        ui->tSICLabel->setText(block_time_string);
         break;
     case 3://Dual
-        ui->tDUALTimeLineEdit->setText(block_time);
-        ui->tDUALLabel->setText(block_time);
+        ui->tDUALTimeLineEdit->setText(block_time_string);
+        ui->tDUALLabel->setText(block_time_string);
         break;
     case 4://Instructor
-        ui->tFITimeLineEdit->setText(block_time);
-        ui->tFILabel->setText(block_time);
-        ui->tPICTimeLineEdit->setText(block_time);
-        ui->tPICLabel->setText(block_time);
+        ui->tFITimeLineEdit->setText(block_time_string);
+        ui->tFILabel->setText(block_time_string);
+        ui->tPICTimeLineEdit->setText(block_time_string);
+        ui->tPICLabel->setText(block_time_string);
     }
 }
+
 /*!
  * \brief Collect input and create a Data map for the entry object.
  *
@@ -477,18 +480,17 @@ RowData NewFlightDialog::collectInput()
 {
     RowData newData;
     DEB << "Collecting Input...";
+    //Block Time
+    const auto tofb = ATime::fromString(ui->tofbTimeLineEdit->text(), opl::time::Default);
+    const auto tonb = ATime::fromString(ui->tonbTimeLineEdit->text(), opl::time::Default);
+    const auto tblk = ATime::blocktime(tofb, tonb);
+    const auto block_minutes = ATime::toMinutes(tblk);
     // Mandatory data
     newData.insert(opl::db::FLIGHTS_DOFT, ui->doftLineEdit->text());
     newData.insert(opl::db::FLIGHTS_DEPT, ui->deptLocLineEdit->text());
-    newData.insert(opl::db::FLIGHTS_TOFB, ACalc::stringToMinutes(ui->tofbTimeLineEdit->text()));
+    newData.insert(opl::db::FLIGHTS_TOFB, ATime::toMinutes(tofb));
     newData.insert(opl::db::FLIGHTS_DEST, ui->destLocLineEdit->text());
-    newData.insert(opl::db::FLIGHTS_TONB, ACalc::stringToMinutes(ui->tonbTimeLineEdit->text()));
-    //Block Time
-    const auto tofb = QTime::fromString(ui->tofbTimeLineEdit->text(), opl::datetime::TIME_DEFAULT_FORMAT);
-    const auto tonb = QTime::fromString(ui->tonbTimeLineEdit->text(), opl::datetime::TIME_DEFAULT_FORMAT);
-    const QString block_time = ACalc::blocktime(tofb, tonb).toString(opl::datetime::FLIGHT_TIME_DEFAULT_FORMAT);
-    const int block_minutes = ACalc::stringToMinutes(block_time);
-
+    newData.insert(opl::db::FLIGHTS_TONB, ATime::toMinutes(tonb));
     newData.insert(opl::db::FLIGHTS_TBLK, block_minutes);
     // Aircraft
     newData.insert(opl::db::FLIGHTS_ACFT, tailsIdMap.value(ui->acftLineEdit->text()));
@@ -500,14 +502,17 @@ RowData NewFlightDialog::collectInput()
     // Extra Times
     ui->tSPSETimeLineEdit->text().isEmpty() ?
                 newData.insert(opl::db::FLIGHTS_TSPSE, EMPTY_STRING)
-              : newData.insert(opl::db::FLIGHTS_TSPSE, ACalc::stringToMinutes(ui->tSPSETimeLineEdit->text()));
+              : newData.insert(opl::db::FLIGHTS_TSPSE, stringToMinutes(
+                                   ui->tSPSETimeLineEdit->text(), flightTimeFormat));
 
     ui->tSPMETimeLineEdit->text().isEmpty() ?
                 newData.insert(opl::db::FLIGHTS_TSPME, EMPTY_STRING)
-              : newData.insert(opl::db::FLIGHTS_TSPME, ACalc::stringToMinutes(ui->tSPMETimeLineEdit->text()));
+              : newData.insert(opl::db::FLIGHTS_TSPME, stringToMinutes(
+                                   ui->tSPMETimeLineEdit->text(), flightTimeFormat));
     ui->tMPTimeLineEdit->text().isEmpty() ?
                 newData.insert(opl::db::FLIGHTS_TMP, EMPTY_STRING)
-              : newData.insert(opl::db::FLIGHTS_TMP, ACalc::stringToMinutes(ui->tMPTimeLineEdit->text()));
+              : newData.insert(opl::db::FLIGHTS_TMP, stringToMinutes(
+                                   ui->tMPTimeLineEdit->text(), flightTimeFormat));
 
     if (ui->IfrCheckBox->isChecked()) {
         newData.insert(opl::db::FLIGHTS_TIFR, block_minutes);
@@ -515,16 +520,17 @@ RowData NewFlightDialog::collectInput()
         newData.insert(opl::db::FLIGHTS_TIFR, EMPTY_STRING);
     }
     // Night
-    const auto dept_date = ui->doftLineEdit->text() + QStringLiteral("T") + tofb.toString(opl::datetime::TIME_DEFAULT_FORMAT);
+    const auto dept_date = ui->doftLineEdit->text() + 'T'
+            + ATime::toString(tofb, opl::time::Default);
     const auto dept_date_time = QDateTime::fromString(dept_date, QStringLiteral("yyyy-MM-ddThh:mm"));
-
-    const auto night_angle = ASettings::read(ASettings::FlightLogging::NightAngle).toInt();
-    const auto night_minutes = ACalc::calculateNightTime(
-                    ui->deptLocLineEdit->text(),
-                    ui->destLocLineEdit->text(),
-                    dept_date_time,
-                    block_minutes,
-                    night_angle);
+    const int night_angle = ASettings::read(ASettings::FlightLogging::NightAngle).toInt();
+    const auto night_time = ATime::fromMinutes(ACalc::calculateNightTime(
+                                             ui->deptLocLineEdit->text(),
+                                             ui->destLocLineEdit->text(),
+                                             dept_date_time,
+                                             block_minutes,
+                                             night_angle));
+    const auto night_minutes = ATime::toMinutes(night_time);
     newData.insert(opl::db::FLIGHTS_TNIGHT, night_minutes);
 
     // Function times - This is a little explicit but these are mutually exclusive so its better to be safe than sorry here.
@@ -596,7 +602,8 @@ RowData NewFlightDialog::collectInput()
             newData.insert(opl::db::FLIGHTS_LDGDAY, 0);
             newData.insert(opl::db::FLIGHTS_LDGNIGHT, ui->LandingSpinBox->value());
         } else { //check
-            const auto dest_date = ui->doftLineEdit->text() + QStringLiteral("T") + tonb.toString(opl::datetime::TIME_DEFAULT_FORMAT);
+            const auto dest_date = ui->doftLineEdit->text() + 'T'
+                    + ATime::toString(tonb, opl::time::Default);
             const auto dest_date_time = QDateTime::fromString(dest_date, QStringLiteral("yyyy-MM-ddThh:mm"));
             if (ACalc::isNight(ui->destLocLineEdit->text(), dest_date_time,  night_angle)) {
                 newData.insert(opl::db::FLIGHTS_LDGDAY, 0);
@@ -665,16 +672,16 @@ void NewFlightDialog::formFiller()
                 //DEB << "Time Match found: " << key << " - " << leName);
                 auto line_edits = this->findChild<QLineEdit *>(leName);
                 if(line_edits != nullptr){
-                    DEB << "Setting " << line_edits->objectName() << " to " << ACalc::minutesToString(flightEntry.getData().value(data_key).toInt());
-                    line_edits->setText(ACalc::minutesToString(
-                                            flightEntry.getData().value(data_key).toInt()));
+                    DEB << "Setting " << line_edits->objectName() << " to " << minutesToString(flightEntry.getData().value(data_key).toInt(), flightTimeFormat);
+                    line_edits->setText(minutesToString(flightEntry.getData().value(data_key).toInt(),
+                                                        flightTimeFormat));
                     line_edits_names.removeOne(leName);
                 }
                 break;
             }
         }
         rx = QRegularExpression(data_key + "Name\\w+?");
-        for(const auto& leName : line_edits_names){
+        for(const auto& leName : qAsConst(line_edits_names)){
             if(rx.match(leName).hasMatch())  {
                 auto line_edits = this->findChild<QLineEdit *>(leName);
                 if(line_edits != nullptr){
@@ -751,25 +758,25 @@ bool NewFlightDialog::isLessOrEqualThanBlockTime(const QString time_string)
 {
     if (mandatoryLineEditsGood.count(true) != 7){
         QMessageBox message_box(this);
-        message_box.setText("Unable to determine total block time.\n"
-                            "Please fill out Departure and Arrival Time\n"
+        message_box.setText("Unable to determine total block time.<br>"
+                            "Please fill out all Mandatory Fields<br>"
                             "before manually editing these times.");
         message_box.exec();
         return false;
     }
 
-    auto extra_time = QTime::fromString(time_string, opl::datetime::TIME_DEFAULT_FORMAT);
-    auto block_time = ACalc::blocktime(QTime::fromString(
-                                           ui->tofbTimeLineEdit->text(), opl::datetime::TIME_DEFAULT_FORMAT),
-                                       QTime::fromString(
-                                           ui->tonbTimeLineEdit->text(), opl::datetime::TIME_DEFAULT_FORMAT));
+    auto extra_time = ATime::fromString(time_string, flightTimeFormat);
+    auto block_time = ATime::blocktime(ATime::fromString(
+                                           ui->tofbTimeLineEdit->text(), flightTimeFormat),
+                                       ATime::fromString(
+                                           ui->tonbTimeLineEdit->text(), flightTimeFormat));
     if (extra_time <= block_time) {
         return true;
     } else {
         QMessageBox message_box(this);
         message_box.setWindowTitle("Error");
         message_box.setText("The flight time you have entered is longer than the total blocktime:<br><center><b>"
-                            + block_time.toString(opl::datetime::TIME_DEFAULT_FORMAT)
+                            + ATime::toString(block_time, flightTimeFormat)
                             + "</b></center>");
         message_box.exec();
         return false;
@@ -916,8 +923,6 @@ void NewFlightDialog::onBadInputReceived(QLineEdit *line_edit)
 
     DEB << "Mandatory Good: " << mandatoryLineEditsGood.count(true) << " out of "
         << mandatoryLineEditsGood.size() << ". Array: " << mandatoryLineEditsGood;
-    ui->submissonReadyLabel->setText("INCOMPLETE");
-    ui->submissonReadyLabel->setStyleSheet("color: rgb(237, 212, 0);");
 }
 
 // capitalize input for dept, dest and registration input
@@ -1113,16 +1118,17 @@ void NewFlightDialog::onTimeLineEdit_editingFinished()
     auto line_edit = this->findChild<QLineEdit*>(sender_object->objectName());
     DEB << line_edit->objectName() << "Editing Finished -" << line_edit->text();
 
-    line_edit->setText(ACalc::formatTimeInput(line_edit->text()));
-    const auto time = QTime::fromString(line_edit->text(),opl::datetime::TIME_DEFAULT_FORMAT);
+    line_edit->setText(ATime::formatTimeInput(line_edit->text()));
+    const auto time = ATime::fromString(line_edit->text(), opl::time::Default);
     if(time.isValid()){
         if(primaryTimeLineEdits.contains(line_edit)) {
             onGoodInputReceived(line_edit);
         } else { // is extra time line edit
-            isLessOrEqualThanBlockTime(line_edit->text());
-            line_edit->setText(EMPTY_STRING);
-            line_edit->setFocus();
-            return;
+            if (!isLessOrEqualThanBlockTime(line_edit->text())) {
+                line_edit->setText(EMPTY_STRING);
+                line_edit->setFocus();
+                return;
+            }
         }
     } else {
         if (!line_edit->text().isEmpty())

+ 22 - 0
src/gui/dialogues/newflightdialog.h

@@ -30,11 +30,13 @@
 #include <QCalendarWidget>
 #include <QTabWidget>
 #include <QKeyEvent>
+#include "src/functions/atime.h"
 
 #include "src/classes/aflightentry.h"
 #include "src/classes/apilotentry.h"
 #include "src/classes/atailentry.h"
 
+
 namespace Ui {
 class NewFlight;
 }
@@ -116,6 +118,8 @@ private:
     QMap<QString, int> airportIataIdMap;
     QMap<QString, int> airportNameIdMap;
 
+    opl::time::FlightTimeFormat flightTimeFormat;
+
     /*!
      * \brief If the user elects to manually edit function times, automatic updating
      * is disabled.
@@ -142,6 +146,24 @@ private:
     void addNewPilot(QLineEdit *);
 
     RowData collectInput();
+
+    /*!
+     * \brief converts a time string as used in the UI to an integer of minutes for
+     * use in the database based on the format in use in the Dialog
+     */
+    inline int stringToMinutes(const QString &time_string, opl::time::FlightTimeFormat format)
+    {
+        return ATime::toMinutes(ATime::fromString(time_string, format));
+    }
+
+    /*!
+     * \brief minutesToString converts an integer of minutes as received from the database
+     * to a String to be displayed in the UI, based on the format in use in the Dialog.
+     */
+    inline QString minutesToString(const int minutes, opl::time::FlightTimeFormat format)
+    {
+        return ATime::toString(ATime::fromMinutes(minutes), format);
+    }
 };
 
 

+ 7 - 0
src/gui/widgets/debugwidget.cpp

@@ -5,6 +5,7 @@
 #include "src/gui/widgets/pilotswidget.h"
 #include "src/gui/widgets/aircraftwidget.h"
 #include <QtGlobal>
+#include "src/functions/atime.h"
 
 DebugWidget::DebugWidget(QWidget *parent) :
     QWidget(parent),
@@ -166,6 +167,12 @@ void DebugWidget::on_importCsvPushButton_clicked()
 void DebugWidget::on_debugPushButton_clicked()
 {
     // space for debugging
+    QTime test(1,15,0);
+
+    DEB << "Qtime: " << test.toString(QStringLiteral("hh:mm"));
+
+    DEB << "ATime from String: " << ATime::fromString("12:45",opl::time::Default);
+    DEB << "ATime from String: " << ATime::fromString("12.75", opl::time::Decimal);
 }
 
 /* //Comparing two functions template

+ 25 - 10
src/oplconstants.h

@@ -4,21 +4,36 @@
 #include <QtCore>
 
 /*!
- *  A namespace to collect constants used throughout the application.
+ *  \brief A namespace to collect constants and enums used throughout the application.
+ *
+ *  \details The opl namespace collects enums and constants that are used throughout
+ *  the application and provide uniform access.
+ *
+ *  The date, time and datetime namespaces include enums used to differentiate
+ *  date and time formats for QDate, QTime and QDateTime that deviate from standard values
+ *  included in the Qt Framework like Qt::ISODate and are to be used in conjunction with the
+ *  .toString() members of these classes.
+ *
+ *  The db namespace contains constants for programatically accessing the database in a fast
+ *  and uniform manner.
  */
 namespace opl {
 
-/*!
- * The datetime namespace specifies date and time formats by QDate, QTime
- * and QDateTime that deviate from standard values included in the Qt Framework
- * like Qt::ISODate and are to be used in conjunction with the .toString() members
- * of these classes
- */
+namespace date {
+
+enum DateFormat {Default, Text};
+
+} // namespace opl::date
+
+namespace time {
+
+enum FlightTimeFormat {Default, Decimal};
+
+} // namespace opl::time
+
 namespace datetime {
 
-static const auto TIME_DEFAULT_FORMAT    = QStringLiteral("hh:mm");
-static const auto FLIGHT_TIME_DEFAULT_FORMAT    = QStringLiteral("hh:mm");
-static const auto DATETIME_BACKUP_FORMAT = QStringLiteral("yyyy_MM_dd_T_hh_mm");
+enum DateTimeFormat {Default, Backup};
 
 } // namespace opl::datetime