123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- #ifndef NEWFLIGHT_H
- #define NEWFLIGHT_H
- #include <QDialog>
- #include <QRegularExpression>
- #include <QMessageBox>
- #include <QDebug>
- #include <QCompleter>
- #include <QStringList>
- #include <QButtonGroup>
- #include <QBitArray>
- #include <QLineEdit>
- #include <QCalendarWidget>
- #include <QComboBox>
- #include <QTabWidget>
- #include <QKeyEvent>
- #include "src/functions/atime.h"
- #include "src/classes/aflightentry.h"
- #include "src/classes/apilotentry.h"
- #include "src/classes/atailentry.h"
- #include "src/database/database.h"
- #include "src/classes/acompletiondata.h"
- namespace Ui {
- class NewFlight;
- }
- class NewFlightDialog : public QDialog
- {
- Q_OBJECT
- public:
-
- explicit NewFlightDialog(ACompletionData &completion_data, QWidget *parent = nullptr);
-
- explicit NewFlightDialog(ACompletionData &completion_data, int row_id, QWidget *parent = nullptr);
- ~NewFlightDialog();
-
- struct ValidationSetupData
- {
- ValidationSetupData(QStringList* completion_data, const QRegularExpression* validation_RegEx)
- : completionData(completion_data), validationRegEx(validation_RegEx){};
- ValidationSetupData(const QRegularExpression* validation_RegEx)
- : completionData(nullptr), validationRegEx(validation_RegEx){};
- const QStringList* completionData;
- const QRegularExpression* validationRegEx;
- };
- private slots:
- void onToUpperTriggered_textChanged(const QString&);
- void onPilotNameLineEdit_editingFinished();
- void onLocationEditingFinished(QLineEdit*, QLabel*);
- void onTimeLineEdit_editingFinished();
- void onCompleter_highlighted(const QString&);
- void onCompleter_activated(const QString &);
- void onCalendarWidget_clicked(const QDate &date);
- void on_doftLineEdit_editingFinished();
- void on_cancelButton_clicked();
- void on_submitButton_clicked();
- void on_setAsDefaultButton_clicked();
- void on_restoreDefaultButton_clicked();
- void on_PilotFlyingCheckBox_stateChanged(int arg1);
- void on_IfrCheckBox_stateChanged(int);
- void on_manualEditingCheckBox_stateChanged(int arg1);
- void on_ApproachComboBox_currentTextChanged(const QString &arg1);
- void on_FunctionComboBox_currentIndexChanged(int index);
- void on_deptLocLineEdit_editingFinished();
- void on_destLocLineEdit_editingFinished();
- void on_acftLineEdit_editingFinished();
- void on_deptTZComboBox_currentIndexChanged(int index);
- void on_destTZComboBox_currentIndexChanged(int index);
- void on_calendarPushButton_clicked();
- private:
- Ui::NewFlight *ui;
-
- AFlightEntry flightEntry;
- QVector<QLineEdit*> mandatoryLineEdits;
- QVector<QLineEdit*> primaryTimeLineEdits;
- QVector<QLineEdit*> pilotsLineEdits;
-
- QBitArray mandatoryLineEditsValid;
- enum mandatoryLineEdit {
- doft = 0,
- dept = 1,
- dest = 2,
- tofb = 3,
- tonb = 4,
- pic = 5,
- acft = 6
- };
- void validateMandatoryLineEdit(mandatoryLineEdit line_edit){mandatoryLineEditsValid.setBit(line_edit, true);}
- void invalidateMandatoryLineEdit(mandatoryLineEdit line_edit){mandatoryLineEditsValid.setBit(line_edit, false);}
- bool timeLineEditsValid(){return mandatoryLineEditsValid[mandatoryLineEdit::tofb]
- && mandatoryLineEditsValid[mandatoryLineEdit::tonb];}
- bool acftLineEditValid(){return mandatoryLineEditsValid[mandatoryLineEdit::acft];}
- bool locLineEditsValid(){return mandatoryLineEditsValid[mandatoryLineEdit::dept]
- && mandatoryLineEditsValid[mandatoryLineEdit::dest];}
- bool allMandatoryLineEditsValid(){return mandatoryLineEditsValid.count(true) == 7;}
-
- void validationStatus();
-
- ACompletionData completionData;
- Opl::Time::FlightTimeFormat flightTimeFormat;
-
- bool updateEnabled;
- void setup();
- void readSettings();
- void setupUi();
- void writeSettings();
- void setupButtonGroups();
- void setupRawInputValidation();
- void setupSignalsAndSlots();
- void formFiller();
- void fillDeductibleData();
- void onMandatoryLineEditsFilled();
- void onGoodInputReceived(QLineEdit*);
- void onBadInputReceived(QLineEdit *);
- bool eventFilter(QObject *object, QEvent *event);
- bool isLessOrEqualThanBlockTime(const QString time_string);
- void addNewTail(QLineEdit*);
- void addNewPilot(QLineEdit *);
-
- RowData_T collectInput();
-
- inline int stringToMinutes(const QString &time_string, Opl::Time::FlightTimeFormat format)
- {
- return ATime::toMinutes(ATime::fromString(time_string, format));
- }
-
- inline QString minutesToString(const int minutes, Opl::Time::FlightTimeFormat format)
- {
- return ATime::toString(ATime::qTimefromMinutes(minutes), format);
- }
- };
- #endif
|