diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2021-01-04 15:47:33 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2021-01-10 15:16:52 -0800 |
commit | eb2b0f0a3eb9cf84970c9a21dda9553112b99b17 (patch) | |
tree | bf25194d1cdc96975f2279e566474e09bf6299ac /mobile-widgets/statsmanager.cpp | |
parent | d77f25432850ea2e2ea9e7fb84c49d52c3a308eb (diff) | |
download | subsurface-eb2b0f0a3eb9cf84970c9a21dda9553112b99b17.tar.gz |
mobile/statistics: add a statistics page on mobile
This adds a reasonably flexibile mobile page that tries to do the right
thing for both portrait and landscape mode. In order to get the most out
of a mobile screen, it's implemented in a way that always gives it the
full screen (it does so by emptying out the page stack and being the
only page shown - brutal, but effective).
This commit also contains a bunch of other random cleanups that didn't
really justify being in separate commits.
Parts of this was written by Berthold, hence the double SOB.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'mobile-widgets/statsmanager.cpp')
-rw-r--r-- | mobile-widgets/statsmanager.cpp | 63 |
1 files changed, 62 insertions, 1 deletions
diff --git a/mobile-widgets/statsmanager.cpp b/mobile-widgets/statsmanager.cpp index 2864a5f16..d149c9978 100644 --- a/mobile-widgets/statsmanager.cpp +++ b/mobile-widgets/statsmanager.cpp @@ -7,13 +7,14 @@ StatsManager::StatsManager() : view(nullptr) state.var1Changed(2); state.var2Changed(3); state.binner2Changed(2); + updateUi(); } StatsManager::~StatsManager() { } -void StatsManager::init(StatsView *v) +void StatsManager::init(StatsView *v, QObject *o) { if (!v) fprintf(stderr, "StatsManager::init(): no StatsView - statistics will not work.\n"); @@ -26,3 +27,63 @@ void StatsManager::doit() return; view->plot(state); } + +static void setVariableList(const StatsState::VariableList &list, QStringList &stringList) +{ + stringList.clear(); + for (const StatsState::Variable &v: list.variables) + stringList.push_back(v.name); +} + +static void setBinnerList(const StatsState::BinnerList &list, QStringList &stringList) +{ + stringList.clear(); + for (const QString &v: list.binners) + stringList.push_back(v); +} + +void StatsManager::updateUi() +{ + uiState = state.getUIState(); + setVariableList(uiState.var1, var1List); + setBinnerList(uiState.binners1, binner1List); + setVariableList(uiState.var2, var2List); + setBinnerList(uiState.binners2, binner2List); + var1ListChanged(); + binner1ListChanged(); + var2ListChanged(); + binner2ListChanged(); + + if (view) + view->plot(state); +} + +void StatsManager::var1Changed(int idx) +{ + if (uiState.var1.variables.empty()) + return; + idx = std::clamp(idx, 0, (int)uiState.var1.variables.size()); + state.var1Changed(uiState.var1.variables[idx].id); + updateUi(); +} + +void StatsManager::var1BinnerChanged(int idx) +{ + state.binner1Changed(idx); + updateUi(); +} + +void StatsManager::var2Changed(int idx) +{ + if (uiState.var2.variables.empty()) + return; + idx = std::clamp(idx, 0, (int)uiState.var2.variables.size()); + state.var2Changed(uiState.var2.variables[idx].id); + updateUi(); +} + +void StatsManager::var2BinnerChanged(int idx) +{ + state.binner2Changed(idx); + updateUi(); +} |