statistics: create themes on demand

Create the themes only when needed (singleton pattern). If
the themes should do more than colors, such as for example
fonts, it is not clear whether that can be done before main()
runs. By creating the themes on demand, the Qt UI should
be initialized in the constructors of the themes.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2021-02-21 16:17:24 +01:00 committed by Dirk Hohndel
parent 7f1107408d
commit 5f91c69f9c
4 changed files with 21 additions and 10 deletions

View file

@ -35,7 +35,7 @@ static const double selectionLassoWidth = 2.0; // Border between title and char
StatsView::StatsView(QQuickItem *parent) : QQuickItem(parent),
backgroundDirty(true),
currentTheme(statsThemes[0]),
currentTheme(&getStatsTheme(false)),
highlightedSeries(nullptr),
xAxis(nullptr),
yAxis(nullptr),
@ -300,10 +300,9 @@ QQuickWindow *StatsView::w() const
return window();
}
void StatsView::setTheme(int idx)
void StatsView::setTheme(bool dark)
{
idx = std::clamp(idx, 0, (int)statsThemes.size() - 1);
currentTheme = statsThemes[idx];
currentTheme = &getStatsTheme(dark);
rootNode->backgroundNode->setColor(currentTheme->backgroundColor);
}