openPilotLog
newflightdialog.h
1 /*
2  *openPilotLog - A FOSS Pilot Logbook Application
3  *Copyright (C) 2020-2022 Felix Turowsky
4  *
5  *This program is free software: you can redistribute it and/or modify
6  *it under the terms of the GNU General Public License as published by
7  *the Free Software Foundation, either version 3 of the License, or
8  *(at your option) any later version.
9  *
10  *This program is distributed in the hope that it will be useful,
11  *but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  *GNU General Public License for more details.
14  *
15  *You should have received a copy of the GNU General Public License
16  *along with this program. If not, see <https://www.gnu.org/licenses/>.
17  */
18 #ifndef NewFlightDialog_H
19 #define NewFlightDialog_H
20 
21 #include <QDialog>
22 #include <QDebug>
23 #include <QLineEdit>
24 #include <QList>
25 #include <QBitArray>
26 
27 #include "src/functions/time.h"
28 #include "src/database/database.h"
29 #include "src/database/dbcompletiondata.h"
30 #include "src/opl.h"
31 #include "src/database/row.h"
32 
33 
34 
41 public:
42  ValidationState() = default;
43 
48  enum ValidationItem {doft = 0, dept = 1, dest = 2, tofb = 3, tonb = 4, pic = 5, acft = 6};
49 
50  void validate(ValidationItem item) { validationArray[item] = true;};
51  void validate(int index) { validationArray[index] = true;};
52  void invalidate(ValidationItem item) { validationArray[item] = false;}
53  void invalidate(int index) { validationArray[index] = false;}
54  inline bool allValid() const { return validationArray.count(true) == 7;};
55  inline bool timesValid() const { return validationArray[ValidationItem::tofb] && validationArray[ValidationItem::tonb];}
56  inline bool locationsValid() const { return validationArray[ValidationItem::dept] && validationArray[ValidationItem::dest];}
57  inline bool nightDataValid() const { return timesValid() && locationsValid() && validationArray[ValidationItem::doft];}
58  inline bool acftValid() const { return validationArray[ValidationItem::acft];}
59  inline bool validAt(int index) const { return validationArray[index];}
60  inline bool validAt(ValidationItem item) const { return validationArray[item];}
61 
62  // Debug
63  void printValidationStatus() const {
64  QString deb_string("\033[mValidation State:\tdoft\tdept\tdest\ttofb\ttonb\tpic\tacft\n");
65  deb_string += "\t\t\t\t";
66  for (int i = 0; i < 7; i++) { //\033[32m
67  if (validationArray[i])
68  deb_string += "\t\033[32m" + QString::number(validationArray[i]);
69  else
70  deb_string += "\t\033[31m" + QString::number(validationArray[i]);
71  }
72  deb_string += QLatin1String("\u001b[38;5;75m"); // return to default DEB
73  qDebug().noquote() << deb_string;
74  }
75 private:
76  QBitArray validationArray = QBitArray(7);
77 };
78 
79 namespace Ui {
80 class NewFlightDialog;
81 }
107 class NewFlightDialog : public QDialog
108 {
109  Q_OBJECT
110 
111 public:
112 
117  explicit NewFlightDialog(OPL::DbCompletionData& completion_data, QWidget *parent = nullptr);
123  explicit NewFlightDialog(OPL::DbCompletionData& completion_data, int row_id, QWidget* parent = nullptr);
124  ~NewFlightDialog();
125 
126 private:
127  Ui::NewFlightDialog *ui;
128  OPL::DbCompletionData completionData;
129  ValidationState validationState;
130 
136  OPL::FlightEntry flightEntry;
137 
141  static const inline QList<QLineEdit*>* timeLineEdits;
145  static const inline QList<QLineEdit*>* locationLineEdits;
149  static const inline QList<QLineEdit*>* pilotNameLineEdits;
154  static const inline QList<QLineEdit*>* mandatoryLineEdits;
155  static const inline QLatin1String self = QLatin1String("self");
156 
157  void init();
158  void setupRawInputValidation();
159  void setupSignalsAndSlots();
160  void readSettings();
161  void fillWithEntryData();
162 
168  void onGoodInputReceived(QLineEdit *line_edit);
174  void onBadInputReceived(QLineEdit *line_edit);
175 
176  void updateBlockTimeLabel();
177  void updateNightCheckBoxes();
178  void setNightCheckboxes();
179 
180  bool addNewTail(QLineEdit& parent_line_edit);
181  bool addNewPilot(QLineEdit& parent_line_edit);
182 
183 
184  bool checkPilotFunctionsValid();
185  OPL::RowData_T prepareFlightEntryData();
186 
187 
188 private slots:
189  void toUpper(const QString& text);
190  void onTimeLineEdit_editingFinished();
191  void onPilotNameLineEdit_editingFinshed();
192  void onLocationLineEdit_editingFinished();
193  void on_acftLineEdit_editingFinished();
194  void on_doftLineEdit_editingFinished();
195  void on_buttonBox_accepted();
196  void on_pilotFlyingCheckBox_stateChanged(int arg1);
197  void on_approachComboBox_currentTextChanged(const QString &arg1);
198  void on_functionComboBox_currentIndexChanged(int index);
199 
200 protected:
201  bool eventFilter(QObject* object, QEvent* event) override;
202 };
203 
204 
205 #endif // NewFlightDialog_H
The NewFlightDialog is used to add or edit entries from the flights table in the database.
Definition: newflightdialog.h:108
bool eventFilter(QObject *object, QEvent *event) override
NewFlightDialog::eventFilter invalidates mandatory line edits on focus in.
Definition: newflightdialog.cpp:162
NewFlightDialog(OPL::DbCompletionData &completion_data, QWidget *parent=nullptr)
NewFlightDialog - Creates a NewFlightDialog that can be used to add a new flight entry to the logbook...
Definition: newflightdialog.cpp:32
Provides data for QCompleters and QHashs.
Definition: dbcompletiondata.h:48
A Row representing a Flight entry. See Row class for details.
Definition: row.h:133
The ValidationState class encapsulates a QBitArray that has a bit set (or unset) depending on wether ...
Definition: newflightdialog.h:40
ValidationItem
The ValidationItem enum contains the items that are mandatory for logging a flight: Date of Flight,...
Definition: newflightdialog.h:48