cleanup: replace function static variable by member variable

Global variables are evil. In this case not a problem, since
this is a singleton anyway. However, it is bad style and does
unnecessary thread synchronization.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2022-01-05 18:26:19 +01:00 committed by Dirk Hohndel
parent 510f623c77
commit 1cff14fa7f
2 changed files with 10 additions and 8 deletions

View file

@ -50,12 +50,14 @@ ThemeInterface *ThemeInterface::instance()
return self; return self;
} }
ThemeInterface::ThemeInterface() ThemeInterface::ThemeInterface() :
m_basePointSize(-1.0), // simply a placeholder to declare 'this isn't set, yet'
m_currentTheme(qPrefDisplay::theme()),
m_needSignals(true) // make sure the signals fire the first time
{ {
// get current theme // get current theme
m_currentTheme = qPrefDisplay::theme();
update_theme(); update_theme();
m_basePointSize = -1.0; // simply a placeholder to declare 'this isn't set, yet'
} }
void ThemeInterface::set_currentTheme(const QString &theme) void ThemeInterface::set_currentTheme(const QString &theme)
@ -79,14 +81,12 @@ double ThemeInterface::currentScale()
void ThemeInterface::set_currentScale(double newScale) void ThemeInterface::set_currentScale(double newScale)
{ {
static bool needSignals = true; // make sure the signals fire the first time
if (!IS_FP_SAME(newScale, qPrefDisplay::mobile_scale())) { if (!IS_FP_SAME(newScale, qPrefDisplay::mobile_scale())) {
qPrefDisplay::set_mobile_scale(newScale); qPrefDisplay::set_mobile_scale(newScale);
emit currentScaleChanged(); emit currentScaleChanged();
needSignals = true; m_needSignals = true;
} }
if (needSignals) { if (m_needSignals) {
// adjust all used font sizes // adjust all used font sizes
m_regularPointSize = m_basePointSize * newScale; m_regularPointSize = m_basePointSize * newScale;
defaultModelFont().setPointSizeF(m_regularPointSize); defaultModelFont().setPointSizeF(m_regularPointSize);
@ -101,7 +101,7 @@ void ThemeInterface::set_currentScale(double newScale)
m_titlePointSize = m_regularPointSize * 1.5; m_titlePointSize = m_regularPointSize * 1.5;
emit titlePointSizeChanged(); emit titlePointSizeChanged();
needSignals = false; m_needSignals = false;
} }
} }

View file

@ -87,5 +87,7 @@ private:
double m_titlePointSize; double m_titlePointSize;
QString m_currentTheme; QString m_currentTheme;
bool m_needSignals;
}; };
#endif #endif