statistics: switch themes on the mobile version

When changing the theme to a dark theme, also change the
statistics theme. The code is a mess, because it crashes
when setting the theme right at the beginning. Therefore,
there is a "theme has been set" flag. Also, this directly
accesses the ThemeInterface singleton object. I have no
time to fight QML, sorry.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2022-01-07 17:28:09 +01:00 committed by Dirk Hohndel
parent 1cff14fa7f
commit ba95edc2d2
3 changed files with 22 additions and 2 deletions

View file

@ -1,4 +1,5 @@
- profile: include profile editing in undo system
- mobile: Add a dark theme for statistics
- core: avoid crash with corrupted cloud storage
- mobile: fix profile scaling issue on high DPR devices
- mobile: bring back profile icons

View file

@ -1,8 +1,9 @@
// SPDX-License-Identifier: GPL-2.0
#include "statsmanager.h"
#include "themeinterface.h"
#include "stats/chartlistmodel.h"
StatsManager::StatsManager() : view(nullptr), charts(nullptr)
StatsManager::StatsManager() : view(nullptr), charts(nullptr), themeInitialized(false)
{
updateUi();
}
@ -19,6 +20,9 @@ void StatsManager::init(StatsView *v, ChartListModel *m)
fprintf(stderr, "StatsManager::init(): no ChartListModel - statistics will not work.\n");
view = v;
charts = m;
connect(ThemeInterface::instance(), &ThemeInterface::currentThemeChanged,
this, &StatsManager::themeChanged);
}
void StatsManager::doit()
@ -64,6 +68,8 @@ void StatsManager::updateUi()
operation2IndexChanged();
sortMode1IndexChanged();
if (view && !std::exchange(themeInitialized, true))
themeChanged();
if (charts)
charts->update(uiState.charts);
if (view)
@ -123,3 +129,14 @@ void StatsManager::setChart(int idx)
state.chartChanged(idx);
updateUi();
}
void StatsManager::themeChanged()
{
if (!view)
return;
// We could just make currentTheme accessible instead of
// using Qt's inane propertySystem. Whatever.
QString theme = ThemeInterface::instance()->property("currentTheme").toString();
view->setTheme(theme == "Dark");
}

View file

@ -49,6 +49,8 @@ signals:
void binner2IndexChanged();
void operation2IndexChanged();
void sortMode1IndexChanged();
private slots:
void themeChanged();
private:
StatsView *view;
ChartListModel *charts;
@ -66,8 +68,8 @@ private:
int operation2Index;
int sortMode1Index;
StatsState::UIState uiState; // Remember UI state so that we can interpret indexes
bool themeInitialized; // setTheme() crashes if called in init()
void updateUi();
};
#endif