diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2021-02-12 10:56:48 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2021-02-13 13:02:54 -0800 |
commit | 5a8d7617ce3d1b54f22a0438f593e844757ecc46 (patch) | |
tree | 3ec045749e4535fa38094300dcb639299e4a7b2d /desktop-widgets/statswidget.cpp | |
parent | 2943b1cbde1a60ef00f1878a27f811246d9b2bc3 (diff) | |
download | subsurface-5a8d7617ce3d1b54f22a0438f593e844757ecc46.tar.gz |
statistics: implement primitive "restrict to selection" feature
Allow the user to restrict the analyzed dives based on the
current selection. One button restricts to the current selection
and one button resets the restriction.
Thus, the user can for example select bars in the bar chart
or a range in the scatter plot and perform statistics on
these sets.
The restriction works on top of the filter.
The UI can certainly be improved, but it is a start.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets/statswidget.cpp')
-rw-r--r-- | desktop-widgets/statswidget.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/desktop-widgets/statswidget.cpp b/desktop-widgets/statswidget.cpp index 33174778d..b74a26863 100644 --- a/desktop-widgets/statswidget.cpp +++ b/desktop-widgets/statswidget.cpp @@ -84,6 +84,8 @@ StatsWidget::StatsWidget(QWidget *parent) : QWidget(parent) connect(ui.var1Binner, QOverload<int>::of(&QComboBox::activated), this, &StatsWidget::var1BinnerChanged); connect(ui.var2Binner, QOverload<int>::of(&QComboBox::activated), this, &StatsWidget::var2BinnerChanged); connect(ui.var2Operation, QOverload<int>::of(&QComboBox::activated), this, &StatsWidget::var2OperationChanged); + connect(ui.restrictButton, &QToolButton::clicked, this, &StatsWidget::restrict); + connect(ui.unrestrictButton, &QToolButton::clicked, this, &StatsWidget::unrestrict); ui.stats->setSource(urlStatsView); ui.stats->setResizeMode(QQuickWidget::SizeRootObjectToView); @@ -141,6 +143,18 @@ void StatsWidget::updateUi() view->plot(state); } +void StatsWidget::updateRestrictionLabel() +{ + if (!view) + return; + int num = view->restrictionCount(); + if (num < 0) + ui.restrictionLabel->setText(tr("Analyzing all dives")); + else + ui.restrictionLabel->setText(tr("Analyzing subset (%L1) dives").arg(num)); + ui.unrestrictButton->setEnabled(num > 0); +} + void StatsWidget::closeStats() { MainWindow::instance()->setApplicationState(ApplicationState::Default); @@ -192,6 +206,21 @@ void StatsWidget::featureChanged(int idx, bool status) void StatsWidget::showEvent(QShowEvent *e) { + unrestrict(); updateUi(); QWidget::showEvent(e); } + +void StatsWidget::restrict() +{ + if (view) + view->restrictToSelection(); + updateRestrictionLabel(); +} + +void StatsWidget::unrestrict() +{ + if (view) + view->unrestrict(); + updateRestrictionLabel(); +} |