From 7b0455b4d8af2d8a917810cc467376a6d7653a23 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sun, 3 Jan 2021 00:31:55 +0100 Subject: statistics: reverse chart selection logic The old ways was to select the chart first, then depending on the chart choose the binning. Willem says that it should work the other way round: select the binning (or operation) and make the charts depend on that. I'm not arguing one way or the other, just note that the new way is much more tricky, because it is easy to get unsupported combinations. For example, there is no chart where the first variable is unbinned, but the second axis is binned or has an operation. This makes things distinctly more tricky and this code still needs a thorough audit. Since this is all more tricky, implement a "invalid" chart state. Ideally that should be never shown to the user, but let's try to be defensive. Signed-off-by: Berthold Stoeger --- desktop-widgets/statswidget.cpp | 34 ++++++---------------------------- 1 file changed, 6 insertions(+), 28 deletions(-) (limited to 'desktop-widgets') diff --git a/desktop-widgets/statswidget.cpp b/desktop-widgets/statswidget.cpp index 874a6db15..01fd16eb1 100644 --- a/desktop-widgets/statswidget.cpp +++ b/desktop-widgets/statswidget.cpp @@ -89,45 +89,23 @@ StatsWidget::StatsWidget(QWidget *parent) : QWidget(parent) static void setVariableList(QComboBox *combo, const StatsState::VariableList &list) { combo->clear(); + combo->setEnabled(!list.variables.empty()); for (const StatsState::Variable &v: list.variables) combo->addItem(v.name, QVariant(v.id)); combo->setCurrentIndex(list.selected); } // Initialize QComboBox and QLabel of binners. Hide if there are no binners. -static void setBinList(QLabel *label, QComboBox *combo, const QString &varName, const StatsState::BinnerList &list) +static void setBinList(QLabel *label, QComboBox *combo, const StatsState::BinnerList &list) { combo->clear(); - if (list.binners.empty()) { - label->hide(); - combo->hide(); - return; - } - - label->show(); - combo->show(); + combo->setEnabled(!list.binners.empty()); for (const QString &s: list.binners) combo->addItem(s); combo->setCurrentIndex(list.selected); } -// Initialize QComboBox and QLabel of operations. Hide if there are no operations. -static void setOperationList(QLabel *label, QComboBox *combo, const QString &varName, const StatsState::VariableList &list) -{ - combo->clear(); - if (list.variables.empty()) { - label->hide(); - combo->hide(); - return; - } - - label->show(); - combo->show(); - - setVariableList(combo, list); -} - void StatsWidget::updateUi() { StatsState::UIState uiState = state.getUIState(); @@ -136,9 +114,9 @@ void StatsWidget::updateUi() int pos = charts.update(uiState.charts); ui.chartType->setCurrentIndex(pos); ui.chartType->setItemDelegate(new ChartItemDelegate); - setBinList(ui.var1BinnerLabel, ui.var1Binner, uiState.var1Name, uiState.binners1); - setBinList(ui.var2BinnerLabel, ui.var2Binner, uiState.var2Name, uiState.binners2); - setOperationList(ui.var2OperationLabel, ui.var2Operation, uiState.var2Name, uiState.operations2); + setBinList(ui.var1BinnerLabel, ui.var1Binner, uiState.binners1); + setBinList(ui.var2BinnerLabel, ui.var2Binner, uiState.binners2); + setVariableList(ui.var2Operation, uiState.operations2); // Add checkboxes for additional features features.clear(); -- cgit v1.2.3-70-g09d2