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
This commit is contained in:
Magnus Gille
2026-01-12 11:37:17 -08:00
committed by GitHub
parent 2910799610
commit 1c69798463
3 changed files with 17 additions and 18 deletions

View File

@@ -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();

View File

@@ -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<DataProcessor*> processors = factory.getProcessorsSorted();
toolMapper = new QSignalMapper(this); // maps each option
connect(toolMapper, &QSignalMapper::mappedString, this, &MainWindow::manualProcess);
for (QList<DataProcessor*>::iterator iter = processors.begin(); iter != processors.end(); ++iter) {
if (! (*iter)->isAutomatedOnly()) {
toolMapper = std::make_unique<QSignalMapper>(); // 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<void(QSignalMapper::*)()>(&QSignalMapper::map));
toolMapper->setMapping(action, iter->id());
editMenu->addAction(action);
connect(action, SIGNAL(triggered()), toolMapper, SLOT(map()));
toolMapper->setMapping(action, (*iter)->id());
}
}
}

View File

@@ -22,6 +22,8 @@
#include "GoldenCheetah.h"
#include "NewSideBar.h"
#include <memory>
#include <QDir>
#include <QSqlDatabase>
#include <QtGui>
@@ -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<QSignalMapper> toolMapper;
#ifdef GC_HAS_CLOUD_DB
CloudDBVersionClient *versionClient;
CloudDBTelemetryClient *telemetryClient;