From 08542055c41beeb09e514d2baa7c92e2c49e6c0c Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Mon, 11 Oct 2021 11:33:41 +0200 Subject: [PATCH] Sketcher: Redesign of Constraint settings ========================================= => The old controltab is substituted by: direct controls (buttons on the constraint widget) and a settings dialog that is independently fired via a button with a settings icon This makes more space for the list of constraints and generates a lower amount of confussion regarding the old tab names and functions. Direct control ensures that the most used operations are at hand, while other less changed settings are moved to the settings dialog. => Direct controls One time visibility to match the list selection can be triggered from a new button "Visibility" This button has drop selections for visibility selections, which are checkable items (currently only one option, but more are envisaged). The one option currently is the "visibility tracking" functionality. This is a "shortcut" to the option in the settings panel to save unnecessary clicks in typical operations. => Settings dialog This dialog is live, in that changes to settings are immediatedly propagated to the list control and visibility. --- src/Mod/Sketcher/Gui/CMakeLists.txt | 3 + .../Sketcher/Gui/ConstraintSettingsDialog.cpp | 136 +++++++++++ .../Sketcher/Gui/ConstraintSettingsDialog.h | 70 ++++++ .../Sketcher/Gui/ConstraintSettingsDialog.ui | 195 +++++++++++++++ .../Sketcher/Gui/TaskSketcherConstrains.cpp | 111 +++++++-- src/Mod/Sketcher/Gui/TaskSketcherConstrains.h | 4 + .../Sketcher/Gui/TaskSketcherConstrains.ui | 225 +++++------------- 7 files changed, 558 insertions(+), 186 deletions(-) create mode 100644 src/Mod/Sketcher/Gui/ConstraintSettingsDialog.cpp create mode 100644 src/Mod/Sketcher/Gui/ConstraintSettingsDialog.h create mode 100644 src/Mod/Sketcher/Gui/ConstraintSettingsDialog.ui diff --git a/src/Mod/Sketcher/Gui/CMakeLists.txt b/src/Mod/Sketcher/Gui/CMakeLists.txt index 2be18fd827..317d91c208 100644 --- a/src/Mod/Sketcher/Gui/CMakeLists.txt +++ b/src/Mod/Sketcher/Gui/CMakeLists.txt @@ -47,6 +47,7 @@ set(SketcherGui_UIC_SRCS SketchRectangularArrayDialog.ui SketcherRegularPolygonDialog.ui ConstraintMultiFilterDialog.ui + ConstraintSettingsDialog.ui ) if(BUILD_QT5) @@ -120,6 +121,8 @@ SET(SketcherGui_SRCS SketcherRegularPolygonDialog.cpp ConstraintMultiFilterDialog.h ConstraintMultiFilterDialog.cpp + ConstraintSettingsDialog.h + ConstraintSettingsDialog.cpp TaskDlgEditSketch.cpp TaskDlgEditSketch.h ViewProviderPython.cpp diff --git a/src/Mod/Sketcher/Gui/ConstraintSettingsDialog.cpp b/src/Mod/Sketcher/Gui/ConstraintSettingsDialog.cpp new file mode 100644 index 0000000000..b107047610 --- /dev/null +++ b/src/Mod/Sketcher/Gui/ConstraintSettingsDialog.cpp @@ -0,0 +1,136 @@ +/*************************************************************************** + * Copyright (c) 2021 Abdullah Tahiri * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#include "PreCompiled.h" + +#ifndef _PreComp_ +# include +# include +#endif + +#include +#include +#include +#include +#include + +#include "ui_ConstraintSettingsDialog.h" +#include "ConstraintSettingsDialog.h" + +using namespace SketcherGui; + +ConstraintSettingsDialog::ConstraintSettingsDialog(void) + : QDialog(Gui::getMainWindow()), ui(new Ui_ConstraintSettingsDialog) +{ + ui->setupUi(this); + + { // in case any signal is connected before this + QSignalBlocker block(this); + loadSettings(); + snapshotInitialSettings(); + } + + QObject::connect( + ui->filterInternalAlignment, SIGNAL(stateChanged(int)), + this , SLOT (on_filterInternalAlignment_stateChanged(int)) + ); + QObject::connect( + ui->extendedInformation, SIGNAL(stateChanged(int)), + this , SLOT (on_extendedInformation_stateChanged(int)) + ); + QObject::connect( + ui->visualisationTrackingFilter, SIGNAL(stateChanged(int)), + this , SLOT (on_visualisationTrackingFilter_stateChanged(int)) + ); +} + +void ConstraintSettingsDialog::saveSettings() +{ + ui->extendedInformation->onSave(); + ui->filterInternalAlignment->onSave(); + ui->visualisationTrackingFilter->onSave(); +} + +void ConstraintSettingsDialog::loadSettings() +{ + ui->extendedInformation->onRestore(); + ui->filterInternalAlignment->onRestore(); + ui->visualisationTrackingFilter->onRestore(); +} + +void ConstraintSettingsDialog::snapshotInitialSettings() +{ + auto isChecked = [] (auto prefwidget) {return prefwidget->checkState() == Qt::Checked;}; + + extendedInformation = isChecked(ui->extendedInformation); + filterInternalAlignment = isChecked(ui->filterInternalAlignment); + visualisationTrackingFilter = isChecked(ui->visualisationTrackingFilter); +} + +void ConstraintSettingsDialog::restoreInitialSettings() +{ + auto restoreCheck = [] (auto prefwidget, bool initialvalue) { + if( initialvalue != (prefwidget->checkState() == Qt::Checked)) // if the state really changed + initialvalue ? prefwidget->setCheckState(Qt::Checked) : prefwidget->setCheckState(Qt::Unchecked); + }; + + restoreCheck(ui->extendedInformation, extendedInformation); + restoreCheck(ui->filterInternalAlignment, filterInternalAlignment); + restoreCheck(ui->visualisationTrackingFilter, visualisationTrackingFilter); +} + +void ConstraintSettingsDialog::accept() +{ + saveSettings(); + QDialog::accept(); +} + +void ConstraintSettingsDialog::reject() +{ + restoreInitialSettings(); + saveSettings(); + QDialog::reject(); +} + +void ConstraintSettingsDialog::on_filterInternalAlignment_stateChanged(int state) +{ + ui->filterInternalAlignment->onSave(); + Q_EMIT emit_filterInternalAlignment_stateChanged(state); +} + +void ConstraintSettingsDialog::on_visualisationTrackingFilter_stateChanged(int state) +{ + ui->visualisationTrackingFilter->onSave(); + Q_EMIT emit_visualisationTrackingFilter_stateChanged(state); +} + +void ConstraintSettingsDialog::on_extendedInformation_stateChanged(int state) +{ + ui->extendedInformation->onSave(); + Q_EMIT emit_extendedInformation_stateChanged(state); +} + +ConstraintSettingsDialog::~ConstraintSettingsDialog() +{ +} + +#include "moc_ConstraintSettingsDialog.cpp" diff --git a/src/Mod/Sketcher/Gui/ConstraintSettingsDialog.h b/src/Mod/Sketcher/Gui/ConstraintSettingsDialog.h new file mode 100644 index 0000000000..e190692ddd --- /dev/null +++ b/src/Mod/Sketcher/Gui/ConstraintSettingsDialog.h @@ -0,0 +1,70 @@ +/*************************************************************************** + * Copyright (c) 2021 Abdullah Tahiri * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#ifndef SKETCHERGUI_ConstraintSettingsDialog_H +#define SKETCHERGUI_ConstraintSettingsDialog_H + +#include + +#include "ConstraintFilters.h" + +namespace SketcherGui { + +using namespace ConstraintFilter; + +class Ui_ConstraintSettingsDialog; +class ConstraintSettingsDialog : public QDialog +{ + Q_OBJECT + +public: + ConstraintSettingsDialog(void); + ~ConstraintSettingsDialog(); + +Q_SIGNALS: + void emit_filterInternalAlignment_stateChanged(int); + void emit_extendedInformation_stateChanged(int); + void emit_visualisationTrackingFilter_stateChanged(int); + +public Q_SLOTS: + void accept(); + void reject(); + void on_filterInternalAlignment_stateChanged(int state); + void on_extendedInformation_stateChanged(int state); + void on_visualisationTrackingFilter_stateChanged(int state); + +private: + void saveSettings(); + void loadSettings(); + void snapshotInitialSettings(); + void restoreInitialSettings(); + +private: + std::unique_ptr ui; + bool extendedInformation; + bool filterInternalAlignment; + bool visualisationTrackingFilter; +}; + +} + +#endif // SKETCHERGUI_ConstraintSettingsDialog_H diff --git a/src/Mod/Sketcher/Gui/ConstraintSettingsDialog.ui b/src/Mod/Sketcher/Gui/ConstraintSettingsDialog.ui new file mode 100644 index 0000000000..340305ed43 --- /dev/null +++ b/src/Mod/Sketcher/Gui/ConstraintSettingsDialog.ui @@ -0,0 +1,195 @@ + + + SketcherGui::ConstraintSettingsDialog + + + Qt::WindowModal + + + + 0 + 0 + 275 + 215 + + + + + 0 + 0 + + + + Constraint widget settings + + + + + + + 0 + 0 + + + + List control + + + + + + + 0 + 0 + + + + Internal alignments will be hidden + + + Hide internal alignment + + + true + + + HideInternalAlignment + + + Mod/Sketcher + + + + + + + + 0 + 0 + + + + Extended information will be added to the list + + + Extended information + + + false + + + ExtendedConstraintInformation + + + Mod/Sketcher + + + + + + + + + + + 0 + 0 + + + + 3D view control + + + + + + + 0 + 0 + + + + Constraint visualisation tracks filter selection so that filtered out constraints are hidden + + + Show only filtered constraints + + + false + + + VisualisationTrackingFilter + + + Mod/Sketcher + + + + + + + + + + Qt::Vertical + + + + 20 + 0 + + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + Gui::PrefCheckBox + QCheckBox +
Gui/PrefWidgets.h
+
+
+ + + + buttonBox + accepted() + SketcherGui::ConstraintSettingsDialog + accept() + + + 20 + 20 + + + 20 + 20 + + + + + buttonBox + rejected() + SketcherGui::ConstraintSettingsDialog + reject() + + + 20 + 20 + + + 20 + 20 + + + + +
diff --git a/src/Mod/Sketcher/Gui/TaskSketcherConstrains.cpp b/src/Mod/Sketcher/Gui/TaskSketcherConstrains.cpp index 4add6a36ec..1f04614880 100644 --- a/src/Mod/Sketcher/Gui/TaskSketcherConstrains.cpp +++ b/src/Mod/Sketcher/Gui/TaskSketcherConstrains.cpp @@ -58,6 +58,7 @@ #include #include "ConstraintMultiFilterDialog.h" +#include "ConstraintSettingsDialog.h" using namespace SketcherGui; using namespace Gui::TaskView; @@ -642,6 +643,8 @@ TaskSketcherConstrains::TaskSketcherConstrains(ViewProviderSketch *sketchView) : ui->listWidgetConstraints->setEditTriggers(QListWidget::EditKeyPressed); //QMetaObject::connectSlotsByName(this); + createVisibilityButtonActions(); + // connecting the needed signals QObject::connect( ui->comboBoxFilter, SIGNAL(currentIndexChanged(int)), @@ -671,14 +674,6 @@ TaskSketcherConstrains::TaskSketcherConstrains(ViewProviderSketch *sketchView) : ui->listWidgetConstraints, SIGNAL(onUpdateActiveStatus(QListWidgetItem *, bool)), this , SLOT (on_listWidgetConstraints_updateActiveStatus(QListWidgetItem *, bool)) ); - QObject::connect( - ui->filterInternalAlignment, SIGNAL(stateChanged(int)), - this , SLOT (on_filterInternalAlignment_stateChanged(int)) - ); - QObject::connect( - ui->extendedInformation, SIGNAL(stateChanged(int)), - this , SLOT (on_extendedInformation_stateChanged(int)) - ); QObject::connect( ui->showAllButton, SIGNAL(clicked(bool)), this , SLOT (on_showAllButton_clicked(bool)) @@ -695,23 +690,29 @@ TaskSketcherConstrains::TaskSketcherConstrains(ViewProviderSketch *sketchView) : ui->listWidgetConstraints, SIGNAL(emitShowSelection3DVisibility()), this , SLOT (on_listWidgetConstraints_emitShowSelection3DVisibility()) ); - QObject::connect( - ui->visualisationTrackingFilter, SIGNAL(stateChanged(int)), - this , SLOT (on_visualisationTrackingFilter_stateChanged(int)) - ); QObject::connect( ui->multipleFilterButton, SIGNAL(clicked(bool)), this , SLOT (on_multipleFilterButton_clicked(bool)) ); + QObject::connect( + ui->settingsDialogButton, SIGNAL(clicked(bool)), + this , SLOT (on_settingsDialogButton_clicked(bool)) + ); + QObject::connect( + ui->visibilityButton, SIGNAL(clicked(bool)), + this , SLOT (on_visibilityButton_clicked(bool)) + ); + + QObject::connect( + ui->visibilityButton->actions()[0], SIGNAL(changed()), + this , SLOT (on_visibilityButton_trackingaction_changed()) + ); connectionConstraintsChanged = sketchView->signalConstraintsChanged.connect( boost::bind(&SketcherGui::TaskSketcherConstrains::slotConstraintsChanged, this)); this->groupLayout()->addWidget(proxy); - this->ui->filterInternalAlignment->onRestore(); - this->ui->extendedInformation->onRestore(); - multiFilterStatus.set(); // Match 'All' selection, all bits set. slotConstraintsChanged(); @@ -719,11 +720,27 @@ TaskSketcherConstrains::TaskSketcherConstrains(ViewProviderSketch *sketchView) : TaskSketcherConstrains::~TaskSketcherConstrains() { - this->ui->filterInternalAlignment->onSave(); - this->ui->extendedInformation->onSave(); connectionConstraintsChanged.disconnect(); } + +void TaskSketcherConstrains::createVisibilityButtonActions() +{ + QAction* action = new QAction(QString::fromLatin1("Show only filtered Constraints"),this); + + action->setCheckable(true); + + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool visibilityTracksFilter = hGrp->GetBool("VisualisationTrackingFilter",false); + + { + QSignalBlocker block(this); + action->setChecked(visibilityTracksFilter); + } + + ui->visibilityButton->addAction(action); +} + void TaskSketcherConstrains::updateSelectionFilter() { // Snapshot current selection @@ -738,7 +755,8 @@ void TaskSketcherConstrains::updateSelectionFilter() void TaskSketcherConstrains::updateList() { // enforce constraint visibility - bool visibilityTracksFilter = ui->visualisationTrackingFilter->isChecked(); + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool visibilityTracksFilter = hGrp->GetBool("VisualisationTrackingFilter",false); if(visibilityTracksFilter) change3DViewVisibilityToTrackFilter(); // it will call slotConstraintChanged via update mechanism @@ -766,6 +784,26 @@ void TaskSketcherConstrains::on_multipleFilterButton_clicked(bool) } } +void TaskSketcherConstrains::on_settingsDialogButton_clicked(bool) +{ + ConstraintSettingsDialog cs; + + QObject::connect( + &cs, SIGNAL(emit_filterInternalAlignment_stateChanged(int)), + this , SLOT (on_filterInternalAlignment_stateChanged(int)) + ); + QObject::connect( + &cs, SIGNAL(emit_extendedInformation_stateChanged(int)), + this , SLOT (on_extendedInformation_stateChanged(int)) + ); + QObject::connect( + &cs, SIGNAL(emit_visualisationTrackingFilter_stateChanged(int)), + this , SLOT (on_visualisationTrackingFilter_stateChanged(int)) + ); + + cs.exec(); // The dialog reacted on any change, so the result of running the dialog is already reflected on return. +} + void TaskSketcherConstrains::changeFilteredVisibility(bool show, ActionTarget target) { assert(sketchView); @@ -934,14 +972,43 @@ void TaskSketcherConstrains::on_filterInternalAlignment_stateChanged(int state) void TaskSketcherConstrains::on_visualisationTrackingFilter_stateChanged(int state) { - if(state) + // Synchronise button drop state + { + QSignalBlocker block(this); + + if(ui->visibilityButton->actions()[0]->isChecked() != (state == Qt::Checked)) + ui->visibilityButton->actions()[0]->setChecked(state); + } + + if(state == Qt::Checked) change3DViewVisibilityToTrackFilter(); } +void TaskSketcherConstrains::on_visibilityButton_trackingaction_changed() +{ + // synchronise VisualisationTrackingFilter parameter + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool visibilityTracksFilter = hGrp->GetBool("VisualisationTrackingFilter",false); + + bool bstate = ui->visibilityButton->actions()[0]->isChecked(); + + if(visibilityTracksFilter != bstate) { + hGrp->SetBool("VisualisationTrackingFilter", bstate); + } + + // Act + if(bstate) + change3DViewVisibilityToTrackFilter(); +} + +void TaskSketcherConstrains::on_visibilityButton_clicked(bool) +{ + change3DViewVisibilityToTrackFilter(); +} + void TaskSketcherConstrains::on_extendedInformation_stateChanged(int state) { Q_UNUSED(state); - this->ui->extendedInformation->onSave(); slotConstraintsChanged(); } @@ -1150,7 +1217,9 @@ bool TaskSketcherConstrains::isConstraintFiltered(QListWidgetItem * item) const Sketcher::Constraint * constraint = vals[it->ConstraintNbr]; int Filter = ui->comboBoxFilter->currentIndex(); - bool hideInternalAlignment = this->ui->filterInternalAlignment->isChecked(); + + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool hideInternalAlignment = hGrp->GetBool("HideInternalAlignment",false); bool visible = true; bool showAll = (Filter == FilterValue::All); diff --git a/src/Mod/Sketcher/Gui/TaskSketcherConstrains.h b/src/Mod/Sketcher/Gui/TaskSketcherConstrains.h index f273b767ab..7965f60fbf 100644 --- a/src/Mod/Sketcher/Gui/TaskSketcherConstrains.h +++ b/src/Mod/Sketcher/Gui/TaskSketcherConstrains.h @@ -94,6 +94,7 @@ private: void changeFilteredVisibility(bool show, ActionTarget target = ActionTarget::All); void updateSelectionFilter(); void updateList(); + void createVisibilityButtonActions(); template bool isFilter(T filterValue); @@ -109,11 +110,14 @@ public Q_SLOTS: void on_filterInternalAlignment_stateChanged(int state); void on_extendedInformation_stateChanged(int state); void on_visualisationTrackingFilter_stateChanged(int state); + void on_visibilityButton_trackingaction_changed(); + void on_visibilityButton_clicked(bool); void on_showAllButton_clicked(bool); void on_hideAllButton_clicked(bool); void on_listWidgetConstraints_emitShowSelection3DVisibility(); void on_listWidgetConstraints_emitHideSelection3DVisibility(); void on_multipleFilterButton_clicked(bool); + void on_settingsDialogButton_clicked(bool); protected: void changeEvent(QEvent *e); diff --git a/src/Mod/Sketcher/Gui/TaskSketcherConstrains.ui b/src/Mod/Sketcher/Gui/TaskSketcherConstrains.ui index e2e4d454b6..dca26d8b8a 100644 --- a/src/Mod/Sketcher/Gui/TaskSketcherConstrains.ui +++ b/src/Mod/Sketcher/Gui/TaskSketcherConstrains.ui @@ -6,7 +6,7 @@ 0 0 - 357 + 405 388 @@ -30,6 +30,12 @@ + + + 0 + 0 + + Filter: @@ -37,6 +43,12 @@ + + + 0 + 0 + + 0 @@ -194,49 +206,34 @@ + + + + + 0 + 0 + + + + Settings + + + + + + + :/icons/dialogs/Sketcher_Settings.svg:/icons/dialogs/Sketcher_Settings.svg + + + - - - - 0 - 0 - - - - - 0 - 95 - - - - - - - 0 - - - - - 0 - 0 - - - - View - + + - - - 10 - 10 - 135 - 27 - - - + 0 0 @@ -248,17 +245,11 @@ Show Listed + + - - - 150 - 10 - 135 - 27 - - - + 0 0 @@ -270,132 +261,39 @@ Hide Listed - - - - Controls visualisation in the 3D view - - - Automation - - - - - 0 - 0 - 271 - 36 - - + + + - + 0 0 - Constraint visualisation tracks filter selection so that filtered out constraints are hidden + Restricts 3D visibility to the listed elements - Show only filtered constraints + Restrict Visibility - - false + + QToolButton::MenuButtonPopup - - VisualisationTrackingFilter - - - Mod/Sketcher + + Qt::ToolButtonTextOnly - - - - - 0 - 0 - - - - - 0 - 0 - - - - Controls widget list behaviour - - - List - - - - - 0 - 30 - 189 - 36 - - - - - 0 - 0 - - - - Extended information will be added to the list - - - Extended information - - - false - - - ExtendedConstraintInformation - - - Mod/Sketcher - - - - - - 0 - 0 - 189 - 36 - - - - - 0 - 0 - - - - Internal alignments will be hidden - - - Hide internal alignment - - - true - - - HideInternalAlignment - - - Mod/Sketcher - - - - + + + + + 0 + 0 + + 0 @@ -404,17 +302,14 @@ - - Gui::PrefCheckBox - QCheckBox -
Gui/PrefWidgets.h
-
ConstraintView QListWidget
QListWidget
- + + +