瀏覽代碼

refactoring of variables

fiffty-50 4 年之前
父節點
當前提交
2212a96b0a
共有 3 個文件被更改,包括 64 次插入13 次删除
  1. 52 7
      src/gui/dialogues/newflight.cpp
  2. 9 3
      src/gui/dialogues/newflight.ui
  3. 3 3
      src/gui/dialogues/newpilot.cpp

+ 52 - 7
src/gui/dialogues/newflight.cpp

@@ -45,7 +45,8 @@ void NewFlight::nope()
 
 static const auto IATA = QLatin1String("[a-zA-Z0-9]{3}");
 static const auto ICAO = QLatin1String("[a-zA-Z0-9]{4}");
-static const auto name = QLatin1String("(\\p{L}+(\\s|'|\\-)?\\s?(\\p{L}+)?\\s?)");
+static const auto name_rx = QLatin1String("(\\p{L}+('|\\-)?)");//(\\p{L}+(\\s|'|\\-)?\\s?(\\p{L}+)?\\s?)
+static const auto name_add_rx = QLatin1String("\\s?(\\p{L}+('|\\-)?)");
 static const auto self = QLatin1String("(self|SELF)");
 
 /// Raw Input validation
@@ -53,8 +54,8 @@ const auto TIME_VALID_RGX       = QRegularExpression("([01]?[0-9]|2[0-3]):?[0-5]
 const auto LOC_VALID_RGX        = QRegularExpression(IATA + "|" + ICAO);
 const auto AIRCRAFT_VALID_RGX   = QRegularExpression("[A-Z0-9]+-?[A-Z0-9]+");
 const auto PILOT_NAME_VALID_RGX = QRegularExpression(self + QLatin1Char('|')
-                                                     + name + name + name + name + ",\\s+" // up to 4 first names
-                                                     + name + name + name + name);// up to 4 last names
+                                                     + name_rx + name_add_rx + ",\\s+" // up to 4 first names
+                                                     + name_rx + name_add_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:]");
@@ -163,8 +164,6 @@ void NewFlight::setup(){
     PilotTaskGroup->addButton(ui->PilotFlyingCheckBox);
     PilotTaskGroup->addButton(ui->PilotMonitoringCheckBox);
 
-    ui->deptTZ->setFocusPolicy(Qt::NoFocus);
-    ui->destTZ->setFocusPolicy(Qt::NoFocus);
     //set date for new object
     auto date = QDate::currentDate();
     ui->newDoft->setDate(date);
@@ -184,16 +183,62 @@ void NewFlight::setup(){
 
 void NewFlight::formFiller(Flight oldFlight)
 {
+    DEBUG("Filling Line Edits...");
     auto line_edits = parent()->findChildren<QLineEdit *>();
     QStringList line_edits_names;
     for(const auto& le : line_edits){
         line_edits_names << le->objectName();
     }
     for(const auto& key : oldFlight.data.keys()){
-        auto rx = QRegularExpression(key + "\\w+?");
+        auto rx = QRegularExpression(key + "LineEdit");//acftLineEdit
         for(const auto& leName : line_edits_names){
             if(rx.match(leName).hasMatch())  {
-                DEBUG("Match found: " << key << " - " << rx.match(leName).captured(0));
+                //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);
+                }
+                break;
+            }
+        }
+        rx = QRegularExpression(key + "Loc\\w+?");
+        for(const auto& leName : line_edits_names){
+            if(rx.match(leName).hasMatch())  {
+                //DEBUG("Loc Match found: " << key << " - " << leName);
+                auto le = parent()->findChild<QLineEdit *>(leName);
+                if(le != nullptr){
+                    le->setText(oldFlight.data.value(key));
+                }
+                break;
+            }
+        }
+        rx = QRegularExpression(key + "Time\\w+?");
+        for(const auto& leName : line_edits_names){
+            if(rx.match(leName).hasMatch())  {
+                //DEBUG("Time Match found: " << key << " - " << leName);
+                auto le = parent()->findChild<QLineEdit *>(leName);
+                if(le != nullptr){
+                    le->setText(Calc::minutesToString(
+                                oldFlight.data.value(key)));
+                }
+                break;
+            }
+        }
+        rx = QRegularExpression(key + "Name\\w+?");
+        for(const auto& leName : line_edits_names){
+            if(rx.match(leName).hasMatch())  {
+                //DEBUG("Time Match found: " << key << " - " << leName);
+                auto le = parent()->findChild<QLineEdit *>(leName);
+                if(le != nullptr){
+                    const QString& column = "piclastname||', '||picfirstname";
+                    const QString& name = Db::singleSelect(column, "pilots", "pilot_id",
+                                                    oldFlight.data.value(key),
+                                                    Db::exactMatch);
+                    le->setText(name);
+                }
                 break;
             }
         }

+ 9 - 3
src/gui/dialogues/newflight.ui

@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>588</width>
-    <height>708</height>
+    <width>719</width>
+    <height>816</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -229,7 +229,7 @@
            <second>0</second>
            <year>2019</year>
            <month>12</month>
-           <day>6</day>
+           <day>5</day>
           </datetime>
          </property>
          <property name="displayFormat">
@@ -298,6 +298,9 @@
        </item>
        <item row="1" column="3">
         <widget class="QComboBox" name="deptTZ">
+         <property name="focusPolicy">
+          <enum>Qt::NoFocus</enum>
+         </property>
          <property name="toolTip">
           <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;UTC - Universal Time Coordinated&lt;/p&gt;&lt;p&gt;LOCAL - Local time at Airfield&lt;/p&gt;&lt;p&gt;BASE - Local time at Home Base&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
          </property>
@@ -315,6 +318,9 @@
        </item>
        <item row="4" column="3">
         <widget class="QComboBox" name="destTZ">
+         <property name="focusPolicy">
+          <enum>Qt::NoFocus</enum>
+         </property>
          <property name="toolTip">
           <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;UTC - Universal Time Coordinated&lt;/p&gt;&lt;p&gt;LOCAL - Local time at Airfield&lt;/p&gt;&lt;p&gt;BASE - Local time at Home Base&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
          </property>

+ 3 - 3
src/gui/dialogues/newpilot.cpp

@@ -35,11 +35,11 @@
  * Mathias d'Arras
  * Martin Luther King, Jr.
  */
-static const auto name = QLatin1String("(\\p{L}+(\\s|'|\\-)?\\s?(\\p{L}+)?\\s?)");
+static const auto NAME_RX = QLatin1String("(\\p{L}+(\\s|'|\\-)?\\s?(\\p{L}+)?\\s?)");
 static const auto FIRSTNAME_VALID = QPair<QString, QRegularExpression> {
-    "picfirstnameLineEdit", QRegularExpression(name + name + name)};
+    "picfirstnameLineEdit", QRegularExpression(NAME_RX + NAME_RX + NAME_RX)};
 static const auto LASTNAME_VALID = QPair<QString, QRegularExpression> {
-    "piclastnameLineEdit", QRegularExpression(name + name + name)};
+    "piclastnameLineEdit", QRegularExpression(NAME_RX + NAME_RX + NAME_RX)};
 static const auto PHONE_VALID = QPair<QString, QRegularExpression> {
     "phoneLineEdit", QRegularExpression("^[+]{0,1}[0-9\\-\\s]+")};
 static const auto EMAIL_VALID = QPair<QString, QRegularExpression> {