Browse Source

Added a draft for a widget to show totals.

This widget can either show the grand total of the logbook
when used on the home screen or can be used to display and edit
the previous experience in the settings widget.
Felix Turowsky 1 year ago
parent
commit
88625943d2

+ 46 - 1
src/database/database.cpp

@@ -41,7 +41,7 @@ bool Database::connect()
     }
 
 
-    LOG << "Database connection established.";
+    LOG << "Database connection established: " + databaseFile.absoluteFilePath();
     // Enable foreign key restrictions
     QSqlQuery query;
     query.prepare(QStringLiteral("PRAGMA foreign_keys = ON;"));
@@ -469,6 +469,51 @@ int Database::getLastEntry(OPL::DbTable table)
     }
 }
 
+const RowData_T Database::getTotals()
+{
+    const QString statement = "SELECT"
+        " SUM(tblk) AS tblk,"
+        " SUM(tSPSE) AS tSPSE,"
+        " SUM(tSPME) AS tSPME,"
+        " SUM(tMP) AS tMP,"
+        " SUM(tPIC) AS tPIC,"
+        " SUM(tSIC) AS tSIC,"
+        " SUM(tDUAL) AS tDUAL,"
+        " SUM(tFI) AS tFI,"
+        " SUM(tPICUS) AS tPICUS,"
+        " SUM(tNIGHT) AS tNIGHT,"
+        " SUM(tIFR) AS tIFR,"
+        " SUM(tSIM) AS tSIM,"
+        " SUM(toDay) AS toDay,"
+        " SUM(toNight) AS toNight,"
+        " SUM(ldgDay) AS ldgDay,"
+        " SUM(ldgNight) AS ldgNight"
+        " FROM flights";
+    QSqlQuery query;
+    query.prepare(statement);
+    if (!query.exec()) {
+        DEB << "SQL error: " << query.lastError().text();
+        DEB << "Statement: " << query.lastQuery();
+        lastError = query.lastError();
+        return {}; // return invalid Row
+    }
+
+    RowData_T entry_data;
+    if(query.next()) {
+        auto r = query.record(); // retreive record
+        if (r.count() == 0)  // row is empty
+            return {};
+
+        for (int i = 0; i < r.count(); i++){ // iterate through fields to get key:value map
+            if(!r.value(i).isNull()) {
+                entry_data.insert(r.fieldName(i), r.value(i));
+            }
+        }
+    }
+
+    return entry_data;
+}
+
 QList<int> Database::getForeignKeyConstraints(int foreign_row_id, OPL::DbTable table)
 {
     QString statement = QLatin1String("SELECT ROWID FROM flights WHERE ");

+ 5 - 0
src/database/database.h

@@ -327,6 +327,11 @@ public:
 
 
 
+    /*!
+     * \brief Retreive the total time of all flight entries in the databasRe
+     * \return The sum of all entries in the flights table
+     */
+    const RowData_T getTotals();
 signals:
     /*!
      * \brief updated is emitted whenever the database contents have been updated.

+ 1 - 1
src/functions/statistics.cpp

@@ -132,7 +132,6 @@ QVector<QPair<QString, QString>> OPL::Statistics::totals()
     }
     return output;
 }
-
 /*!
  * \brief Calculates the date of expiry for the take-off and landing currency.
  *
@@ -166,3 +165,4 @@ QDate OPL::Statistics::currencyTakeOffLandingExpiry(int expiration_days)
 
     return expiration_date.addDays(expiration_days);;
 }
+

+ 1 - 1
src/functions/time.h

@@ -57,7 +57,7 @@ inline const QString toString(int minutes_in, OPL::FlightTimeFormat format = OPL
         if (minute.size() < 2) {
             minute.prepend(QStringLiteral("0"));
         }
-        return hour + ':' + minute;
+        return hour + QLatin1Char(':') + minute;
     }
     case OPL::FlightTimeFormat::Decimal:
     {

+ 4 - 5
src/gui/widgets/homewidget.cpp

@@ -16,6 +16,7 @@
  *along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 #include "homewidget.h"
+#include "src/gui/widgets/totalswidget.h"
 #include "ui_homewidget.h"
 #include "src/database/database.h"
 #include "src/functions/time.h"
@@ -98,11 +99,9 @@ void HomeWidget::changeEvent(QEvent *event)
  */
 void HomeWidget::fillTotals()
 {
-    const auto data = OPL::Statistics::totals();
-    for (const auto &field : data) {
-        auto line_edit = this->findChild<QLineEdit *>(field.first + QLatin1String("LineEdit"));
-        line_edit->setText(field.second);
-    }
+    auto tw = new TotalsWidget(TotalsWidget::TotalTimeWidget, this);
+    ui->totalsStackedWidget->addWidget(tw);
+    ui->totalsStackedWidget->setCurrentWidget(tw);
 }
 
 void HomeWidget::fillCurrency(OPL::CurrencyName currency_name, QLabel* display_label)

+ 96 - 633
src/gui/widgets/homewidget.ui

@@ -14,84 +14,7 @@
    <string>Form</string>
   </property>
   <layout class="QGridLayout" name="gridLayout_4">
-   <item row="3" column="0">
-    <widget class="Line" name="line_7">
-     <property name="orientation">
-      <enum>Qt::Horizontal</enum>
-     </property>
-    </widget>
-   </item>
-   <item row="2" column="0">
-    <widget class="Line" name="line_2">
-     <property name="orientation">
-      <enum>Qt::Horizontal</enum>
-     </property>
-    </widget>
-   </item>
-   <item row="8" column="0">
-    <widget class="Line" name="line_4">
-     <property name="orientation">
-      <enum>Qt::Horizontal</enum>
-     </property>
-    </widget>
-   </item>
-   <item row="4" column="0">
-    <widget class="QLabel" name="totalsLabel">
-     <property name="font">
-      <font>
-       <weight>75</weight>
-       <bold>true</bold>
-      </font>
-     </property>
-     <property name="text">
-      <string>Your Totals</string>
-     </property>
-     <property name="alignment">
-      <set>Qt::AlignBottom|Qt::AlignHCenter</set>
-     </property>
-    </widget>
-   </item>
-   <item row="1" column="0">
-    <widget class="QLabel" name="welcomeLabel">
-     <property name="text">
-      <string>Welcome to openPilotLog!</string>
-     </property>
-     <property name="alignment">
-      <set>Qt::AlignCenter</set>
-     </property>
-    </widget>
-   </item>
-   <item row="7" column="0">
-    <widget class="QLabel" name="currencyLabel">
-     <property name="font">
-      <font>
-       <weight>75</weight>
-       <bold>true</bold>
-      </font>
-     </property>
-     <property name="text">
-      <string>Currency</string>
-     </property>
-     <property name="alignment">
-      <set>Qt::AlignBottom|Qt::AlignHCenter</set>
-     </property>
-    </widget>
-   </item>
-   <item row="5" column="0">
-    <widget class="Line" name="line">
-     <property name="orientation">
-      <enum>Qt::Horizontal</enum>
-     </property>
-    </widget>
-   </item>
-   <item row="11" column="0">
-    <widget class="Line" name="line_3">
-     <property name="orientation">
-      <enum>Qt::Horizontal</enum>
-     </property>
-    </widget>
-   </item>
-   <item row="12" column="0">
+   <item row="13" column="0">
     <layout class="QGridLayout" name="gridLayout_2">
      <item row="0" column="0">
       <widget class="QLabel" name="FlightTime28dLabel">
@@ -156,22 +79,6 @@
     </layout>
    </item>
    <item row="10" column="0">
-    <widget class="QLabel" name="limitationsLabel">
-     <property name="font">
-      <font>
-       <weight>75</weight>
-       <bold>true</bold>
-      </font>
-     </property>
-     <property name="text">
-      <string>Limitations</string>
-     </property>
-     <property name="alignment">
-      <set>Qt::AlignBottom|Qt::AlignHCenter</set>
-     </property>
-    </widget>
-   </item>
-   <item row="9" column="0">
     <layout class="QGridLayout" name="gridLayout_3">
      <item row="0" column="0">
       <widget class="QLabel" name="TakeOffLabel">
@@ -184,7 +91,6 @@
       <widget class="QLabel" name="TakeOffDisplayLabel">
        <property name="font">
         <font>
-         <weight>75</weight>
          <bold>true</bold>
         </font>
        </property>
@@ -210,7 +116,6 @@
       <widget class="QLabel" name="LandingsDisplayLabel">
        <property name="font">
         <font>
-         <weight>75</weight>
          <bold>true</bold>
         </font>
        </property>
@@ -241,7 +146,6 @@
       <widget class="QLabel" name="currToLdgDisplayLabel">
        <property name="font">
         <font>
-         <weight>75</weight>
          <bold>true</bold>
         </font>
        </property>
@@ -269,7 +173,6 @@
       <widget class="QLabel" name="currLicDisplayLabel">
        <property name="font">
         <font>
-         <weight>75</weight>
          <bold>true</bold>
         </font>
        </property>
@@ -297,7 +200,6 @@
       <widget class="QLabel" name="currTrDisplayLabel">
        <property name="font">
         <font>
-         <weight>75</weight>
          <bold>true</bold>
         </font>
        </property>
@@ -325,7 +227,6 @@
       <widget class="QLabel" name="currLckDisplayLabel">
        <property name="font">
         <font>
-         <weight>75</weight>
          <bold>true</bold>
         </font>
        </property>
@@ -353,7 +254,6 @@
       <widget class="QLabel" name="currMedDisplayLabel">
        <property name="font">
         <font>
-         <weight>75</weight>
          <bold>true</bold>
         </font>
        </property>
@@ -381,7 +281,6 @@
       <widget class="QLabel" name="currCustom1DisplayLabel">
        <property name="font">
         <font>
-         <weight>75</weight>
          <bold>true</bold>
         </font>
        </property>
@@ -409,7 +308,6 @@
       <widget class="QLabel" name="currCustom2DisplayLabel">
        <property name="font">
         <font>
-         <weight>75</weight>
          <bold>true</bold>
         </font>
        </property>
@@ -423,536 +321,56 @@
      </item>
     </layout>
    </item>
-   <item row="6" column="0">
-    <layout class="QGridLayout" name="gridLayout">
-     <item row="0" column="0">
-      <widget class="QLabel" name="totalLabel">
-       <property name="maximumSize">
-        <size>
-         <width>120</width>
-         <height>16777215</height>
-        </size>
-       </property>
-       <property name="text">
-        <string>Total</string>
-       </property>
-      </widget>
-     </item>
-     <item row="0" column="1">
-      <widget class="QLineEdit" name="totalLineEdit">
-       <property name="minimumSize">
-        <size>
-         <width>100</width>
-         <height>0</height>
-        </size>
-       </property>
-       <property name="maximumSize">
-        <size>
-         <width>120</width>
-         <height>16777215</height>
-        </size>
-       </property>
-       <property name="focusPolicy">
-        <enum>Qt::NoFocus</enum>
-       </property>
-       <property name="text">
-        <string/>
-       </property>
-      </widget>
-     </item>
-     <item row="0" column="2">
-      <widget class="QLabel" name="picusLabel">
-       <property name="maximumSize">
-        <size>
-         <width>120</width>
-         <height>16777215</height>
-        </size>
-       </property>
-       <property name="text">
-        <string>PICus</string>
-       </property>
-      </widget>
-     </item>
-     <item row="0" column="3">
-      <widget class="QLineEdit" name="picusLineEdit">
-       <property name="minimumSize">
-        <size>
-         <width>100</width>
-         <height>0</height>
-        </size>
-       </property>
-       <property name="maximumSize">
-        <size>
-         <width>120</width>
-         <height>16777215</height>
-        </size>
-       </property>
-       <property name="focusPolicy">
-        <enum>Qt::NoFocus</enum>
-       </property>
-      </widget>
-     </item>
-     <item row="1" column="0">
-      <widget class="QLabel" name="spseLabel">
-       <property name="maximumSize">
-        <size>
-         <width>120</width>
-         <height>16777215</height>
-        </size>
-       </property>
-       <property name="text">
-        <string>SP SE</string>
-       </property>
-      </widget>
-     </item>
-     <item row="1" column="1">
-      <widget class="QLineEdit" name="spseLineEdit">
-       <property name="minimumSize">
-        <size>
-         <width>100</width>
-         <height>0</height>
-        </size>
-       </property>
-       <property name="maximumSize">
-        <size>
-         <width>120</width>
-         <height>16777215</height>
-        </size>
-       </property>
-       <property name="focusPolicy">
-        <enum>Qt::NoFocus</enum>
-       </property>
-      </widget>
-     </item>
-     <item row="1" column="2">
-      <widget class="QLabel" name="ifrLabel">
-       <property name="maximumSize">
-        <size>
-         <width>120</width>
-         <height>16777215</height>
-        </size>
-       </property>
-       <property name="text">
-        <string>IFR</string>
-       </property>
-      </widget>
-     </item>
-     <item row="1" column="3">
-      <widget class="QLineEdit" name="ifrLineEdit">
-       <property name="minimumSize">
-        <size>
-         <width>100</width>
-         <height>0</height>
-        </size>
-       </property>
-       <property name="maximumSize">
-        <size>
-         <width>120</width>
-         <height>16777215</height>
-        </size>
-       </property>
-       <property name="focusPolicy">
-        <enum>Qt::NoFocus</enum>
-       </property>
-      </widget>
-     </item>
-     <item row="2" column="0">
-      <widget class="QLabel" name="spmeLabel">
-       <property name="maximumSize">
-        <size>
-         <width>120</width>
-         <height>16777215</height>
-        </size>
-       </property>
-       <property name="text">
-        <string>SP ME</string>
-       </property>
-      </widget>
-     </item>
-     <item row="2" column="1">
-      <widget class="QLineEdit" name="spmeLineEdit">
-       <property name="minimumSize">
-        <size>
-         <width>100</width>
-         <height>0</height>
-        </size>
-       </property>
-       <property name="maximumSize">
-        <size>
-         <width>120</width>
-         <height>16777215</height>
-        </size>
-       </property>
-       <property name="focusPolicy">
-        <enum>Qt::NoFocus</enum>
-       </property>
-      </widget>
-     </item>
-     <item row="2" column="2">
-      <widget class="QLabel" name="nightLabel">
-       <property name="maximumSize">
-        <size>
-         <width>120</width>
-         <height>16777215</height>
-        </size>
-       </property>
-       <property name="text">
-        <string>Night</string>
-       </property>
-      </widget>
-     </item>
-     <item row="2" column="3">
-      <widget class="QLineEdit" name="nightLineEdit">
-       <property name="minimumSize">
-        <size>
-         <width>100</width>
-         <height>0</height>
-        </size>
-       </property>
-       <property name="maximumSize">
-        <size>
-         <width>120</width>
-         <height>16777215</height>
-        </size>
-       </property>
-       <property name="focusPolicy">
-        <enum>Qt::NoFocus</enum>
-       </property>
-      </widget>
-     </item>
-     <item row="3" column="0">
-      <widget class="QLabel" name="multipilotLabel">
-       <property name="maximumSize">
-        <size>
-         <width>120</width>
-         <height>16777215</height>
-        </size>
-       </property>
-       <property name="text">
-        <string>Multi Pilot</string>
-       </property>
-      </widget>
-     </item>
-     <item row="3" column="1">
-      <widget class="QLineEdit" name="multipilotLineEdit">
-       <property name="minimumSize">
-        <size>
-         <width>100</width>
-         <height>0</height>
-        </size>
-       </property>
-       <property name="maximumSize">
-        <size>
-         <width>120</width>
-         <height>16777215</height>
-        </size>
-       </property>
-       <property name="focusPolicy">
-        <enum>Qt::NoFocus</enum>
-       </property>
-      </widget>
-     </item>
-     <item row="3" column="2">
-      <widget class="QLabel" name="simLabel">
-       <property name="maximumSize">
-        <size>
-         <width>120</width>
-         <height>16777215</height>
-        </size>
-       </property>
-       <property name="text">
-        <string>Simulator</string>
-       </property>
-      </widget>
-     </item>
-     <item row="3" column="3">
-      <widget class="QLineEdit" name="simLineEdit">
-       <property name="minimumSize">
-        <size>
-         <width>100</width>
-         <height>0</height>
-        </size>
-       </property>
-       <property name="maximumSize">
-        <size>
-         <width>120</width>
-         <height>16777215</height>
-        </size>
-       </property>
-       <property name="focusPolicy">
-        <enum>Qt::NoFocus</enum>
-       </property>
-      </widget>
-     </item>
-     <item row="4" column="0">
-      <widget class="QLabel" name="piclabel">
-       <property name="maximumSize">
-        <size>
-         <width>120</width>
-         <height>16777215</height>
-        </size>
-       </property>
-       <property name="text">
-        <string>PIC</string>
-       </property>
-      </widget>
-     </item>
-     <item row="4" column="1">
-      <widget class="QLineEdit" name="picLineEdit">
-       <property name="minimumSize">
-        <size>
-         <width>100</width>
-         <height>0</height>
-        </size>
-       </property>
-       <property name="maximumSize">
-        <size>
-         <width>120</width>
-         <height>16777215</height>
-        </size>
-       </property>
-       <property name="focusPolicy">
-        <enum>Qt::NoFocus</enum>
-       </property>
-      </widget>
-     </item>
-     <item row="4" column="2">
-      <widget class="QLabel" name="todayLabel">
-       <property name="maximumSize">
-        <size>
-         <width>120</width>
-         <height>16777215</height>
-        </size>
-       </property>
-       <property name="text">
-        <string>TO Day</string>
-       </property>
-      </widget>
-     </item>
-     <item row="4" column="3">
-      <widget class="QLineEdit" name="todayLineEdit">
-       <property name="minimumSize">
-        <size>
-         <width>100</width>
-         <height>0</height>
-        </size>
-       </property>
-       <property name="maximumSize">
-        <size>
-         <width>120</width>
-         <height>16777215</height>
-        </size>
-       </property>
-       <property name="focusPolicy">
-        <enum>Qt::NoFocus</enum>
-       </property>
-       <property name="text">
-        <string>0</string>
-       </property>
-      </widget>
-     </item>
-     <item row="5" column="0">
-      <widget class="QLabel" name="sicLabel">
-       <property name="maximumSize">
-        <size>
-         <width>120</width>
-         <height>16777215</height>
-        </size>
-       </property>
-       <property name="text">
-        <string>SIC</string>
-       </property>
-      </widget>
-     </item>
-     <item row="5" column="1">
-      <widget class="QLineEdit" name="sicLineEdit">
-       <property name="minimumSize">
-        <size>
-         <width>100</width>
-         <height>0</height>
-        </size>
-       </property>
-       <property name="maximumSize">
-        <size>
-         <width>120</width>
-         <height>16777215</height>
-        </size>
-       </property>
-       <property name="focusPolicy">
-        <enum>Qt::NoFocus</enum>
-       </property>
-      </widget>
-     </item>
-     <item row="5" column="2">
-      <widget class="QLabel" name="tonightLabel">
-       <property name="maximumSize">
-        <size>
-         <width>120</width>
-         <height>16777215</height>
-        </size>
-       </property>
-       <property name="text">
-        <string>TO Night</string>
-       </property>
-      </widget>
-     </item>
-     <item row="5" column="3">
-      <widget class="QLineEdit" name="tonightLineEdit">
-       <property name="minimumSize">
-        <size>
-         <width>100</width>
-         <height>0</height>
-        </size>
-       </property>
-       <property name="maximumSize">
-        <size>
-         <width>120</width>
-         <height>16777215</height>
-        </size>
-       </property>
-       <property name="focusPolicy">
-        <enum>Qt::NoFocus</enum>
-       </property>
-       <property name="text">
-        <string>0</string>
-       </property>
-      </widget>
-     </item>
-     <item row="6" column="0">
-      <widget class="QLabel" name="dualLabel">
-       <property name="maximumSize">
-        <size>
-         <width>120</width>
-         <height>16777215</height>
-        </size>
-       </property>
-       <property name="text">
-        <string>DUAL</string>
-       </property>
-      </widget>
-     </item>
-     <item row="6" column="1">
-      <widget class="QLineEdit" name="dualLineEdit">
-       <property name="minimumSize">
-        <size>
-         <width>100</width>
-         <height>0</height>
-        </size>
-       </property>
-       <property name="maximumSize">
-        <size>
-         <width>120</width>
-         <height>16777215</height>
-        </size>
-       </property>
-       <property name="focusPolicy">
-        <enum>Qt::NoFocus</enum>
-       </property>
-      </widget>
-     </item>
-     <item row="6" column="2">
-      <widget class="QLabel" name="ldgdayLabel">
-       <property name="maximumSize">
-        <size>
-         <width>120</width>
-         <height>16777215</height>
-        </size>
-       </property>
-       <property name="text">
-        <string>LDG Day</string>
-       </property>
-      </widget>
-     </item>
-     <item row="6" column="3">
-      <widget class="QLineEdit" name="ldgdayLineEdit">
-       <property name="minimumSize">
-        <size>
-         <width>100</width>
-         <height>0</height>
-        </size>
-       </property>
-       <property name="maximumSize">
-        <size>
-         <width>120</width>
-         <height>16777215</height>
-        </size>
-       </property>
-       <property name="focusPolicy">
-        <enum>Qt::NoFocus</enum>
-       </property>
-       <property name="text">
-        <string>0</string>
-       </property>
-      </widget>
-     </item>
-     <item row="7" column="0">
-      <widget class="QLabel" name="fiLabel">
-       <property name="maximumSize">
-        <size>
-         <width>120</width>
-         <height>16777215</height>
-        </size>
-       </property>
-       <property name="text">
-        <string>FI</string>
-       </property>
-      </widget>
-     </item>
-     <item row="7" column="2">
-      <widget class="QLabel" name="ldgnightLabel">
-       <property name="maximumSize">
-        <size>
-         <width>120</width>
-         <height>16777215</height>
-        </size>
-       </property>
-       <property name="text">
-        <string>LDG Night</string>
-       </property>
-      </widget>
-     </item>
-     <item row="7" column="3">
-      <widget class="QLineEdit" name="ldgnightLineEdit">
-       <property name="minimumSize">
-        <size>
-         <width>100</width>
-         <height>0</height>
-        </size>
-       </property>
-       <property name="maximumSize">
-        <size>
-         <width>120</width>
-         <height>16777215</height>
-        </size>
-       </property>
-       <property name="focusPolicy">
-        <enum>Qt::NoFocus</enum>
-       </property>
-       <property name="text">
-        <string>0</string>
-       </property>
-      </widget>
-     </item>
-     <item row="7" column="1">
-      <widget class="QLineEdit" name="fiLineEdit">
-       <property name="minimumSize">
-        <size>
-         <width>100</width>
-         <height>0</height>
-        </size>
-       </property>
-       <property name="maximumSize">
-        <size>
-         <width>120</width>
-         <height>16777215</height>
-        </size>
-       </property>
-       <property name="focusPolicy">
-        <enum>Qt::NoFocus</enum>
-       </property>
-      </widget>
-     </item>
-    </layout>
+   <item row="9" column="0">
+    <widget class="Line" name="line_4">
+     <property name="orientation">
+      <enum>Qt::Horizontal</enum>
+     </property>
+    </widget>
+   </item>
+   <item row="8" column="0">
+    <widget class="QLabel" name="currencyLabel">
+     <property name="font">
+      <font>
+       <bold>true</bold>
+      </font>
+     </property>
+     <property name="text">
+      <string>Currency</string>
+     </property>
+     <property name="alignment">
+      <set>Qt::AlignBottom|Qt::AlignHCenter</set>
+     </property>
+    </widget>
+   </item>
+   <item row="12" column="0">
+    <widget class="Line" name="line_3">
+     <property name="orientation">
+      <enum>Qt::Horizontal</enum>
+     </property>
+    </widget>
+   </item>
+   <item row="5" column="0">
+    <widget class="QLabel" name="totalsLabel">
+     <property name="font">
+      <font>
+       <bold>true</bold>
+      </font>
+     </property>
+     <property name="text">
+      <string>Your Totals</string>
+     </property>
+     <property name="alignment">
+      <set>Qt::AlignBottom|Qt::AlignHCenter</set>
+     </property>
+    </widget>
+   </item>
+   <item row="4" column="0">
+    <widget class="Line" name="line_7">
+     <property name="orientation">
+      <enum>Qt::Horizontal</enum>
+     </property>
+    </widget>
    </item>
    <item row="0" column="0">
     <widget class="QLabel" name="logoLabel">
@@ -964,6 +382,51 @@
      </property>
     </widget>
    </item>
+   <item row="6" column="0">
+    <widget class="Line" name="line">
+     <property name="orientation">
+      <enum>Qt::Horizontal</enum>
+     </property>
+    </widget>
+   </item>
+   <item row="2" column="0">
+    <widget class="Line" name="line_2">
+     <property name="orientation">
+      <enum>Qt::Horizontal</enum>
+     </property>
+    </widget>
+   </item>
+   <item row="1" column="0">
+    <widget class="QLabel" name="welcomeLabel">
+     <property name="text">
+      <string>Welcome to openPilotLog!</string>
+     </property>
+     <property name="alignment">
+      <set>Qt::AlignCenter</set>
+     </property>
+    </widget>
+   </item>
+   <item row="11" column="0">
+    <widget class="QLabel" name="limitationsLabel">
+     <property name="font">
+      <font>
+       <bold>true</bold>
+      </font>
+     </property>
+     <property name="text">
+      <string>Limitations</string>
+     </property>
+     <property name="alignment">
+      <set>Qt::AlignBottom|Qt::AlignHCenter</set>
+     </property>
+    </widget>
+   </item>
+   <item row="7" column="0">
+    <widget class="QStackedWidget" name="totalsStackedWidget">
+     <widget class="QWidget" name="page"/>
+     <widget class="QWidget" name="page_2"/>
+    </widget>
+   </item>
   </layout>
  </widget>
  <resources/>

+ 9 - 0
src/gui/widgets/settingswidget.cpp

@@ -17,6 +17,7 @@
  */
 #include "settingswidget.h"
 #include "src/gui/dialogues/exporttocsvdialog.h"
+#include "src/gui/widgets/totalswidget.h"
 #include "ui_settingswidget.h"
 #include "src/classes/style.h"
 #include "src/classes/settings.h"
@@ -34,6 +35,7 @@ SettingsWidget::SettingsWidget(QWidget *parent) :
     ui->tabWidget->setCurrentIndex(0);
 
     loadBackupWidget();
+    loadPreviousExperienceWidget();
     setupComboBoxes();
     setupDateEdits();
     setupValidators();
@@ -106,6 +108,13 @@ void SettingsWidget::loadBackupWidget()
     ui->backupStackedWidget->setCurrentWidget(bw);
 }
 
+void SettingsWidget::loadPreviousExperienceWidget()
+{
+    auto pxp = new TotalsWidget(TotalsWidget::WidgetType::PreviousExperienceWidget);
+    ui->previousExpStackedWidget->addWidget(pxp);
+    ui->previousExpStackedWidget->setCurrentWidget(pxp);
+}
+
 /*!
  * \brief SettingsWidget::readSettings Reads settings from Settings and sets up the UI accordingly
  */

+ 2 - 0
src/gui/widgets/settingswidget.h

@@ -105,6 +105,8 @@ private:
 
     void loadBackupWidget();
 
+    void loadPreviousExperienceWidget();
+
     void updatePersonalDetails();
 
     bool usingStylesheet();

+ 1 - 529
src/gui/widgets/settingswidget.ui

@@ -316,535 +316,7 @@
       </attribute>
       <layout class="QGridLayout" name="gridLayout_9">
        <item row="0" column="0">
-        <layout class="QGridLayout" name="gridLayout_3">
-         <item row="0" column="0">
-          <widget class="QLabel" name="totalLabel">
-           <property name="maximumSize">
-            <size>
-             <width>120</width>
-             <height>16777215</height>
-            </size>
-           </property>
-           <property name="text">
-            <string>Total</string>
-           </property>
-          </widget>
-         </item>
-         <item row="0" column="1">
-          <widget class="QLineEdit" name="totalLineEdit">
-           <property name="minimumSize">
-            <size>
-             <width>100</width>
-             <height>0</height>
-            </size>
-           </property>
-           <property name="maximumSize">
-            <size>
-             <width>120</width>
-             <height>16777215</height>
-            </size>
-           </property>
-           <property name="focusPolicy">
-            <enum>Qt::NoFocus</enum>
-           </property>
-           <property name="text">
-            <string/>
-           </property>
-          </widget>
-         </item>
-         <item row="0" column="2">
-          <widget class="QLabel" name="picusLabel">
-           <property name="maximumSize">
-            <size>
-             <width>120</width>
-             <height>16777215</height>
-            </size>
-           </property>
-           <property name="text">
-            <string>PICus</string>
-           </property>
-          </widget>
-         </item>
-         <item row="0" column="3">
-          <widget class="QLineEdit" name="picusLineEdit">
-           <property name="minimumSize">
-            <size>
-             <width>100</width>
-             <height>0</height>
-            </size>
-           </property>
-           <property name="maximumSize">
-            <size>
-             <width>120</width>
-             <height>16777215</height>
-            </size>
-           </property>
-           <property name="focusPolicy">
-            <enum>Qt::NoFocus</enum>
-           </property>
-          </widget>
-         </item>
-         <item row="1" column="0">
-          <widget class="QLabel" name="spseLabel">
-           <property name="maximumSize">
-            <size>
-             <width>120</width>
-             <height>16777215</height>
-            </size>
-           </property>
-           <property name="text">
-            <string>SP SE</string>
-           </property>
-          </widget>
-         </item>
-         <item row="1" column="1">
-          <widget class="QLineEdit" name="spseLineEdit">
-           <property name="minimumSize">
-            <size>
-             <width>100</width>
-             <height>0</height>
-            </size>
-           </property>
-           <property name="maximumSize">
-            <size>
-             <width>120</width>
-             <height>16777215</height>
-            </size>
-           </property>
-           <property name="focusPolicy">
-            <enum>Qt::NoFocus</enum>
-           </property>
-          </widget>
-         </item>
-         <item row="1" column="2">
-          <widget class="QLabel" name="ifrLabel">
-           <property name="maximumSize">
-            <size>
-             <width>120</width>
-             <height>16777215</height>
-            </size>
-           </property>
-           <property name="text">
-            <string>IFR</string>
-           </property>
-          </widget>
-         </item>
-         <item row="1" column="3">
-          <widget class="QLineEdit" name="ifrLineEdit">
-           <property name="minimumSize">
-            <size>
-             <width>100</width>
-             <height>0</height>
-            </size>
-           </property>
-           <property name="maximumSize">
-            <size>
-             <width>120</width>
-             <height>16777215</height>
-            </size>
-           </property>
-           <property name="focusPolicy">
-            <enum>Qt::NoFocus</enum>
-           </property>
-          </widget>
-         </item>
-         <item row="2" column="0">
-          <widget class="QLabel" name="spmeLabel">
-           <property name="maximumSize">
-            <size>
-             <width>120</width>
-             <height>16777215</height>
-            </size>
-           </property>
-           <property name="text">
-            <string>SP ME</string>
-           </property>
-          </widget>
-         </item>
-         <item row="2" column="1">
-          <widget class="QLineEdit" name="spmeLineEdit">
-           <property name="minimumSize">
-            <size>
-             <width>100</width>
-             <height>0</height>
-            </size>
-           </property>
-           <property name="maximumSize">
-            <size>
-             <width>120</width>
-             <height>16777215</height>
-            </size>
-           </property>
-           <property name="focusPolicy">
-            <enum>Qt::NoFocus</enum>
-           </property>
-          </widget>
-         </item>
-         <item row="2" column="2">
-          <widget class="QLabel" name="nightLabel_2">
-           <property name="maximumSize">
-            <size>
-             <width>120</width>
-             <height>16777215</height>
-            </size>
-           </property>
-           <property name="text">
-            <string>Night</string>
-           </property>
-          </widget>
-         </item>
-         <item row="2" column="3">
-          <widget class="QLineEdit" name="nightLineEdit">
-           <property name="minimumSize">
-            <size>
-             <width>100</width>
-             <height>0</height>
-            </size>
-           </property>
-           <property name="maximumSize">
-            <size>
-             <width>120</width>
-             <height>16777215</height>
-            </size>
-           </property>
-           <property name="focusPolicy">
-            <enum>Qt::NoFocus</enum>
-           </property>
-          </widget>
-         </item>
-         <item row="3" column="0">
-          <widget class="QLabel" name="multipilotLabel">
-           <property name="maximumSize">
-            <size>
-             <width>120</width>
-             <height>16777215</height>
-            </size>
-           </property>
-           <property name="text">
-            <string>Multi Pilot</string>
-           </property>
-          </widget>
-         </item>
-         <item row="3" column="1">
-          <widget class="QLineEdit" name="multipilotLineEdit">
-           <property name="minimumSize">
-            <size>
-             <width>100</width>
-             <height>0</height>
-            </size>
-           </property>
-           <property name="maximumSize">
-            <size>
-             <width>120</width>
-             <height>16777215</height>
-            </size>
-           </property>
-           <property name="focusPolicy">
-            <enum>Qt::NoFocus</enum>
-           </property>
-          </widget>
-         </item>
-         <item row="3" column="2">
-          <widget class="QLabel" name="simLabel">
-           <property name="maximumSize">
-            <size>
-             <width>120</width>
-             <height>16777215</height>
-            </size>
-           </property>
-           <property name="text">
-            <string>Simulator</string>
-           </property>
-          </widget>
-         </item>
-         <item row="3" column="3">
-          <widget class="QLineEdit" name="simLineEdit">
-           <property name="minimumSize">
-            <size>
-             <width>100</width>
-             <height>0</height>
-            </size>
-           </property>
-           <property name="maximumSize">
-            <size>
-             <width>120</width>
-             <height>16777215</height>
-            </size>
-           </property>
-           <property name="focusPolicy">
-            <enum>Qt::NoFocus</enum>
-           </property>
-          </widget>
-         </item>
-         <item row="4" column="0">
-          <widget class="QLabel" name="piclabel">
-           <property name="maximumSize">
-            <size>
-             <width>120</width>
-             <height>16777215</height>
-            </size>
-           </property>
-           <property name="text">
-            <string>PIC</string>
-           </property>
-          </widget>
-         </item>
-         <item row="4" column="1">
-          <widget class="QLineEdit" name="picLineEdit">
-           <property name="minimumSize">
-            <size>
-             <width>100</width>
-             <height>0</height>
-            </size>
-           </property>
-           <property name="maximumSize">
-            <size>
-             <width>120</width>
-             <height>16777215</height>
-            </size>
-           </property>
-           <property name="focusPolicy">
-            <enum>Qt::NoFocus</enum>
-           </property>
-          </widget>
-         </item>
-         <item row="4" column="2">
-          <widget class="QLabel" name="todayLabel">
-           <property name="maximumSize">
-            <size>
-             <width>120</width>
-             <height>16777215</height>
-            </size>
-           </property>
-           <property name="text">
-            <string>TO Day</string>
-           </property>
-          </widget>
-         </item>
-         <item row="4" column="3">
-          <widget class="QLineEdit" name="todayLineEdit">
-           <property name="minimumSize">
-            <size>
-             <width>100</width>
-             <height>0</height>
-            </size>
-           </property>
-           <property name="maximumSize">
-            <size>
-             <width>120</width>
-             <height>16777215</height>
-            </size>
-           </property>
-           <property name="focusPolicy">
-            <enum>Qt::NoFocus</enum>
-           </property>
-           <property name="text">
-            <string>0</string>
-           </property>
-          </widget>
-         </item>
-         <item row="5" column="0">
-          <widget class="QLabel" name="sicLabel">
-           <property name="maximumSize">
-            <size>
-             <width>120</width>
-             <height>16777215</height>
-            </size>
-           </property>
-           <property name="text">
-            <string>SIC</string>
-           </property>
-          </widget>
-         </item>
-         <item row="5" column="1">
-          <widget class="QLineEdit" name="sicLineEdit">
-           <property name="minimumSize">
-            <size>
-             <width>100</width>
-             <height>0</height>
-            </size>
-           </property>
-           <property name="maximumSize">
-            <size>
-             <width>120</width>
-             <height>16777215</height>
-            </size>
-           </property>
-           <property name="focusPolicy">
-            <enum>Qt::NoFocus</enum>
-           </property>
-          </widget>
-         </item>
-         <item row="5" column="2">
-          <widget class="QLabel" name="tonightLabel">
-           <property name="maximumSize">
-            <size>
-             <width>120</width>
-             <height>16777215</height>
-            </size>
-           </property>
-           <property name="text">
-            <string>TO Night</string>
-           </property>
-          </widget>
-         </item>
-         <item row="5" column="3">
-          <widget class="QLineEdit" name="tonightLineEdit">
-           <property name="minimumSize">
-            <size>
-             <width>100</width>
-             <height>0</height>
-            </size>
-           </property>
-           <property name="maximumSize">
-            <size>
-             <width>120</width>
-             <height>16777215</height>
-            </size>
-           </property>
-           <property name="focusPolicy">
-            <enum>Qt::NoFocus</enum>
-           </property>
-           <property name="text">
-            <string>0</string>
-           </property>
-          </widget>
-         </item>
-         <item row="6" column="0">
-          <widget class="QLabel" name="dualLabel">
-           <property name="maximumSize">
-            <size>
-             <width>120</width>
-             <height>16777215</height>
-            </size>
-           </property>
-           <property name="text">
-            <string>DUAL</string>
-           </property>
-          </widget>
-         </item>
-         <item row="6" column="1">
-          <widget class="QLineEdit" name="dualLineEdit">
-           <property name="minimumSize">
-            <size>
-             <width>100</width>
-             <height>0</height>
-            </size>
-           </property>
-           <property name="maximumSize">
-            <size>
-             <width>120</width>
-             <height>16777215</height>
-            </size>
-           </property>
-           <property name="focusPolicy">
-            <enum>Qt::NoFocus</enum>
-           </property>
-          </widget>
-         </item>
-         <item row="6" column="2">
-          <widget class="QLabel" name="ldgdayLabel">
-           <property name="maximumSize">
-            <size>
-             <width>120</width>
-             <height>16777215</height>
-            </size>
-           </property>
-           <property name="text">
-            <string>LDG Day</string>
-           </property>
-          </widget>
-         </item>
-         <item row="6" column="3">
-          <widget class="QLineEdit" name="ldgdayLineEdit">
-           <property name="minimumSize">
-            <size>
-             <width>100</width>
-             <height>0</height>
-            </size>
-           </property>
-           <property name="maximumSize">
-            <size>
-             <width>120</width>
-             <height>16777215</height>
-            </size>
-           </property>
-           <property name="focusPolicy">
-            <enum>Qt::NoFocus</enum>
-           </property>
-           <property name="text">
-            <string>0</string>
-           </property>
-          </widget>
-         </item>
-         <item row="7" column="0">
-          <widget class="QLabel" name="fiLabel">
-           <property name="maximumSize">
-            <size>
-             <width>120</width>
-             <height>16777215</height>
-            </size>
-           </property>
-           <property name="text">
-            <string>FI</string>
-           </property>
-          </widget>
-         </item>
-         <item row="7" column="2">
-          <widget class="QLabel" name="ldgnightLabel">
-           <property name="maximumSize">
-            <size>
-             <width>120</width>
-             <height>16777215</height>
-            </size>
-           </property>
-           <property name="text">
-            <string>LDG Night</string>
-           </property>
-          </widget>
-         </item>
-         <item row="7" column="3">
-          <widget class="QLineEdit" name="ldgnightLineEdit">
-           <property name="minimumSize">
-            <size>
-             <width>100</width>
-             <height>0</height>
-            </size>
-           </property>
-           <property name="maximumSize">
-            <size>
-             <width>120</width>
-             <height>16777215</height>
-            </size>
-           </property>
-           <property name="focusPolicy">
-            <enum>Qt::NoFocus</enum>
-           </property>
-           <property name="text">
-            <string>0</string>
-           </property>
-          </widget>
-         </item>
-         <item row="7" column="1">
-          <widget class="QLineEdit" name="fiLineEdit">
-           <property name="minimumSize">
-            <size>
-             <width>100</width>
-             <height>0</height>
-            </size>
-           </property>
-           <property name="maximumSize">
-            <size>
-             <width>120</width>
-             <height>16777215</height>
-            </size>
-           </property>
-           <property name="focusPolicy">
-            <enum>Qt::NoFocus</enum>
-           </property>
-          </widget>
-         </item>
-        </layout>
+        <widget class="QStackedWidget" name="previousExpStackedWidget"/>
        </item>
       </layout>
      </widget>

+ 165 - 43
src/gui/widgets/totalswidget.cpp

@@ -1,7 +1,10 @@
 #include "totalswidget.h"
 #include "QtWidgets/qlineedit.h"
-#include "src/functions/statistics.h"
+#include "src/database/database.h"
+#include "src/gui/verification/timeinput.h"
 #include "src/opl.h"
+#include "src/functions/time.h"
+#include "src/database/row.h"
 #include "ui_totalswidget.h"
 
 TotalsWidget::TotalsWidget(WidgetType widgetType, QWidget *parent) :
@@ -23,23 +26,40 @@ TotalsWidget::~TotalsWidget()
  */
 void TotalsWidget::fillTotals(WidgetType widgetType)
 {
+    OPL::RowData_T time_data;
+
+    // retreive times from database
     switch (widgetType) {
     case TotalTimeWidget:
-    {
-        const auto data = OPL::Statistics::totals();
-        for (const auto &field : data) {
-            auto line_edit = this->findChild<QLineEdit *>(field.first + QLatin1String("LineEdit"));
-            line_edit->setText(field.second);
-        }
+        time_data = DB->getTotals();
         break;
-    }
     case PreviousExperienceWidget:
-        WARN("NOT IMPLEMENTED!");
-        qApp->quit();
-        // get previous exp data and fill
-        // implement query in opl statistics
+        time_data = DB->getRowData(OPL::DbTable::Flights, TOTALS_DATA_ROW_ID);
+        DEB << time_data;
     }
 
+    // fill the line edits with the data obtained
+    const OPL::RowData_T &const_time_data = qAsConst(time_data);
+    for (const auto &field : const_time_data) {
+        // match the db entries to the line edits using their object name
+        const QString search_term = time_data.key(field) + QLatin1String("LineEdit");
+        QLineEdit* line_edit = this->findChild<QLineEdit *>(search_term);
+        // fill the line edit with the corresponding data
+        if(line_edit != nullptr) {
+            const QString &le_name = line_edit->objectName();
+            if(le_name.contains("to") || le_name.contains("ldg")) {
+                // line edits for take offs and landings
+                line_edit->setText(field.toString());
+//                DEB << "Setting: " + le_name + ": " + field.toString();
+            } else {
+                // line edits for total times
+                const QString time_string = OPL::Time::toString(field.toInt());
+                line_edit->setText(time_string);
+//                DEB << "Setting " + le_name + ": " + time_string;
+            }
+        }
+
+    }
 }
 
 /*!
@@ -54,15 +74,22 @@ void TotalsWidget::setup(WidgetType widgetType)
 
     switch (widgetType) {
     case TotalTimeWidget:
+        LOG << "Setting up totals widget";
         for (const auto &lineEdit : lineEdits) {
             lineEdit->setFocusPolicy(Qt::FocusPolicy::NoFocus);
         }
         fillTotals(widgetType);
         break;
     case PreviousExperienceWidget:
+        LOG << "Setting up previous XP widget";
         for (const auto &lineEdit : lineEdits) {
             lineEdit->setFocusPolicy(Qt::FocusPolicy::ClickFocus);
+            lineEdit->setValidator(m_timeValidator);
         }
+        // initialise m_rowData
+        m_rowData = DB->getRowData(OPL::DbTable::Flights, TOTALS_DATA_ROW_ID);
+
+        // fill the totals
         fillTotals(widgetType);
         connectSignalsAndSlots();
         break;
@@ -77,118 +104,213 @@ void TotalsWidget::setup(WidgetType widgetType)
 void TotalsWidget::connectSignalsAndSlots()
 {
     // connect signals and slots that edit the applicable field in the database on editing finished
-    connect(ui->totalLineEdit, &QLineEdit::editingFinished,
+    connect(ui->tblkLineEdit, &QLineEdit::editingFinished,
             this, &TotalsWidget::totalTimeEdited);
-    connect(ui->spseLineEdit, &QLineEdit::editingFinished,
+    connect(ui->tSPSELineEdit, &QLineEdit::editingFinished,
             this, &TotalsWidget::spseTimeEdited);
-    connect(ui->spmeLineEdit, &QLineEdit::editingFinished,
+    connect(ui->tSPMELineEdit, &QLineEdit::editingFinished,
             this, &TotalsWidget::spmeTimeEdited);
-    connect(ui->multipilotLineEdit, &QLineEdit::editingFinished,
+    connect(ui->tMPLineEdit, &QLineEdit::editingFinished,
             this, &TotalsWidget::multipilotTimeEdited);
 
-    connect(ui->picLineEdit, &QLineEdit::editingFinished,
+    connect(ui->tPICLineEdit, &QLineEdit::editingFinished,
             this, &TotalsWidget::picTimeEdited);
-    connect(ui->sicLineEdit, &QLineEdit::editingFinished,
+    connect(ui->tSICLineEdit, &QLineEdit::editingFinished,
             this, &TotalsWidget::sicTimeEdited);
-    connect(ui->dualLineEdit, &QLineEdit::editingFinished,
+    connect(ui->tDUALLineEdit, &QLineEdit::editingFinished,
             this, &TotalsWidget::dualTimeEdited);
-    connect(ui->fiLineEdit, &QLineEdit::editingFinished,
+    connect(ui->tFILineEdit, &QLineEdit::editingFinished,
             this, &TotalsWidget::fiTimeEdited);
-    connect(ui->picusLineEdit, &QLineEdit::editingFinished,
+    connect(ui->tPICUSLineEdit, &QLineEdit::editingFinished,
             this, &TotalsWidget::picusTimeEdited);
-    connect(ui->ifrLineEdit, &QLineEdit::editingFinished,
+    connect(ui->tIFRLineEdit, &QLineEdit::editingFinished,
             this, &TotalsWidget::ifrTimeEdited);
-    connect(ui->simLineEdit, &QLineEdit::editingFinished,
+    connect(ui->tSIMLineEdit, &QLineEdit::editingFinished,
             this, &TotalsWidget::simulatorTimeEdited);
 
-    connect(ui->todayLineEdit, &QLineEdit::editingFinished,
+    connect(ui->toDayLineEdit, &QLineEdit::editingFinished,
             this, &TotalsWidget::toDayEdited);
-    connect(ui->tonightLineEdit, &QLineEdit::editingFinished,
+    connect(ui->toNightLineEdit, &QLineEdit::editingFinished,
             this, &TotalsWidget::toNightedited);
-    connect(ui->ldgdayLineEdit, &QLineEdit::editingFinished,
+    connect(ui->ldgDayLineEdit, &QLineEdit::editingFinished,
             this, &TotalsWidget::ldgDayEdited);
-    connect(ui->ldgnightLineEdit, &QLineEdit::editingFinished,
+    connect(ui->ldgNightLineEdit, &QLineEdit::editingFinished,
             this, &TotalsWidget::ldgNightEdited);
 }
 
+bool TotalsWidget::verifyUserTimeInput(QLineEdit *line_edit, const TimeInput &input)
+{
+    if(!input.isValid()) {
+        // try to fix
+        QString fixed = input.fixup();
+        if(fixed == QString()) {
+            WARN(tr("Invalid input. Please use the following format for time:<br><br><tt>hh:mm</tt>"));
+            return false;
+        } else {
+            line_edit->setText(fixed);
+            return true;
+        }
+    }
+    return true;
+}
+
+bool TotalsWidget::updateDatabase(const QString &db_field, const QString &value) {
+    m_rowData.insert(db_field, value);
+    const OPL::FlightEntry entry = OPL::FlightEntry(TOTALS_DATA_ROW_ID, m_rowData);
+
+    return DB->commit(entry);
+}
+
 void TotalsWidget::totalTimeEdited()
 {
-    INFO("Total Time Edited.");
+    LOG << sender()->objectName() + "Editing finished.";
+    QLineEdit* line_edit = this->findChild<QLineEdit*>(sender()->objectName());
+    if (verifyUserTimeInput(line_edit, TimeInput(line_edit->text()))) {
+        // write to DB
+    } else {
+        // (re-) set to previous value from DB (or 0)
+    }
 }
 
 void TotalsWidget::spseTimeEdited()
 {
-
+    LOG << sender()->objectName() + "Editing finished.";
+    QLineEdit* line_edit = this->findChild<QLineEdit*>(sender()->objectName());
+    if (verifyUserTimeInput(line_edit, TimeInput(line_edit->text()))) {
+        // write to DB
+    } else {
+        // (re-) set to previous value from DB (or 0)
+    }
 }
 
 void TotalsWidget::spmeTimeEdited()
 {
-
+    LOG << sender()->objectName() + "Editing finished.";
+    QLineEdit* line_edit = this->findChild<QLineEdit*>(sender()->objectName());
+    if (verifyUserTimeInput(line_edit, TimeInput(line_edit->text()))) {
+        // write to DB
+    } else {
+        // (re-) set to previous value from DB (or 0)
+    }
 }
 
 void TotalsWidget::multipilotTimeEdited()
 {
-
+    LOG << sender()->objectName() + "Editing finished.";
+    QLineEdit* line_edit = this->findChild<QLineEdit*>(sender()->objectName());
+    if (verifyUserTimeInput(line_edit, TimeInput(line_edit->text()))) {
+        // write to DB
+    } else {
+        // (re-) set to previous value from DB (or 0)
+    }
 }
 
 void TotalsWidget::picTimeEdited()
 {
-
+    LOG << sender()->objectName() + "Editing finished.";
+    QLineEdit* line_edit = this->findChild<QLineEdit*>(sender()->objectName());
+    if (verifyUserTimeInput(line_edit, TimeInput(line_edit->text()))) {
+        // write to DB
+    } else {
+        // (re-) set to previous value from DB (or 0)
+    }
 }
 
 void TotalsWidget::sicTimeEdited()
 {
-
+    LOG << sender()->objectName() + "Editing finished.";
+    QLineEdit* line_edit = this->findChild<QLineEdit*>(sender()->objectName());
+    if (verifyUserTimeInput(line_edit, TimeInput(line_edit->text()))) {
+        // write to DB
+    } else {
+        // (re-) set to previous value from DB (or 0)
+    }
 }
 
 void TotalsWidget::dualTimeEdited()
 {
-
+    LOG << sender()->objectName() + "Editing finished.";
+    QLineEdit* line_edit = this->findChild<QLineEdit*>(sender()->objectName());
+    if (verifyUserTimeInput(line_edit, TimeInput(line_edit->text()))) {
+        // write to DB
+    } else {
+        // (re-) set to previous value from DB (or 0)
+    }
 }
 
 void TotalsWidget::fiTimeEdited()
 {
-
+    LOG << sender()->objectName() + "Editing finished.";
+    QLineEdit* line_edit = this->findChild<QLineEdit*>(sender()->objectName());
+    if (verifyUserTimeInput(line_edit, TimeInput(line_edit->text()))) {
+        // write to DB
+    } else {
+        // (re-) set to previous value from DB (or 0)
+    }
 }
 
 void TotalsWidget::picusTimeEdited()
 {
-
+    LOG << sender()->objectName() + "Editing finished.";
+    QLineEdit* line_edit = this->findChild<QLineEdit*>(sender()->objectName());
+    if (verifyUserTimeInput(line_edit, TimeInput(line_edit->text()))) {
+        // write to DB
+    } else {
+        // (re-) set to previous value from DB (or 0)
+    }
 }
 
 void TotalsWidget::ifrTimeEdited()
 {
-
+    LOG << sender()->objectName() + "Editing finished.";
+    QLineEdit* line_edit = this->findChild<QLineEdit*>(sender()->objectName());
+    if (verifyUserTimeInput(line_edit, TimeInput(line_edit->text()))) {
+        // write to DB
+    } else {
+        // (re-) set to previous value from DB (or 0)
+    }
 }
 
 void TotalsWidget::nightTimeEdited()
 {
-
+    LOG << sender()->objectName() + "Editing finished.";
+    QLineEdit* line_edit = this->findChild<QLineEdit*>(sender()->objectName());
+    if (verifyUserTimeInput(line_edit, TimeInput(line_edit->text()))) {
+        // write to DB
+    } else {
+        // (re-) set to previous value from DB (or 0)
+    }
 }
 
 void TotalsWidget::simulatorTimeEdited()
 {
-
+    LOG << sender()->objectName() + "Editing finished.";
+    QLineEdit* line_edit = this->findChild<QLineEdit*>(sender()->objectName());
+    if (verifyUserTimeInput(line_edit, TimeInput(line_edit->text()))) {
+        // write to DB
+    } else {
+        // (re-) set to previous value from DB (or 0)
+    }
 }
 
 void TotalsWidget::toDayEdited()
 {
-
+    LOG << sender()->objectName() + "Editing finished.";
 }
 
 void TotalsWidget::toNightedited()
 {
-
+    LOG << sender()->objectName() + "Editing finished.";
 }
 
 void TotalsWidget::ldgDayEdited()
 {
-
+    LOG << sender()->objectName() + "Editing finished.";
 }
 
 void TotalsWidget::ldgNightEdited()
 {
-
+    LOG << sender()->objectName() + "Editing finished.";
 }
 
 

+ 12 - 1
src/gui/widgets/totalswidget.h

@@ -1,7 +1,11 @@
 #ifndef TOTALSWIDGET_H
 #define TOTALSWIDGET_H
 
+#include "QtWidgets/qlineedit.h"
+#include "src/gui/verification/timeinput.h"
+#include "src/opl.h"
 #include <QWidget>
+#include <QRegularExpressionValidator>
 
 namespace Ui {
 class TotalsWidget;
@@ -10,9 +14,9 @@ class TotalsWidget;
 class TotalsWidget : public QWidget
 {
     Q_OBJECT
-    enum WidgetType {TotalTimeWidget, PreviousExperienceWidget};
 
 public:
+    enum WidgetType {TotalTimeWidget, PreviousExperienceWidget};
     explicit TotalsWidget(WidgetType widgetType, QWidget *parent = nullptr);
     ~TotalsWidget();
 
@@ -20,9 +24,16 @@ public:
 
 private:
     Ui::TotalsWidget *ui;
+    OPL::RowData_T m_rowData;
+    const QRegularExpressionValidator *m_timeValidator = new QRegularExpressionValidator(QRegularExpression("([01]?[0-9]|2[0-3]):?[0-5][0-9]?"), this);
+    const static int TOTALS_DATA_ROW_ID = 1;
+
     void fillTotals(WidgetType widgetType);
     void setup(WidgetType widgetType);
     void connectSignalsAndSlots();
+    bool verifyUserTimeInput(QLineEdit *line_edit, const TimeInput &input);
+    bool updateDatabase(const QString &db_field, const QString &value);
+
 private slots:
     void totalTimeEdited();
     void spseTimeEdited();

+ 21 - 16
src/gui/widgets/totalswidget.ui

@@ -30,7 +30,7 @@
       </widget>
      </item>
      <item row="0" column="1">
-      <widget class="QLineEdit" name="totalLineEdit">
+      <widget class="QLineEdit" name="tblkLineEdit">
        <property name="minimumSize">
         <size>
          <width>100</width>
@@ -43,6 +43,11 @@
          <height>16777215</height>
         </size>
        </property>
+       <property name="font">
+        <font>
+         <family>.AppleSystemUIFont</family>
+        </font>
+       </property>
        <property name="focusPolicy">
         <enum>Qt::NoFocus</enum>
        </property>
@@ -65,7 +70,7 @@
       </widget>
      </item>
      <item row="0" column="3">
-      <widget class="QLineEdit" name="picusLineEdit">
+      <widget class="QLineEdit" name="tPICUSLineEdit">
        <property name="minimumSize">
         <size>
          <width>100</width>
@@ -97,7 +102,7 @@
       </widget>
      </item>
      <item row="1" column="1">
-      <widget class="QLineEdit" name="spseLineEdit">
+      <widget class="QLineEdit" name="tSPSELineEdit">
        <property name="minimumSize">
         <size>
          <width>100</width>
@@ -129,7 +134,7 @@
       </widget>
      </item>
      <item row="1" column="3">
-      <widget class="QLineEdit" name="ifrLineEdit">
+      <widget class="QLineEdit" name="tIFRLineEdit">
        <property name="minimumSize">
         <size>
          <width>100</width>
@@ -161,7 +166,7 @@
       </widget>
      </item>
      <item row="2" column="1">
-      <widget class="QLineEdit" name="spmeLineEdit">
+      <widget class="QLineEdit" name="tSPMELineEdit">
        <property name="minimumSize">
         <size>
          <width>100</width>
@@ -193,7 +198,7 @@
       </widget>
      </item>
      <item row="2" column="3">
-      <widget class="QLineEdit" name="nightLineEdit">
+      <widget class="QLineEdit" name="tNIGHTLineEdit">
        <property name="minimumSize">
         <size>
          <width>100</width>
@@ -225,7 +230,7 @@
       </widget>
      </item>
      <item row="3" column="1">
-      <widget class="QLineEdit" name="multipilotLineEdit">
+      <widget class="QLineEdit" name="tMPLineEdit">
        <property name="minimumSize">
         <size>
          <width>100</width>
@@ -257,7 +262,7 @@
       </widget>
      </item>
      <item row="3" column="3">
-      <widget class="QLineEdit" name="simLineEdit">
+      <widget class="QLineEdit" name="tSIMLineEdit">
        <property name="minimumSize">
         <size>
          <width>100</width>
@@ -289,7 +294,7 @@
       </widget>
      </item>
      <item row="4" column="1">
-      <widget class="QLineEdit" name="picLineEdit">
+      <widget class="QLineEdit" name="tPICLineEdit">
        <property name="minimumSize">
         <size>
          <width>100</width>
@@ -321,7 +326,7 @@
       </widget>
      </item>
      <item row="4" column="3">
-      <widget class="QLineEdit" name="todayLineEdit">
+      <widget class="QLineEdit" name="toDayLineEdit">
        <property name="minimumSize">
         <size>
          <width>100</width>
@@ -356,7 +361,7 @@
       </widget>
      </item>
      <item row="5" column="1">
-      <widget class="QLineEdit" name="sicLineEdit">
+      <widget class="QLineEdit" name="tSICLineEdit">
        <property name="minimumSize">
         <size>
          <width>100</width>
@@ -388,7 +393,7 @@
       </widget>
      </item>
      <item row="5" column="3">
-      <widget class="QLineEdit" name="tonightLineEdit">
+      <widget class="QLineEdit" name="toNightLineEdit">
        <property name="minimumSize">
         <size>
          <width>100</width>
@@ -423,7 +428,7 @@
       </widget>
      </item>
      <item row="6" column="1">
-      <widget class="QLineEdit" name="dualLineEdit">
+      <widget class="QLineEdit" name="tDUALLineEdit">
        <property name="minimumSize">
         <size>
          <width>100</width>
@@ -455,7 +460,7 @@
       </widget>
      </item>
      <item row="6" column="3">
-      <widget class="QLineEdit" name="ldgdayLineEdit">
+      <widget class="QLineEdit" name="ldgDayLineEdit">
        <property name="minimumSize">
         <size>
          <width>100</width>
@@ -503,7 +508,7 @@
       </widget>
      </item>
      <item row="7" column="3">
-      <widget class="QLineEdit" name="ldgnightLineEdit">
+      <widget class="QLineEdit" name="ldgNightLineEdit">
        <property name="minimumSize">
         <size>
          <width>100</width>
@@ -525,7 +530,7 @@
       </widget>
      </item>
      <item row="7" column="1">
-      <widget class="QLineEdit" name="fiLineEdit">
+      <widget class="QLineEdit" name="tFILineEdit">
        <property name="minimumSize">
         <size>
          <width>100</width>

+ 10 - 0
src/opl.h

@@ -94,6 +94,16 @@ public:
 
 using RowData_T = QHash<QString, QVariant>;
 
+struct ToLdgCount_T {
+    int toDay;
+    int toNight;
+    int ldgDay;
+    int ldgNight;
+
+    ToLdgCount_T(int toDay, int toNight, int ldgDay, int ldgNight)
+        : toDay(toDay), toNight(toNight), ldgDay(ldgDay), ldgNight(ldgNight) {}
+};
+
 /*!
  * \brief ADateFormats enumerates the accepted date formats for QDateEdits
  * \todo At the moment, only ISODate is accepet as a valid date format.