newflightdialog.h
/*
*openPilotLog - A FOSS Pilot Logbook Application
*Copyright (C) 2020-2022 Felix Turowsky
*
*This program is free software: you can redistribute it and/or modify
*it under the terms of the GNU General Public License as published by
*the Free Software Foundation, either version 3 of the License, or
*(at your option) any later version.
*
*This program is distributed in the hope that it will be useful,
*but WITHOUT ANY WARRANTY; without even the implied warranty of
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
*GNU General Public License for more details.
*
*You should have received a copy of the GNU General Public License
*along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef NewFlightDialog_H
#define NewFlightDialog_H
#include <QDialog>
#include <QDebug>
#include <QLineEdit>
#include <QList>
#include <QBitArray>
#include "src/functions/time.h"
#include "src/database/database.h"
#include "src/database/dbcompletiondata.h"
#include "src/opl.h"
#include "src/database/row.h"
class ValidationState {
public:
ValidationState() = default;
enum ValidationItem {doft = 0, dept = 1, dest = 2, tofb = 3, tonb = 4, pic = 5, acft = 6};
void validate(ValidationItem item) { validationArray[item] = true;};
void validate(int index) { validationArray[index] = true;};
void invalidate(ValidationItem item) { validationArray[item] = false;}
void invalidate(int index) { validationArray[index] = false;}
inline bool allValid() const { return validationArray.count(true) == 7;};
inline bool timesValid() const { return validationArray[ValidationItem::tofb] && validationArray[ValidationItem::tonb];}
inline bool locationsValid() const { return validationArray[ValidationItem::dept] && validationArray[ValidationItem::dest];}
inline bool nightDataValid() const { return timesValid() && locationsValid() && validationArray[ValidationItem::doft];}
inline bool acftValid() const { return validationArray[ValidationItem::acft];}
inline bool validAt(int index) const { return validationArray[index];}
inline bool validAt(ValidationItem item) const { return validationArray[item];}
// Debug
void printValidationStatus() const {
QString deb_string("\033[mValidation State:\tdoft\tdept\tdest\ttofb\ttonb\tpic\tacft\n");
deb_string += "\t\t\t\t";
for (int i = 0; i < 7; i++) { //\033[32m
if (validationArray[i])
deb_string += "\t\033[32m" + QString::number(validationArray[i]);
else
deb_string += "\t\033[31m" + QString::number(validationArray[i]);
}
deb_string += QLatin1String("\u001b[38;5;75m"); // return to default DEB
qDebug().noquote() << deb_string;
}
private:
QBitArray validationArray = QBitArray(7);
};
namespace Ui {
class NewFlightDialog;
}
class NewFlightDialog : public QDialog
{
Q_OBJECT
public:
explicit NewFlightDialog(OPL::DbCompletionData& completion_data, QWidget *parent = nullptr);
explicit NewFlightDialog(OPL::DbCompletionData& completion_data, int row_id, QWidget* parent = nullptr);
~NewFlightDialog();
private:
Ui::NewFlightDialog *ui;
OPL::DbCompletionData completionData;
ValidationState validationState;
OPL::FlightEntry flightEntry;
static const inline QList<QLineEdit*>* timeLineEdits;
static const inline QList<QLineEdit*>* locationLineEdits;
static const inline QList<QLineEdit*>* pilotNameLineEdits;
static const inline QList<QLineEdit*>* mandatoryLineEdits;
static const inline QLatin1String self = QLatin1String("self");
void init();
void setupRawInputValidation();
void setupSignalsAndSlots();
void readSettings();
void fillWithEntryData();
void onGoodInputReceived(QLineEdit *line_edit);
void onBadInputReceived(QLineEdit *line_edit);
void updateBlockTimeLabel();
void updateNightCheckBoxes();
void setNightCheckboxes();
bool addNewTail(QLineEdit& parent_line_edit);
bool addNewPilot(QLineEdit& parent_line_edit);
bool checkPilotFunctionsValid();
OPL::RowData_T prepareFlightEntryData();
private slots:
void toUpper(const QString& text);
void onTimeLineEdit_editingFinished();
void onPilotNameLineEdit_editingFinshed();
void onLocationLineEdit_editingFinished();
void on_acftLineEdit_editingFinished();
void on_doftLineEdit_editingFinished();
void on_buttonBox_accepted();
void on_pilotFlyingCheckBox_stateChanged(int arg1);
void on_approachComboBox_currentTextChanged(const QString &arg1);
void on_functionComboBox_currentIndexChanged(int index);
protected:
bool eventFilter(QObject* object, QEvent* event) override;
};
#endif // NewFlightDialog_H
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:162
NewFlightDialog::NewFlightDialog
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
OPL::DbCompletionData
Provides data for QCompleters and QHashs.
Definition: dbcompletiondata.h:48
OPL::FlightEntry
A Row representing a Flight entry. See Row class for details.
Definition: row.h:133
ValidationState
The ValidationState class encapsulates a QBitArray that has a bit set (or unset) depending on wether ...
Definition: newflightdialog.h:40
ValidationState::ValidationItem
ValidationItem
The ValidationItem enum contains the items that are mandatory for logging a flight: Date of Flight,...
Definition: newflightdialog.h:48