|
@@ -16,9 +16,11 @@
|
|
|
*along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
*/
|
|
|
#include "newflightdialog.h"
|
|
|
+#include "QtWidgets/qcalendarwidget.h"
|
|
|
#include "src/classes/time.h"
|
|
|
#include "src/database/database.h"
|
|
|
#include "src/database/databasecache.h"
|
|
|
+#include "src/gui/dialogues/newairportdialog.h"
|
|
|
#include "src/gui/verification/airportinput.h"
|
|
|
#include "src/gui/verification/completerprovider.h"
|
|
|
#include "src/gui/verification/pilotinput.h"
|
|
@@ -28,6 +30,7 @@
|
|
|
#include "src/opl.h"
|
|
|
#include "src/functions/datetime.h"
|
|
|
#include "src/classes/settings.h"
|
|
|
+#include "src/classes/date.h"
|
|
|
#include "src/functions/calc.h"
|
|
|
#include "src/gui/dialogues/newtaildialog.h"
|
|
|
#include "src/gui/dialogues/newpilotdialog.h"
|
|
@@ -37,28 +40,18 @@
|
|
|
|
|
|
|
|
|
NewFlightDialog::NewFlightDialog(QWidget *parent)
|
|
|
- : QDialog(parent),
|
|
|
+ : EntryEditDialog(parent),
|
|
|
ui(new Ui::NewFlightDialog)
|
|
|
{
|
|
|
init();
|
|
|
- // Set up UI (New Flight)
|
|
|
- LOG << Settings::read(Settings::FlightLogging::Function);
|
|
|
- if(Settings::read(Settings::FlightLogging::Function).toInt() == static_cast<int>(OPL::PilotFunction::PIC)){
|
|
|
- ui->picNameLineEdit->setText(self);
|
|
|
- ui->functionComboBox->setCurrentIndex(0);
|
|
|
- emit ui->picNameLineEdit->editingFinished();
|
|
|
- }
|
|
|
- if (Settings::read(Settings::FlightLogging::Function).toInt() == static_cast<int>(OPL::PilotFunction::SIC)) {
|
|
|
- ui->sicNameLineEdit->setText(self);
|
|
|
- ui->functionComboBox->setCurrentIndex(2);
|
|
|
- emit ui->sicNameLineEdit->editingFinished();
|
|
|
- }
|
|
|
- ui->doftLineEdit->setText(OPL::DateTime::currentDate());
|
|
|
- emit ui->doftLineEdit->editingFinished();
|
|
|
+ setPilotFunction();
|
|
|
+
|
|
|
+ ui->doftLineEdit->setText(OPL::Date::today(m_format).toString());
|
|
|
+// emit ui->doftLineEdit->editingFinished();
|
|
|
}
|
|
|
|
|
|
NewFlightDialog::NewFlightDialog(int row_id, QWidget *parent)
|
|
|
- : QDialog(parent),
|
|
|
+ : EntryEditDialog(parent),
|
|
|
ui(new Ui::NewFlightDialog)
|
|
|
{
|
|
|
init();
|
|
@@ -71,6 +64,20 @@ NewFlightDialog::~NewFlightDialog()
|
|
|
delete ui;
|
|
|
}
|
|
|
|
|
|
+void NewFlightDialog::setPilotFunction()
|
|
|
+{
|
|
|
+ const QString &self = DBCache->getPilotNamesMap().value(1);
|
|
|
+ if(Settings::getPilotFunction() == OPL::PilotFunction::PIC){
|
|
|
+ ui->picNameLineEdit->setText(self);
|
|
|
+ ui->functionComboBox->setCurrentIndex(0);
|
|
|
+ }
|
|
|
+ if (Settings::getPilotFunction() == OPL::PilotFunction::SIC) {
|
|
|
+ ui->sicNameLineEdit->setText(self);
|
|
|
+ ui->functionComboBox->setCurrentIndex(2);
|
|
|
+ }
|
|
|
+ ui->pilotFlyingCheckBox->setCheckState(Qt::Checked);
|
|
|
+}
|
|
|
+
|
|
|
void NewFlightDialog::init()
|
|
|
{
|
|
|
// Setup UI
|
|
@@ -94,6 +101,11 @@ void NewFlightDialog::init()
|
|
|
OPL::GLOBALS->loadApproachTypes(ui->approachComboBox);
|
|
|
OPL::GLOBALS->loadPilotFunctios(ui->functionComboBox);
|
|
|
|
|
|
+ // allocate a widget for date selection
|
|
|
+ calendar = new QCalendarWidget(this);
|
|
|
+ calendar->setVisible(false);
|
|
|
+ calendar->setWindowFlags(Qt::Dialog); // pop-up calendar
|
|
|
+
|
|
|
setupRawInputValidation();
|
|
|
setupSignalsAndSlots();
|
|
|
readSettings();
|
|
@@ -140,6 +152,9 @@ void NewFlightDialog::setupSignalsAndSlots()
|
|
|
for (const auto& line_edit : *pilotNameLineEdits)
|
|
|
QObject::connect(line_edit, &QLineEdit::editingFinished,
|
|
|
this, &NewFlightDialog::onPilotNameLineEdit_editingFinshed);
|
|
|
+
|
|
|
+ QObject::connect(calendar, &QCalendarWidget::selectionChanged,
|
|
|
+ this, &NewFlightDialog::calendarDateSelected);
|
|
|
}
|
|
|
|
|
|
/*!
|
|
@@ -167,10 +182,12 @@ bool NewFlightDialog::eventFilter(QObject *object, QEvent *event)
|
|
|
*/
|
|
|
void NewFlightDialog::readSettings()
|
|
|
{
|
|
|
- ui->functionComboBox->setCurrentIndex(Settings::read(Settings::FlightLogging::Function).toInt());
|
|
|
- ui->approachComboBox->setCurrentIndex(Settings::read(Settings::FlightLogging::Approach).toInt());
|
|
|
- ui->flightRulesComboBox->setCurrentIndex(Settings::read(Settings::FlightLogging::LogIFR).toInt());
|
|
|
- ui->flightNumberLineEdit->setText(Settings::read(Settings::FlightLogging::FlightNumberPrefix).toString());
|
|
|
+ ui->functionComboBox->setCurrentIndex(static_cast<int>(Settings::getPilotFunction()));
|
|
|
+ ui->approachComboBox->setCurrentText(Settings::getApproachType());
|
|
|
+ ui->flightRulesComboBox->setCurrentIndex(Settings::getLogIfr());
|
|
|
+ ui->flightNumberLineEdit->setText(Settings::getFlightNumberPrefix());
|
|
|
+
|
|
|
+ m_format = Settings::getDisplayFormat();
|
|
|
}
|
|
|
|
|
|
/*!
|
|
@@ -181,55 +198,54 @@ void NewFlightDialog::fillWithEntryData()
|
|
|
{
|
|
|
DEB << "Restoring Flight: ";
|
|
|
DEB << flightEntry;
|
|
|
+ using namespace OPL;
|
|
|
|
|
|
const auto &flight_data = flightEntry.getData();
|
|
|
|
|
|
// Date of Flight
|
|
|
- ui->doftLineEdit->setText(flight_data.value(OPL::FlightEntry::DOFT).toString());
|
|
|
+ const QDate date = QDate::fromJulianDay(flight_data.value(FlightEntry::DOFT).toInt());
|
|
|
+ calendar->setSelectedDate(date);
|
|
|
+ ui->doftLineEdit->setText(Date(date, m_format).toString());
|
|
|
+
|
|
|
// Location
|
|
|
ui->deptLocationLineEdit->setText(flight_data.value(OPL::FlightEntry::DEPT).toString());
|
|
|
ui->destLocationLineEdit->setText(flight_data.value(OPL::FlightEntry::DEST).toString());
|
|
|
// Times
|
|
|
- ui->tofbTimeLineEdit->setText(OPL::Time(flight_data.value(OPL::FlightEntry::TOFB).toInt()).toString());
|
|
|
- ui->tonbTimeLineEdit->setText(OPL::Time(flight_data.value(OPL::FlightEntry::TONB).toInt()).toString());
|
|
|
+ ui->tofbTimeLineEdit->setText(OPL::Time(flight_data.value(OPL::FlightEntry::TOFB).toInt(), m_format).toString());
|
|
|
+ ui->tonbTimeLineEdit->setText(OPL::Time(flight_data.value(OPL::FlightEntry::TONB).toInt(), m_format).toString());
|
|
|
ui->acftLineEdit->setText(DBCache->getTailsMap().value(flight_data.value(OPL::FlightEntry::ACFT).toInt()));
|
|
|
ui->picNameLineEdit->setText(DBCache->getPilotNamesMap().value(flight_data.value(OPL::FlightEntry::PIC).toInt()));
|
|
|
ui->sicNameLineEdit->setText(DBCache->getPilotNamesMap().value(flight_data.value(OPL::FlightEntry::SECONDPILOT).toInt()));
|
|
|
ui->thirdPilotNameLineEdit->setText(DBCache->getPilotNamesMap().value(flight_data.value(OPL::FlightEntry::THIRDPILOT).toInt()));
|
|
|
|
|
|
//Function
|
|
|
- const QHash<int, QString> functions = {
|
|
|
- {0, OPL::FlightEntry::TPIC},
|
|
|
- {1, OPL::FlightEntry::TPICUS},
|
|
|
- {2, OPL::FlightEntry::TSIC},
|
|
|
- {3, OPL::FlightEntry::TDUAL},
|
|
|
- {4, OPL::FlightEntry::TFI},
|
|
|
- };
|
|
|
for (int i = 0; i < 5; i++) { // QHash::iterator not guarenteed to be in ordetr
|
|
|
- if(flight_data.value(functions.value(i)).toInt() != 0)
|
|
|
+ if(flight_data.value(pilotFuncionsMap.value(i)).toInt() != 0)
|
|
|
ui->functionComboBox->setCurrentIndex(i);
|
|
|
}
|
|
|
// Approach ComboBox
|
|
|
- const QString& app = flight_data.value(OPL::FlightEntry::APPROACHTYPE).toString();
|
|
|
- if(app != QString()){
|
|
|
+ const QString app = flight_data.value(OPL::FlightEntry::APPROACHTYPE).toString();
|
|
|
+ if(app != QString()) {
|
|
|
ui->approachComboBox->setCurrentText(app);
|
|
|
}
|
|
|
- // Flight Rules
|
|
|
+ // Flight Rules, check if tIFR > 0
|
|
|
bool time_ifr = flight_data.value(OPL::FlightEntry::TIFR).toBool();
|
|
|
- int rulesIndex = time_ifr ? 1 : 0;
|
|
|
- ui->flightRulesComboBox->setCurrentIndex(rulesIndex);
|
|
|
+ ui->flightRulesComboBox->setCurrentIndex(time_ifr);
|
|
|
+
|
|
|
// Take-Off and Landing
|
|
|
- int takeOffCount = flight_data.value(OPL::FlightEntry::TODAY).toInt()
|
|
|
+ int takeOffCount = flight_data.value(OPL::FlightEntry::TODAY).toInt()
|
|
|
+ flight_data.value(OPL::FlightEntry::TONIGHT).toInt();
|
|
|
int landingCount = flight_data.value(OPL::FlightEntry::LDGDAY).toInt()
|
|
|
+ flight_data.value(OPL::FlightEntry::LDGNIGHT).toInt();
|
|
|
ui->takeOffSpinBox->setValue(takeOffCount);
|
|
|
ui->landingSpinBox->setValue(landingCount);
|
|
|
- // Remarks
|
|
|
+ ui->pilotFlyingCheckBox->setChecked(flight_data.value(OPL::FlightEntry::PILOTFLYING).toBool());
|
|
|
+
|
|
|
+ // Remarks and Flight Number
|
|
|
ui->remarksLineEdit->setText(flight_data.value(OPL::FlightEntry::REMARKS).toString());
|
|
|
- // Flight Number
|
|
|
ui->flightNumberLineEdit->setText(flight_data.value(OPL::FlightEntry::FLIGHTNUMBER).toString());
|
|
|
|
|
|
+ // re-trigger input verification
|
|
|
for(const auto &line_edit : *mandatoryLineEdits)
|
|
|
emit line_edit->editingFinished();
|
|
|
}
|
|
@@ -262,7 +278,10 @@ void NewFlightDialog::onGoodInputReceived(QLineEdit *line_edit)
|
|
|
validationState.validate(mandatoryLineEdits->indexOf(line_edit));
|
|
|
|
|
|
if (validationState.timesValid()) {
|
|
|
- updateBlockTimeLabel();
|
|
|
+ const OPL::Time tofb = OPL::Time::fromString(ui->tofbTimeLineEdit->text(), m_format);
|
|
|
+ const OPL::Time tonb = OPL::Time::fromString(ui->tonbTimeLineEdit->text(), m_format);
|
|
|
+ const OPL::Time tblk = OPL::Time::blockTime(tofb, tonb);
|
|
|
+ ui->tblkDisplayLabel->setText(tblk.toString());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -278,81 +297,90 @@ void NewFlightDialog::onBadInputReceived(QLineEdit *line_edit)
|
|
|
validationState.printValidationStatus();
|
|
|
}
|
|
|
|
|
|
-void NewFlightDialog::updateBlockTimeLabel()
|
|
|
+bool NewFlightDialog::addNewDatabaseElement(QLineEdit *parent, OPL::DbTable table)
|
|
|
{
|
|
|
- const OPL::Time tofb = OPL::Time::fromString(ui->tofbTimeLineEdit->text());
|
|
|
- const OPL::Time tonb = OPL::Time::fromString(ui->tonbTimeLineEdit->text());
|
|
|
- const OPL::Time tblk = OPL::Time::blockTime(tofb, tonb);
|
|
|
-
|
|
|
- ui->tblkDisplayLabel->setText(tblk.toString());
|
|
|
-}
|
|
|
+ QDialog *dialog = nullptr;
|
|
|
+ if(userWantsToAddNewEntry(table)) {
|
|
|
+ switch (table) {
|
|
|
+ case OPL::DbTable::Pilots:
|
|
|
+ dialog = new NewPilotDialog(parent->text(), this);
|
|
|
+ break;
|
|
|
+ case OPL::DbTable::Tails:
|
|
|
+ dialog = new NewTailDialog(ui->acftLineEdit->text(), this);
|
|
|
+ break;
|
|
|
+ case OPL::DbTable::Airports:
|
|
|
+ dialog = new NewAirportDialog(this);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ return false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ } else
|
|
|
+ return false;
|
|
|
|
|
|
-/*!
|
|
|
- * \brief NewFlightDialog::addNewTail If the user input is not in the aircraftList, the user
|
|
|
- * is prompted if he wants to add a new entry to the database
|
|
|
- */
|
|
|
-bool NewFlightDialog::addNewTail(QLineEdit& parent_line_edit)
|
|
|
-{
|
|
|
- QMessageBox::StandardButton reply;
|
|
|
- reply = QMessageBox::question(this, tr("No Aircraft found"),
|
|
|
- tr("No aircraft with this registration found.<br>"
|
|
|
- "If this is the first time you log a flight with this aircraft, "
|
|
|
- "you have to add the registration to the database first."
|
|
|
- "<br><br>Would you like to add a new aircraft to the database?"),
|
|
|
- QMessageBox::Yes|QMessageBox::No);
|
|
|
- if (reply == QMessageBox::Yes) {
|
|
|
- // create and open new aircraft dialog
|
|
|
- NewTailDialog nt(ui->acftLineEdit->text(), this);
|
|
|
- int ret = nt.exec();
|
|
|
- // update map and list, set line edit
|
|
|
- if (ret == QDialog::Accepted) {
|
|
|
- DEB << "New Tail Entry added:";
|
|
|
- DEB << DB->getTailEntry(DB->getLastEntry(OPL::DbTable::Tails));
|
|
|
-
|
|
|
- // update Line Edit with newly added tail
|
|
|
- parent_line_edit.setText(DBCache->getTailsMap().value(DB->getLastEntry(OPL::DbTable::Tails)));
|
|
|
- emit parent_line_edit.editingFinished();
|
|
|
- return true;
|
|
|
- } else {
|
|
|
+ // execute the dialog and check for success. Set the line edit to the newly created entry.
|
|
|
+ if(dialog->exec() == QDialog::Accepted) {
|
|
|
+ delete dialog;
|
|
|
+ int latestEntry = DB->getLastEntry(table);
|
|
|
+ switch (table) {
|
|
|
+ case OPL::DbTable::Pilots:
|
|
|
+ parent->setText(DBCache->getPilotNamesMap().value(latestEntry));
|
|
|
+ break;
|
|
|
+ case OPL::DbTable::Tails:
|
|
|
+ parent->setText(DBCache->getTailsMap().value(latestEntry));
|
|
|
+ break;
|
|
|
+ case OPL::DbTable::Airports:
|
|
|
+ parent->setText(DBCache->getAirportsMapICAO().value(latestEntry));
|
|
|
+ break;
|
|
|
+ default:
|
|
|
return false;
|
|
|
+ break;
|
|
|
}
|
|
|
} else {
|
|
|
+ delete dialog;
|
|
|
return false;
|
|
|
}
|
|
|
+
|
|
|
+ // re-emit editing finished to trigger input validation
|
|
|
+ emit parent->editingFinished();
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
-/*!
|
|
|
- * \brief NewFlightDialog::addNewPilot If the user input is not in the pilotNameList, the user
|
|
|
- * is prompted if he wants to add a new entry to the database
|
|
|
- */
|
|
|
-bool NewFlightDialog::addNewPilot(QLineEdit& parent_line_edit)
|
|
|
+bool NewFlightDialog::userWantsToAddNewEntry(OPL::DbTable table)
|
|
|
{
|
|
|
QMessageBox::StandardButton reply;
|
|
|
- reply = QMessageBox::question(this, tr("No Pilot found"),
|
|
|
- tr("No pilot found.<br>Please enter the Name as"
|
|
|
- "<br><br><center><b>Lastname, Firstname</b></center><br><br>"
|
|
|
- "If this is the first time you log a flight with this pilot, "
|
|
|
- "you have to add the pilot to the database first."
|
|
|
- "<br><br>Would you like to add a new pilot to the database?"),
|
|
|
- QMessageBox::Yes|QMessageBox::No);
|
|
|
- if (reply == QMessageBox::Yes) {
|
|
|
- // create and open new pilot dialog
|
|
|
- NewPilotDialog np(this);
|
|
|
- int ret = np.exec();
|
|
|
- // update map and list, set line edit
|
|
|
- if (ret == QDialog::Accepted) {
|
|
|
- DEB << "New Pilot Entry added:";
|
|
|
- DEB << DB->getPilotEntry(DB->getLastEntry(OPL::DbTable::Pilots));
|
|
|
-
|
|
|
- // update Line Edit with newly added pilot
|
|
|
- parent_line_edit.setText(DBCache->getPilotNamesMap().value(DB->getLastEntry(OPL::DbTable::Pilots)));
|
|
|
- emit parent_line_edit.editingFinished();
|
|
|
- return true;
|
|
|
- } else {
|
|
|
- return false;
|
|
|
- }
|
|
|
- } else
|
|
|
- return false;
|
|
|
+ switch (table) {
|
|
|
+ case OPL::DbTable::Pilots:
|
|
|
+ reply = QMessageBox::question(this, tr("No Pilot found"),
|
|
|
+ tr("No pilot found.<br>Please enter the Name as"
|
|
|
+ "<br><br><center><b>Lastname, Firstname</b></center><br><br>"
|
|
|
+ "If this is the first time you log a flight with this pilot, "
|
|
|
+ "you have to add the pilot to the database first."
|
|
|
+ "<br><br>Would you like to add a new pilot to the database?"),
|
|
|
+ QMessageBox::Yes|QMessageBox::No, QMessageBox::StandardButton::Yes);
|
|
|
+ break;
|
|
|
+ case OPL::DbTable::Tails:
|
|
|
+ reply = QMessageBox::question(this, tr("No Aircraft found"),
|
|
|
+ tr("No aircraft with this registration found.<br>"
|
|
|
+ "If this is the first time you log a flight with this aircraft, "
|
|
|
+ "you have to add the registration to the database first."
|
|
|
+ "<br><br>Would you like to add a new aircraft to the database?"),
|
|
|
+ QMessageBox::Yes|QMessageBox::No, QMessageBox::StandardButton::Yes);
|
|
|
+ break;
|
|
|
+ case OPL::DbTable::Airports:
|
|
|
+ reply = QMessageBox::question(this, tr("No Airport found"),
|
|
|
+ tr("No Airport with this identifier found.<br>"
|
|
|
+ "If this is the first time you log a flight to this airport, "
|
|
|
+ "you have to add the airport to the database first."
|
|
|
+ "<br><br>Would you like to add a new airport to the database?"),
|
|
|
+ QMessageBox::Yes|QMessageBox::No, QMessageBox::StandardButton::Yes);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ reply = QMessageBox::No;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ return reply == QMessageBox::Yes;
|
|
|
}
|
|
|
|
|
|
/*!
|
|
@@ -369,15 +397,15 @@ OPL::RowData_T NewFlightDialog::prepareFlightEntryData()
|
|
|
OPL::RowData_T new_data;
|
|
|
|
|
|
// Calculate Block and Night Time
|
|
|
- const OPL::Time tofb = OPL::Time::fromString(ui->tofbTimeLineEdit->text());
|
|
|
- const OPL::Time tonb = OPL::Time::fromString(ui->tonbTimeLineEdit->text());
|
|
|
+ const OPL::Time tofb = OPL::Time::fromString(ui->tofbTimeLineEdit->text(), m_format);
|
|
|
+ const OPL::Time tonb = OPL::Time::fromString(ui->tonbTimeLineEdit->text(), m_format);
|
|
|
const int block_minutes = OPL::Time::blockMinutes(tofb, tonb);
|
|
|
|
|
|
- QDateTime departure_date_time = OPL::DateTime::fromString(ui->doftLineEdit->text() + ui->tofbTimeLineEdit->text());
|
|
|
+ const QDateTime departure_date_time = OPL::DateTime::fromString(ui->doftLineEdit->text() + ui->tofbTimeLineEdit->text());
|
|
|
const auto night_time_data = OPL::Calc::NightTimeValues(ui->deptLocationLineEdit->text(), ui->destLocationLineEdit->text(),
|
|
|
- departure_date_time, block_minutes, Settings::read(Settings::FlightLogging::NightAngle).toInt());
|
|
|
+ departure_date_time, block_minutes, Settings::getNightAngle());
|
|
|
// Mandatory data
|
|
|
- new_data.insert(OPL::FlightEntry::DOFT, ui->doftLineEdit->text());
|
|
|
+ new_data.insert(OPL::FlightEntry::DOFT, QDate::fromString(ui->doftLineEdit->text(), Qt::ISODate).toJulianDay());
|
|
|
new_data.insert(OPL::FlightEntry::DEPT, ui->deptLocationLineEdit->text());
|
|
|
new_data.insert(OPL::FlightEntry::TOFB, tofb.toMinutes());
|
|
|
new_data.insert(OPL::FlightEntry::DEST, ui->destLocationLineEdit->text());
|
|
@@ -461,7 +489,7 @@ OPL::RowData_T NewFlightDialog::prepareFlightEntryData()
|
|
|
new_data.insert(OPL::FlightEntry::AUTOLAND, ui->landingSpinBox->value());
|
|
|
|
|
|
// Pilot flying / Pilot monitoring
|
|
|
- bool isPilotFlying = toDay + toNight + ldgDay + ldgNight > 0;
|
|
|
+ bool isPilotFlying = toDay + toNight + ldgDay + ldgNight;
|
|
|
new_data.insert(OPL::FlightEntry::PILOTFLYING, isPilotFlying);
|
|
|
|
|
|
// Additional Data
|
|
@@ -485,15 +513,28 @@ void NewFlightDialog::toUpper(const QString &text)
|
|
|
|
|
|
void NewFlightDialog::onTimeLineEdit_editingFinished()
|
|
|
{
|
|
|
- auto line_edit = this->findChild<QLineEdit*>(sender()->objectName());
|
|
|
- verifyUserInput(line_edit, TimeInput(line_edit->text()));
|
|
|
+ const auto line_edit = this->findChild<QLineEdit*>(sender()->objectName());
|
|
|
+
|
|
|
+ if(!verifyUserInput(line_edit, TimeInput(line_edit->text(), m_format))) {
|
|
|
+ onBadInputReceived(line_edit);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
void NewFlightDialog::onPilotNameLineEdit_editingFinshed()
|
|
|
{
|
|
|
auto line_edit = this->findChild<QLineEdit*>(sender()->objectName());
|
|
|
+ if(line_edit->text() == QString())
|
|
|
+ return;
|
|
|
+
|
|
|
+ // create a copy to refill line edit and pass through to creation dialog if verification fails
|
|
|
+ QString userInput = line_edit->text();
|
|
|
+
|
|
|
if(!verifyUserInput(line_edit, PilotInput(line_edit->text()))) {
|
|
|
- if(!addNewPilot(*line_edit))
|
|
|
+ {
|
|
|
+ QSignalBlocker blocker(line_edit);
|
|
|
+ line_edit->setText(userInput);
|
|
|
+ }
|
|
|
+ if(!addNewDatabaseElement(line_edit, OPL::DbTable::Pilots))
|
|
|
onBadInputReceived(line_edit);
|
|
|
}
|
|
|
}
|
|
@@ -514,17 +555,31 @@ void NewFlightDialog::onLocationLineEdit_editingFinished()
|
|
|
name_label->setText(DBCache->getAirportsMapNames().value(
|
|
|
DBCache->getAirportsMapICAO().key(
|
|
|
line_edit->text())));
|
|
|
- } else
|
|
|
+ } else {
|
|
|
name_label->setText("Unknown Airport");
|
|
|
+ addNewDatabaseElement(line_edit, OPL::DbTable::Airports);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
void NewFlightDialog::on_acftLineEdit_editingFinished()
|
|
|
{
|
|
|
const auto line_edit = ui->acftLineEdit;
|
|
|
+ if(line_edit->text().isEmpty()){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ const QString user_input = line_edit->text(); // keep around for adding new tail if needed
|
|
|
|
|
|
- if(!verifyUserInput(line_edit, TailInput(line_edit->text())))
|
|
|
- if(!addNewTail(*line_edit))
|
|
|
+ if(!verifyUserInput(line_edit, TailInput(line_edit->text()))) {
|
|
|
+ // re-populate user input to hand through to NewTailDialog
|
|
|
+ {
|
|
|
+ QSignalBlocker blocker(line_edit);
|
|
|
+ line_edit->setText(user_input);
|
|
|
+ }
|
|
|
+ if(!addNewDatabaseElement(line_edit, OPL::DbTable::Tails)) {
|
|
|
onBadInputReceived(line_edit);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
const auto space = QLatin1Char(' ');
|
|
|
if(line_edit->text().contains(space))
|
|
@@ -534,21 +589,19 @@ void NewFlightDialog::on_acftLineEdit_editingFinished()
|
|
|
void NewFlightDialog::on_doftLineEdit_editingFinished()
|
|
|
{
|
|
|
const auto line_edit = ui->doftLineEdit;
|
|
|
- auto text = ui->doftLineEdit->text();
|
|
|
- auto label = ui->doftDisplayLabel;
|
|
|
-
|
|
|
- TODO << "Non-default Date formats not implemented yet.";
|
|
|
- OPL::DateFormat date_format = OPL::DateFormat::ISODate;
|
|
|
- auto date = OPL::DateTime::parseInput(text, date_format);
|
|
|
- if (date.isValid()) {
|
|
|
- label->setText(date.toString(Qt::TextDate));
|
|
|
- line_edit->setText(OPL::DateTime::dateToString(date, date_format));
|
|
|
- onGoodInputReceived(line_edit);
|
|
|
+ OPL::Date date(ui->doftLineEdit->text(), m_format);
|
|
|
+
|
|
|
+
|
|
|
+ LOG << "Date: " << date.toString();
|
|
|
+ LOG << "is valid? " << date.isValid();
|
|
|
+
|
|
|
+ line_edit->setText(date.toString());
|
|
|
+ if(ui->doftLineEdit->text().isEmpty()) {
|
|
|
+ onBadInputReceived(line_edit);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- label->setText(tr("Invalid Date."));
|
|
|
- onBadInputReceived(line_edit);
|
|
|
+ onGoodInputReceived(line_edit);
|
|
|
}
|
|
|
|
|
|
void NewFlightDialog::on_pilotFlyingCheckBox_stateChanged(int arg1)
|
|
@@ -577,18 +630,45 @@ void NewFlightDialog::on_approachComboBox_currentTextChanged(const QString &arg1
|
|
|
*/
|
|
|
void NewFlightDialog::on_functionComboBox_currentIndexChanged(int index)
|
|
|
{
|
|
|
- if (index == static_cast<int>(OPL::PilotFunction::PIC)) {
|
|
|
+ int picPilotId = DBCache->getPilotNamesMap().key(ui->picNameLineEdit->text());
|
|
|
+ int sicPilotId = DBCache->getPilotNamesMap().key(ui->sicNameLineEdit->text());
|
|
|
+ int thirdPilotId = DBCache->getPilotNamesMap().key(ui->thirdPilotNameLineEdit->text());
|
|
|
+ const QString &self = DBCache->getPilotNamesMap().value(1);
|
|
|
+
|
|
|
+ switch (index) {
|
|
|
+ case static_cast<int>(OPL::PilotFunction::PIC):
|
|
|
+ DEB << "PIC selected...";
|
|
|
ui->picNameLineEdit->setText(self);
|
|
|
emit ui->picNameLineEdit->editingFinished();
|
|
|
- if (DBCache->getPilotNamesMap().key(ui->picNameLineEdit->text())
|
|
|
- == DBCache->getPilotNamesMap().key(ui->sicNameLineEdit->text()))
|
|
|
- ui->sicNameLineEdit->setText(QString());
|
|
|
- } else if (index == static_cast<int>(OPL::PilotFunction::SIC)) {
|
|
|
+ picPilotId = DBCache->getPilotNamesMap().key(ui->picNameLineEdit->text());
|
|
|
+
|
|
|
+ if (picPilotId == sicPilotId) {
|
|
|
+ ui->sicNameLineEdit->setText(QString());
|
|
|
+ onBadInputReceived(ui->sicNameLineEdit);
|
|
|
+ }
|
|
|
+ if (picPilotId == thirdPilotId) {
|
|
|
+ ui->thirdPilotNameLineEdit->setText(QString());
|
|
|
+ onBadInputReceived(ui->thirdPilotNameLineEdit);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case static_cast<int>(OPL::PilotFunction::SIC):
|
|
|
+ DEB << "SIC selected...";
|
|
|
ui->sicNameLineEdit->setText(self);
|
|
|
emit ui->sicNameLineEdit->editingFinished();
|
|
|
- if (DBCache->getPilotNamesMap().key(ui->picNameLineEdit->text())
|
|
|
- == DBCache->getPilotNamesMap().key(ui->sicNameLineEdit->text()))
|
|
|
+ sicPilotId = DBCache->getPilotNamesMap().key(ui->sicNameLineEdit->text());
|
|
|
+
|
|
|
+ if (sicPilotId == picPilotId) {
|
|
|
ui->picNameLineEdit->setText(QString());
|
|
|
+ onBadInputReceived(ui->picNameLineEdit);
|
|
|
+ }
|
|
|
+ if (sicPilotId == thirdPilotId) {
|
|
|
+ ui->thirdPilotNameLineEdit->setText(QString());
|
|
|
+ onBadInputReceived(ui->thirdPilotNameLineEdit);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -601,7 +681,7 @@ void NewFlightDialog::on_functionComboBox_currentIndexChanged(int index)
|
|
|
* \param error_msg - the error string displayed to the user
|
|
|
* \return
|
|
|
*/
|
|
|
-bool NewFlightDialog::checkPilotFunctionsValid()
|
|
|
+bool NewFlightDialog::pilotFunctionsInvalid()
|
|
|
{
|
|
|
int pic_id = DBCache->getPilotNamesMap().key(ui->picNameLineEdit->text());
|
|
|
int function_index = ui->functionComboBox->currentIndex();
|
|
@@ -610,17 +690,52 @@ bool NewFlightDialog::checkPilotFunctionsValid()
|
|
|
if (!(function_index == static_cast<int>(OPL::PilotFunction::PIC) || function_index == static_cast<int>(OPL::PilotFunction::FI))) {
|
|
|
INFO(tr("The PIC is set to %1 but the Pilot Function is set to %2")
|
|
|
.arg(ui->picNameLineEdit->text(), ui->functionComboBox->currentText()));
|
|
|
- return false;
|
|
|
+ return true;
|
|
|
}
|
|
|
} else {
|
|
|
if (function_index == static_cast<int>(OPL::PilotFunction::PIC) || function_index == static_cast<int>(OPL::PilotFunction::FI)) {
|
|
|
INFO(tr("The Pilot Function is set to %1, but the PIC is set to %2")
|
|
|
.arg(ui->functionComboBox->currentText(), ui->picNameLineEdit->text()));
|
|
|
- return false;
|
|
|
+ return true;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return true;
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
+bool NewFlightDialog::duplicateNamesPresent()
|
|
|
+{
|
|
|
+ const int picId = DBCache->getPilotNamesMap().key(ui->picNameLineEdit->text());
|
|
|
+ const int sicId = DBCache->getPilotNamesMap().key(ui->sicNameLineEdit->text());
|
|
|
+ const int thirdPilotId = DBCache->getPilotNamesMap().key(ui->thirdPilotNameLineEdit->text());
|
|
|
+
|
|
|
+ // this is a bit explicit but better point out to the user what the case is
|
|
|
+ if (picId == sicId) {
|
|
|
+ INFO(tr("PIC and SIC names are the same."));
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ if (picId == thirdPilotId && picId > 0) {
|
|
|
+ INFO(tr("PIC and third Pilot names are the same."));
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ if (sicId == thirdPilotId && sicId > 0) {
|
|
|
+ INFO(tr("SIC and third Pilot names are the same."));
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
+bool NewFlightDialog::flightTimeIsZero()
|
|
|
+{
|
|
|
+ const OPL::Time tofb = OPL::Time::fromString(ui->tofbTimeLineEdit->text(), m_format);
|
|
|
+ const OPL::Time tonb = OPL::Time::fromString(ui->tonbTimeLineEdit->text(), m_format);
|
|
|
+ const int block_minutes = OPL::Time::blockMinutes(tofb, tonb);
|
|
|
+ if(block_minutes == 0) {
|
|
|
+ INFO(tr("Total time of flight is zero."));
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
/*!
|
|
@@ -638,17 +753,12 @@ void NewFlightDialog::on_buttonBox_accepted()
|
|
|
emit le->editingFinished();
|
|
|
// If input verification is passed, continue, otherwise prompt user to correct
|
|
|
if (!validationState.allValid()) {
|
|
|
- const auto display_names = QHash<ValidationState::ValidationItem, QString> {
|
|
|
- {ValidationState::ValidationItem::doft, QObject::tr("Date of Flight")}, {ValidationState::ValidationItem::dept, QObject::tr("Departure Airport")},
|
|
|
- {ValidationState::ValidationItem::dest, QObject::tr("Destination Airport")}, {ValidationState::ValidationItem::tofb, QObject::tr("Time Off Blocks")},
|
|
|
- {ValidationState::ValidationItem::tonb, QObject::tr("Time on Blocks")}, {ValidationState::ValidationItem::pic, QObject::tr("PIC Name")},
|
|
|
- {ValidationState::ValidationItem::acft, QObject::tr("Aircraft Registration")}
|
|
|
- };
|
|
|
+
|
|
|
QString missing_items;
|
|
|
for (int i=0; i < mandatoryLineEdits->size(); i++) {
|
|
|
if (!validationState.validAt(i)){
|
|
|
- missing_items.append(display_names.value(static_cast<ValidationState::ValidationItem>(i)) + "<br>");
|
|
|
- mandatoryLineEdits->at(i)->setStyleSheet(QStringLiteral("border: 1px solid red"));
|
|
|
+ missing_items.append(validationItemsDisplayNames.value(static_cast<ValidationState::ValidationItem>(i)) + "<br>");
|
|
|
+ mandatoryLineEdits->at(i)->setStyleSheet(OPL::CssStyles::RED_BORDER);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -660,7 +770,11 @@ void NewFlightDialog::on_buttonBox_accepted()
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if(!checkPilotFunctionsValid())
|
|
|
+ if(pilotFunctionsInvalid())
|
|
|
+ return;
|
|
|
+ if(duplicateNamesPresent())
|
|
|
+ return;
|
|
|
+ if(flightTimeIsZero())
|
|
|
return;
|
|
|
|
|
|
// If input verification passed, collect input and submit to database
|
|
@@ -682,3 +796,30 @@ void NewFlightDialog::on_buttonBox_accepted()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+void NewFlightDialog::on_calendarPushButton_clicked()
|
|
|
+{
|
|
|
+ calendar->setVisible(true);
|
|
|
+}
|
|
|
+
|
|
|
+void NewFlightDialog::calendarDateSelected()
|
|
|
+{
|
|
|
+ calendar->setVisible(false);
|
|
|
+ ui->doftLineEdit->setText(OPL::Date(calendar->selectedDate(), m_format).toString());
|
|
|
+ emit ui->doftLineEdit->editingFinished();
|
|
|
+}
|
|
|
+
|
|
|
+// EntryEditDialog interface
|
|
|
+
|
|
|
+void NewFlightDialog::loadEntry(int rowID)
|
|
|
+{
|
|
|
+ flightEntry = DB->getFlightEntry(rowID);
|
|
|
+ fillWithEntryData();
|
|
|
+}
|
|
|
+
|
|
|
+bool NewFlightDialog::deleteEntry(int rowID)
|
|
|
+{
|
|
|
+ const auto entry = DB->getFlightEntry(rowID);
|
|
|
+ return DB->remove(entry);
|
|
|
+}
|
|
|
+
|