mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-02-13 16:18:42 +00:00
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:
@@ -236,7 +236,7 @@ void ConfigDialog::closeClicked()
|
|||||||
// ! new mode: change the CP associated with the present mode
|
// ! new mode: change the CP associated with the present mode
|
||||||
void ConfigDialog::saveClicked()
|
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!
|
// update all the configuration settings!
|
||||||
context->athlete->rideCache->cancel();
|
context->athlete->rideCache->cancel();
|
||||||
|
|
||||||
|
|||||||
@@ -626,7 +626,9 @@ MainWindow::MainWindow(const QDir &home)
|
|||||||
|
|
||||||
|
|
||||||
editMenu = menuBar()->addMenu(tr("&Edit"));
|
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);
|
HelpWhatsThis *editMenuHelp = new HelpWhatsThis(editMenu);
|
||||||
editMenu->setWhatsThis(editMenuHelp->getWhatsThisText(HelpWhatsThis::MenuBar_Edit));
|
editMenu->setWhatsThis(editMenuHelp->getWhatsThisText(HelpWhatsThis::MenuBar_Edit));
|
||||||
@@ -757,8 +759,6 @@ MainWindow::MainWindow(const QDir &home)
|
|||||||
versionClient = new CloudDBVersionClient();
|
versionClient = new CloudDBVersionClient();
|
||||||
versionClient->informUserAboutLatestVersions();
|
versionClient->informUserAboutLatestVersions();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// get rid of splash when currentTab is shown
|
// get rid of splash when currentTab is shown
|
||||||
@@ -2651,24 +2651,23 @@ MainWindow::ridesAutoImport() {
|
|||||||
|
|
||||||
void MainWindow::onEditMenuAboutToShow()
|
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();
|
editMenu->clear();
|
||||||
if (toolMapper != nullptr) {
|
if (toolMapper != nullptr) {
|
||||||
delete toolMapper;
|
toolMapper.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add all the data processors to the tools menu
|
// Add all the data processors to the tools menu
|
||||||
const DataProcessorFactory &factory = DataProcessorFactory::instance();
|
const DataProcessorFactory &factory = DataProcessorFactory::instance();
|
||||||
QList<DataProcessor*> processors = factory.getProcessorsSorted();
|
QList<DataProcessor*> processors = factory.getProcessorsSorted();
|
||||||
toolMapper = new QSignalMapper(this); // maps each option
|
toolMapper = std::make_unique<QSignalMapper>(); // maps each option
|
||||||
connect(toolMapper, &QSignalMapper::mappedString, this, &MainWindow::manualProcess);
|
connect(toolMapper.get(), &QSignalMapper::mappedString, this, &MainWindow::manualProcess);
|
||||||
|
for (const auto& iter : processors) {
|
||||||
for (QList<DataProcessor*>::iterator iter = processors.begin(); iter != processors.end(); ++iter) {
|
if (!iter->isAutomatedOnly()) {
|
||||||
if (! (*iter)->isAutomatedOnly()) {
|
|
||||||
// The localized processor name is shown in menu
|
// 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);
|
editMenu->addAction(action);
|
||||||
connect(action, SIGNAL(triggered()), toolMapper, SLOT(map()));
|
|
||||||
toolMapper->setMapping(action, (*iter)->id());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,8 @@
|
|||||||
#include "GoldenCheetah.h"
|
#include "GoldenCheetah.h"
|
||||||
#include "NewSideBar.h"
|
#include "NewSideBar.h"
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QSqlDatabase>
|
#include <QSqlDatabase>
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
@@ -277,8 +279,6 @@ class MainWindow : public QMainWindow
|
|||||||
// autoload rides from athlete specific directory (preferences)
|
// autoload rides from athlete specific directory (preferences)
|
||||||
void ridesAutoImport();
|
void ridesAutoImport();
|
||||||
|
|
||||||
void onEditMenuAboutToShow();
|
|
||||||
|
|
||||||
#ifdef GC_HAS_CLOUD_DB
|
#ifdef GC_HAS_CLOUD_DB
|
||||||
// CloudDB actions
|
// CloudDB actions
|
||||||
void cloudDBuserEditChart();
|
void cloudDBuserEditChart();
|
||||||
@@ -294,6 +294,7 @@ class MainWindow : public QMainWindow
|
|||||||
void restoreGCState(Context *);
|
void restoreGCState(Context *);
|
||||||
|
|
||||||
void configChanged(qint32);
|
void configChanged(qint32);
|
||||||
|
void onEditMenuAboutToShow();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
@@ -354,8 +355,7 @@ class MainWindow : public QMainWindow
|
|||||||
QAction *checkAction;
|
QAction *checkAction;
|
||||||
|
|
||||||
// Miscellany
|
// Miscellany
|
||||||
QSignalMapper *toolMapper = nullptr;
|
std::unique_ptr<QSignalMapper> toolMapper;
|
||||||
|
|
||||||
#ifdef GC_HAS_CLOUD_DB
|
#ifdef GC_HAS_CLOUD_DB
|
||||||
CloudDBVersionClient *versionClient;
|
CloudDBVersionClient *versionClient;
|
||||||
CloudDBTelemetryClient *telemetryClient;
|
CloudDBTelemetryClient *telemetryClient;
|
||||||
|
|||||||
Reference in New Issue
Block a user