From a4192448a96e95f92bc9f5b5ab2f8c6635669792 Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Mon, 4 Oct 2021 16:25:55 +0200 Subject: [PATCH] Sketcher: redefine filters and groups of filters ================================================ Filters redefined to match: https://forum.freecadweb.org/viewtopic.php?p=537777#p537777 Group "Datum" stops comprising group "Reference" Datums+References are now selectable as a multi-filter. Fixes the akward behaviour of multiselection: https://forum.freecadweb.org/viewtopic.php?p=537722#p537722 Now when a selection of a filter causes a group of filters comprising the selection to be fulfiled, this is also checked. --- src/Mod/Sketcher/Gui/ConstraintFilters.h | 2 +- .../Gui/ConstraintMultiFilterDialog.cpp | 38 ++++++++++++++++--- .../Sketcher/Gui/TaskSketcherConstrains.cpp | 2 +- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/Mod/Sketcher/Gui/ConstraintFilters.h b/src/Mod/Sketcher/Gui/ConstraintFilters.h index 25a3defdd7..6f86e2e3f0 100644 --- a/src/Mod/Sketcher/Gui/ConstraintFilters.h +++ b/src/Mod/Sketcher/Gui/ConstraintFilters.h @@ -73,7 +73,7 @@ namespace ConstraintFilter { 1 << FilterValue::Geometric | 1 << FilterValue::Horizontal | 1 << FilterValue::Vertical | 1 << FilterValue::Coincident | 1 << FilterValue::PointOnObject | 1 << FilterValue::Parallel | 1 << FilterValue::Perpendicular | 1 << FilterValue::Tangent | 1 << FilterValue::Equality | 1 << FilterValue::Symmetric | 1 << FilterValue::Block | 1 << FilterValue::InternalAlignment, // Geometric = All others not being datums (1) - 1 << FilterValue::Datums | 1 << FilterValue::NonDriving | 1 << FilterValue::Distance | 1 << FilterValue::HorizontalDistance | 1 << FilterValue::VerticalDistance | 1 << FilterValue::Radius | 1 << FilterValue::Weight | 1 << FilterValue::Diameter | 1 << FilterValue::Angle | 1 << FilterValue::SnellsLaw, // Datum = all others not being geometric (2) + 1 << FilterValue::Datums | 1 << FilterValue::Distance | 1 << FilterValue::HorizontalDistance | 1 << FilterValue::VerticalDistance | 1 << FilterValue::Radius | 1 << FilterValue::Weight | 1 << FilterValue::Diameter | 1 << FilterValue::Angle | 1 << FilterValue::SnellsLaw, // Datum = all others not being geometric (2) 1 << FilterValue::Named, // Named = Just this (3) 1 << FilterValue::NonDriving, // NonDriving = Just this (4) 1 << FilterValue::Coincident, // Coincident = Just this (5) diff --git a/src/Mod/Sketcher/Gui/ConstraintMultiFilterDialog.cpp b/src/Mod/Sketcher/Gui/ConstraintMultiFilterDialog.cpp index 22e74bc5b8..88beca930f 100644 --- a/src/Mod/Sketcher/Gui/ConstraintMultiFilterDialog.cpp +++ b/src/Mod/Sketcher/Gui/ConstraintMultiFilterDialog.cpp @@ -93,15 +93,43 @@ void ConstraintMultiFilterDialog::on_listMultiFilter_itemChanged(QListWidgetItem { int filterindex = ui->listMultiFilter->row(item); - auto aggregate = filterAggregates[filterindex]; + auto itemAggregate = filterAggregates[filterindex]; ui->listMultiFilter->blockSignals(true); - if(item->checkState() == Qt::Checked) { - for(int i = 0; i < ui->listMultiFilter->count(); i++) { - if(aggregate[i]) - ui->listMultiFilter->item(i)->setCheckState(Qt::Checked); + + for(int i = 0; i < ui->listMultiFilter->count(); i++) { + // any filter comprised on the filter of the activated item, gets the same check state + if(itemAggregate[i]) + ui->listMultiFilter->item(i)->setCheckState(item->checkState()); + + // if unchecking, in addition uncheck any group comprising the unchecked item + if(item->checkState() == Qt::Unchecked) { + if(filterAggregates[i][filterindex]) + ui->listMultiFilter->item(i)->setCheckState(Qt::Unchecked); } } + + // Now that all filters are correctly updated to match dependencies, + // if checking, in addition check any group comprising all items that are checked, and check it if all checked. + if(item->checkState() == Qt::Checked) { + for(int i = 0; i < ui->listMultiFilter->count(); i++) { + if(filterAggregates[i][filterindex]) { // only for groups comprising the changed filter + bool mustBeChecked = true; + + for(int j = 0; j < FilterValue::NumFilterValue; j++) { + if (i == j) + continue; + + if (filterAggregates[i][j]) // if it is in group + mustBeChecked = mustBeChecked && ui->listMultiFilter->item(j)->checkState() == Qt::Checked; + } + + if(mustBeChecked) + ui->listMultiFilter->item(i)->setCheckState(Qt::Checked); + } + } + } + ui->listMultiFilter->blockSignals(false); } diff --git a/src/Mod/Sketcher/Gui/TaskSketcherConstrains.cpp b/src/Mod/Sketcher/Gui/TaskSketcherConstrains.cpp index 6848c25815..26c199e421 100644 --- a/src/Mod/Sketcher/Gui/TaskSketcherConstrains.cpp +++ b/src/Mod/Sketcher/Gui/TaskSketcherConstrains.cpp @@ -1125,7 +1125,7 @@ bool TaskSketcherConstrains::isConstraintFiltered(QListWidgetItem * item) bool visible = true; bool showAll = (Filter == FilterValue::All); bool showGeometric = (Filter == FilterValue::Geometric); - bool showDatums = (Filter == FilterValue::Datums); + bool showDatums = (Filter == FilterValue::Datums && constraint->isDriving); bool showNamed = (Filter == FilterValue::Named && !(constraint->Name.empty())); bool showNonDriving = (Filter == FilterValue::NonDriving && !constraint->isDriving);