Browse Source

Language change handled through QWidget::changeEvent(QEvent *event)

No need to implement custom signals and slots, overriding changeEvent() is the way.
Felix Turo 3 years ago
parent
commit
709ae40505

+ 0 - 7
src/classes/atranslator.h

@@ -19,13 +19,6 @@ public:
 
 
 private:
 private:
     static QTranslator *translator;
     static QTranslator *translator;
-
-signals:
-    /*!
-     * \brief languageChanged() is emitted whenever the active translator is reset. This signal can be
-     * connected to a slot triggering ui->retranslateUi(this) for the widgets. (To Do)
-     */
-    void languageChanged();
 };
 };
 
 
 #endif // ATRANSLATOR_H
 #endif // ATRANSLATOR_H

+ 7 - 0
src/gui/widgets/aircraftwidget.cpp

@@ -95,6 +95,13 @@ void AircraftWidget::onAircraftWidget_dataBaseUpdated()
     refreshView();
     refreshView();
 }
 }
 
 
+void AircraftWidget::changeEvent(QEvent *event)
+{
+    if (event != nullptr)
+        if(event->type() == QEvent::LanguageChange)
+            ui->retranslateUi(this);
+}
+
 void AircraftWidget::onNewTailDialog_editingFinished()
 void AircraftWidget::onNewTailDialog_editingFinished()
 {
 {
     refreshView();
     refreshView();

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

@@ -108,6 +108,12 @@ private:
     void onDeleteUnsuccessful();
     void onDeleteUnsuccessful();
 
 
     inline void refreshView(){model->select();}
     inline void refreshView(){model->select();}
+
+protected:
+    /*!
+     * \brief Handles change events, like updating the UI to new localisation
+     */
+    void changeEvent(QEvent* event) override;
 };
 };
 
 
 #endif // AIRCRAFTWIDGET_H
 #endif // AIRCRAFTWIDGET_H

+ 8 - 0
src/gui/widgets/backupwidget.cpp

@@ -47,6 +47,13 @@ BackupWidget::~BackupWidget()
     delete ui;
     delete ui;
 }
 }
 
 
+void BackupWidget::changeEvent(QEvent *event)
+{
+    if (event != nullptr)
+        if(event->type() == QEvent::LanguageChange)
+            ui->retranslateUi(this);
+}
+
 void BackupWidget::refresh()
 void BackupWidget::refresh()
 {
 {
     // First column in table, would be created by listing the files in backupdir
     // First column in table, would be created by listing the files in backupdir
@@ -77,6 +84,7 @@ const QString BackupWidget::absoluteBackupPath()
             + QLatin1String(".db");
             + QLatin1String(".db");
     return AStandardPaths::asChildOfDir(AStandardPaths::Backup, backup_name);
     return AStandardPaths::asChildOfDir(AStandardPaths::Backup, backup_name);
 }
 }
+
 const QString BackupWidget::backupName()
 const QString BackupWidget::backupName()
 {
 {
     return  QLatin1String("logbook_backup_")
     return  QLatin1String("logbook_backup_")

+ 6 - 0
src/gui/widgets/backupwidget.h

@@ -126,6 +126,12 @@ private:
      * \brief Generates the absolute path for a new backup file.
      * \brief Generates the absolute path for a new backup file.
      */
      */
     const QString absoluteBackupPath();
     const QString absoluteBackupPath();
+
+protected:
+    /*!
+     * \brief Handles change events, like updating the UI to new localisation
+     */
+    void changeEvent(QEvent* event) override;
 };
 };
 
 
 #endif // BACKUPWIDGET_H
 #endif // BACKUPWIDGET_H

+ 8 - 1
src/gui/widgets/debugwidget.cpp

@@ -191,7 +191,14 @@ void DebugWidget::on_debugPushButton_clicked()
     //auto frdl = new FirstRunDialog(this);
     //auto frdl = new FirstRunDialog(this);
     //frdl->exec();
     //frdl->exec();
     ATranslator::installTranslator(Opl::Translations::Spanish);
     ATranslator::installTranslator(Opl::Translations::Spanish);
-    ui->retranslateUi(this);
+    //ui->retranslateUi(this);
+}
+
+void DebugWidget::changeEvent(QEvent *event)
+{
+    if (event != nullptr)
+        if(event->type() == QEvent::LanguageChange)
+            ui->retranslateUi(this);
 }
 }
 
 
 /* //Comparing two functions template
 /* //Comparing two functions template

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

@@ -67,6 +67,9 @@ private:
     Ui::DebugWidget *ui;
     Ui::DebugWidget *ui;
 
 
     bool downloadComplete = false;
     bool downloadComplete = false;
+
+protected:
+    void changeEvent(QEvent* event) override;
 };
 };
 
 
 #endif // DEBUGWIDGET_H
 #endif // DEBUGWIDGET_H

+ 7 - 0
src/gui/widgets/homewidget.cpp

@@ -78,6 +78,13 @@ void HomeWidget::refresh()
     fillLimitations();
     fillLimitations();
 }
 }
 
 
+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 AStat::totals
  * \brief HomeWidget::fillTotals Retreives a Database Summary of Total Flight Time via the AStat::totals
  * function and parses the return to fill out the QLineEdits.
  * function and parses the return to fill out the QLineEdits.

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

@@ -99,8 +99,15 @@ private:
      */
      */
     const QString userName();
     const QString userName();
     void checkAllCurrencies();
     void checkAllCurrencies();
+
 public slots:
 public slots:
     void refresh();
     void refresh();
+
+protected:
+    /*!
+     * \brief Handles change events, like updating the UI to new localisation
+     */
+    void changeEvent(QEvent* event) override;
 };
 };
 
 
 #endif // HOMEWIDGET_H
 #endif // HOMEWIDGET_H

+ 7 - 0
src/gui/widgets/logbookwidget.cpp

@@ -107,6 +107,13 @@ void LogbookWidget::connectSignalsAndSlots()
     QObject::connect(view->selectionModel(), &QItemSelectionModel::selectionChanged,
     QObject::connect(view->selectionModel(), &QItemSelectionModel::selectionChanged,
                      this, &LogbookWidget::flightsTableView_selectionChanged);
                      this, &LogbookWidget::flightsTableView_selectionChanged);
 }
 }
+
+void LogbookWidget::changeEvent(QEvent *event)
+{
+    if (event != nullptr)
+        if(event->type() == QEvent::LanguageChange)
+            ui->retranslateUi(this);
+}
 /*
 /*
  * Slots
  * Slots
  */
  */

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

@@ -83,6 +83,12 @@ private:
 
 
     void setupModelAndView(int view_id);
     void setupModelAndView(int view_id);
     void connectSignalsAndSlots();
     void connectSignalsAndSlots();
+
+protected:
+    /*!
+     * \brief Handles change events, like updating the UI to new localisation
+     */
+    void changeEvent(QEvent* event) override;
 };
 };
 
 
 #endif // LOGBOOKWIDGET_H
 #endif // LOGBOOKWIDGET_H

+ 7 - 0
src/gui/widgets/pilotswidget.cpp

@@ -74,6 +74,13 @@ void PilotsWidget::connectSignalsAndSlots()
                      this,                              &PilotsWidget::tableView_headerClicked);
                      this,                              &PilotsWidget::tableView_headerClicked);
 }
 }
 
 
+void PilotsWidget::changeEvent(QEvent *event)
+{
+    if (event != nullptr)
+        if(event->type() == QEvent::LanguageChange)
+            ui->retranslateUi(this);
+}
+
 void PilotsWidget::onPilotsWidget_settingChanged(SettingsWidget::SettingSignal signal)
 void PilotsWidget::onPilotsWidget_settingChanged(SettingsWidget::SettingSignal signal)
 {
 {
     if (signal == SettingsWidget::PilotsWidget)
     if (signal == SettingsWidget::PilotsWidget)

+ 6 - 0
src/gui/widgets/pilotswidget.h

@@ -100,6 +100,12 @@ private:
     void connectSignalsAndSlots();
     void connectSignalsAndSlots();
 
 
     inline void refreshView(){model->select();}
     inline void refreshView(){model->select();}
+
+protected:
+    /*!
+     * \brief Handles change events, like updating the UI to new localisation
+     */
+    void changeEvent(QEvent* event) override;
 };
 };
 
 
 #endif // PILOTSWIDGET_H
 #endif // PILOTSWIDGET_H

+ 7 - 0
src/gui/widgets/settingswidget.cpp

@@ -67,6 +67,13 @@ SettingsWidget::~SettingsWidget()
     delete ui;
     delete ui;
 }
 }
 
 
+void SettingsWidget::changeEvent(QEvent *event)
+{
+    if (event != nullptr)
+        if(event->type() == QEvent::LanguageChange)
+            ui->retranslateUi(this);
+}
+
 void SettingsWidget::setupComboBoxes(){
 void SettingsWidget::setupComboBoxes(){
     {
     {
         // Style combo box
         // Style combo box

+ 6 - 0
src/gui/widgets/settingswidget.h

@@ -139,6 +139,12 @@ signals:
      * an update (repaint) to another widget.
      * an update (repaint) to another widget.
      */
      */
     void settingChanged(SettingSignal widget);
     void settingChanged(SettingSignal widget);
+
+protected:
+    /*!
+     * \brief Handles change events, like updating the UI to new localisation
+     */
+    void changeEvent(QEvent* event) override;
 };
 };
 
 
 #endif // SETTINGSWIDGET_H
 #endif // SETTINGSWIDGET_H