Selaa lähdekoodia

Bugfix in NewFlightDialog

Pressing the enter key in the NewFlightDialog triggers QDialog::accept - if the user presses enter when only few of the mandatory fields are filled, the input verification triggered by the call to accept() causes multiple pop-ups to show which are designed to give user feedback about specific fields if they are filled incorrectly. accept() now checks how many mandatory fields are missing and informs the user about those items before triggering input verification for all mandatory line edits.

Also added an emission of editing finished for the date line edit after it has been pre-populated with the current date.
Felix Turowsky 1 vuosi sitten
vanhempi
commit
4e28b25bb0

+ 31 - 19
src/gui/dialogues/newflightdialog.cpp

@@ -47,7 +47,7 @@ NewFlightDialog::NewFlightDialog(QWidget *parent)
     setPilotFunction();
 
     ui->doftLineEdit->setText(OPL::Date::today(m_format).toString());
-//    emit ui->doftLineEdit->editingFinished();
+   emit ui->doftLineEdit->editingFinished();
 }
 
 NewFlightDialog::NewFlightDialog(int row_id, QWidget *parent)
@@ -155,6 +155,9 @@ void NewFlightDialog::setupSignalsAndSlots()
 
     QObject::connect(calendar, &QCalendarWidget::selectionChanged,
                      this, &NewFlightDialog::calendarDateSelected);
+    QObject::connect(calendar, &QCalendarWidget::clicked,
+                     this, &NewFlightDialog::calendarDateSelected);
+
 }
 
 /*!
@@ -383,6 +386,24 @@ bool NewFlightDialog::userWantsToAddNewEntry(OPL::DbTable table)
     return reply == QMessageBox::Yes;
 }
 
+void NewFlightDialog::informUserAboutMissingItems()
+{
+    QString missing_items;
+    for (int i=0; i < mandatoryLineEdits->size(); i++) {
+        if (!validationState.validAt(i)){
+            missing_items.append(validationItemsDisplayNames.value(static_cast<ValidationState::ValidationItem>(i)) + QStringLiteral("<br>"));
+            mandatoryLineEdits->at(i)->setStyleSheet(OPL::CssStyles::RED_BORDER);
+        }
+    }
+
+    INFO(tr("Not all mandatory entries are valid.<br>"
+            "The following item(s) are empty or invalid:"
+            "<br><br><center><b>%1</b></center><br>"
+            "Please go back and fill in the required data."
+            ).arg(missing_items));
+    return;
+}
+
 /*!
  * \brief NewFlightDialog::prepareFlightEntryData reads the user input from the UI and converts it into
  * the database format.
@@ -747,29 +768,20 @@ bool NewFlightDialog::flightTimeIsZero()
  */
 void NewFlightDialog::on_buttonBox_accepted()
 {
-    // Debug
-    validationState.printValidationStatus();
+    // one item is always invalid if the user accepts when the currently edited line edit is mandatory (invalidation on focus in event)
+    if(!validationState.allButOneValid()) {
+        informUserAboutMissingItems();
+        return;
+    }
+    // trigger validation for all mandatory items to toggle verification state
     for (const auto& le : *mandatoryLineEdits)
         emit le->editingFinished();
-    // If input verification is passed, continue, otherwise prompt user to correct
     if (!validationState.allValid()) {
-
-        QString missing_items;
-        for (int i=0; i < mandatoryLineEdits->size(); i++) {
-            if (!validationState.validAt(i)){
-                missing_items.append(validationItemsDisplayNames.value(static_cast<ValidationState::ValidationItem>(i)) + "<br>");
-                mandatoryLineEdits->at(i)->setStyleSheet(OPL::CssStyles::RED_BORDER);
-            }
-        }
-
-        INFO(tr("Not all mandatory entries are valid.<br>"
-                "The following item(s) are empty or invalid:"
-                "<br><br><center><b>%1</b></center><br>"
-                "Please go back and fill in the required data."
-                ).arg(missing_items));
+        informUserAboutMissingItems();
         return;
     }
 
+    // run a couple of reasonableness checks
     if(pilotFunctionsInvalid())
         return;
     if(duplicateNamesPresent())
@@ -777,7 +789,7 @@ void NewFlightDialog::on_buttonBox_accepted()
     if(flightTimeIsZero())
         return;
 
-    // If input verification passed, collect input and submit to database
+    // collect input and submit to database
     const auto newData = prepareFlightEntryData();
     DEB << "Old Data: ";
     DEB << flightEntry;

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

@@ -177,6 +177,7 @@ private:
     bool userWantsToAddNewEntry(OPL::DbTable table);
 
 
+    void informUserAboutMissingItems();
     bool pilotFunctionsInvalid();
     bool duplicateNamesPresent();
     bool flightTimeIsZero();

+ 4 - 3
src/gui/verification/validationstate.h

@@ -18,11 +18,12 @@ public:
      */
     enum ValidationItem {doft = 0, dept = 1, dest = 2, tofb = 3, tonb = 4, pic = 5, acft = 6};
 
-    void validate(ValidationItem item)             { validationArray[item] = true;};
+    void validate(ValidationItem item)             { validationArray[item]  = true;};
     void validate(int index)                       { validationArray[index] = true;};
-    void invalidate(ValidationItem item)           { validationArray[item] = false;}
+    void invalidate(ValidationItem item)           { validationArray[item]  = false;}
     void invalidate(int index)                     { validationArray[index] = false;}
-    inline bool allValid() const                   { return validationArray.count(true) == 7;};
+    inline bool allValid() const                   { return validationArray.count(true) == 7; }
+    inline bool allButOneValid() const			   { return validationArray.count(false) < 2; }
     inline bool timesValid() const                 { return validationArray[ValidationItem::tofb] && validationArray[ValidationItem::tonb];}
     inline bool locationsValid() const             { return validationArray[ValidationItem::dept] && validationArray[ValidationItem::dest];}
     inline bool nightDataValid() const             { return timesValid() && locationsValid() && validationArray[ValidationItem::doft];}