Jelajahi Sumber

Bug fixes and improvements

- Fixed a bug where completion Data was not updated when a new Aircraft/Pilot was added in the respective widgets.
- Temproarily disabled warning about currencies. Review implementations
- Added default constructor for UserDataState and used it in ACompletionData to monitor db changes
- Increased Character Limit on Airline Name in NewPilotDialog
Felix Turo 3 tahun lalu
induk
melakukan
1b5e21693f

+ 8 - 2
main.cpp

@@ -39,6 +39,11 @@
 #define ORGNAME QStringLiteral("opl")
 #define ORGDOMAIN QStringLiteral("https://github.com/fiffty-50/openpilotlog")
 
+/*!
+ *  Helper functions that prepare and set up the application
+ */
+namespace Main {
+
 void init()
 {
     LOG << "Setting up / verifying Application Directories...";
@@ -71,6 +76,7 @@ void firstRun()
     ASettings::write(ASettings::Main::SetupComplete, true);
     LOG << "Initial Setup Completed successfully";
 }
+} // namespace Main
 
 int main(int argc, char *argv[])
 {
@@ -87,11 +93,11 @@ int main(int argc, char *argv[])
     }
 
     // Set Up the Application
-    init();
+    Main::init();
 
     // Check for First Run and launch Setup Wizard
     if (!ASettings::read(ASettings::Main::SetupComplete).toBool())
-        firstRun();
+        Main::firstRun();
 
     // Create Main Window and set Window Icon acc. to Platform
     MainWindow w;

+ 5 - 5
mainwindow.cpp

@@ -42,7 +42,7 @@ MainWindow::MainWindow(QWidget *parent)
         WARN(tr("Error: Database file not found."));
         db_invalid = true;
     }
-    if (database_file.size() == 0) {
+    if (database_file.size() == 0) { // To Do: Check for database errors instead of just checking for empty
         WARN(tr("Database file invalid."));
         db_invalid = true;
     }
@@ -212,13 +212,13 @@ void MainWindow::on_actionHome_triggered()
 
 void MainWindow::on_actionNewFlight_triggered()
 {
-    auto old_state = aDB->getUserDataState();
+    // Make sure latest completion data is used, make this trigger only when needed
+    TODO << "Trigger update only when needed.";
+    completionData.update();
+
     NewFlightDialog nf(completionData,
                        this);
     nf.exec();
-    auto new_state = aDB->getUserDataState();
-    if (old_state != new_state)
-        completionData.update();
 }
 
 void MainWindow::on_actionLogbook_triggered()

+ 12 - 5
src/classes/acompletiondata.cpp

@@ -13,15 +13,22 @@ void ACompletionData::init()
     airportIataIdMap = aDB->getIdMap(ADatabaseTarget::airport_identifier_iata);
     airportNameIdMap = aDB->getIdMap(ADatabaseTarget::airport_names);
     airportList      = aDB->getCompletionList(ADatabaseTarget::airport_identifier_all);
+
+    current_state = aDB->getUserDataState();
 }
 
 void ACompletionData::update()
 {
-    // retreive user modifiable data
-    pilotList   = aDB->getCompletionList(ADatabaseTarget::pilots);
-    tailsList   = aDB->getCompletionList(ADatabaseTarget::registrations);
-    pilotsIdMap = aDB->getIdMap(ADatabaseTarget::pilots);
-    tailsIdMap  = aDB->getIdMap(ADatabaseTarget::tails);
+    if (current_state != aDB->getUserDataState()) {
+        // retreive user modifiable data
+        pilotList   = aDB->getCompletionList(ADatabaseTarget::pilots);
+        tailsList   = aDB->getCompletionList(ADatabaseTarget::registrations);
+        pilotsIdMap = aDB->getIdMap(ADatabaseTarget::pilots);
+        tailsIdMap  = aDB->getIdMap(ADatabaseTarget::tails);
+
+        current_state = aDB->getUserDataState();
+    }
+
 }
 
 void ACompletionData::updateTails()

+ 2 - 0
src/classes/acompletiondata.h

@@ -34,6 +34,8 @@ public:
     QStringList pilotList;
     QStringList tailsList;
     QStringList airportList;
+    // User Data State to trigger update if needed
+    UserDataState current_state;
 };
 
 #endif // ACOMPLETIONDATA_H

+ 2 - 0
src/database/adatabase.h

@@ -95,6 +95,8 @@ enum class ADatabaseSummaryKey {
  * \param numPilots - Number of pilots in the database
  */
 struct UserDataState {
+
+    UserDataState(){numTails = 0; numPilots = 0;}
     UserDataState(int numTails_, int numPilots_)
         : numTails(numTails_), numPilots(numPilots_){}
 

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

@@ -52,7 +52,7 @@
    <item row="2" column="1">
     <widget class="QLineEdit" name="companyLineEdit">
      <property name="maxLength">
-      <number>40</number>
+      <number>69</number>
      </property>
     </widget>
    </item>

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

@@ -183,7 +183,7 @@
    <item row="3" column="1">
     <widget class="QLineEdit" name="companyLineEdit">
      <property name="maxLength">
-      <number>20</number>
+      <number>69</number>
      </property>
      <property name="placeholderText">
       <string>optional</string>

+ 1 - 1
src/gui/widgets/aircraftwidget.cpp

@@ -18,7 +18,6 @@
 #include "aircraftwidget.h"
 #include "ui_aircraftwidget.h"
 #include "src/opl.h"
-#include "src/gui/dialogues/newtaildialog.h"
 #include "src/classes/asettings.h"
 #include "src/database/adatabase.h"
 #include "src/classes/atailentry.h"
@@ -199,6 +198,7 @@ void AircraftWidget::on_deleteAircraftButton_clicked()
         }
     }
     refreshView();
+    ui->stackedWidget->setCurrentIndex(0);
 }
 
 /*!

+ 1 - 0
src/gui/widgets/aircraftwidget.h

@@ -23,6 +23,7 @@
 #include <QSqlTableModel>
 #include <QTableView>
 #include "src/gui/widgets/settingswidget.h"
+#include "src/gui/dialogues/newtaildialog.h"
 
 
 namespace Ui {

+ 6 - 3
src/gui/widgets/homewidget.cpp

@@ -54,7 +54,10 @@ HomeWidget::HomeWidget(QWidget *parent) :
     fillTotals();
     fillSelectedCurrencies();
     fillLimitations();
-    checkAllCurrencies();
+
+    // This implementation is annoying. Review or remove.
+    //if (ASettings::read(ASettings::UserData::CurrWarningEnabled).toBool())
+    //    warnCurrencies();
 }
 
 HomeWidget::~HomeWidget()
@@ -213,10 +216,10 @@ void HomeWidget::fillLimitations()
 }
 
 /*!
- * \brief HomeWidget::checkAllCurrencies loops through all the currencies and warns the user about
+ * \brief HomeWidget::warnCurrencies loops through all the currencies and warns the user about
  * impending expiries.
  */
-void HomeWidget::checkAllCurrencies()
+void HomeWidget::warnCurrencies()
 {
     for (int i = 1 ; i <= 6; i++) {
         // Get the Currency entry

+ 1 - 1
src/gui/widgets/homewidget.h

@@ -98,7 +98,7 @@ private:
      * \brief Retreives the users first name from the database.
      */
     const QString userName();
-    void checkAllCurrencies();
+    void warnCurrencies();
 
 public slots:
     void refresh();