Browse Source

Improvements in FirstRun

closes #73
- Added ADate class to encapsulate handling of Dates across the apllication. Controlling enum located in Opl.
- Added a Setting to save the Date Format selected
- Added a QComboBox in FirstRunDialog to assist in identifying the Date Format currently used and change it if desired
- Adressed the issue of bad behaviour when the user clicks 'Finish' in the FirstRunDialog a second time before the DB creation process has finished by disabling the button.
Felix Turo 3 years ago
parent
commit
3dba7d5255

+ 2 - 0
CMakeLists.txt

@@ -39,6 +39,7 @@ set(PROJECT_SOURCES
     src/functions/alog.cpp
     src/functions/areadcsv.cpp
     src/functions/astat.cpp
+    src/functions/adate.cpp
     src/gui/dialogues/firstrundialog.cpp
     src/gui/dialogues/newflightdialog.cpp
     src/gui/dialogues/newpilotdialog.cpp
@@ -73,6 +74,7 @@ set(PROJECT_SOURCES
     src/functions/alog.h
     src/functions/areadcsv.h
     src/functions/astat.h
+    src/functions/adate.h
     src/functions/atime.h
     src/gui/dialogues/firstrundialog.h
     src/gui/dialogues/newflightdialog.h

+ 2 - 0
openPilotLog.pro

@@ -37,6 +37,7 @@ SOURCES += \
     src/functions/alog.cpp \
     src/functions/areadcsv.cpp \
     src/functions/astat.cpp \
+    src/functions/adate.cpp \
     src/gui/dialogues/firstrundialog.cpp \
     src/gui/dialogues/newflightdialog.cpp \
     src/gui/dialogues/newpilotdialog.cpp \
@@ -72,6 +73,7 @@ HEADERS += \
     src/functions/alog.h \
     src/functions/areadcsv.h \
     src/functions/astat.h \
+    src/functions/adate.h \
     src/functions/atime.h \
     src/gui/dialogues/firstrundialog.h \
     src/gui/dialogues/newflightdialog.h \

+ 2 - 0
src/classes/asettings.cpp

@@ -26,6 +26,7 @@ QMap<ASettings::Main, QString> ASettings::mainMap = {
     {Main::FontSize,                    QStringLiteral("fontSize")},
     {Main::UseSystemFont,               QStringLiteral("useSystemFont")},
     {Main::LogbookView,                 QStringLiteral("logbookView")},
+    {Main::DateFormat,                  QStringLiteral("dateFormat")},
 };
 
 QMap<ASettings::UserData, QString> ASettings::userDataMap = {
@@ -78,6 +79,7 @@ void ASettings::resetToDefaults()
     write(Main::Style, QStringLiteral("Fusion"));
     write(Main::UseSystemFont, true);
     write(Main::LogbookView, 0);
+    write(Main::DateFormat, 0);
 
     write(UserData::DisplaySelfAs, 0);
     write(UserData::FtlWarningThreshold, 0.8); // To Do: UI Option

+ 1 - 0
src/classes/asettings.h

@@ -33,6 +33,7 @@ public:
         FontSize,
         UseSystemFont,
         LogbookView,
+        DateFormat,
     };
 
     enum class UserData {

+ 38 - 0
src/functions/adate.cpp

@@ -0,0 +1,38 @@
+#include "adate.h"
+
+QDate ADate::formatInput(QString user_input, Opl::Date::ADateFormat format)
+{
+    const QString &format_string = ADATEFORMATSMAP.value(format);
+    QDate return_date = QDate::fromString(user_input, format_string);
+    if (return_date.isValid())
+        return return_date;
+
+     // If not successfull, try to fix the user input, it is allowable to ommit date seperators
+    switch (format) {
+    case Opl::Date::ADateFormat::ISODate:
+        user_input.insert(4, QLatin1Char('-'));
+        user_input.insert(7, QLatin1Char('-'));
+        break;
+    case Opl::Date::ADateFormat::DE:
+        user_input.insert(2, QLatin1Char('.'));
+        user_input.insert(5, QLatin1Char('.'));
+        break;
+    case Opl::Date::ADateFormat::EN:
+        user_input.insert(2, QLatin1Char('/'));
+        user_input.insert(5, QLatin1Char('/'));
+        break;
+    }
+
+    return  QDate::fromString(user_input, format_string);
+}
+
+const QStringList& ADate::getDisplayNames()
+{
+    return DISPLAY_NAMES;
+}
+
+const QString ADate::getFormatString(Opl::Date::ADateFormat format)
+{
+    return ADATEFORMATSMAP.value(format);
+}
+

+ 49 - 0
src/functions/adate.h

@@ -0,0 +1,49 @@
+#ifndef ADATE_H
+#define ADATE_H
+#include "src/opl.h"
+
+const static auto ISO = QStringLiteral("yyyy-MM-dd");
+const static auto DE = QStringLiteral("dd.MM.yyyy");
+const static auto EN = QStringLiteral("MM/dd/yyyy");
+
+const static QMap<Opl::Date::ADateFormat, QString> ADATEFORMATSMAP = {
+    {Opl::Date::ADateFormat::ISODate, ISO},
+    {Opl::Date::ADateFormat::DE,      DE },
+    {Opl::Date::ADateFormat::EN,      EN },
+
+};
+
+const static QStringList DISPLAY_NAMES = {
+    QStringLiteral("ISO 8601: yyyy-MM-dd"),
+    QStringLiteral("DE: dd.MM.yyyy"),
+    QStringLiteral("EN: MM/dd/yyyy")
+};
+
+/*!
+ * \brief The ADate class is responsible for input/output of Dates and handling the different
+ * Date Formats.
+ */
+class ADate
+{
+public:
+    /*!
+     * \brief formatInput takes a user-provided input and tries to convert it to a QDate.
+     * \return QDate (invalid if input not recognized)
+     */
+    static QDate formatInput(QString user_input, Opl::Date::ADateFormat format);
+
+    /*!
+     * \brief Reimplements QDate::toString to accept Opl::Date::ADateFormat enums
+     */
+    inline static QString toString(const QDate &date, Opl::Date::ADateFormat format = Opl::Date::ADateFormat::ISODate)
+    {
+        return date.toString(ADATEFORMATSMAP.value(format));
+    };
+
+    static const QStringList& getDisplayNames();
+
+    static const QString getFormatString(Opl::Date::ADateFormat format);
+
+};
+
+#endif // ADATE_H

+ 21 - 1
src/gui/dialogues/firstrundialog.cpp

@@ -24,6 +24,7 @@
 #include "src/classes/adownload.h"
 #include "src/classes/asettings.h"
 #include "src/opl.h"
+#include "src/functions/adate.h"
 #include <QErrorMessage>
 #include "src/classes/astyle.h"
 
@@ -50,9 +51,16 @@ FirstRunDialog::FirstRunDialog(QWidget *parent) :
     ui->styleComboBox->addItem(QStringLiteral("Dark-Palette"));
     ui->styleComboBox->model()->sort(0);
     ui->styleComboBox->setCurrentText(AStyle::defaultStyle);
+    // Prepare Date Edits
+    dateEdits = this->findChildren<QDateEdit *>();
+    for (const auto &date_format : ADate::getDisplayNames())
+        ui->dateFormatComboBox->addItem(date_format);
     // Set Date Edits for currencies
-    for (const auto date_edit : this->findChildren<QDateEdit *>())
+    for (const auto &date_edit : qAsConst(dateEdits)) {
+        date_edit->setDisplayFormat(
+                    ADate::getFormatString(Opl::Date::ADateFormat::ISODate));
         date_edit->setDate(QDate::currentDate());
+    }
 }
 
 FirstRunDialog::~FirstRunDialog()
@@ -96,6 +104,7 @@ void FirstRunDialog::on_nextPushButton_clicked()
         ui->nextPushButton->setText(tr("Done"));
         break;
     case 4:
+        ui->nextPushButton->setDisabled(true);
         if(!finishSetup())
             QDialog::reject();
         else
@@ -349,3 +358,14 @@ void FirstRunDialog::on_currCustom2LineEdit_editingFinished()
 {
     ASettings::write(ASettings::UserData::Custom2CurrencyName, ui->currCustom2LineEdit->text());
 }
+
+void FirstRunDialog::on_dateFormatComboBox_currentIndexChanged(int index)
+{
+    Opl::Date::ADateFormat format = (Opl::Date::ADateFormat)index;
+
+    for (const auto &date_edit : qAsConst(dateEdits)) {
+        date_edit->setDisplayFormat(
+                    ADate::getFormatString(format));
+    }
+    ASettings::write(ASettings::Main::DateFormat, index);
+}

+ 5 - 0
src/gui/dialogues/firstrundialog.h

@@ -22,6 +22,7 @@
 #include <QButtonGroup>
 #include <QMessageBox>
 #include <QStringBuilder>
+#include <QDateEdit>
 
 namespace Ui {
 class FirstRunDialog;
@@ -51,6 +52,8 @@ private slots:
 
     void on_currCustom2LineEdit_editingFinished();
 
+    void on_dateFormatComboBox_currentIndexChanged(int index);
+
 private:
     Ui::FirstRunDialog *ui;
     bool useRessourceData;
@@ -61,6 +64,8 @@ private:
     bool writeCurrencies();
     bool finishSetup();
 
+    QList<QDateEdit*> dateEdits;
+
     void reject() override;
 };
 

+ 125 - 108
src/gui/dialogues/firstrundialog.ui

@@ -17,7 +17,7 @@
    <item row="1" column="0" colspan="2">
     <widget class="QStackedWidget" name="stackedWidget">
      <property name="currentIndex">
-      <number>2</number>
+      <number>4</number>
      </property>
      <widget class="QWidget" name="personalDataPage">
       <layout class="QGridLayout" name="gridLayout_9">
@@ -133,54 +133,10 @@
      </widget>
      <widget class="QWidget" name="currencyPage">
       <layout class="QGridLayout" name="gridLayout_6">
-       <item row="0" column="0">
-        <widget class="QLabel" name="label_6">
-         <property name="text">
-          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-size:20pt;&quot;&gt;Welcome to openPilotLog!&lt;/span&gt;&lt;/p&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-size:14pt;&quot;&gt;The Free and Open Source Logbook application&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;If you would like to keep track of your license and/or medical expiration dates, you can enter them here. By default, only Take-Off and Landing currency is shown on the home page, but any other currency can also be shown as well. This can be enabled in the settings.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
-         </property>
-         <property name="textFormat">
-          <enum>Qt::RichText</enum>
-         </property>
-         <property name="wordWrap">
-          <bool>true</bool>
-         </property>
-        </widget>
-       </item>
-       <item row="2" column="0">
-        <layout class="QHBoxLayout" name="horizontalLayout">
-         <item>
-          <widget class="QCheckBox" name="currWarningCheckBox">
-           <property name="text">
-            <string>Warn me about expiring currencies</string>
-           </property>
-           <property name="checked">
-            <bool>true</bool>
-           </property>
-          </widget>
-         </item>
-         <item>
-          <widget class="QSpinBox" name="currWarningThresholdSpinBox">
-           <property name="maximum">
-            <number>365</number>
-           </property>
-           <property name="value">
-            <number>30</number>
-           </property>
-          </widget>
-         </item>
-         <item>
-          <widget class="QLabel" name="label_3">
-           <property name="text">
-            <string>days before expiry</string>
-           </property>
-          </widget>
-         </item>
-        </layout>
-       </item>
-       <item row="1" column="0">
+       <item row="3" column="0" colspan="2">
         <layout class="QGridLayout" name="gridLayout_5">
-         <item row="1" column="1">
-          <widget class="QDateEdit" name="currTrDateEdit">
+         <item row="0" column="1">
+          <widget class="QDateEdit" name="currLicDateEdit">
            <property name="minimumSize">
             <size>
              <width>140</width>
@@ -208,32 +164,6 @@
            </property>
           </widget>
          </item>
-         <item row="3" column="0">
-          <widget class="QLabel" name="currMedLabel">
-           <property name="minimumSize">
-            <size>
-             <width>280</width>
-             <height>0</height>
-            </size>
-           </property>
-           <property name="text">
-            <string>Medical</string>
-           </property>
-          </widget>
-         </item>
-         <item row="5" column="0">
-          <widget class="QLineEdit" name="currCustom2LineEdit">
-           <property name="minimumSize">
-            <size>
-             <width>280</width>
-             <height>0</height>
-            </size>
-           </property>
-           <property name="placeholderText">
-            <string>custom currency</string>
-           </property>
-          </widget>
-         </item>
          <item row="4" column="0">
           <widget class="QLineEdit" name="currCustom1LineEdit">
            <property name="minimumSize">
@@ -250,21 +180,8 @@
            </property>
           </widget>
          </item>
-         <item row="1" column="0">
-          <widget class="QLabel" name="currTrLabel">
-           <property name="minimumSize">
-            <size>
-             <width>280</width>
-             <height>0</height>
-            </size>
-           </property>
-           <property name="text">
-            <string>Type Rating</string>
-           </property>
-          </widget>
-         </item>
-         <item row="4" column="1">
-          <widget class="QDateEdit" name="currCustom1DateEdit">
+         <item row="3" column="1">
+          <widget class="QDateEdit" name="currMedDateEdit">
            <property name="minimumSize">
             <size>
              <width>140</width>
@@ -292,8 +209,8 @@
            </property>
           </widget>
          </item>
-         <item row="3" column="1">
-          <widget class="QDateEdit" name="currMedDateEdit">
+         <item row="5" column="1">
+          <widget class="QDateEdit" name="currCustom2DateEdit">
            <property name="minimumSize">
             <size>
              <width>140</width>
@@ -321,8 +238,60 @@
            </property>
           </widget>
          </item>
-         <item row="5" column="1">
-          <widget class="QDateEdit" name="currCustom2DateEdit">
+         <item row="2" column="0">
+          <widget class="QLabel" name="currLckLabel">
+           <property name="minimumSize">
+            <size>
+             <width>280</width>
+             <height>0</height>
+            </size>
+           </property>
+           <property name="text">
+            <string>Line Check</string>
+           </property>
+          </widget>
+         </item>
+         <item row="3" column="0">
+          <widget class="QLabel" name="currMedLabel">
+           <property name="minimumSize">
+            <size>
+             <width>280</width>
+             <height>0</height>
+            </size>
+           </property>
+           <property name="text">
+            <string>Medical</string>
+           </property>
+          </widget>
+         </item>
+         <item row="0" column="0">
+          <widget class="QLabel" name="currLicLabel">
+           <property name="minimumSize">
+            <size>
+             <width>280</width>
+             <height>0</height>
+            </size>
+           </property>
+           <property name="text">
+            <string>Licence</string>
+           </property>
+          </widget>
+         </item>
+         <item row="1" column="0">
+          <widget class="QLabel" name="currTrLabel">
+           <property name="minimumSize">
+            <size>
+             <width>280</width>
+             <height>0</height>
+            </size>
+           </property>
+           <property name="text">
+            <string>Type Rating</string>
+           </property>
+          </widget>
+         </item>
+         <item row="4" column="1">
+          <widget class="QDateEdit" name="currCustom1DateEdit">
            <property name="minimumSize">
             <size>
              <width>140</width>
@@ -350,8 +319,8 @@
            </property>
           </widget>
          </item>
-         <item row="0" column="1">
-          <widget class="QDateEdit" name="currLicDateEdit">
+         <item row="2" column="1">
+          <widget class="QDateEdit" name="currLckDateEdit">
            <property name="minimumSize">
             <size>
              <width>140</width>
@@ -379,8 +348,8 @@
            </property>
           </widget>
          </item>
-         <item row="2" column="1">
-          <widget class="QDateEdit" name="currLckDateEdit">
+         <item row="1" column="1">
+          <widget class="QDateEdit" name="currTrDateEdit">
            <property name="minimumSize">
             <size>
              <width>140</width>
@@ -408,34 +377,82 @@
            </property>
           </widget>
          </item>
-         <item row="2" column="0">
-          <widget class="QLabel" name="currLckLabel">
+         <item row="5" column="0">
+          <widget class="QLineEdit" name="currCustom2LineEdit">
            <property name="minimumSize">
             <size>
              <width>280</width>
              <height>0</height>
             </size>
            </property>
+           <property name="placeholderText">
+            <string>custom currency</string>
+           </property>
+          </widget>
+         </item>
+        </layout>
+       </item>
+       <item row="1" column="1">
+        <widget class="QComboBox" name="dateFormatComboBox"/>
+       </item>
+       <item row="0" column="0" colspan="2">
+        <widget class="QLabel" name="label_6">
+         <property name="text">
+          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-size:20pt;&quot;&gt;Welcome to openPilotLog!&lt;/span&gt;&lt;/p&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-size:14pt;&quot;&gt;The Free and Open Source Logbook application&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;If you would like to keep track of your license and/or medical expiration dates, you can enter them here. By default, only Take-Off and Landing currency is shown on the home page, but any other currency can also be shown as well. This can be enabled in the settings.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+         </property>
+         <property name="textFormat">
+          <enum>Qt::RichText</enum>
+         </property>
+         <property name="wordWrap">
+          <bool>true</bool>
+         </property>
+        </widget>
+       </item>
+       <item row="1" column="0">
+        <widget class="QLabel" name="dateFormatLabel">
+         <property name="text">
+          <string>Date Format</string>
+         </property>
+        </widget>
+       </item>
+       <item row="4" column="0" colspan="2">
+        <layout class="QHBoxLayout" name="horizontalLayout">
+         <item>
+          <widget class="QCheckBox" name="currWarningCheckBox">
            <property name="text">
-            <string>Line Check</string>
+            <string>Warn me about expiring currencies</string>
+           </property>
+           <property name="checked">
+            <bool>true</bool>
            </property>
           </widget>
          </item>
-         <item row="0" column="0">
-          <widget class="QLabel" name="currLicLabel">
-           <property name="minimumSize">
-            <size>
-             <width>280</width>
-             <height>0</height>
-            </size>
+         <item>
+          <widget class="QSpinBox" name="currWarningThresholdSpinBox">
+           <property name="maximum">
+            <number>365</number>
+           </property>
+           <property name="value">
+            <number>30</number>
            </property>
+          </widget>
+         </item>
+         <item>
+          <widget class="QLabel" name="label_3">
            <property name="text">
-            <string>Licence</string>
+            <string>days before expiry</string>
            </property>
           </widget>
          </item>
         </layout>
        </item>
+       <item row="2" column="0" colspan="2">
+        <widget class="Line" name="line">
+         <property name="orientation">
+          <enum>Qt::Horizontal</enum>
+         </property>
+        </widget>
+       </item>
       </layout>
      </widget>
      <widget class="QWidget" name="flightLoggingPage">

+ 26 - 15
src/gui/dialogues/newflightdialog.cpp

@@ -23,7 +23,7 @@
 #include "src/testing/atimer.h"
 #include "src/database/adatabase.h"
 #include "src/opl.h"
-
+#include "src/functions/adate.h"
 #include "src/functions/alog.h"
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -1032,26 +1032,37 @@ void NewFlightDialog::on_doftLineEdit_editingFinished()
     auto label = ui->doftDisplayLabel;
     DEB << line_edit->objectName() << "Editing finished - " << text;
 
-    auto date = QDate::fromString(text, Qt::ISODate);
+    TODO << "Implement other Date Formats";
+    Opl::Date::ADateFormat date_format = Opl::Date::ADateFormat::ISODate;
+    TODO << "Remove calendar or fix implementation... too hacky as it is";
+    auto date = ADate::formatInput(text, date_format);
     if (date.isValid()) {
         label->setText(date.toString(Qt::TextDate));
+        line_edit->setText(ADate::toString(date, date_format));
         onGoodInputReceived(line_edit);
         return;
     }
 
-    //try to correct input if only numbers are entered, eg 20200101
-    if(text.length() == 8) {
-        DEB << "Trying to fix input...";
-        text.insert(4,'-');
-        text.insert(7,'-');
-        date = QDate::fromString(text, Qt::ISODate);
-        if (date.isValid()) {
-            line_edit->setText(date.toString(Qt::ISODate));
-            label->setText(date.toString(Qt::TextDate));
-            onGoodInputReceived(line_edit);
-            return;
-        }
-    }
+    //auto date = QDate::fromString(text, Qt::ISODate);
+    //if (date.isValid()) {
+    //    label->setText(date.toString(Qt::TextDate));
+    //    onGoodInputReceived(line_edit);
+    //    return;
+    //}
+    //
+    ////try to correct input if only numbers are entered, eg 20200101
+    //if(text.length() == 8) {
+    //    DEB << "Trying to fix input...";
+    //    text.insert(4,'-');
+    //    text.insert(7,'-');
+    //    date = QDate::fromString(text, Qt::ISODate);
+    //    if (date.isValid()) {
+    //        line_edit->setText(date.toString(Qt::ISODate));
+    //        label->setText(date.toString(Qt::TextDate));
+    //        onGoodInputReceived(line_edit);
+    //        return;
+    //    }
+    //}
     label->setText("Invalid Date.");
     onBadInputReceived(line_edit);
 }

+ 14 - 2
src/gui/widgets/debugwidget.cpp

@@ -184,10 +184,22 @@ void DebugWidget::on_importCsvPushButton_clicked()
     }
 }
 
+#include "src/functions/adate.h"
 void DebugWidget::on_debugPushButton_clicked()
 {
-    WARN("Whoops, a warning!");
-    CRIT("Yikes, this doesn't look good... ");
+    QMap<QString, Opl::Date::ADateFormat> dates = {
+        {"2020-01-01", Opl::Date::ADateFormat::ISODate},
+        {"20200101", Opl::Date::ADateFormat::ISODate},
+        {"03.01.2020", Opl::Date::ADateFormat::DE},
+        {"03012020", Opl::Date::ADateFormat::DE},
+        {"01/04/2020", Opl::Date::ADateFormat::EN},
+        {"01042020", Opl::Date::ADateFormat::EN},
+        {"01", Opl::Date::ADateFormat::EN}
+    };
+    QMap<QString, Opl::Date::ADateFormat>::iterator i;
+    for (i = dates.begin(); i != dates.end(); i++) {
+        DEB << ADate::formatInput(i.key(), i.value());
+    }
 }
 
 /* //Comparing two functions template

+ 26 - 1
src/gui/widgets/settingswidget.cpp

@@ -23,6 +23,7 @@
 #include "src/database/adatabase.h"
 #include "src/classes/apilotentry.h"
 #include "src/opl.h"
+#include "src/functions/adate.h"
 
 static const auto FIRSTNAME_VALID = QPair<QString, QRegularExpression> {
     QStringLiteral("firstnameLineEdit"), QRegularExpression("[a-zA-Z]+")};
@@ -87,6 +88,19 @@ void SettingsWidget::setupComboBoxes(){
 
 void SettingsWidget::setupDateEdits()
 {
+    // Read Display Format Setting
+    int date_format_index = ASettings::read(ASettings::Main::DateFormat).toInt();
+    const QString date_format_string = ADate::getFormatString(
+                static_cast<Opl::Date::ADateFormat>(date_format_index));
+    // Set Up Date Format Combo Box
+    const QSignalBlocker blocker_date(ui->dateFormatComboBox);
+    for (const auto &date_format : ADate::getDisplayNames())
+        ui->dateFormatComboBox->addItem(date_format);
+    ui->dateFormatComboBox->setCurrentIndex(date_format_index);
+    for (const auto & date_edit : this->findChildren<QDateEdit*>()) {
+        date_edit->setDisplayFormat(date_format_string);
+    }
+    // Fill currencies
     const QList<QPair<ACurrencyEntry::CurrencyName, QDateEdit* >> currencies = {
         {ACurrencyEntry::CurrencyName::Licence,     ui->currLicDateEdit},
         {ACurrencyEntry::CurrencyName::TypeRating,  ui->currTrDateEdit},
@@ -204,7 +218,7 @@ void SettingsWidget::updatePersonalDetails()
         QString name;
         name.append(ui->lastnameLineEdit->text());
         name.append(QLatin1String(", "));
-        name.append(ui->firstnameLineEdit->text().left(1));
+        name.append(ui->firstnameLineEdit->text().leftRef(1));
         name.append(QLatin1Char('.'));
         user_data.insert(Opl::Db::PILOTS_ALIAS, name);
     }
@@ -675,3 +689,14 @@ void SettingsWidget::on_currCustom2LineEdit_editingFinished()
 {
     ASettings::write(ASettings::UserData::Custom2CurrencyName, ui->currCustom2LineEdit->text());
 }
+
+void SettingsWidget::on_dateFormatComboBox_currentIndexChanged(int index)
+{
+    ASettings::write(ASettings::Main::DateFormat, index);
+
+    for (const auto & date_edit : this->findChildren<QDateEdit*>()) {
+        date_edit->setDisplayFormat(
+                    ADate::getFormatString(
+                        static_cast<Opl::Date::ADateFormat>(ASettings::read(ASettings::Main::DateFormat).toInt())));
+    }
+}

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

@@ -109,6 +109,8 @@ private slots:
 
     void on_currCustom2LineEdit_editingFinished();
 
+    void on_dateFormatComboBox_currentIndexChanged(int index);
+
 private:
     Ui::SettingsWidget *ui;
 

+ 111 - 101
src/gui/widgets/settingswidget.ui

@@ -17,7 +17,7 @@
    <item row="0" column="0">
     <widget class="QTabWidget" name="tabWidget">
      <property name="currentIndex">
-      <number>3</number>
+      <number>1</number>
      </property>
      <widget class="QWidget" name="personalTab">
       <attribute name="title">
@@ -172,6 +172,16 @@
       </attribute>
       <layout class="QGridLayout" name="gridLayout_4">
        <item row="0" column="1">
+        <widget class="QLabel" name="dateFormatLabel">
+         <property name="text">
+          <string>Date Format</string>
+         </property>
+        </widget>
+       </item>
+       <item row="0" column="2">
+        <widget class="QComboBox" name="dateFormatComboBox"/>
+       </item>
+       <item row="1" column="1">
         <widget class="QLabel" name="aliasLabel">
          <property name="toolTip">
           <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;How your own name is displayed in your logbook&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
@@ -181,7 +191,7 @@
          </property>
         </widget>
        </item>
-       <item row="0" column="2">
+       <item row="1" column="2">
         <widget class="QComboBox" name="aliasComboBox">
          <item>
           <property name="text">
@@ -200,7 +210,7 @@
          </item>
         </widget>
        </item>
-       <item row="1" column="1">
+       <item row="2" column="1">
         <widget class="QLabel" name="functionLabel">
          <property name="toolTip">
           <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Default function for auto-logging&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
@@ -210,7 +220,7 @@
          </property>
         </widget>
        </item>
-       <item row="1" column="2">
+       <item row="2" column="2">
         <widget class="QComboBox" name="functionComboBox">
          <item>
           <property name="text">
@@ -234,7 +244,7 @@
          </item>
         </widget>
        </item>
-       <item row="2" column="1">
+       <item row="3" column="1">
         <widget class="QLabel" name="rulesLabel">
          <property name="toolTip">
           <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Default Flight Rules for auto-logging&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
@@ -244,7 +254,7 @@
          </property>
         </widget>
        </item>
-       <item row="2" column="2">
+       <item row="3" column="2">
         <widget class="QComboBox" name="rulesComboBox">
          <item>
           <property name="text">
@@ -258,7 +268,7 @@
          </item>
         </widget>
        </item>
-       <item row="3" column="0">
+       <item row="4" column="0">
         <spacer name="horizontalSpacer_3">
          <property name="orientation">
           <enum>Qt::Horizontal</enum>
@@ -271,7 +281,7 @@
          </property>
         </spacer>
        </item>
-       <item row="3" column="1">
+       <item row="4" column="1">
         <widget class="QLabel" name="approachLabel">
          <property name="toolTip">
           <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;The default approach for auto-logging&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
@@ -281,10 +291,10 @@
          </property>
         </widget>
        </item>
-       <item row="3" column="2">
+       <item row="4" column="2">
         <widget class="QComboBox" name="approachComboBox"/>
        </item>
-       <item row="3" column="3">
+       <item row="4" column="3">
         <spacer name="horizontalSpacer_4">
          <property name="orientation">
           <enum>Qt::Horizontal</enum>
@@ -297,7 +307,7 @@
          </property>
         </spacer>
        </item>
-       <item row="4" column="1">
+       <item row="5" column="1">
         <widget class="QLabel" name="nightLabel">
          <property name="toolTip">
           <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Determines how (if) night time is automatically calculated. &lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
@@ -310,7 +320,7 @@
          </property>
         </widget>
        </item>
-       <item row="4" column="2">
+       <item row="5" column="2">
         <widget class="QComboBox" name="nightComboBox">
          <property name="toolTip">
           <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;EASA: End of civil evening twilight until beginning of civil morning twilight&lt;/p&gt;&lt;p&gt;SR/SS: From sunrise to sunset.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
@@ -335,7 +345,7 @@
          </item>
         </widget>
        </item>
-       <item row="5" column="1">
+       <item row="6" column="1">
         <widget class="QLabel" name="prefixLabel">
          <property name="toolTip">
           <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Enter you airline Prefix to speed up logging of flight numbers&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
@@ -345,7 +355,7 @@
          </property>
         </widget>
        </item>
-       <item row="5" column="2">
+       <item row="6" column="2">
         <widget class="QLineEdit" name="prefixLineEdit">
          <property name="maxLength">
           <number>10</number>
@@ -887,53 +897,6 @@
        <string>Appearance</string>
       </attribute>
       <layout class="QGridLayout" name="gridLayout_5">
-       <item row="0" column="0">
-        <widget class="QLabel" name="styleLabel">
-         <property name="sizePolicy">
-          <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
-           <horstretch>0</horstretch>
-           <verstretch>0</verstretch>
-          </sizepolicy>
-         </property>
-         <property name="text">
-          <string>Style</string>
-         </property>
-        </widget>
-       </item>
-       <item row="0" column="1">
-        <widget class="QPushButton" name="resetStylePushButton">
-         <property name="text">
-          <string>Reset to Default</string>
-         </property>
-        </widget>
-       </item>
-       <item row="0" column="2">
-        <widget class="QComboBox" name="styleComboBox"/>
-       </item>
-       <item row="1" column="0">
-        <widget class="QLabel" name="fontLabel">
-         <property name="text">
-          <string>Font</string>
-         </property>
-        </widget>
-       </item>
-       <item row="1" column="1">
-        <widget class="QCheckBox" name="fontCheckBox">
-         <property name="text">
-          <string>Use System Font</string>
-         </property>
-         <property name="checked">
-          <bool>true</bool>
-         </property>
-        </widget>
-       </item>
-       <item row="1" column="2">
-        <widget class="QFontComboBox" name="fontComboBox">
-         <property name="enabled">
-          <bool>false</bool>
-         </property>
-        </widget>
-       </item>
        <item row="1" column="3">
         <widget class="QSpinBox" name="fontSpinBox">
          <property name="enabled">
@@ -956,6 +919,16 @@
          </property>
         </widget>
        </item>
+       <item row="1" column="1">
+        <widget class="QCheckBox" name="fontCheckBox">
+         <property name="text">
+          <string>Use System Font</string>
+         </property>
+         <property name="checked">
+          <bool>true</bool>
+         </property>
+        </widget>
+       </item>
        <item row="2" column="0">
         <widget class="QLabel" name="pilotSortLabel">
          <property name="sizePolicy">
@@ -975,6 +948,51 @@
          </property>
         </widget>
        </item>
+       <item row="3" column="0">
+        <widget class="QLabel" name="acftSortLabel">
+         <property name="sizePolicy">
+          <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
+           <horstretch>0</horstretch>
+           <verstretch>0</verstretch>
+          </sizepolicy>
+         </property>
+         <property name="toolTip">
+          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Determines by which column to sort the display of Aircaft in the Aircraft Tab.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+         </property>
+         <property name="whatsThis">
+          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Determines by which column to sort the display of Aircaft in the Aircraft Tab.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+         </property>
+         <property name="text">
+          <string>Sort Aircraft by</string>
+         </property>
+        </widget>
+       </item>
+       <item row="4" column="0">
+        <widget class="QLabel" name="acAllowIncompleteLabel">
+         <property name="sizePolicy">
+          <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
+           <horstretch>0</horstretch>
+           <verstretch>0</verstretch>
+          </sizepolicy>
+         </property>
+         <property name="toolTip">
+          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Determines whether incomplete database entries are permitted. It is highly recommended to keep this option off.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+         </property>
+         <property name="text">
+          <string>Allow incomplete Entries </string>
+         </property>
+        </widget>
+       </item>
+       <item row="0" column="2">
+        <widget class="QComboBox" name="styleComboBox"/>
+       </item>
+       <item row="1" column="2">
+        <widget class="QFontComboBox" name="fontComboBox">
+         <property name="enabled">
+          <bool>false</bool>
+         </property>
+        </widget>
+       </item>
        <item row="2" column="2">
         <widget class="QComboBox" name="pilotSortComboBox">
          <property name="toolTip">
@@ -997,8 +1015,28 @@
          </item>
         </widget>
        </item>
-       <item row="3" column="0">
-        <widget class="QLabel" name="acftSortLabel">
+       <item row="0" column="1">
+        <widget class="QPushButton" name="resetStylePushButton">
+         <property name="text">
+          <string>Reset to Default</string>
+         </property>
+        </widget>
+       </item>
+       <item row="0" column="0">
+        <widget class="QLabel" name="styleLabel">
+         <property name="sizePolicy">
+          <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
+           <horstretch>0</horstretch>
+           <verstretch>0</verstretch>
+          </sizepolicy>
+         </property>
+         <property name="text">
+          <string>Style</string>
+         </property>
+        </widget>
+       </item>
+       <item row="5" column="0">
+        <widget class="QLabel" name="logbookViewLabel">
          <property name="sizePolicy">
           <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
            <horstretch>0</horstretch>
@@ -1006,13 +1044,20 @@
           </sizepolicy>
          </property>
          <property name="toolTip">
-          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Determines by which column to sort the display of Aircaft in the Aircraft Tab.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Determines how your logbook is displayed in the logbook tab. This has no influence on what details are logged, just on what is displayed by default.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
          </property>
          <property name="whatsThis">
-          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Determines by which column to sort the display of Aircaft in the Aircraft Tab.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Determines how your logbook is displayed in the logbook tab. This has no influence on what details are logged, just on what is displayed by default.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
          </property>
          <property name="text">
-          <string>Sort Aircraft by</string>
+          <string>Logbook Dispay</string>
+         </property>
+        </widget>
+       </item>
+       <item row="1" column="0">
+        <widget class="QLabel" name="fontLabel">
+         <property name="text">
+          <string>Font</string>
          </property>
         </widget>
        </item>
@@ -1038,22 +1083,6 @@
          </item>
         </widget>
        </item>
-       <item row="4" column="0">
-        <widget class="QLabel" name="acAllowIncompleteLabel">
-         <property name="sizePolicy">
-          <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
-           <horstretch>0</horstretch>
-           <verstretch>0</verstretch>
-          </sizepolicy>
-         </property>
-         <property name="toolTip">
-          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Determines whether incomplete database entries are permitted. It is highly recommended to keep this option off.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
-         </property>
-         <property name="text">
-          <string>Allow incomplete Entries </string>
-         </property>
-        </widget>
-       </item>
        <item row="4" column="2">
         <widget class="QComboBox" name="acAllowIncompleteComboBox">
          <property name="toolTip">
@@ -1071,25 +1100,6 @@
          </item>
         </widget>
        </item>
-       <item row="5" column="0">
-        <widget class="QLabel" name="logbookViewLabel">
-         <property name="sizePolicy">
-          <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
-           <horstretch>0</horstretch>
-           <verstretch>0</verstretch>
-          </sizepolicy>
-         </property>
-         <property name="toolTip">
-          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Determines how your logbook is displayed in the logbook tab. This has no influence on what details are logged, just on what is displayed by default.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
-         </property>
-         <property name="whatsThis">
-          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Determines how your logbook is displayed in the logbook tab. This has no influence on what details are logged, just on what is displayed by default.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
-         </property>
-         <property name="text">
-          <string>Logbook Dispay</string>
-         </property>
-        </widget>
-       </item>
        <item row="5" column="2">
         <widget class="QComboBox" name="logbookViewComboBox">
          <property name="toolTip">

+ 4 - 1
src/opl.h

@@ -111,7 +111,10 @@ static const auto ApproachTypes = QStringList{
 
 namespace Date {
 
-enum DateFormat {Default, Text};
+/*!
+ * \brief ADateFormats enumerates the accepted date formats for QDateEdits
+ */
+enum class ADateFormat {ISODate, DE, EN };
 
 } // namespace opl::date