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
|
void
|
||||||
CloudServiceSyncDialog::refreshClicked()
|
CloudServiceSyncDialog::refreshClicked()
|
||||||
{
|
{
|
||||||
double distanceFactor = GlobalContext().useMetricUnits ? 1.0 : MILES_PER_KM;
|
double distanceFactor = GlobalContext::context()->useMetricUnits ? 1.0 : MILES_PER_KM;
|
||||||
QString distanceUnits = GlobalContext().useMetricUnits ? tr("km") : tr("mi");
|
QString distanceUnits = GlobalContext::context()->useMetricUnits ? tr("km") : tr("mi");
|
||||||
|
|
||||||
progressLabel->setText(tr(""));
|
progressLabel->setText(tr(""));
|
||||||
progressBar->setMinimum(0);
|
progressBar->setMinimum(0);
|
||||||
|
|||||||
@@ -33,8 +33,7 @@
|
|||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
#include <QWebEngineProfile>
|
#include <QWebEngineProfile>
|
||||||
|
|
||||||
// singleton
|
|
||||||
static GlobalContext *globalContext = NULL;
|
|
||||||
static QList<Context*> _contexts;
|
static QList<Context*> _contexts;
|
||||||
|
|
||||||
GlobalContext::GlobalContext()
|
GlobalContext::GlobalContext()
|
||||||
@@ -44,6 +43,14 @@ GlobalContext::GlobalContext()
|
|||||||
readConfig(0); // don't reread user metrics just yet
|
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
|
void
|
||||||
GlobalContext::notifyConfigChanged(qint32 state)
|
GlobalContext::notifyConfigChanged(qint32 state)
|
||||||
{
|
{
|
||||||
@@ -130,11 +137,6 @@ GlobalContext::userMetricsConfigChanged()
|
|||||||
SpecialFields::getInstance().reloadFields();
|
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); }
|
bool Context::isValid(Context *p) { return p != NULL &&_contexts.contains(p); }
|
||||||
|
|
||||||
|
|||||||
@@ -82,8 +82,8 @@ class GlobalContext : public QObject
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
GlobalContext();
|
|
||||||
static GlobalContext *context();
|
static GlobalContext *context();
|
||||||
|
|
||||||
void notifyConfigChanged(qint32);
|
void notifyConfigChanged(qint32);
|
||||||
|
|
||||||
// metadata etc
|
// metadata etc
|
||||||
@@ -100,6 +100,11 @@ class GlobalContext : public QObject
|
|||||||
signals:
|
signals:
|
||||||
void configChanged(qint32); // for global widgets that aren't athlete specific
|
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;
|
class RideNavigator;
|
||||||
|
|||||||
Reference in New Issue
Block a user