| openPilotLog

newflightdialog.h
1 /*
2 *openPilotLog - A FOSS Pilot Logbook Application
3 *Copyright (C) 2020-2021 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/atime.h"
28 #include "src/classes/acompletiondata.h"
29 #include "src/classes/aflightentry.h"
30 #include "src/classes/apilotentry.h"
31 #include "src/classes/atailentry.h"
32 #include "src/database/adatabase.h"
33 #include "src/opl.h"
34
39 enum ValidationItem {doft = 0, dept = 1, dest = 2, tofb = 3, tonb = 4, pic = 5, acft = 6};
40
46 class ValidationState {
47 public:
48 ValidationState() = default;
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(ACompletionData& completion_data, QWidget *parent = nullptr);
123 explicit NewFlightDialog(ACompletionData& completion_data, RowId_T row_id, QWidget* parent = nullptr);
124 ~NewFlightDialog();
125
126 private:
127 Ui::NewFlightDialog *ui;
128 ACompletionData completionData;
129 ValidationState validationState;
130
136 AFlightEntry 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 updateNightCheckBoxes();
177 void setNightCheckboxes();
178 void updateBlockTimeLabel();
179
180 bool addNewTail(QLineEdit& parent_line_edit);
181 bool addNewPilot(QLineEdit& parent_line_edit);
182
183 RowData_T prepareFlightEntryData();
184
185
186 private slots:
187 void toUpper(const QString& text);
188 void onTimeLineEdit_editingFinished();
189 void onPilotNameLineEdit_editingFinshed();
190 void onLocationLineEdit_editingFinished();
191 void on_acftLineEdit_editingFinished();
192 void on_doftLineEdit_editingFinished();
193 void on_buttonBox_accepted();
194 void on_pilotFlyingCheckBox_stateChanged(int arg1);
195 void on_approachComboBox_currentTextChanged(const QString &arg1);
196 void on_functionComboBox_currentIndexChanged(int index);
197 protected:
198 bool eventFilter(QObject* object, QEvent* event) override;
199 };
200
201
202 #endif // NewFlightDialog_H
ACompletionData
The ACompletionData class provides data to QCompleters and QHashs used for mapping user input to data...
Definition: acompletiondata.h:12
AFlightEntry
Definition: aflightentry.h:23
NewFlightDialog
The NewFlightDialog is used to add or edit entries from the flights table in the database.
Definition: newflightdialog.h:108
NewFlightDialog::eventFilter
bool eventFilter(QObject *object, QEvent *event) override
NewFlightDialog::eventFilter invalidates mandatory line edits on focus in.
Definition: newflightdialog.cpp:164
NewFlightDialog::NewFlightDialog
NewFlightDialog(ACompletionData &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
ValidationState
The ValidationState class encapsulates a QBitArray that has a bit set (or unset) depending on wether ...
Definition: newflightdialog.h:46