123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- #include "newpilotdialog.h"
- #include "src/gui/verification/completerprovider.h"
- #include "ui_newpilot.h"
- #include "src/opl.h"
- #include "src/database/database.h"
- #include "src/database/row.h"
- NewPilotDialog::NewPilotDialog(QWidget *parent) :
- QDialog(parent),
- ui(new Ui::NewPilot)
- {
- setup();
- ui->lastnameLineEdit->setFocus();
- }
- NewPilotDialog::NewPilotDialog(int rowId, QWidget *parent) :
- QDialog(parent),
- ui(new Ui::NewPilot)
- {
- setup();
- pilotEntry = DB->getPilotEntry(rowId);
- DEB << "Editing Pilot: " << pilotEntry;
- formFiller();
- ui->lastnameLineEdit->setFocus();
- }
- NewPilotDialog::~NewPilotDialog()
- {
- delete ui;
- }
- void NewPilotDialog::setup()
- {
- ui->setupUi(this);
- ui->companyLineEdit->setCompleter(QCompleterProvider.getCompleter(CompleterProvider::Companies));
- }
- void NewPilotDialog::on_buttonBox_accepted()
- {
- if (ui->lastnameLineEdit->text().isEmpty() || ui->firstnameLineEdit->text().isEmpty()) {
- QMessageBox message_box(this);
- message_box.setText(tr("Last Name and First Name are required."));
- message_box.exec();
- } else {
- submitForm();
- }
- }
- void NewPilotDialog::formFiller()
- {
- auto line_edits = this->findChildren<QLineEdit *>();
- for (const auto &le : line_edits) {
- auto key = le->objectName().remove(QStringLiteral("LineEdit"));
- le->setText(pilotEntry.getData().value(key).toString());
- }
- }
- void NewPilotDialog::submitForm()
- {
- OPL::RowData_T new_data;
- const auto line_edits = this->findChildren<QLineEdit *>();
- for(auto& le : line_edits) {
- auto key = le->objectName().remove(QStringLiteral("LineEdit"));
- auto value = le->text();
- new_data.insert(key, value);
- }
- pilotEntry.setData(new_data);
- DEB << "Submitting Pilot:";
- DEB << pilotEntry;
- if (!DB->commit(pilotEntry)) {
- QMessageBox message_box(this);
- message_box.setText(tr("The following error has ocurred:"
- "<br><br>%1<br><br>"
- "The entry has not been saved."
- ).arg(DB->lastError.text()));
- message_box.exec();
- return;
- } else {
- QDialog::accept();
- }
- }
|