Browse Source

reduced use of signals where not required

- Added database member variable lastError which replaces sqlError signal and holds error information.
- Logbookwidget, for (un)successful deletion now uses if statements
- NewTailDialog and NewPilotDialog now use if statements and boolean returns for accepting the dialog
- Edited Tab order in NewTailDialog
- Fixed a bug in NewTailDialog where loading a template would overwrite the registration
- Added some information to pilot and acft display in NewFlightDialog
Felix Turowsky 4 years ago
parent
commit
36e9076bb1

+ 3 - 3
mainwindow.cpp

@@ -132,11 +132,11 @@ void MainWindow::on_actionDebug_triggered()
 
 void MainWindow::connectWidgets()
 {
-    QObject::connect(experimental::aDB(), &experimental::ADataBase::commitSuccessful,
+    QObject::connect(experimental::aDB(), &experimental::ADataBase::updated,
                      logbookWidget, &LogbookWidget::onDatabaseChanged);
-    QObject::connect(experimental::aDB(), &experimental::ADataBase::commitSuccessful,
+    QObject::connect(experimental::aDB(), &experimental::ADataBase::updated,
                      pilotsWidget, &PilotsWidget::onDatabaseChanged);
-    QObject::connect(experimental::aDB(), &experimental::ADataBase::commitSuccessful,
+    QObject::connect(experimental::aDB(), &experimental::ADataBase::updated,
                      aircraftWidget, &AircraftWidget::onDatabaseChanged);
 }
 

+ 34 - 19
src/experimental/adatabase.cpp

@@ -86,7 +86,8 @@ bool ADataBase::commit(AEntry entry)
 bool ADataBase::remove(AEntry entry)
 {
     if (!exists(entry)) {
-        DEB("Error: Entry does not exist.");
+        DEB("Error: Database entry not found.");
+        lastError = "Database Error: Database entry not found.";
         return false;
     }
 
@@ -97,13 +98,14 @@ bool ADataBase::remove(AEntry entry)
     if (query.lastError().type() == QSqlError::NoError)
     {
         DEB("Entry " << entry.getPosition().tableName << entry.getPosition().rowId << " removed.");
-        emit deleteSuccessful();
+        emit updated();
+        lastError = QString();
         return true;
     } else {
         DEB("Unable to delete.");
         DEB("Query: " << statement);
         DEB("Query Error: " << query.lastError().text());
-        emit sqlError(query.lastError(), statement);
+        lastError = query.lastError().text();
         return false;
     }
 }
@@ -117,7 +119,7 @@ bool ADataBase::removeMany(QList<DataPosition> data_position_list)
 
     for (const auto data_position : data_position_list) {
         if (!exists(data_position)) {
-            DEB("Error: Entry does not exist.");
+            lastError = "Database Error: Database entry not found.";
             errorCount++;
         }
         QString statement = "DELETE FROM " + data_position.first +
@@ -134,16 +136,17 @@ bool ADataBase::removeMany(QList<DataPosition> data_position_list)
         query.prepare("COMMIT");
         query.exec();
         if(query.lastError().type() == QSqlError::NoError) {
-            emit deleteSuccessful();
+            emit updated();
+            lastError = QString();
             return true;
         } else {
-            emit sqlError(query.lastError(), "Transaction unsuccessful. Error count: " + QString::number(errorCount));
+            lastError = "Transaction unsuccessful (Interrupted). Error count: " + QString::number(errorCount);
             return false;
         }
     } else {
         query.prepare("ROLLBACK");
         query.exec();
-        emit sqlError(query.lastError(), "Transaction unsuccessful(rolled back). Error count: " + QString::number(errorCount));
+        lastError = "Transaction unsuccessful (no changes have been made). Error count: " + QString::number(errorCount);
         return false;
     }
 }
@@ -162,8 +165,9 @@ bool ADataBase::exists(AEntry entry)
     query.exec();
     //this returns either 1 or 0 since row ids are unique
     if (!query.isActive()) {
-        emit sqlError(query.lastError(), statement);
+        lastError = query.lastError().text();
         DEB("Query Error: " << query.lastError().text() << statement);
+        return false;
     }
     query.next();
     int rowId = query.value(0).toInt();
@@ -171,7 +175,8 @@ bool ADataBase::exists(AEntry entry)
         DEB("Entry " << entry.getPosition() << " exists.");
         return true;
     } else {
-        DEB("Entry does not exist.");
+        DEB("Database entry not found.");
+        lastError = "Database Error: Database entry not found.";
         return false;
     }
 }
@@ -190,7 +195,7 @@ bool ADataBase::exists(DataPosition data_position)
     query.exec();
     //this returns either 1 or 0 since row ids are unique
     if (!query.isActive()) {
-        emit sqlError(query.lastError(), statement);
+        lastError = query.lastError().text();
         DEB("Query Error: " << query.lastError().text() << statement);
     }
     query.next();
@@ -200,6 +205,7 @@ bool ADataBase::exists(DataPosition data_position)
         return true;
     } else {
         DEB("No entry exists at DataPosition: " << data_position);
+        lastError = "Database Error: Database entry not found.";
         return false;
     }
 }
@@ -225,13 +231,14 @@ bool ADataBase::update(AEntry updated_entry)
     if (query.lastError().type() == QSqlError::NoError)
     {
         DEB("Entry successfully committed.");
-        emit commitSuccessful();
+        emit updated();
+        lastError = QString();
         return true;
     } else {
         DEB("Unable to commit.");
         DEB("Query: " << statement);
         DEB("Query Error: " << query.lastError().text());
-        emit sqlError(query.lastError(), statement);
+        lastError = query.lastError().text();
         return false;
     }
 }
@@ -263,13 +270,14 @@ bool ADataBase::insert(AEntry new_entry)
     if (query.lastError().type() == QSqlError::NoError)
     {
         DEB("Entry successfully committed.");
-        emit commitSuccessful();
+        emit updated();
+        lastError = QString();
         return true;
     } else {
         DEB("Unable to commit.");
         DEB("Query: " << statement);
         DEB("Query Error: " << query.lastError().text());
-        emit sqlError(query.lastError(), statement);
+        lastError = query.lastError().text();
         return false;
     }
 
@@ -294,12 +302,14 @@ TableData ADataBase::getEntryData(DataPosition data_position)
     if (check_query.lastError().type() != QSqlError::NoError) {
         DEB("SQL error: " << check_query.lastError().text());
         DEB("Statement: " << statement);
+        lastError = check_query.lastError().text();
         return TableData();
     }
 
     check_query.next();
     if (check_query.value(0).toInt() == 0) {
         DEB("No Entry found for row id: " << data_position.second );
+        lastError = "Database Error: Database entry not found.";
         return TableData();
     }
 
@@ -316,6 +326,7 @@ TableData ADataBase::getEntryData(DataPosition data_position)
     if (select_query.lastError().type() != QSqlError::NoError) {
         DEB("SQL error: " << select_query.lastError().text());
         DEB("Statement: " << statement);
+        lastError = select_query.lastError().text();
         return TableData();
     }
 
@@ -395,8 +406,10 @@ const QStringList ADataBase::getCompletionList(ADataBase::DatabaseTarget target)
     query.setForwardOnly(true);
     query.exec();
 
-    if(!query.isActive())
-        emit sqlError(query.lastError(), statement);
+    if(!query.isActive()) {
+        lastError = query.lastError().text();
+        return QStringList();
+    }
 
     QStringList completer_list;
     while (query.next())
@@ -445,7 +458,7 @@ const QMap<QString, int> ADataBase::getIdMap(ADataBase::DatabaseTarget target)
         DEB("No result found. Check Query and Error.");
         DEB("Query: " << statement);
         DEB("Error: " << query.lastError().text());
-        emit sqlError(query.lastError(), statement);
+        lastError = query.lastError().text();
         return QMap<QString, int>();
     } else {
         QVector<QString> query_result;
@@ -478,6 +491,7 @@ int ADataBase::getLastEntry(ADataBase::DatabaseTarget target)
     if (query.first()) {
         return query.value(0).toInt();
     } else {
+        lastError = "Database Error: Database entry not found.";
         DEB("No entry found.");
         return 0;
     }
@@ -492,7 +506,7 @@ QVector<QString> ADataBase::customQuery(QString statement, int return_values)
         DEB("No result found. Check Query and Error.");
         DEB("Error: " << query.lastError().text());
         DEB("Statement: " << statement);
-        emit sqlError(query.lastError(), statement);
+        lastError = query.lastError().text();
         return QVector<QString>();
     } else {
         query.first();
@@ -503,7 +517,8 @@ QVector<QString> ADataBase::customQuery(QString statement, int return_values)
                 result.append(query.value(i).toString());
             }
         }
-        emit commitSuccessful();
+        emit updated();
+        lastError = QString();
         return result;
     }
 }

+ 9 - 6
src/experimental/adatabase.h

@@ -51,6 +51,7 @@ public:
     ADataBase(const ADataBase&) = delete;
     void operator=(const ADataBase&) = delete;
     static ADataBase* getInstance();
+    QString lastError;
 
     /*!
      * \brief The CompleterTarget enum provides the items for which QCompleter
@@ -179,13 +180,15 @@ public:
     const QMap<QString, int> getIdMap(DatabaseTarget);
 
     int getLastEntry(DatabaseTarget);
-signals:
-    void commitSuccessful();
-
-    void deleteSuccessful();
-
-    void sqlError(const QSqlError &sqlError, const QString &sqlStatement);
 
+signals:
+    /*!
+     * \brief updated is emitted whenever the database contents have been updated.
+     * This can be either a commit, update or remove. This signal should be used to
+     * trigger an update to the models of the views displaying database contents in
+     * the user interface so that a user is always presented with up-to-date information.
+     */
+    void updated();
 };
 
 /*!

+ 2 - 2
src/experimental/aflightentry.cpp

@@ -30,7 +30,7 @@ const QString AFlightEntry::summary()
     return flight_summary;
 }
 
-const QString AFlightEntry::registration()
+const QString AFlightEntry::getRegistration()
 {
     QString tail_id = tableData.value("acft");
     if(tail_id.isEmpty())
@@ -49,7 +49,7 @@ const QString AFlightEntry::registration()
     }
 }
 
-const QString AFlightEntry::pilotName(pilot pilot_)
+const QString AFlightEntry::getPilotName(pilot pilot_)
 {
     QString row_id;
     switch (pilot_) {

+ 4 - 4
src/experimental/aflightentry.h

@@ -14,24 +14,24 @@ public:
     AFlightEntry(int row_id);
     AFlightEntry(TableData table_data);
 
-    enum pilot {pic, sic, thirdPilot };
+    enum pilot { pic, sic, thirdPilot };
 
     /*!
-     * \brief Returs a summary of the flight data
+     * \brief Returs a summary of the flight data, if struct holds data
      * \return "doft, dept, tofb, dest, tonb"
      */
     const QString summary();
     /*!
      * \brief Returns the tails' registration from the database.
      */
-    const QString registration();
+    const QString getRegistration();
     /*!
      * \brief Returns the pilots name from the Database
      *
      * \param pilot_number - 1=pic, 2=second Pilot, 3 = third Pilot
      * \return "Lastname, Firstname"
      */
-    const QString pilotName(pilot);
+    const QString getPilotName(pilot);
 };
 
 } // namespace experimental

+ 18 - 0
src/experimental/atailentry.cpp

@@ -31,4 +31,22 @@ ATailEntry::ATailEntry(TableData table_data)
     : AEntry::AEntry(DEFAULT_TAIL_POSITION, table_data)
 {}
 
+const QString ATailEntry::registration()
+{
+    return getData().value("registration");
+}
+
+const QString ATailEntry::type()
+{
+    QString type_string;
+    if (!getData().value("make").isEmpty())
+        type_string.append(getData().value("make") + ' ');
+    if (!getData().value("model").isEmpty())
+        type_string.append(getData().value("model"));
+    if (!getData().value("variant").isEmpty())
+        type_string.append('-' + getData().value("variant") + ' ');
+
+    return type_string;
+}
+
 } // namespace experimental

+ 4 - 0
src/experimental/atailentry.h

@@ -30,6 +30,10 @@ public:
     ATailEntry& operator=(const ATailEntry& te) = default;
     ATailEntry(int row_id);
     ATailEntry(TableData table_data);
+
+    const QString registration();
+
+    const QString type();
 };
 
 } // namespace experimental

+ 9 - 1
src/gui/dialogues/newflight.ui

@@ -17,7 +17,7 @@
    <item row="0" column="0" colspan="2">
     <widget class="QTabWidget" name="flightDataTabWidget">
      <property name="currentIndex">
-      <number>1</number>
+      <number>0</number>
      </property>
      <widget class="QWidget" name="flightDataTab">
       <attribute name="title">
@@ -826,6 +826,13 @@
          </property>
         </widget>
        </item>
+       <item row="6" column="5">
+        <widget class="QLabel" name="picCompanyLabel">
+         <property name="text">
+          <string/>
+         </property>
+        </widget>
+       </item>
       </layout>
       <zorder>placeLabel2</zorder>
       <zorder>deptLocLineEdit</zorder>
@@ -881,6 +888,7 @@
       <zorder>doftDisplayLabel</zorder>
       <zorder>placeLabel1</zorder>
       <zorder>calendarCheckBox</zorder>
+      <zorder>picCompanyLabel</zorder>
      </widget>
      <widget class="QWidget" name="autoLoggingTab">
       <attribute name="title">

+ 19 - 11
src/gui/dialogues/newflightdialog.cpp

@@ -630,7 +630,7 @@ void NewFlightDialog::formFiller()
         line_edits_names << le->objectName();
     }
 
-    ui->acftLineEdit->setText(flightEntry.registration());
+    ui->acftLineEdit->setText(flightEntry.getRegistration());
     line_edits_names.removeOne("acftLineEdit");
 
     for (const auto& data_key : flightEntry.getData().keys()) {
@@ -866,13 +866,16 @@ void NewFlightDialog::on_submitButton_clicked()
     DEB("Committing...");
     if (!aDB()->commit(flightEntry)) {
         auto message_box = QMessageBox(this);
-        message_box.setText("An error has ocurred. Your entry has not been saved.");
+        message_box.setText("The following error has ocurred:\n\n"
+                            + aDB()->lastError
+                            + "\n\nYour entry has not been saved.");
         message_box.setIcon(QMessageBox::Warning);
         message_box.exec();
         return;
-        /// [F] To do: get error info and display here.
+    } else {
+        QDialog::accept();
     }
-    QDialog::accept();
+
 }
 
 
@@ -1077,7 +1080,7 @@ void NewFlightDialog::on_destLocLineEdit_editingFinished()
 void NewFlightDialog::onLocLineEdit_editingFinished(QLineEdit *line_edit, QLabel *name_label)
 {
     const auto &text = line_edit->text();
-    DEB(line_edit->objectName() << " Editing finished. " << text);
+    //DEB(line_edit->objectName() << " Editing finished. " << text);
     int airport_id = 0;
 
     // try to map iata or icao code to airport id;
@@ -1106,7 +1109,7 @@ void NewFlightDialog::onTimeLineEdit_editingFinished()
 {
     auto sender_object = sender();
     auto line_edit = this->findChild<QLineEdit*>(sender_object->objectName());
-    DEB(line_edit->objectName() << "Editing Finished -" << line_edit->text());
+    //DEB(line_edit->objectName() << "Editing Finished -" << line_edit->text());
 
     line_edit->setText(ACalc::formatTimeInput(line_edit->text()));
     const auto time = QTime::fromString(line_edit->text(),TIME_FORMAT);
@@ -1128,11 +1131,12 @@ void NewFlightDialog::onTimeLineEdit_editingFinished()
 void NewFlightDialog::on_acftLineEdit_editingFinished()
 {
     auto line_edit = ui->acftLineEdit;
-    DEB(line_edit->objectName() << "Editing Finished!" << line_edit->text());
+    //DEB(line_edit->objectName() << "Editing Finished!" << line_edit->text());
 
     if (tailsIdMap.value(line_edit->text()) != 0) {
         DEB("Mapped: " << line_edit->text() << tailsIdMap.value(line_edit->text()));
-        ui->acftTypeLabel->setText(line_edit->text()); // to do: display ac info
+        auto acft = aDB()->getTailEntry(tailsIdMap.value(line_edit->text()));
+        ui->acftTypeLabel->setText(acft.type());
         emit goodInputReceived(line_edit);
         return;
     }
@@ -1159,16 +1163,21 @@ void NewFlightDialog::onPilotNameLineEdit_editingFinished()
 {
     auto sender_object = sender();
     auto line_edit = this->findChild<QLineEdit*>(sender_object->objectName());
-    DEB(line_edit->objectName() << "Editing Finished -" << line_edit->text());
+    //DEB(line_edit->objectName() << "Editing Finished -" << line_edit->text());
 
     if(line_edit->text().contains(SELF_RX)) {
         DEB("self recognized.");
         line_edit->setText(pilotsIdMap.key(1));
+        auto pilot = aDB()->getPilotEntry(1);
+        ui->picCompanyLabel->setText(pilot.getData().value("company"));
         emit goodInputReceived(line_edit);
         return;
     }
+
     if(pilotsIdMap.value(line_edit->text()) != 0) {
         DEB("Mapped: " << line_edit->text() << pilotsIdMap.value(line_edit->text()));
+        auto pilot = aDB()->getPilotEntry(pilotsIdMap.value(line_edit->text()));
+        ui->picCompanyLabel->setText(pilot.getData().value("company"));
         emit goodInputReceived(line_edit);
         return;
     }
@@ -1177,7 +1186,6 @@ void NewFlightDialog::onPilotNameLineEdit_editingFinished()
         return;
     }
 
-
     if (!line_edit->completer()->currentCompletion().isEmpty()) {
         DEB("Trying to fix input...");
         line_edit->setText(line_edit->completer()->currentCompletion());
@@ -1272,7 +1280,7 @@ void NewFlightDialog::on_ApproachComboBox_currentTextChanged(const QString &arg1
     }
 }
 
-void NewFlightDialog::on_FunctionComboBox_currentIndexChanged(int index)
+void NewFlightDialog::on_FunctionComboBox_currentIndexChanged(int)
 {
     if (updateEnabled)
         fillDeductibleData();

+ 1 - 1
src/gui/dialogues/newpilot.ui

@@ -128,8 +128,8 @@
   </layout>
  </widget>
  <tabstops>
-  <tabstop>picfirstnameLineEdit</tabstop>
   <tabstop>piclastnameLineEdit</tabstop>
+  <tabstop>picfirstnameLineEdit</tabstop>
   <tabstop>companyLineEdit</tabstop>
   <tabstop>aliasLineEdit</tabstop>
   <tabstop>employeeidLineEdit</tabstop>

+ 10 - 27
src/gui/dialogues/newpilotdialog.cpp

@@ -112,17 +112,6 @@ void NewPilotDialog::setup()
     completer->setCompletionMode(QCompleter::InlineCompletion);
     completer->setCaseSensitivity(Qt::CaseSensitive);
     ui->companyLineEdit->setCompleter(completer);
-
-    ///[F] moved connecting the slots here because
-    /// - no need to declare the slots public as would be the case if connected in mainwindow
-    /// - only one place where slots are connected vs. several places (mainwindow, pilotswidget),
-    ///   makes it easier to maintain.
-    /// - these signals and slots are specific to this dialog, for communication with
-    ///   other widgets we have the QDialog::accepted() and QDialog::rejected signals.
-    QObject::connect(aDB(), &ADataBase::commitSuccessful,
-                     this, &NewPilotDialog::onCommitSuccessful);
-    QObject::connect(aDB(), &ADataBase::sqlError,
-                     this, &NewPilotDialog::onCommitUnsuccessful);
 }
 
 void NewPilotDialog::on_buttonBox_accepted()
@@ -136,21 +125,6 @@ void NewPilotDialog::on_buttonBox_accepted()
     }
 }
 
-void NewPilotDialog::onCommitSuccessful()
-{
-    accept();
-}
-
-void NewPilotDialog::onCommitUnsuccessful(const QSqlError &sqlError, const QString &)
-{
-    auto mb = QMessageBox(this);
-    mb.setIcon(QMessageBox::Critical);
-    mb.setText("The following error has ocurred.\n\n"
-               + sqlError.text()
-               + "\n\nYour entry has not been saved.");
-    mb.exec();
-}
-
 void NewPilotDialog::formFiller()
 {
     DEB("Filling Form...");
@@ -178,5 +152,14 @@ void NewPilotDialog::submitForm()
     pilotEntry.setData(new_data);
     DEB("Pilot entry position: " << pilotEntry.getPosition());
     DEB("Pilot entry data: " << pilotEntry.getData());
-    aDB()->commit(pilotEntry);
+    if (!aDB()->commit(pilotEntry)) {
+        auto message_box = QMessageBox(this);
+        message_box.setText("The following error has ocurred:\n\n"
+                            + aDB()->lastError
+                            + "\n\nThe entry has not been saved.");
+        message_box.exec();
+        return;
+    } else {
+        QDialog::accept();
+    }
 }

+ 0 - 4
src/gui/dialogues/newpilotdialog.h

@@ -44,10 +44,6 @@ public:
 
 private slots:
     void on_buttonBox_accepted();
-
-    void onCommitSuccessful();
-
-    void onCommitUnsuccessful(const QSqlError &sqlError, const QString &);
 private:
     Ui::NewPilot *ui;
 

+ 19 - 24
src/gui/dialogues/newtaildialog.cpp

@@ -37,7 +37,6 @@ NewTailDialog::NewTailDialog(QString new_registration, QWidget *parent) :
     DEB("new NewTailDialog (experimental)");
     ui->setupUi(this);
 
-    connectSignals();
     setupCompleter();
     setupValidators();
 
@@ -60,10 +59,9 @@ NewTailDialog::NewTailDialog(int row_id, QWidget *parent) :
     ui->searchLineEdit->hide();
     ui->line->hide();
 
-    connectSignals();
     setupValidators();
     entry = aDB()->getTailEntry(row_id);
-    fillForm(entry);
+    fillForm(entry, false);
 }
 
 NewTailDialog::~NewTailDialog()
@@ -108,15 +106,6 @@ void NewTailDialog::setupValidators()
     }
 }
 
-void NewTailDialog::connectSignals()
-{
-    using namespace experimental;
-    QObject::connect(aDB(), &ADataBase::commitSuccessful,
-                     this,  &NewTailDialog::onCommitSuccessful);
-    QObject::connect(aDB(), &ADataBase::sqlError,
-                     this,  &NewTailDialog::onCommitUnsuccessful);
-}
-
 /*!
  * \brief NewTailDialog::fillForm populates the Dialog with the
  * information contained in an entry object. This can be either
@@ -124,11 +113,15 @@ void NewTailDialog::connectSignals()
  * a tail (ATail, used when editing an existing entry)
  * \param entry
  */
-void NewTailDialog::fillForm(experimental::AEntry entry)
+void NewTailDialog::fillForm(experimental::AEntry entry, bool is_template)
 {
     DEB("Filling Form for (experimental) a/c" << entry.getPosition());
     //fill Line Edits
     auto line_edits = this->findChildren<QLineEdit *>();
+
+    if (is_template)
+        line_edits.removeOne(ui->registrationLineEdit);
+
     for (const auto &le : line_edits) {
         QString name = le->objectName().remove("LineEdit");
         QString value = entry.getData().value(name);
@@ -235,7 +228,16 @@ void NewTailDialog::submitForm()
     //create db object
 
     entry.setData(new_data);
-    aDB()->commit(entry);
+    if (!aDB()->commit(entry)) {
+        auto message_box = QMessageBox(this);
+        message_box.setText("The following error has ocurred:\n\n"
+                            + aDB()->lastError
+                            + "\n\nThe entry has not been saved.");
+        message_box.exec();
+        return;
+    } else {
+        QDialog::accept();
+    }
 }
 
 /// Slots
@@ -314,7 +316,7 @@ void NewTailDialog::onSearchCompleterActivated()
             DEB("Template Selected. aircraft_id is: " << idMap.value(text));
             //call autofiller for dialog
             using namespace experimental;
-            fillForm(aDB()->getAircraftEntry(idMap.value(text)));
+            fillForm(aDB()->getAircraftEntry(idMap.value(text)), true);
             ui->searchLineEdit->setStyleSheet("border: 1px solid green");
             ui->searchLabel->setText(text);
         } else {
@@ -328,18 +330,11 @@ void NewTailDialog::on_registrationLineEdit_textChanged(const QString &arg1)
     ui->registrationLineEdit->setText(arg1.toUpper());
 }
 
-void NewTailDialog::onCommitSuccessful()
-{
-    ACalc::updateAutoTimes(entry.getPosition().second); // To do: update to use new db architecture with new ATailEntry
-    accept();
-}
-
-void NewTailDialog::onCommitUnsuccessful(const QSqlError &sqlError, const QString &)
-{
+/*
     auto mb = QMessageBox(this);
     mb.setIcon(QMessageBox::Critical);
     mb.setText("The following error has ocurred.\n\n"
                + sqlError.text()
                + "\n\nYour entry has not been saved.");
     mb.exec();
-}
+*/

+ 1 - 6
src/gui/dialogues/newtaildialog.h

@@ -67,9 +67,7 @@ private:
 
     void setupValidators();
 
-    void connectSignals();
-
-    void fillForm(experimental::AEntry entry);
+    void fillForm(experimental::AEntry entry, bool is_template);
 
     void submitForm();
 
@@ -91,9 +89,6 @@ private slots:
 
     void onSearchCompleterActivated();
 
-    void onCommitSuccessful();
-
-    void onCommitUnsuccessful(const QSqlError &sqlError, const QString &);
 };
 
 #endif // NEWTAIL_H

+ 3 - 5
src/gui/widgets/debugwidget.cpp

@@ -166,11 +166,9 @@ void DebugWidget::on_debugPushButton_clicked()
 {
     using namespace experimental;
 
-    auto pilotsIdMap  = aDB()->getIdMap(ADataBase::pilots);
-    auto pilotList    = aDB()->getCompletionList(ADataBase::pilots);
-
-    DEB(pilotsIdMap.key(aDB()->getLastEntry(ADataBase::pilots)));
-    DEB(pilotList);
+    auto acft = aDB()->getTailEntry(5);
+    DEB(acft.getData().key("make"));
+    DEB(acft.type());
 
 
 }

+ 20 - 21
src/gui/widgets/logbookwidget.cpp

@@ -19,6 +19,8 @@
 #include "ui_logbookwidget.h"
 #include "src/testing/adebug.h"
 
+using namespace experimental;
+
 const QMap<int, QString> FILTER_MAP = {
     {0, "Date LIKE \"%"},
     {1, "Dept LIKE \"%"},
@@ -75,11 +77,6 @@ void LogbookWidget::connectSignalsAndSlots()
     selection = view->selectionModel();
     QObject::connect(view->selectionModel(), &QItemSelectionModel::selectionChanged,
                      this, &LogbookWidget::flightsTableView_selectionChanged);
-    using namespace experimental;
-    QObject::connect(aDB(), &ADataBase::deleteSuccessful,
-                     this, &LogbookWidget::onDeletedSuccessfully);
-    QObject::connect(aDB(), &ADataBase::sqlError,
-                     this, &LogbookWidget::onDeleteUnsuccessful);
 }
 
 void LogbookWidget::setupDefaultView()
@@ -230,8 +227,14 @@ void LogbookWidget::on_deleteFlightPushButton_clicked()
         if (reply == QMessageBox::Yes) {
             for (auto& flight : flights_list) {
                 DEB("Deleting flight: " << flight.summary());
-                experimental::aDB()->remove(flight);
+                if(!aDB()->remove(flight)) {
+                    messageBox->setText(" Error "); // [F]: To Do: error info
+                    messageBox->exec();
+                    return;
+                }
             }
+            messageBox->setText(QString::number(selectedFlights.length()) + " flights have been deleted successfully.");
+            messageBox->exec();
             displayModel->select();
         }
     } else if (selectedFlights.length() > 10) {
@@ -246,16 +249,25 @@ void LogbookWidget::on_deleteFlightPushButton_clicked()
         confirm.setText(warningMsg);
         int reply = confirm.exec();
         if(reply == QMessageBox::Yes) {
-            QList<experimental::DataPosition> selected_flights;
+            QList<DataPosition> selected_flights;
             for (const auto& flight_id : selectedFlights) {
                 selected_flights.append({"flights", flight_id});
             }
-            experimental::aDB()->removeMany(selected_flights);
+            if (!aDB()->removeMany(selected_flights)) {
+
+                messageBox->setText(" Error "); // [F]: To Do: error info
+                messageBox->exec();
+                return;
+            }
+            messageBox->setText(QString::number(selectedFlights.length()) + " flights have been deleted successfully.");
+            messageBox->exec();
             displayModel->select();
         }
+        displayModel->select();
     }
 }
 
+
 void LogbookWidget::on_tableView_customContextMenuRequested(const QPoint &pos)
 {
     menu->popup(ui->tableView->viewport()->mapToGlobal(pos));
@@ -266,19 +278,6 @@ void LogbookWidget::on_actionDelete_Flight_triggered()
     emit ui->deleteFlightPushButton->clicked();
 }
 
-void LogbookWidget::onDeletedSuccessfully()
-{
-    messageBox->setText(QString::number(selectedFlights.length()) + " entries have been deleted.");
-    messageBox->exec();
-}
-
-void LogbookWidget::onDeleteUnsuccessful(const QSqlError error)
-{
-    messageBox->setText("Error deleting " + QString::number(selectedFlights.length())
-                        + " flights.\n\nThe following error has ocurred:\n\n" + error.text());
-    messageBox->exec();
-}
-
 void LogbookWidget::on_actionEdit_Flight_triggered()
 {
     emit ui->editFlightButton->clicked();

+ 0 - 3
src/gui/widgets/logbookwidget.h

@@ -60,9 +60,6 @@ private slots:
 
     void on_actionDelete_Flight_triggered();
 
-    void onDeletedSuccessfully();
-    void onDeleteUnsuccessful(const QSqlError);
-
     void on_actionEdit_Flight_triggered();
 
     void on_tableView_doubleClicked();