From 1c69798463a3ce2ecbf714047e1e940bd47a3e62 Mon Sep 17 00:00:00 2001 From: Magnus Gille Date: Mon, 12 Jan 2026 11:37:17 -0800 Subject: [PATCH] Fix the Edit menu disappearing when changing languages. (#4797) The edit menu attempted to populate itself with aboutToShow() but this is fragile on Mac when the system menu is empty. Also fixed a (very minor) memory leak and rewrote some code in more modern C++. Fixes: #4647 --- src/Gui/ConfigDialog.cpp | 2 +- src/Gui/MainWindow.cpp | 25 ++++++++++++------------- src/Gui/MainWindow.h | 8 ++++---- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/Gui/ConfigDialog.cpp b/src/Gui/ConfigDialog.cpp index 270a26ddb..1dc0519ca 100644 --- a/src/Gui/ConfigDialog.cpp +++ b/src/Gui/ConfigDialog.cpp @@ -236,7 +236,7 @@ void ConfigDialog::closeClicked() // ! new mode: change the CP associated with the present mode void ConfigDialog::saveClicked() { - // if a refresh is happenning stop it, whilst we + // if a refresh is happening stop it, whilst we // update all the configuration settings! context->athlete->rideCache->cancel(); diff --git a/src/Gui/MainWindow.cpp b/src/Gui/MainWindow.cpp index 2400c9ec5..1664a624e 100644 --- a/src/Gui/MainWindow.cpp +++ b/src/Gui/MainWindow.cpp @@ -626,7 +626,9 @@ MainWindow::MainWindow(const QDir &home) editMenu = menuBar()->addMenu(tr("&Edit")); - connect(editMenu, SIGNAL(aboutToShow()), this, SLOT(onEditMenuAboutToShow())); + // Force the signal to emit, without this on MacOS the edit menu disappears if we have translation enabled. + onEditMenuAboutToShow(); + connect(editMenu, &QMenu::aboutToShow, this, &MainWindow::onEditMenuAboutToShow); HelpWhatsThis *editMenuHelp = new HelpWhatsThis(editMenu); editMenu->setWhatsThis(editMenuHelp->getWhatsThisText(HelpWhatsThis::MenuBar_Edit)); @@ -757,8 +759,6 @@ MainWindow::MainWindow(const QDir &home) versionClient = new CloudDBVersionClient(); versionClient->informUserAboutLatestVersions(); - - #endif // get rid of splash when currentTab is shown @@ -2651,24 +2651,23 @@ MainWindow::ridesAutoImport() { void MainWindow::onEditMenuAboutToShow() { + // On MacOS the clear here is dangerous because it's a system menu so we can't do this via aboutToShow. editMenu->clear(); if (toolMapper != nullptr) { - delete toolMapper; + toolMapper.reset(); } - // Add all the data processors to the tools menu const DataProcessorFactory &factory = DataProcessorFactory::instance(); QList processors = factory.getProcessorsSorted(); - toolMapper = new QSignalMapper(this); // maps each option - connect(toolMapper, &QSignalMapper::mappedString, this, &MainWindow::manualProcess); - - for (QList::iterator iter = processors.begin(); iter != processors.end(); ++iter) { - if (! (*iter)->isAutomatedOnly()) { + toolMapper = std::make_unique(); // maps each option + connect(toolMapper.get(), &QSignalMapper::mappedString, this, &MainWindow::manualProcess); + for (const auto& iter : processors) { + if (!iter->isAutomatedOnly()) { // The localized processor name is shown in menu - QAction *action = new QAction(QString("%1...").arg((*iter)->name()), this); + auto* action = new QAction(QString("%1...").arg(iter->name()), toolMapper.get()); + connect(action, &QAction::triggered, toolMapper.get(), static_cast(&QSignalMapper::map)); + toolMapper->setMapping(action, iter->id()); editMenu->addAction(action); - connect(action, SIGNAL(triggered()), toolMapper, SLOT(map())); - toolMapper->setMapping(action, (*iter)->id()); } } } diff --git a/src/Gui/MainWindow.h b/src/Gui/MainWindow.h index 9b361d917..b9bfbafde 100644 --- a/src/Gui/MainWindow.h +++ b/src/Gui/MainWindow.h @@ -22,6 +22,8 @@ #include "GoldenCheetah.h" #include "NewSideBar.h" +#include + #include #include #include @@ -277,8 +279,6 @@ class MainWindow : public QMainWindow // autoload rides from athlete specific directory (preferences) void ridesAutoImport(); - void onEditMenuAboutToShow(); - #ifdef GC_HAS_CLOUD_DB // CloudDB actions void cloudDBuserEditChart(); @@ -294,6 +294,7 @@ class MainWindow : public QMainWindow void restoreGCState(Context *); void configChanged(qint32); + void onEditMenuAboutToShow(); private: @@ -354,8 +355,7 @@ class MainWindow : public QMainWindow QAction *checkAction; // Miscellany - QSignalMapper *toolMapper = nullptr; - + std::unique_ptr toolMapper; #ifdef GC_HAS_CLOUD_DB CloudDBVersionClient *versionClient; CloudDBTelemetryClient *telemetryClient;