desktop: add statistics widget dummy and application state

Add a new "statistics" application state. In the statistics state
show the statistics widget and the filter in the top quadrants.
The idea is to allow filtering and doing statistics at the same
time.

Sadly, we can't use the filter-widget in different quadrants,
because Qt's ownership model is completely broken / inflexible.
It does not support a widget having different parents and
thus a widget can only belong to one QStackedWidget.

Hiding the map in the statistics view is quite hacky:
Since the view of the quadrants is not determined by the
"ApplicationState", we have to restore the original quadrant
visibility when exiting the stats mode. Therefore, set the
original visibility-state when changing application state.

The MainWindow-quadrant code really needs to be rewritten!

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2020-10-28 12:23:41 +01:00 committed by Dirk Hohndel
parent 165dce4a0e
commit 106f7a8e0e
6 changed files with 34 additions and 2 deletions

View file

@ -12,4 +12,3 @@ void setAppState(ApplicationState state)
{
appState = state;
}

View file

@ -12,6 +12,7 @@ enum class ApplicationState {
EditPlannedDive,
EditDiveSite,
FilterDive,
Statistics,
Count
};

View file

@ -40,6 +40,7 @@ set (SUBSURFACE_UI
setpoint.ui
shiftimagetimes.ui
shifttimes.ui
statswidget.ui
tableview.ui
templateedit.ui
tripselectiodialog.ui
@ -104,6 +105,8 @@ set(SUBSURFACE_INTERFACE
simplewidgets.cpp
simplewidgets.h
starwidget.cpp
statswidget.h
statswidget.cpp
starwidget.h
subsurfacewebservices.cpp
subsurfacewebservices.h

View file

@ -50,6 +50,7 @@
#include "desktop-widgets/tab-widgets/maintab.h"
#include "desktop-widgets/updatemanager.h"
#include "desktop-widgets/simplewidgets.h"
#include "desktop-widgets/statswidget.h"
#include "commands/command.h"
#include "profile-widget/profilewidget2.h"
@ -141,6 +142,7 @@ MainWindow::MainWindow() : QMainWindow(),
graphics = new ProfileWidget2(this);
MapWidget *mapWidget = MapWidget::instance();
plannerWidgets.reset(new PlannerWidgets);
StatsWidget *statistics = new StatsWidget(this);
// what is a sane order for those icons? we should have the ones the user is
// most likely to want towards the top so they are always visible
@ -183,6 +185,8 @@ MainWindow::MainWindow() : QMainWindow(),
{ diveList, FLAG_DISABLED }, { mapWidget, FLAG_NONE } });
registerApplicationState(ApplicationState::FilterDive, { { mainTab.get(), FLAG_NONE }, { profileContainer, FLAG_NONE },
{ diveList, FLAG_NONE }, { &filterWidget, FLAG_NONE } });
registerApplicationState(ApplicationState::Statistics, { { statistics, FLAG_NONE }, { profileContainer, FLAG_NONE },
{ diveList, FLAG_DISABLED }, { &filterWidget, FLAG_NONE } });
setApplicationState(ApplicationState::Default);
setWindowIcon(QIcon(":subsurface-icon"));
@ -1593,6 +1597,15 @@ void MainWindow::on_actionFilterTags_triggered()
showFilterIfEnabled();
}
void MainWindow::on_actionStats_triggered()
{
setApplicationState(getAppState() == ApplicationState::Statistics ? ApplicationState::Default : ApplicationState::Statistics);
toggleCollapsible(true);
ui.topSplitter->setSizes({ EXPANDED, COLLAPSED });
ui.mainSplitter->setSizes({ EXPANDED, EXPANDED });
ui.bottomSplitter->setSizes({ EXPANDED, EXPANDED });
}
void MainWindow::showFilterIfEnabled()
{
if (getAppState() == ApplicationState::FilterDive) {
@ -1642,6 +1655,11 @@ void MainWindow::setApplicationState(ApplicationState state)
setQuadrant(quadrants.topRight, ui.topRight);
setQuadrant(quadrants.bottomLeft, ui.bottomLeft);
setQuadrant(quadrants.bottomRight, ui.bottomRight);
// The statistics view does its own thing with respect to visibility
// of quadrants. So in case we leave that state, change to the
// original visibility of the quadrants.
enterState(this->state);
}
void MainWindow::showProgressBar()

View file

@ -51,7 +51,7 @@ public:
MAP_MAXIMIZED,
INFO_MAXIMIZED,
PROFILE_MAXIMIZED,
LIST_MAXIMIZED,
LIST_MAXIMIZED
};
MainWindow();
@ -131,6 +131,7 @@ slots:
void on_copy_triggered();
void on_paste_triggered();
void on_actionFilterTags_triggered();
void on_actionStats_triggered();
void on_actionConfigure_Dive_Computer_triggered();
void setDefaultState();
void setAutomaticTitle();

View file

@ -97,6 +97,7 @@
<addaction name="actionAutoGroup"/>
<addaction name="separator"/>
<addaction name="actionFilterTags"/>
<addaction name="actionStats"/>
</widget>
<widget class="QMenu" name="menuView">
<property name="title">
@ -107,6 +108,7 @@
<addaction name="actionViewProfile"/>
<addaction name="actionViewInfo"/>
<addaction name="actionViewMap"/>
<addaction name="actionViewStats"/>
<addaction name="separator"/>
<addaction name="actionYearlyStatistics"/>
<addaction name="actionPreviousDC"/>
@ -640,6 +642,14 @@
<string notr="true">Ctrl+F</string>
</property>
</action>
<action name="actionStats">
<property name="text">
<string>Dive statistics</string>
</property>
<property name="shortcut">
<string notr="true">Ctrl+T</string>
</property>
</action>
<action name="profTissues">
<property name="checkable">
<bool>true</bool>