Browse Source

bugfixes in NewFlight Dialog

fiffty-50 4 years ago
parent
commit
cd0b2ccc50
3 changed files with 139 additions and 71 deletions
  1. 99 57
      src/gui/dialogues/newflight.cpp
  2. 6 3
      src/gui/dialogues/newflight.h
  3. 34 11
      src/gui/dialogues/newflight.ui

+ 99 - 57
src/gui/dialogues/newflight.cpp

@@ -32,15 +32,6 @@ void NewFlight::on_verifyButton_clicked()//debug button
     collectBasicData();
     collectAdditionalData();
 }
-/*!
- * \brief NewFlight::nope for features that are not yet implemented
- */
-void NewFlight::nope()
-{
-    QMessageBox nope(this); //error box
-    nope.setText("This feature is not yet available!");
-    nope.exec();
-}
 
 
 static const auto IATA_RX = QLatin1String("[a-zA-Z0-9]{3}");
@@ -50,23 +41,24 @@ static const auto ADD_NAME_RX = QLatin1String("(\\s?(\\p{L}+('|\\-)?))?");
 static const auto SELF_RX = QLatin1String("(self|SELF)");
 
 /// Raw Input validation
-const auto TIME_VALID_RGX       = QRegularExpression("([01]?[0-9]|2[0-3]):?[0-5][0-9]?");// We only want to allow inputs that make sense as a time, e.g. 99:99 is not a valid time
-const auto LOC_VALID_RGX        = QRegularExpression(IATA_RX + "|" + ICAO_RX);
-const auto AIRCRAFT_VALID_RGX   = QRegularExpression("[A-Z0-9]+\\-?[A-Z0-9]+");
-const auto PILOT_NAME_VALID_RGX = QRegularExpression(SELF_RX + QLatin1Char('|')
+static const auto TIME_VALID_RGX       = QRegularExpression("([01]?[0-9]|2[0-3]):?[0-5][0-9]?");// We only want to allow inputs that make sense as a time, e.g. 99:99 is not a valid time
+static const auto LOC_VALID_RGX        = QRegularExpression(IATA_RX + "|" + ICAO_RX);
+static const auto AIRCRAFT_VALID_RGX   = QRegularExpression("[A-Z0-9]+\\-?[A-Z0-9]+");
+static const auto PILOT_NAME_VALID_RGX = QRegularExpression(SELF_RX + QLatin1Char('|')
                                                      + NAME_RX + ADD_NAME_RX + ADD_NAME_RX + ADD_NAME_RX + ",\\s?" // up to 4 first names
                                                      + NAME_RX + ADD_NAME_RX + ADD_NAME_RX + ADD_NAME_RX );// up to 4 last names
 
 /// Invalid characters (validators keep text even if it returns Invalid, see `onInputRejected` below)
-const auto TIME_INVALID_RGX       = QRegularExpression("[^0-9:]");
-const auto LOC_INVALID_RGX        = QRegularExpression("[^A-Z0-9]");
-const auto AIRCRAFT_INVALID_RGX   = QRegularExpression("[^a-zA-Z0-9\\-]");
-const auto PILOT_NAME_INVALID_RGX = QRegularExpression("[^\\p{L}|\\s|,]");
+static const auto TIME_INVALID_RGX       = QRegularExpression("[^0-9:]");
+static const auto LOC_INVALID_RGX        = QRegularExpression("[^A-Z0-9]");
+static const auto AIRCRAFT_INVALID_RGX   = QRegularExpression("[^a-zA-Z0-9\\-]");
+static const auto PILOT_NAME_INVALID_RGX = QRegularExpression("[^\\p{L}|\\s|,]");
+static const auto INVALID_CHARS_RGX      = QRegularExpression("[^\\p{L}|\\s|,|\\-|']");
 
 /// Sql columns
-const auto LOC_SQL_COL        = SqlColumnNum(1);  // TODO: locations are iata/icao so 1,2 merge columns in sql?
-const auto AIRCRAFT_SQL_COL   = SqlColumnNum(4);
-const auto PILOT_NAME_SQL_COL = SqlColumnNum(6);
+static const auto LOC_SQL_COL        = SqlColumnNum(1);  // TODO: locations are iata/icao so 1,2 merge columns in sql?
+static const auto AIRCRAFT_SQL_COL   = SqlColumnNum(4);
+static const auto PILOT_NAME_SQL_COL = SqlColumnNum(6);
 
 
 
@@ -89,7 +81,7 @@ NewFlight::NewFlight(QWidget *parent, Flight oldFlight, Db::editRole edRole) :
 {
     ui->setupUi(this);
     role=edRole;
-    oldEntry = oldFlight;
+    entry = oldFlight;
     setup();
     formFiller(oldFlight);
 }
@@ -180,17 +172,25 @@ void NewFlight::setup(){
     ui->acftLineEdit->setStyleSheet("border: 1px solid orange");
 
     readSettings();
+    ui->flightDataTabWidget->setCurrentIndex(0);
     ui->deptLocLineEdit->setFocus();
 }
 
 void NewFlight::formFiller(Flight oldFlight)
 {
     DEBUG("Filling Line Edits...");
+    QStringList filled;
     auto line_edits = parent()->findChildren<QLineEdit *>();
     QStringList line_edits_names;
     for(const auto& le : line_edits){
         line_edits_names << le->objectName();
     }
+    const QString& acft = Db::singleSelect("registration", "tails", "tail_id",
+                                    oldFlight.data.value("acft"),
+                                    Db::exactMatch);
+    ui->acftLineEdit->setText(acft);
+    line_edits_names.removeOne("acftLineEdit");
+
     for(const auto& key : oldFlight.data.keys()){
         auto rx = QRegularExpression(key + "LineEdit");//acftLineEdit
         for(const auto& leName : line_edits_names){
@@ -198,10 +198,9 @@ void NewFlight::formFiller(Flight oldFlight)
                 //DEBUG("Loc Match found: " << key << " - " << leName);
                 auto le = parent()->findChild<QLineEdit *>(leName);
                 if(le != nullptr){
-                    const QString& acft = Db::singleSelect("registration", "tails", "tail_id",
-                                                    oldFlight.data.value(key),
-                                                    Db::exactMatch);
-                    le->setText(acft);
+                    le->setText(oldFlight.data.value(key));
+                    filled << leName;
+                    line_edits_names.removeOne(leName);
                 }
                 break;
             }
@@ -213,6 +212,8 @@ void NewFlight::formFiller(Flight oldFlight)
                 auto le = parent()->findChild<QLineEdit *>(leName);
                 if(le != nullptr){
                     le->setText(oldFlight.data.value(key));
+                    filled << leName;
+                    line_edits_names.removeOne(leName);
                 }
                 break;
             }
@@ -225,6 +226,8 @@ void NewFlight::formFiller(Flight oldFlight)
                 if(le != nullptr){
                     le->setText(Calc::minutesToString(
                                 oldFlight.data.value(key)));
+                    filled << leName;
+                    line_edits_names.removeOne(leName);
                 }
                 break;
             }
@@ -240,6 +243,8 @@ void NewFlight::formFiller(Flight oldFlight)
                                                     oldFlight.data.value(key),
                                                     Db::exactMatch);
                     le->setText(name);
+                    filled << leName;
+                    line_edits_names.removeOne(leName);
                 }
                 break;
             }
@@ -248,6 +253,10 @@ void NewFlight::formFiller(Flight oldFlight)
     for(const auto& le : mandatoryLineEdits){
         emit le->editingFinished();
     }
+    DEBUG("Filled: ");
+    DEBUG(filled);
+    DEBUG("Unfilled: ");
+    DEBUG(line_edits_names);
 }
 
 /*
@@ -413,6 +422,12 @@ void NewFlight::collectBasicData()
         int tonb = timeOn.hour() * 60 + timeOn.minute();
         newData.insert("tonb",QString::number(tonb));
     }
+    //Block Time
+    auto tofb = QTime::fromString(ui->tofbTimeLineEdit->text(),"hh:mm");
+    auto tonb = QTime::fromString(ui->tonbTimeLineEdit->text(),"hh:mm");
+    QString blockTime = Calc::blocktime(tofb, tonb).toString("hh:mm");
+    QString blockMinutes = QString::number(Calc::stringToMinutes(blockTime));
+    newData.insert("tblk",blockMinutes);
 
     // Aircraft
     QString reg = ui->acftLineEdit->text();
@@ -598,7 +613,7 @@ void NewFlight::collectAdditionalData()
  */
 void NewFlight::fillExtras()
 {
-    //reset labels and line edits
+    //zero labels and line edits
     QList<QLineEdit*>   LE = {ui->tSPSETimeLineEdit, ui->tSPMETimeLineEdit, ui->tMPTimeLineEdit,    ui->tIFRTimeLineEdit,
                               ui->tNIGHTTimeLineEdit,ui->tPICTimeLineEdit,  ui->tPICUSTimeLineEdit, ui->tSICTimeLineEdit,
                               ui->tDualTimeLineEdit, ui->tFITimeLineEdit,};
@@ -717,37 +732,24 @@ void NewFlight::on_buttonBox_accepted()
         collectAdditionalData();
 
         switch (role) {
-        case Db::createNew: {
-            auto newEntry = Flight(newData);;
-            if(newEntry.commit()){
-                accept();
-            } else {
-                auto mb = new QMessageBox(this);
-                auto errorMsg = QString("Unable to commit Flight to Logbook."
-                                        "The following error has ocurred:\n\n");
-                errorMsg.append(newEntry.error);
-                mb->setText(errorMsg);
-                mb->show();
-            }
-        }
         case Db::editExisting:
-            oldEntry.setData(newData);
-            if(oldEntry.commit()){
-                accept();
-            }else{
-                auto mb = new QMessageBox(this);
-                auto errorMsg = QString("Unable to commit Flight to Logbook."
-                                        "The following error has ocurred:\n\n");
-                errorMsg.append(oldEntry.error);
-                mb->setText(errorMsg);
-                mb->show();
-            }
+            entry.setData(newData);
+            break;
+        case Db::createNew:
+            entry = Flight(newData);
             break;
         }
 
-
-
-
+        if(entry.commit()){
+            accept();
+        }else{
+            auto mb = new QMessageBox(this);
+            auto errorMsg = QString("Unable to commit Flight to Logbook."
+                                    "The following error has ocurred:\n\n");
+            errorMsg.append(entry.error);
+            mb->setText(errorMsg);
+            mb->show();
+        }
     }
 }
 
@@ -766,8 +768,13 @@ void NewFlight::onInputRejected(QLineEdit* line_edit, QRegularExpression rgx){
     line_edit->setStyleSheet("border: 1px solid red");
     this->allOkBits.setBit(this->lineEditBitMap[line_edit], false);
     auto text = line_edit->text();
-    if(rgx.match(text).hasMatch())
+    if(!rgx.match(text).hasMatch())
     {
+        DEBUG("1");
+        line_edit->setText(text);
+    }
+    if(INVALID_CHARS_RGX.match(text).hasMatch()){//remove globaly inacceptable chars
+        DEBUG("invalid char");
         text.chop(1);
         line_edit->setText(text);
     }
@@ -787,13 +794,15 @@ QStringList* NewFlight::getResult() { return &this->result; }
 
 void NewFlight::on_deptTZ_currentTextChanged(const QString &arg1)
 {
-    if(arg1 == "Local"){nope();}  // currently only UTC time logging is supported
+    DEBUG(arg1);
+    // currently only UTC time logging is supported
     ui->deptTZ->setCurrentIndex(0);
 }
 
 void NewFlight::on_destTZ_currentIndexChanged(const QString &arg1)
 {
-    if(arg1 == "Local"){nope();}  // currently only UTC time logging is supported
+    DEBUG(arg1);
+    // currently only UTC time logging is supported
     ui->destTZ->setCurrentIndex(0);
 }
 
@@ -1165,6 +1174,10 @@ inline bool NewFlight::isLessOrEqualToTotalTime(QString timeString)
 {
     if(newData.value("tblk").isEmpty()){
         DEBUG("Total Time not set.");
+        auto mb = new QMessageBox(this);
+        mb->setText("Please fill out Departure and Arrival Time\n"
+                    "before manually editing these times.");
+        mb->show();
         return false;
     } else {
         int minutes = Calc::stringToMinutes(timeString);
@@ -1172,7 +1185,9 @@ inline bool NewFlight::isLessOrEqualToTotalTime(QString timeString)
             return true;
         } else {
             auto mb = new QMessageBox(this);
-            mb->setText("Cannot be more than Total Time of Flight (" + Calc::minutesToString(newData.value("tblk")) + ')');
+            mb->setText("Cannot be more than Total Time of Flight:<br><br><center><b>"
+                        + Calc::minutesToString(newData.value("tblk"))
+                        + "</b></center><br>");
             mb->show();
             return false;
         }
@@ -1295,3 +1310,30 @@ void NewFlight::on_tFITimeLineEdit_editingFinished()
         le->setText(QString());
     }
 }
+
+
+void NewFlight::on_manualEditingCheckBox_stateChanged(int arg1)
+{
+    QList<QLineEdit*>   LE = {ui->tSPSETimeLineEdit, ui->tSPMETimeLineEdit, ui->tMPTimeLineEdit,    ui->tIFRTimeLineEdit,
+                              ui->tNIGHTTimeLineEdit,ui->tPICTimeLineEdit,  ui->tPICUSTimeLineEdit, ui->tSICTimeLineEdit,
+                              ui->tDualTimeLineEdit, ui->tFITimeLineEdit,};
+    switch (arg1) {
+    case 0:
+        for(const auto& le : LE){
+            le->setFocusPolicy(Qt::NoFocus);
+        }
+        break;
+    case 2:
+        for(const auto& le : LE){
+            le->setFocusPolicy(Qt::StrongFocus);
+        }
+        break;
+    default:
+        break;
+    }
+}
+
+void NewFlight::on_FunctionComboBox_currentTextChanged()
+{
+    update();
+}

+ 6 - 3
src/gui/dialogues/newflight.h

@@ -93,8 +93,6 @@ private:
 
     void setupLineEdit(QLineEdit* line_edit, LineEditSettings settings);
 
-    void nope();//error box
-
     void addNewPilotMessageBox();
 
     void readSettings();
@@ -172,12 +170,17 @@ private slots:
     void on_tFITimeLineEdit_editingFinished();
     void on_FlightNumberLineEdit_textChanged(const QString &arg1);
 
+
+    void on_manualEditingCheckBox_stateChanged(int arg1);
+
+    void on_FunctionComboBox_currentTextChanged();
+
 signals:
     void mandatoryFieldsValid(NewFlight* nf);
 
 private:
     Db::editRole role;
-    Flight oldEntry;
+    Flight entry;
     Ui::NewFlight *ui;
     QMap<QLineEdit*, int> lineEditBitMap;
     QVector<QLineEdit*> mandatoryLineEdits;

+ 34 - 11
src/gui/dialogues/newflight.ui

@@ -17,7 +17,7 @@
    <item row="0" column="0" colspan="3">
     <widget class="QTabWidget" name="flightDataTabWidget">
      <property name="currentIndex">
-      <number>0</number>
+      <number>1</number>
      </property>
      <widget class="QWidget" name="flightDataTab">
       <attribute name="title">
@@ -32,7 +32,7 @@
         </widget>
        </item>
        <item row="7" column="0">
-        <widget class="QLabel" name="picLabel_2">
+        <widget class="QLabel" name="secondPilotLabel">
          <property name="text">
           <string>Second Pilot</string>
          </property>
@@ -201,7 +201,7 @@
            <second>0</second>
            <year>2019</year>
            <month>12</month>
-           <day>5</day>
+           <day>4</day>
           </datetime>
          </property>
          <property name="displayFormat">
@@ -832,13 +832,6 @@
          </property>
         </widget>
        </item>
-       <item row="10" column="4">
-        <widget class="QLabel" name="label_3">
-         <property name="text">
-          <string/>
-         </property>
-        </widget>
-       </item>
       </layout>
      </widget>
      <widget class="QWidget" name="autoLoggingTab">
@@ -1122,7 +1115,7 @@
         </widget>
        </item>
        <item row="7" column="1">
-        <widget class="QCheckBox" name="checkBox">
+        <widget class="QCheckBox" name="manualEditingCheckBox">
          <property name="minimumSize">
           <size>
            <width>0</width>
@@ -1155,6 +1148,9 @@
            <height>20</height>
           </size>
          </property>
+         <property name="focusPolicy">
+          <enum>Qt::NoFocus</enum>
+         </property>
         </widget>
        </item>
        <item row="8" column="2">
@@ -1172,6 +1168,9 @@
            <height>20</height>
           </size>
          </property>
+         <property name="focusPolicy">
+          <enum>Qt::NoFocus</enum>
+         </property>
         </widget>
        </item>
        <item row="9" column="0">
@@ -1189,6 +1188,9 @@
            <height>20</height>
           </size>
          </property>
+         <property name="focusPolicy">
+          <enum>Qt::NoFocus</enum>
+         </property>
         </widget>
        </item>
        <item row="9" column="2">
@@ -1206,6 +1208,9 @@
            <height>20</height>
           </size>
          </property>
+         <property name="focusPolicy">
+          <enum>Qt::NoFocus</enum>
+         </property>
         </widget>
        </item>
        <item row="10" column="0">
@@ -1223,6 +1228,9 @@
            <height>20</height>
           </size>
          </property>
+         <property name="focusPolicy">
+          <enum>Qt::NoFocus</enum>
+         </property>
         </widget>
        </item>
        <item row="10" column="2">
@@ -1240,6 +1248,9 @@
            <height>20</height>
           </size>
          </property>
+         <property name="focusPolicy">
+          <enum>Qt::NoFocus</enum>
+         </property>
         </widget>
        </item>
        <item row="11" column="0">
@@ -1257,6 +1268,9 @@
            <height>20</height>
           </size>
          </property>
+         <property name="focusPolicy">
+          <enum>Qt::NoFocus</enum>
+         </property>
         </widget>
        </item>
        <item row="11" column="2">
@@ -1274,6 +1288,9 @@
            <height>20</height>
           </size>
          </property>
+         <property name="focusPolicy">
+          <enum>Qt::NoFocus</enum>
+         </property>
         </widget>
        </item>
        <item row="12" column="0">
@@ -1291,6 +1308,9 @@
            <height>20</height>
           </size>
          </property>
+         <property name="focusPolicy">
+          <enum>Qt::NoFocus</enum>
+         </property>
         </widget>
        </item>
        <item row="12" column="2">
@@ -1308,6 +1328,9 @@
            <height>20</height>
           </size>
          </property>
+         <property name="focusPolicy">
+          <enum>Qt::NoFocus</enum>
+         </property>
         </widget>
        </item>
       </layout>