mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-02-13 08:08:42 +00:00
Cloud Service creates unnecessary GlobalContext instances (#4823)
Changes GlobalContext to hide the constructor so this doesn't occur again since it is a singleton.
This commit is contained in:
@@ -968,8 +968,8 @@ CloudServiceSyncDialog::cancelClicked()
|
||||
void
|
||||
CloudServiceSyncDialog::refreshClicked()
|
||||
{
|
||||
double distanceFactor = GlobalContext().useMetricUnits ? 1.0 : MILES_PER_KM;
|
||||
QString distanceUnits = GlobalContext().useMetricUnits ? tr("km") : tr("mi");
|
||||
double distanceFactor = GlobalContext::context()->useMetricUnits ? 1.0 : MILES_PER_KM;
|
||||
QString distanceUnits = GlobalContext::context()->useMetricUnits ? tr("km") : tr("mi");
|
||||
|
||||
progressLabel->setText(tr(""));
|
||||
progressBar->setMinimum(0);
|
||||
|
||||
@@ -33,8 +33,7 @@
|
||||
#include <QMutex>
|
||||
#include <QWebEngineProfile>
|
||||
|
||||
// singleton
|
||||
static GlobalContext *globalContext = NULL;
|
||||
|
||||
static QList<Context*> _contexts;
|
||||
|
||||
GlobalContext::GlobalContext()
|
||||
@@ -44,6 +43,14 @@ GlobalContext::GlobalContext()
|
||||
readConfig(0); // don't reread user metrics just yet
|
||||
}
|
||||
|
||||
GlobalContext*
|
||||
GlobalContext::context()
|
||||
{
|
||||
// Meyer's singleton pattern
|
||||
static GlobalContext globalContext; // Guaranteed thread-safe initialization
|
||||
return &globalContext;
|
||||
}
|
||||
|
||||
void
|
||||
GlobalContext::notifyConfigChanged(qint32 state)
|
||||
{
|
||||
@@ -130,11 +137,6 @@ GlobalContext::userMetricsConfigChanged()
|
||||
SpecialFields::getInstance().reloadFields();
|
||||
}
|
||||
|
||||
GlobalContext *GlobalContext::context()
|
||||
{
|
||||
if (globalContext == NULL) globalContext = new GlobalContext();
|
||||
return globalContext;
|
||||
}
|
||||
|
||||
bool Context::isValid(Context *p) { return p != NULL &&_contexts.contains(p); }
|
||||
|
||||
|
||||
@@ -82,8 +82,8 @@ class GlobalContext : public QObject
|
||||
|
||||
public:
|
||||
|
||||
GlobalContext();
|
||||
static GlobalContext *context();
|
||||
|
||||
void notifyConfigChanged(qint32);
|
||||
|
||||
// metadata etc
|
||||
@@ -100,6 +100,11 @@ class GlobalContext : public QObject
|
||||
signals:
|
||||
void configChanged(qint32); // for global widgets that aren't athlete specific
|
||||
|
||||
private:
|
||||
// singleton pattern
|
||||
GlobalContext();
|
||||
GlobalContext(const GlobalContext&) = delete;
|
||||
GlobalContext& operator=(const GlobalContext&) = delete;
|
||||
};
|
||||
|
||||
class RideNavigator;
|
||||
|
||||
Reference in New Issue
Block a user