Browse Source

Cleaning up home widget and CurrencyWidget

Felix Turowsky 1 year ago
parent
commit
2c748ed4d1

+ 21 - 57
mainwindow.cpp

@@ -33,13 +33,6 @@
 // Quick and dirty Debug area
 void MainWindow::doDebugStuff()
 {
-    const OPL::DateTimeFormat defaultFormat(
-        OPL::DateTimeFormat::DateFormat::Default,
-        QStringLiteral("yyyy-MM-dd"),
-        OPL::DateTimeFormat::TimeFormat::Default,
-        QStringLiteral("hh:mm")
-        );
-    Settings::setDisplayFormat(defaultFormat);
 //    LogbookTableEditWidget *widget = new LogbookTableEditWidget(this);
 //    widget->init();
 //    widget->setWindowFlags(Qt::Dialog);
@@ -52,9 +45,6 @@ MainWindow::MainWindow(QWidget *parent)
 {
     ui->setupUi(this);
     init();
-
-    // set Startup Screen (Home Screen)
-    ui->stackedWidget->setCurrentWidget(homeWidget);
 }
 
 MainWindow::~MainWindow()
@@ -69,6 +59,7 @@ void MainWindow::init()
     setupToolbar();
     connectWidgets();
     setActionIcons(OPL::Style::getStyleType());
+    ui->stackedWidget->setCurrentWidget(homeWidget);
 }
 
 void MainWindow::setupToolbar()
@@ -96,9 +87,6 @@ void MainWindow::initialiseWidgets()
     homeWidget = new HomeWidget(this);
     ui->stackedWidget->addWidget(homeWidget);
 
-//    logbookWidget = new LogbookWidget(this);
-//    ui->stackedWidget->addWidget(logbookWidget);
-
     logbookWidget = new LogbookTableEditWidget(this);
     logbookWidget->init();
     ui->stackedWidget->addWidget(logbookWidget);
@@ -132,8 +120,9 @@ void MainWindow::connectDatabase()
         WARN(tr("Error establishing database connection. The following error has ocurred:<br><br>%1")
              .arg(DB->lastError.text()));
     }
-    DBCache->init();
+
     // Load Cache
+    DBCache->init();
 }
 
 void MainWindow::setActionIcons(OPL::Style::StyleType style)
@@ -141,27 +130,27 @@ void MainWindow::setActionIcons(OPL::Style::StyleType style)
     switch (style){
     case OPL::Style::StyleType::Light:
         LOG << "Setting Light Icon theme";
-        ui->actionHome->setIcon(QIcon(OPL::Assets::ICON_TOOLBAR_HOME));
-        ui->actionNewFlight->setIcon(QIcon(OPL::Assets::ICON_TOOLBAR_NEW_FLIGHT));
-        ui->actionNewSim->setIcon(QIcon(OPL::Assets::ICON_TOOLBAR_NEW_FLIGHT)); // pending seperate icon
-        ui->actionLogbook->setIcon(QIcon(OPL::Assets::ICON_TOOLBAR_LOGBOOK));
-        ui->actionAircraft->setIcon(QIcon(OPL::Assets::ICON_TOOLBAR_AIRCRAFT));
-        ui->actionPilots->setIcon(QIcon(OPL::Assets::ICON_TOOLBAR_PILOT));
-        ui->actionAirports->setIcon(QIcon(OPL::Assets::ICON_TOOLBAR_BACKUP));
-        ui->actionSettings->setIcon(QIcon(OPL::Assets::ICON_TOOLBAR_SETTINGS));
-        ui->actionQuit->setIcon(QIcon(OPL::Assets::ICON_TOOLBAR_QUIT));
+        ui->actionHome->setIcon(		QIcon(OPL::Assets::ICON_TOOLBAR_HOME));
+        ui->actionNewFlight->setIcon(	QIcon(OPL::Assets::ICON_TOOLBAR_NEW_FLIGHT));
+        ui->actionNewSim->setIcon(		QIcon(OPL::Assets::ICON_TOOLBAR_NEW_FLIGHT)); // TODO seperate icon
+        ui->actionLogbook->setIcon(		QIcon(OPL::Assets::ICON_TOOLBAR_LOGBOOK));
+        ui->actionAircraft->setIcon(	QIcon(OPL::Assets::ICON_TOOLBAR_AIRCRAFT));
+        ui->actionPilots->setIcon(		QIcon(OPL::Assets::ICON_TOOLBAR_PILOT));
+        ui->actionAirports->setIcon(	QIcon(OPL::Assets::ICON_TOOLBAR_BACKUP));
+        ui->actionSettings->setIcon(	QIcon(OPL::Assets::ICON_TOOLBAR_SETTINGS));
+        ui->actionQuit->setIcon(		QIcon(OPL::Assets::ICON_TOOLBAR_QUIT));
         break;
     case OPL::Style::StyleType::Dark:
         LOG << "Setting Dark Icon theme";
-        ui->actionHome->setIcon(QIcon(OPL::Assets::ICON_TOOLBAR_HOME_DARK));
-        ui->actionNewFlight->setIcon(QIcon(OPL::Assets::ICON_TOOLBAR_NEW_FLIGHT_DARK));
-        ui->actionNewSim->setIcon(QIcon(OPL::Assets::ICON_TOOLBAR_NEW_FLIGHT_DARK)); // pending separate icon
-        ui->actionLogbook->setIcon(QIcon(OPL::Assets::ICON_TOOLBAR_LOGBOOK_DARK));
-        ui->actionAircraft->setIcon(QIcon(OPL::Assets::ICON_TOOLBAR_AIRCRAFT_DARK));
-        ui->actionPilots->setIcon(QIcon(OPL::Assets::ICON_TOOLBAR_PILOT_DARK));
-        ui->actionAirports->setIcon(QIcon(OPL::Assets::ICON_TOOLBAR_BACKUP_DARK));
-        ui->actionSettings->setIcon(QIcon(OPL::Assets::ICON_TOOLBAR_SETTINGS_DARK));
-        ui->actionQuit->setIcon(QIcon(OPL::Assets::ICON_TOOLBAR_QUIT_DARK));
+        ui->actionHome->setIcon(		QIcon(OPL::Assets::ICON_TOOLBAR_HOME_DARK));
+        ui->actionNewFlight->setIcon(	QIcon(OPL::Assets::ICON_TOOLBAR_NEW_FLIGHT_DARK));
+        ui->actionNewSim->setIcon(		QIcon(OPL::Assets::ICON_TOOLBAR_NEW_FLIGHT_DARK)); // pending separate icon
+        ui->actionLogbook->setIcon(		QIcon(OPL::Assets::ICON_TOOLBAR_LOGBOOK_DARK));
+        ui->actionAircraft->setIcon(	QIcon(OPL::Assets::ICON_TOOLBAR_AIRCRAFT_DARK));
+        ui->actionPilots->setIcon(		QIcon(OPL::Assets::ICON_TOOLBAR_PILOT_DARK));
+        ui->actionAirports->setIcon(	QIcon(OPL::Assets::ICON_TOOLBAR_BACKUP_DARK));
+        ui->actionSettings->setIcon(	QIcon(OPL::Assets::ICON_TOOLBAR_SETTINGS_DARK));
+        ui->actionQuit->setIcon(		QIcon(OPL::Assets::ICON_TOOLBAR_QUIT_DARK));
         break;
     }
 }
@@ -180,40 +169,16 @@ void MainWindow::nope()
  */
 void MainWindow::connectWidgets()
 {
-    QObject::connect(DB,             &OPL::Database::dataBaseUpdated,
-                     homeWidget,     &HomeWidget::refresh);
-    QObject::connect(settingsWidget, &SettingsWidget::settingChanged,
-                     homeWidget,     &HomeWidget::refresh);
-
-//    QObject::connect(DB,             &OPL::Database::dataBaseUpdated,
-//                     logbookWidget,  &LogbookWidget::refresh);
     QObject::connect(settingsWidget, &SettingsWidget::settingChanged,
                      logbookWidget,  &LogbookTableEditWidget::viewSelectionChanged);
 
-//    QObject::connect(DB,             &OPL::Database::dataBaseUpdated,
-//                     tailsWidget, &TailsWidget::onAircraftWidget_dataBaseUpdated);
-//    QObject::connect(settingsWidget, &SettingsWidget::settingChanged,
-//                     tailsWidget, &TailsWidget::onAircraftWidget_settingChanged);
-
-//    QObject::connect(DB,             &OPL::Database::dataBaseUpdated,
-//                     pilotsWidget,   &PilotsWidget::onPilotsWidget_databaseUpdated);
-//    QObject::connect(settingsWidget, &SettingsWidget::settingChanged,
-//                     pilotsWidget,   &PilotsWidget::onPilotsWidget_settingChanged);
     QObject::connect(settingsWidget, &SettingsWidget::settingChanged,
                      this,           &MainWindow::onStyleChanged);
-
-//    QObject::connect(DB,              &OPL::Database::connectionReset,
-//                     logbookWidget,   &LogbookWidget::repopulateModel);
-//    QObject::connect(DB,              &OPL::Database::connectionReset,
-//                     pilotsWidget,    &PilotsWidget::repopulateModel);
-//    QObject::connect(DB,              &OPL::Database::connectionReset,
-//                     tailsWidget,  &TailsWidget::repopulateModel);
 }
 
 void MainWindow::onDatabaseInvalid()
 {
     QMessageBox db_error(this);
-    //db_error.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
     db_error.addButton(tr("Restore Backup"), QMessageBox::ButtonRole::AcceptRole);
     db_error.addButton(tr("Create New Database"), QMessageBox::ButtonRole::RejectRole);
     db_error.addButton(tr("Abort"), QMessageBox::ButtonRole::DestructiveRole);
@@ -246,7 +211,6 @@ void MainWindow::onDatabaseInvalid()
             on_actionQuit_triggered();
         }
         Settings::setSetupCompleted(true);
-//        Settings::write(Settings::Main::SetupComplete, true);
         LOG << "Initial Setup Completed successfully";
     }
 }

+ 26 - 16
src/gui/widgets/currencywidget.cpp

@@ -12,7 +12,6 @@
 #include <QInputDialog>
 #include <QLabel>
 
-
 CurrencyWidget::CurrencyWidget(QWidget *parent)
     : QWidget{parent}
 {
@@ -23,11 +22,10 @@ CurrencyWidget::CurrencyWidget(QWidget *parent)
     fillTakeOffAndLandingCurrencies();
     fillFlightTimeLimitations();
 
+    warnAboutExpiries();
+
     // warn the user about impending currencies if warning threshold > 0
-    int warningThreshold = Settings::getCurrencyWarningThreshold();
-    if(warningThreshold) {
-        warnAboutExpiries(warningThreshold);
-    }
+
 }
 
 void CurrencyWidget::setupModelAndView()
@@ -187,6 +185,9 @@ void CurrencyWidget::refresh()
     model->select();
     fillTakeOffAndLandingCurrencies();
     fillFlightTimeLimitations();
+
+    view->resizeColumnsToContents();
+    view->horizontalHeader()->setStretchLastSection(QHeaderView::Stretch);
 }
 
 void CurrencyWidget::displayNameEditRequested(const QModelIndex &index)
@@ -205,17 +206,15 @@ void CurrencyWidget::displayNameEditRequested(const QModelIndex &index)
         model->setData(index, text);
         model->submitAll();
     }
-    view->resizeColumnsToContents();
-
 }
 
 void CurrencyWidget::expiryDateEditRequested(const QModelIndex &index)
 {
-    const QString selection = index.data().toString();
-    const QDate selectedDate = QDate::fromString(selection, Qt::ISODate);
-    if(selectedDate.isValid()) {
+    const int selectedDate = index.data().toInt();
+
+    if(selectedDate > 0) {
         const QSignalBlocker blocker(calendar);
-        calendar->setSelectedDate(selectedDate);
+        calendar->setSelectedDate(QDate::fromJulianDay(selectedDate));
         calendar->show();
     } else {
         calendar->show();
@@ -231,18 +230,29 @@ void CurrencyWidget::newExpiryDateSelected()
     model->select();
 }
 
-void CurrencyWidget::warnAboutExpiries(int warningThreshold)
+void CurrencyWidget::warnAboutExpiries()
 {
+    int warningThreshold = Settings::getCurrencyWarningThreshold();
+    if(warningThreshold < 1) {
+        return;
+    }
+
     const QDate today = QDate::currentDate();
 
     for(int i = 0; i < model->rowCount(); i++) {
         const QModelIndex dateIndex = model->index(i, EXPIRY_DATE_COLUMN);
-        QDate date = QDate::fromString(dateIndex.data().toString(), Qt::ISODate);
+        if(dateIndex.data().toInt() == 0) {
+            continue;
+        }
+        const auto expiryDate = QDate::fromJulianDay(dateIndex.data().toInt());
+        const auto warningDate = QDate::fromJulianDay(expiryDate.toJulianDay() - warningThreshold);
 
-        if(date.addDays(warningThreshold) > today) {
-            const QString dateString = date.toString(Qt::ISODate);
+        if(today >= warningDate) {
+            const QString dateString = expiryDate.toString(Qt::ISODate);
             const QString nameString = model->index(i, CURRENCY_NAME_COLUMN).data().toString();
-            QString msg = tr("%1 expires on<br><br>%2").arg(nameString, dateString);
+            const QString daysLeft = QString::number(expiryDate.toJulianDay() - today.toJulianDay());
+
+            QString msg = tr("Your %1 expires in %2 days: <br><br><tt>%3</tt>").arg(nameString, daysLeft, dateString);
             WARN(msg);
         }
     }

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

@@ -25,7 +25,7 @@ class CurrencyWidget : public QWidget
     void setupUI();
     void fillTakeOffAndLandingCurrencies();
     void fillFlightTimeLimitations();
-    void warnAboutExpiries(int warningThreshold);
+    void warnAboutExpiries();
 
     void displayNameEditRequested(const QModelIndex &index);
     void expiryDateEditRequested(const QModelIndex &index);

+ 9 - 168
src/gui/widgets/homewidget.cpp

@@ -16,23 +16,10 @@
  *along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 #include "homewidget.h"
-#include "src/functions/statistics.h"
 #include "src/gui/widgets/currencywidget.h"
 #include "src/gui/widgets/totalswidget.h"
 #include "ui_homewidget.h"
 #include "src/database/database.h"
-#include "src/classes/time.h"
-#include "src/classes/settings.h"
-#include "src/database/row.h"
-
-// EASA FTL Limitations in minutes
-// 100 hours per 28 days
-static const int ROLLING_28_DAYS = 6000;
-// 900 hours per calendar year
-static const int CALENDAR_YEAR = 54000;
-// 1000 hours per rolling 12 months
-static const int ROLLING_12_MONTHS = 60000;
-// Todo: Encapsulate and plan to also use non-EASA (FAA,...) options
 
 HomeWidget::HomeWidget(QWidget *parent) :
     QWidget(parent),
@@ -40,23 +27,12 @@ HomeWidget::HomeWidget(QWidget *parent) :
 {
     ui->setupUi(this);
 
-    auto logo = QPixmap(OPL::Assets::LOGO);
+    const auto logo = QPixmap(OPL::Assets::LOGO);
     ui->logoLabel->setPixmap(logo);
     ui->welcomeLabel->setText(tr("Welcome to openPilotLog, %1!").arg(getLogbookOwnerName()));
 
-// 	today = QDate::currentDate();
-//    ftlWarningThreshold = Settings::getFtlWarningThreshold();
-//    currWarningThreshold = Settings::getCurrencyWarningThreshold();
-//    limitationDisplayLabels = {
-//        ui->TakeOffDisplayLabel,       ui->LandingsDisplayLabel,
-//        ui->FlightTime28dDisplayLabel, ui->FlightTimeCalYearDisplayLabel,
-//        ui->FlightTime12mDisplayLabel
-//    };
-
     fillTotals();
     fillCurrencies();
-//    fillSelectedCurrencies();
-//    fillLimitations();
 
     QObject::connect(DB,    &OPL::Database::dataBaseUpdated,
                      this,  &HomeWidget::onPilotsDatabaseChanged);
@@ -67,37 +43,6 @@ HomeWidget::~HomeWidget()
     delete ui;
 }
 
-void HomeWidget::refresh()
-{
-//    const auto label_list = this->findChildren<QLabel *>();
-//    for (const auto label : label_list)
-//        label->setVisible(true);
-//    for (const auto &label : qAsConst(limitationDisplayLabels))
-//        label->setStyleSheet(QString());
-
-//    fillTotals();
-//    fillSelectedCurrencies();
-//    fillLimitations();
-}
-
-void HomeWidget::onPilotsDatabaseChanged(const OPL::DbTable table)
-{
-    // maybe logbook owner name has changed, redraw
-    if (table == OPL::DbTable::Pilots)
-        ui->welcomeLabel->setText(tr("Welcome to openPilotLog, %1!").arg(getLogbookOwnerName()));
-}
-
-void HomeWidget::changeEvent(QEvent *event)
-{
-    if (event != nullptr)
-        if(event->type() == QEvent::LanguageChange)
-            ui->retranslateUi(this);
-}
-
-/*!
- * \brief HomeWidget::fillTotals Retreives a Database Summary of Total Flight Time via the OPL::Statistics::totals
- * function and parses the return to fill out the QLineEdits.
- */
 void HomeWidget::fillTotals()
 {
     auto tw = new TotalsWidget(TotalsWidget::TotalTimeWidget, this);
@@ -110,124 +55,20 @@ void HomeWidget::fillCurrencies()
     ui->tabWidget->insertTab(1, cw, tr("Currencies"));
 }
 
-void HomeWidget::fillCurrency(OPL::CurrencyEntry::Currency currency, QLabel* display_label)
-{
-//    const auto currency_entry = DB->getCurrencyEntry(currency);
-
-//    if (currency_entry.isValid()) {
-//        // set label for custom currencies
-//        if (currency == OPL::CurrencyEntry::Custom1) {
-//            ui->currCustom1Label->setText(currency_entry.getDisplayName());
-//        } else if (currency == OPL::CurrencyEntry::Custom2) {
-//            ui->currCustom2Label->setText(currency_entry.getDisplayName());
-//        }
-//        // get date and set visible
-//        const QDate date = currency_entry.getExpiryDate();
-//        display_label->setText(date.toString(Qt::ISODate));
-//        setLabelColour(display_label, Colour::None);
-
-//        if (today >= date) {
-//            // currency is expired
-//            setLabelColour(display_label, Colour::Red);
-//            return;
-//        } else if (today.addDays(currWarningThreshold) >= date) {
-//            // currency expires less than <currWarningThreshold> days from current Date
-//            setLabelColour(display_label, Colour::Orange);
-//        }
-//    } else {
-//        display_label->setText(tr("Invalid Date"));
-//    }
-}
-
-/*!
- * \brief HomeWidget::fillSelectedCurrencies Checks whether a currency is selected and
- * retreives and displays relevant data.
- */
-void HomeWidget::fillSelectedCurrencies()
-{
-//    fillCurrencyTakeOffLanding();
-
-//    Settings::getShowCurrency(OPL::CurrencyEntry::Licence) ?
-//                fillCurrency(OPL::CurrencyEntry::Licence, ui->currLicDisplayLabel)
-//              : hideLabels(ui->currLicLabel, ui->currLicDisplayLabel);
-//    Settings::getShowCurrency(OPL::CurrencyEntry::TypeRating) ?
-//                fillCurrency(OPL::CurrencyEntry::TypeRating, ui->currTrDisplayLabel)
-//              : hideLabels(ui->currTrLabel, ui->currTrDisplayLabel);
-//    Settings::getShowCurrency(OPL::CurrencyEntry::LineCheck) ?
-//                fillCurrency(OPL::CurrencyEntry::LineCheck, ui->currLckDisplayLabel)
-//              : hideLabels(ui->currLckLabel, ui->currLckDisplayLabel);
-//    Settings::getShowCurrency(OPL::CurrencyEntry::Medical) ?
-//                fillCurrency(OPL::CurrencyEntry::Medical, ui->currMedDisplayLabel)
-//              : hideLabels(ui->currMedLabel, ui->currMedDisplayLabel);
-//    Settings::getShowCurrency(OPL::CurrencyEntry::Custom1) ?
-//                fillCurrency(OPL::CurrencyEntry::Custom1, ui->currCustom1DisplayLabel)
-//              : hideLabels(ui->currCustom1Label, ui->currCustom1DisplayLabel);
-//    Settings::getShowCurrency(OPL::CurrencyEntry::Custom2) ?
-//                fillCurrency(OPL::CurrencyEntry::Custom2, ui->currCustom2DisplayLabel)
-//              : hideLabels(ui->currCustom2Label, ui->currCustom2DisplayLabel);
-}
-
-/*!
- * \brief HomeWidget::fillCurrencyTakeOffLanding Uses OPL::Statistics::countTakeOffLandings to determine
- * the amount of Take-Offs and Landings in the last 90 days and displays data and notifications
- * as required.
- */
-void HomeWidget::fillCurrencyTakeOffLanding()
+void HomeWidget::onPilotsDatabaseChanged(const OPL::DbTable table)
 {
-//    const auto takeoff_landings = OPL::Statistics::countTakeOffLanding();
-//    if(takeoff_landings.isEmpty())
-//        return;
-
-//    ui->TakeOffDisplayLabel->setText(takeoff_landings[0].toString());
-//    if (takeoff_landings[0].toUInt() < 3)
-//        setLabelColour(ui->TakeOffDisplayLabel, Colour::Red);
-//    ui->LandingsDisplayLabel->setText(takeoff_landings[1].toString());
-//    if (takeoff_landings[1].toUInt() < 3)
-//        setLabelColour(ui->LandingsDisplayLabel, Colour::Red);
-
-//    if (Settings::getShowCurrency(OPL::CurrencyEntry::TakeOffLanding)) {
-//        QDate expiration_date = OPL::Statistics::currencyTakeOffLandingExpiry();
-//        if (expiration_date <= QDate::currentDate())
-//            setLabelColour(ui->currToLdgDisplayLabel, Colour::Red);
-//        ui->currToLdgDisplayLabel->setText(expiration_date.toString(Qt::TextDate));
-//    } else {
-//        ui->currToLdgLabel->hide();
-//        ui->currToLdgDisplayLabel->hide();
-//    }
+    if (table == OPL::DbTable::Pilots)
+        ui->welcomeLabel->setText(tr("Welcome to openPilotLog, %1!").arg(getLogbookOwnerName()));
 }
 
-/*!
- * \brief HomeWidget::fillLimitations Queries OPL::Statistics to obtain information regarding cumulative
- * Flight Times and Calculates and Notifies about approaching Flight Time Limitations
- */
-void HomeWidget::fillLimitations()
+void HomeWidget::changeEvent(QEvent *event)
 {
-//    int minutes = OPL::Statistics::totalTime(OPL::Statistics::TimeFrame::Rolling28Days);
-//    ui->FlightTime28dDisplayLabel->setText(OPL::Time(minutes).toString());
-//    if (minutes >= ROLLING_28_DAYS) {
-//        setLabelColour(ui->FlightTime28dDisplayLabel, Colour::Red);
-//    } else if (minutes >= ROLLING_28_DAYS * ftlWarningThreshold) {
-//        setLabelColour(ui->FlightTime28dDisplayLabel, Colour::Orange);
-//    }
-
-//    minutes = OPL::Statistics::totalTime(OPL::Statistics::TimeFrame::Rolling12Months);
-//    ui->FlightTime12mDisplayLabel->setText(OPL::Time(minutes).toString());
-//    if (minutes >= ROLLING_12_MONTHS) {
-//        setLabelColour(ui->FlightTime12mDisplayLabel, Colour::Red);
-//    } else if (minutes >= ROLLING_12_MONTHS * ftlWarningThreshold) {
-//        setLabelColour(ui->FlightTime12mDisplayLabel, Colour::Orange);
-//    }
-
-//    minutes = OPL::Statistics::totalTime(OPL::Statistics::TimeFrame::CalendarYear);
-//    ui->FlightTimeCalYearDisplayLabel->setText(OPL::Time(minutes).toString());
-//    if (minutes >= CALENDAR_YEAR) {
-//        setLabelColour(ui->FlightTimeCalYearDisplayLabel, Colour::Red);
-//    } else if (minutes >= CALENDAR_YEAR * ftlWarningThreshold) {
-//        setLabelColour(ui->FlightTimeCalYearDisplayLabel, Colour::Orange);
-//    }
+    if (event != nullptr)
+        if(event->type() == QEvent::LanguageChange)
+            ui->retranslateUi(this);
 }
 
-const QString HomeWidget::getLogbookOwnerName()
+const QString HomeWidget::getLogbookOwnerName() const
 {
     OPL::PilotEntry owner = DB->getLogbookOwner();
     QString name = owner.getFirstName();

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

@@ -63,10 +63,6 @@ private:
 
     void fillTotals();
     void fillCurrencies();
-    void fillSelectedCurrencies();
-    void fillCurrencyTakeOffLanding();
-    void fillCurrency(OPL::CurrencyEntry::Currency currency, QLabel *display_label);
-    void fillLimitations();
 
     enum class Colour {Red, Orange, None};
     inline void setLabelColour(QLabel* label, Colour colour)
@@ -95,11 +91,9 @@ private:
     /*!
      * \brief Retreives the users first name from the database.
      */
-    const QString getLogbookOwnerName();
+    const QString getLogbookOwnerName() const;
 
 public slots:
-    void refresh();
-
     void onPilotsDatabaseChanged(const OPL::DbTable table);
 
 protected:

+ 21 - 14
src/gui/widgets/tableeditwidget.cpp

@@ -118,23 +118,23 @@ void TableEditWidget::setupButtonWidget()
 void TableEditWidget::setupSignalsAndSlots()
 {
     // refresh the view when the database is updated
-    QObject::connect(DB,             		   &OPL::Database::dataBaseUpdated,
-                     this,     		 		   &TableEditWidget::databaseContentChanged);
+    QObject::connect(DB,             		   	&OPL::Database::dataBaseUpdated,
+                     this,     		 		   	&TableEditWidget::databaseContentChanged);
     // filter the view
-    QObject::connect(m_filterLineEdit,  		   &QLineEdit::textChanged,
-                     this,                     &TableEditWidget::filterTextChanged);
+    QObject::connect(m_filterLineEdit,  		&QLineEdit::textChanged,
+                     this,                     	&TableEditWidget::filterTextChanged);
     // sort the view by column
-    QObject::connect(m_view->horizontalHeader(), &QHeaderView::sectionClicked,
-                     this,                     &TableEditWidget::sortColumnChanged);
+    QObject::connect(m_view->horizontalHeader(),&QHeaderView::sectionClicked,
+                     this,                     	&TableEditWidget::sortColumnChanged);
     // Edit an entry
-    QObject::connect(m_view,					   &QTableView::clicked,
-                     this, 			    	   &TableEditWidget::editEntryRequested);
+    QObject::connect(m_view,					&QTableView::clicked,
+                     this, 			    	   	&TableEditWidget::editEntryRequested);
     // Add a new entry
-    QObject::connect(m_addNewEntryPushButton,    &QPushButton::clicked,
-                     this, 					   &TableEditWidget::addEntryRequested);
+    QObject::connect(m_addNewEntryPushButton,   &QPushButton::clicked,
+                     this, 					   	&TableEditWidget::addEntryRequested);
     // Delete a selected entry
-    QObject::connect(m_deleteEntryPushButton,    &QPushButton::clicked,
-                     this, 					   &TableEditWidget::deleteEntryRequested);
+    QObject::connect(m_deleteEntryPushButton,   &QPushButton::clicked,
+                     this, 					   	&TableEditWidget::deleteEntryRequested);
 }
 
 void TableEditWidget::addEntryRequested()
@@ -145,8 +145,15 @@ void TableEditWidget::addEntryRequested()
 void TableEditWidget::editEntryRequested(const QModelIndex &selectedIndex)
 {
     int rowId = m_model->index(selectedIndex.row(), 0).data().toInt();
-    m_entryEditDialog->loadEntry(rowId);
-    m_stackedWidget->setCurrentWidget(m_entryEditDialog);
+
+    // clean up old dialog
+    if(m_stackedWidget->indexOf(m_entryEditDialog) != -1) {
+        delete m_entryEditDialog;
+        m_entryEditDialog = getEntryEditDialog(this);
+        m_entryEditDialog->loadEntry(rowId);
+        m_stackedWidget->addWidget(m_entryEditDialog);
+        m_stackedWidget->setCurrentWidget(m_entryEditDialog);
+    }
 
     switch (m_orientation) {
     case Horizontal: