Browse Source

Tweaked Calendar Widget

Simplified the calendar popup widget in the NewFlight Dialog.
- Is now available on demand instead of on Line Edit Entered
- simplified signal/slot/event filter setup
- removed settings associated with popup calendar
Felix Turo 3 years ago
parent
commit
866d70fcf2

+ 0 - 3
src/classes/asettings.cpp

@@ -56,13 +56,11 @@ QMap<ASettings::FlightLogging, QString> ASettings::flightLoggingMap = {
     {FlightLogging::FlightNumberPrefix, QStringLiteral("flightnumberPrefix")},
     {FlightLogging::NumberTakeoffs,     QStringLiteral("numberTakeoffs")},
     {FlightLogging::NumberLandings,     QStringLiteral("numberLandings")},
-    {FlightLogging::PopupCalendar,      QStringLiteral("popupCalendar")},
     {FlightLogging::PilotFlying,        QStringLiteral("pilotFlying")},
     {FlightLogging::NightAngle,         QStringLiteral("nightangle")},
     {FlightLogging::Rules,              QStringLiteral("rules")},
     {FlightLogging::FlightTimeFormat,   QStringLiteral("flightTimeFormat")},
     {FlightLogging::FunctionComboBox,   QStringLiteral("functionComboBox")},
-    {FlightLogging::CalendarCheckBox,   QStringLiteral("calendarCheckBox")},
 };
 
 void ASettings::setup()
@@ -95,7 +93,6 @@ void ASettings::resetToDefaults()
 
     write(FlightLogging::NumberTakeoffs, 1);
     write(FlightLogging::NumberLandings, 1);
-    write(FlightLogging::PopupCalendar, true);
     write(FlightLogging::PilotFlying, true);
     write(FlightLogging::NightAngle, -6);
 }

+ 0 - 2
src/classes/asettings.h

@@ -63,13 +63,11 @@ public:
         FlightNumberPrefix,
         NumberTakeoffs,
         NumberLandings,
-        PopupCalendar,
         PilotFlying,
         NightAngle,
         Rules,
         FlightTimeFormat,
         FunctionComboBox,
-        CalendarCheckBox,
     };
 
     /*!

File diff suppressed because it is too large
+ 393 - 367
src/gui/dialogues/newflight.ui


+ 30 - 139
src/gui/dialogues/newflightdialog.cpp

@@ -139,7 +139,7 @@ NewFlightDialog::NewFlightDialog(QWidget *parent) :
     setup();
     if (ASettings::read(ASettings::FlightLogging::FunctionComboBox).toString() == QLatin1String("SIC")) {
         ui->picNameLineEdit->setText(QString());
-        ui->secondPilotNameLineEdit->setText("self");
+        ui->secondPilotNameLineEdit->setText(QStringLiteral("self"));
     }
     if(ASettings::read(ASettings::FlightLogging::FunctionComboBox).toString() == QLatin1String("PIC")){
         ui->picNameLineEdit->setText(QStringLiteral("self"));
@@ -177,14 +177,8 @@ void NewFlightDialog::setup()
     setupSignalsAndSlots();
     readSettings();
 
-    // Visually mark mandatory fields
-    ui->deptLocLineEdit->setStyleSheet(QStringLiteral("border: 0.1ex solid #3daee9"));
-    ui->destLocLineEdit->setStyleSheet(QStringLiteral("border: 0.1ex solid #3daee9"));
-    ui->tofbTimeLineEdit->setStyleSheet(QStringLiteral("border: 0.1ex solid #3daee9"));
-    ui->tonbTimeLineEdit->setStyleSheet(QStringLiteral("border: 0.1ex solid #3daee9"));
-    ui->picNameLineEdit->setStyleSheet(QStringLiteral("border: 0.1ex solid #3daee9"));
-    ui->acftLineEdit->setStyleSheet(QStringLiteral("border: 0.1ex solid #3daee9"));
-
+    ui->flightDataTabWidget->setCurrentIndex(0);
+    ui->flightDataTabWidget->removeTab(2); // hide calendar widget
     ui->doftLineEdit->setText(QDate::currentDate().toString(Qt::ISODate));
     emit ui->doftLineEdit->editingFinished();
     ui->deptLocLineEdit->setFocus();
@@ -212,11 +206,10 @@ void NewFlightDialog::readSettings()
     }
 
     ui->FlightNumberLineEdit->setText(ASettings::read(ASettings::FlightLogging::FlightNumberPrefix).toString());
-    ui->calendarCheckBox->setChecked(ASettings::read(ASettings::FlightLogging::PopupCalendar).toBool());
 
     // Debug
     ASettings::write(ASettings::FlightLogging::FlightTimeFormat, Opl::Time::Default);
-    //[F]: Support for Decimal Logging is not implemented yet.
+    TODO << "Support for Decimal Logging is not implemented yet.";
     flightTimeFormat = static_cast<Opl::Time::FlightTimeFormat>(
                 ASettings::read(ASettings::FlightLogging::FlightTimeFormat).toInt());
 
@@ -233,7 +226,6 @@ void NewFlightDialog::writeSettings()
     ASettings::write(ASettings::FlightLogging::NumberTakeoffs, ui->TakeoffSpinBox->value());
     ASettings::write(ASettings::FlightLogging::NumberLandings, ui->LandingSpinBox->value());
     ASettings::write(ASettings::FlightLogging::LogIFR, ui->IfrCheckBox->isChecked());
-    ASettings::write(ASettings::FlightLogging::PopupCalendar, ui->calendarCheckBox->isChecked());
 }
 
 void NewFlightDialog::setupButtonGroups()
@@ -276,7 +268,7 @@ void NewFlightDialog::setupRawInputValidation()
         time_line_edit_settings
     };
     //get line edits, set up completers and validators
-    auto line_edits = ui->flightDataTab->findChildren<QLineEdit*>();
+    const auto line_edits = ui->flightDataTab->findChildren<QLineEdit*>();
 
     for (const auto &item : line_edit_settings) {
         for (const auto &line_edit : line_edits) {
@@ -295,7 +287,6 @@ void NewFlightDialog::setupRawInputValidation()
         }
     }
 
-    // [G]: TODO cleanup
     // populate Mandatory Line Edits list and prepare QBitArray
     mandatoryLineEdits = {
         ui->doftLineEdit,
@@ -321,7 +312,7 @@ void NewFlightDialog::setupRawInputValidation()
 
 void NewFlightDialog::setupSignalsAndSlots()
 {
-    auto line_edits = this->findChildren<QLineEdit*>();
+    const auto line_edits = this->findChildren<QLineEdit*>();
 
     for (const auto &line_edit : line_edits){
         line_edit->installEventFilter(this);
@@ -352,43 +343,12 @@ void NewFlightDialog::setupSignalsAndSlots()
                          this, &NewFlightDialog::onCompleter_activated);
     }
 #endif
-}
-
-
-void NewFlightDialog::setPopUpCalendarEnabled(bool state)
-{
-    ui->flightDataTabWidget->setCurrentIndex(0);
-    ui->flightDataTabWidget->removeTab(2); // hide calendar widget
-
-    if (state) {
-        DEB << "Enabling pop-up calendar widget...";
-        ui->calendarWidget->installEventFilter(this);
-        ui->placeLabel1->installEventFilter(this);
-        ui->doftLineEdit->installEventFilter(this);
-
-        QObject::connect(ui->calendarWidget, &QCalendarWidget::clicked,
-                         this, &NewFlightDialog::onCalendarWidget_clicked);
-        QObject::connect(ui->calendarWidget, &QCalendarWidget::activated,
-                         this, &NewFlightDialog::onCalendarWidget_selected);
-    } else {
-        DEB << "Disabling pop-up calendar widget...";
-        ui->calendarWidget->removeEventFilter(this);
-        ui->placeLabel1->removeEventFilter(this);
-        ui->doftLineEdit->removeEventFilter(this);
-        QObject::disconnect(ui->calendarWidget, &QCalendarWidget::clicked,
-                            this, &NewFlightDialog::onCalendarWidget_clicked);
-        QObject::disconnect(ui->calendarWidget, &QCalendarWidget::activated,
-                            this, &NewFlightDialog::onCalendarWidget_selected);
-    }
+    QObject::connect(ui->calendarWidget, &QCalendarWidget::clicked,
+                     this, &NewFlightDialog::onCalendarWidget_clicked);
 }
 
 bool NewFlightDialog::eventFilter(QObject* object, QEvent* event)
 {
-    if (object == ui->doftLineEdit && event->type() == QEvent::MouseButtonPress) {
-        onDoftLineEdit_entered();
-        return false; // let the event continue to the edit
-    }
-
     auto line_edit = qobject_cast<QLineEdit*>(object);
     if (line_edit != nullptr) {
         if (mandatoryLineEdits.contains(line_edit) && event->type() == QEvent::FocusIn) {
@@ -406,7 +366,7 @@ bool NewFlightDialog::eventFilter(QObject* object, QEvent* event)
             }
             return false;
         }
-        if (line_edit->objectName().contains("Name") && event->type() == QEvent::KeyPress) {
+        if (line_edit->objectName().contains(QStringLiteral("Name")) && event->type() == QEvent::KeyPress) {
             // show completion menu when pressing down arrow
             QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
             if (keyEvent->key() == Qt::Key_Down) {
@@ -452,7 +412,6 @@ void NewFlightDialog::fillDeductibleData()
     if (acft.getData().isEmpty())
         DEB << "Error: No valid aircraft object available, unable to deterime auto times.";
 
-
     // SP SE
     if(acft.getData().value(Opl::Db::TAILS_MULTIPILOT).toInt() == 0
             && acft.getData().value(Opl::Db::TAILS_MULTIENGINE).toInt() == 0){
@@ -671,7 +630,6 @@ RowData_T NewFlightDialog::collectInput()
     newData.insert(Opl::Db::FLIGHTS_APPROACHTYPE, ui->ApproachComboBox->currentText());
     newData.insert(Opl::Db::FLIGHTS_FLIGHTNUMBER, ui->FlightNumberLineEdit->text());
     newData.insert(Opl::Db::FLIGHTS_REMARKS, ui->RemarksLineEdit->text());
-
     DEB << "New Flight Data: " << newData;
 
     return newData;
@@ -681,7 +639,7 @@ void NewFlightDialog::formFiller()
 {
     DEB << "Filling Line Edits...";
     // get Line Edits
-    auto line_edits = this->findChildren<QLineEdit *>();
+    const auto line_edits = this->findChildren<QLineEdit *>();
     QStringList line_edits_names;
     for (const auto& le : line_edits) {
         line_edits_names << le->objectName();
@@ -690,7 +648,8 @@ void NewFlightDialog::formFiller()
     ui->acftLineEdit->setText(flightEntry.getRegistration());
     line_edits_names.removeOne(QStringLiteral("acftLineEdit"));
 
-    for (const auto& data_key : flightEntry.getData().keys()) {
+    const auto data_keys = flightEntry.getData().keys();
+    for (const auto& data_key : data_keys) {
         auto rx = QRegularExpression(data_key + QStringLiteral("LineEdit"));//acftLineEdit
         for(const auto& leName : qAsConst(line_edits_names)){
             if(rx.match(leName).hasMatch())  {
@@ -806,11 +765,9 @@ void NewFlightDialog::formFiller()
 bool NewFlightDialog::isLessOrEqualThanBlockTime(const QString time_string)
 {
     if (!mandatoryLineEdits.allValid()){
-        QMessageBox message_box(this);
-        message_box.setText(tr("Unable to determine total block time.<br>"
+        INFO(tr("Unable to determine total block time.<br>"
                                "Please fill out all Mandatory Fields<br>"
                                "before manually editing these times."));
-        message_box.exec();
         return false;
     }
 
@@ -822,12 +779,9 @@ bool NewFlightDialog::isLessOrEqualThanBlockTime(const QString time_string)
     if (extra_time <= block_time) {
         return true;
     } else {
-        QMessageBox message_box(this);
-        message_box.setWindowTitle(tr("Error"));
-        message_box.setText(tr("The flight time you have entered is longer than the total blocktime:"
+        WARN(tr("The flight time you have entered is longer than the total blocktime:"
                                "<br><center><b>%1</b></center>"
                                ).arg(ATime::toString(block_time, flightTimeFormat)));
-        message_box.exec();
         return false;
     }
 }
@@ -919,13 +873,11 @@ void NewFlightDialog::on_submitButton_clicked()
             }
         }
 
-        QMessageBox message_box(this);
-        message_box.setText(tr("Not all mandatory entries are valid.<br>"
-                               "The following item(s) are empty or missing:"
-                               "<br><br><center><b>%1</b></center><br>"
-                               "Please go back and fill in the required data."
-                               ).arg(missing_items));
-        message_box.exec();
+        INFO(tr("Not all mandatory entries are valid.<br>"
+                "The following item(s) are empty or missing:"
+                "<br><br><center><b>%1</b></center><br>"
+                "Please go back and fill in the required data."
+                ).arg(missing_items));
         return;
     }
 
@@ -935,13 +887,10 @@ void NewFlightDialog::on_submitButton_clicked()
     flightEntry.setData(newData);
     DEB << "Committing...";
     if (!aDB->commit(flightEntry)) {
-        QMessageBox message_box(this);
-        message_box.setText(tr("The following error has ocurred:"
+        WARN(tr("The following error has ocurred:"
                                "<br><br>%1<br><br>"
                                "The entry has not been saved."
                                ).arg(aDB->lastError.text()));
-        message_box.setIcon(QMessageBox::Warning);
-        message_box.exec();
         return;
     } else {
         QDialog::accept();
@@ -995,7 +944,6 @@ void NewFlightDialog::onToUpperTriggered_textChanged(const QString &text)
 void NewFlightDialog::onMandatoryLineEditsFilled()
 {
     if (!mandatoryLineEdits.allValid()) {
-        DEB << "erroneously called.";
         return;
     };
 
@@ -1026,7 +974,7 @@ void NewFlightDialog::onCompleter_activated(const QString &)
  */
 
 void NewFlightDialog::on_doftLineEdit_editingFinished()
-{
+{    
     auto line_edit = ui->doftLineEdit;
     auto text = ui->doftLineEdit->text();
     auto label = ui->doftDisplayLabel;
@@ -1034,7 +982,6 @@ void NewFlightDialog::on_doftLineEdit_editingFinished()
 
     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));
@@ -1043,27 +990,7 @@ void NewFlightDialog::on_doftLineEdit_editingFinished()
         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.");
+    label->setText(tr("Invalid Date."));
     onBadInputReceived(line_edit);
 }
 
@@ -1074,21 +1001,10 @@ void NewFlightDialog::onCalendarWidget_clicked(const QDate &date)
     ui->calendarWidget->hide();
     ui->placeLabel1->resize(ui->placeLabel2->size());
     le->setText(date.toString(Qt::ISODate));
-    le->setFocus();
+    emit le->editingFinished();
 }
 
-void NewFlightDialog::onCalendarWidget_selected(const QDate &date)
-{
-    ui->calendarWidget->hide();
-    ui->placeLabel1->resize(ui->placeLabel2->size());
-    ui->doftDisplayLabel->setText(date.toString(Qt::TextDate));
-    const auto& le = ui->doftLineEdit;
-    le->setText(date.toString(Qt::ISODate));
-    le->setFocus();
-    le->blockSignals(false);
-}
-
-void NewFlightDialog::onDoftLineEdit_entered()
+void NewFlightDialog::on_calendarPushButton_clicked()
 {
     const auto& cw = ui->calendarWidget;
     const auto& le = ui->doftLineEdit;
@@ -1119,22 +1035,6 @@ void NewFlightDialog::onDoftLineEdit_entered()
     }
 }
 
-void NewFlightDialog::on_calendarCheckBox_stateChanged(int arg1)
-{
-    ASettings::write(ASettings::FlightLogging::CalendarCheckBox, ui->calendarCheckBox->isChecked());
-    DEB << "Calendar check box state changed.";
-    switch (arg1) {
-    case 0: // unchecked
-        setPopUpCalendarEnabled(false);
-        break;
-    case 2: // checked
-        setPopUpCalendarEnabled(true);
-        break;
-    default:
-        break;
-    }
-}
-
 /*
  * Location Line Edits
  */
@@ -1316,10 +1216,8 @@ void NewFlightDialog::on_IfrCheckBox_stateChanged(int)
 void NewFlightDialog::on_manualEditingCheckBox_stateChanged(int arg1)
 {
     if (!(mandatoryLineEdits.allValid()) && ui->manualEditingCheckBox->isChecked()) {
-        QMessageBox message_box(this);
-        message_box.setText(tr("Before editing times manually, please fill out the required fields "
-                               "in the flight data tab, so that total time can be calculated."));
-        message_box.exec();
+        INFO(tr("Before editing times manually, please fill out the required fields "
+                "in the flight data tab, so that total time can be calculated."));
         ui->manualEditingCheckBox->setChecked(false);
         return;
     }
@@ -1330,7 +1228,7 @@ void NewFlightDialog::on_manualEditingCheckBox_stateChanged(int arg1)
     case 0:
         for(const auto& le : LE){
             le->setFocusPolicy(Qt::NoFocus);
-            le->setStyleSheet("");
+            le->setStyleSheet(QString());
         }
         updateEnabled = true;
         if (mandatoryLineEdits.allValid() && updateEnabled)
@@ -1361,9 +1259,7 @@ void NewFlightDialog::on_ApproachComboBox_currentTextChanged(const QString &arg1
         ui->IfrCheckBox->setChecked(true);
 
     if (arg1 == QLatin1String("OTHER")) {
-        QMessageBox message_box(this);
-        message_box.setText(tr("You can specify the approach type in the Remarks field."));
-        message_box.exec();
+        INFO(tr("You can specify the approach type in the Remarks field."));
     }
 }
 
@@ -1373,14 +1269,11 @@ void NewFlightDialog::on_FunctionComboBox_currentIndexChanged(int)
         fillDeductibleData();
 }
 
-
 // [F]: Not a priority right now.
 void NewFlightDialog::on_deptTZComboBox_currentIndexChanged(int index)
 {
     if (index > 0) {
-        QMessageBox message_box(this);
-        message_box.setText(tr("Currently only logging in UTC time is supported."));
-        message_box.exec();
+        INFO(tr("Currently only logging in UTC time is supported."));
         ui->deptTZComboBox->setCurrentIndex(0);
     }
 }
@@ -1388,8 +1281,6 @@ void NewFlightDialog::on_deptTZComboBox_currentIndexChanged(int index)
 void NewFlightDialog::on_destTZComboBox_currentIndexChanged(int index)
 {
     if (index > 0) {
-        QMessageBox message_box(this);
-        message_box.setText(tr("Currently only logging in UTC time is supported."));
-        message_box.exec();
+        INFO(tr("Currently only logging in UTC time is supported."));
         ui->destTZComboBox->setCurrentIndex(0);}
 }

+ 2 - 4
src/gui/dialogues/newflightdialog.h

@@ -65,9 +65,6 @@ private slots:
     void onCompleter_highlighted(const QString&);
     void onCompleter_activated(const QString &);
     void onCalendarWidget_clicked(const QDate &date);
-    void onCalendarWidget_selected(const QDate &date);
-    void onDoftLineEdit_entered();
-    void on_calendarCheckBox_stateChanged(int arg1);
     void on_doftLineEdit_editingFinished();
     void on_cancelButton_clicked();
     void on_submitButton_clicked();
@@ -84,6 +81,8 @@ private slots:
     void on_deptTZComboBox_currentIndexChanged(int index);
     void on_destTZComboBox_currentIndexChanged(int index);
 
+    void on_calendarPushButton_clicked();
+
 private:
     Ui::NewFlight *ui;
 
@@ -149,7 +148,6 @@ private:
     void readSettings();
     void writeSettings();
     void setupButtonGroups();
-    void setPopUpCalendarEnabled(bool state);
     void setupRawInputValidation();
     void setupSignalsAndSlots();
     void formFiller();

Some files were not shown because too many files changed in this diff