Browse Source

Cleaned up mandatoryLineEdit initialisation

George 4 years ago
parent
commit
f77e209ab6
2 changed files with 19 additions and 8 deletions
  1. 10 3
      src/gui/dialogues/newflightdialog.cpp
  2. 9 5
      src/gui/dialogues/newflightdialog.h

+ 10 - 3
src/gui/dialogues/newflightdialog.cpp

@@ -57,7 +57,15 @@ static const auto MANDATORY_LINE_EDITS_DISPLAY_NAMES = QMap<int, QString> {
 
 //
 // MandatoryLineEdits definition
-//
+// Ugly but works
+NewFlightDialog::MandatoryLineEdits::MandatoryLineEdits(std::initializer_list<QLineEdit*> il)
+    : lineEdits(il), lineEditsOk(il.size())
+{}
+void NewFlightDialog::MandatoryLineEdits::operator= (std::initializer_list<QLineEdit*> il)
+{
+    lineEdits = il;
+    lineEdits.resize(il.size());
+}
 bool NewFlightDialog::MandatoryLineEdits::contains(QLineEdit* le)
 {
     return lineEdits.contains(le);
@@ -290,7 +298,7 @@ void NewFlightDialog::setupRawInputValidation()
 
     // [G]: TODO cleanup
     // populate Mandatory Line Edits list and prepare QBitArray
-    mandatoryLineEdits.lineEdits = {
+    mandatoryLineEdits = {
         ui->doftLineEdit,
         ui->deptLocLineEdit,
         ui->destLocLineEdit,
@@ -299,7 +307,6 @@ void NewFlightDialog::setupRawInputValidation()
         ui->picNameLineEdit,
         ui->acftLineEdit,
     };
-    mandatoryLineEdits.lineEditsOk.resize(mandatoryLineEdits.lineEdits.size());
 
     primaryTimeLineEdits = {
         ui->tofbTimeLineEdit,

+ 9 - 5
src/gui/dialogues/newflightdialog.h

@@ -93,10 +93,18 @@ private:
     AFlightEntry flightEntry;
 
     // [G]: Initial refactoring based on previous use.
+    /*!
+     * \brief Wrapper around Vector of mandatory line edits and their corresponding
+     * "ok" QBitArray.
+     */
     struct MandatoryLineEdits {
         QVector<QLineEdit*> lineEdits;
         QBitArray lineEditsOk;
 
+        MandatoryLineEdits() = default;
+        MandatoryLineEdits(std::initializer_list<QLineEdit*> il);
+        void operator= (std::initializer_list<QLineEdit*> il);
+
         bool contains(QLineEdit* le);
         void validate(QLineEdit* le);
         void unvalidate(QLineEdit* le);
@@ -105,16 +113,12 @@ private:
         bool okAt(int idx);
         bool allOk();
         QLineEdit* operator[] (int idx);
+
     } mandatoryLineEdits;
 
     QList<QLineEdit*> primaryTimeLineEdits;
     QList<QLineEdit*> pilotsLineEdits;
 
-    /*!
-     * \brief holds a bit for each mandatory line edit that is flipped
-     * according to its validity state
-     */
-
     /*!
      * To be used by the QCompleters
      */