From 8ed244df3f6864faaab3c0aac6eb9785b06ab973 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Althaus?= Date: Wed, 21 Feb 2024 19:28:28 +0100 Subject: [PATCH] Add a new preference for the visibility icons Add a preference to Display->UI that allows the user to choose if the visibility icons are shown in the tree view. --- src/Gui/PreferencePages/DlgSettingsUI.cpp | 29 ++++++++++----- src/Gui/PreferencePages/DlgSettingsUI.h | 1 + src/Gui/PreferencePages/DlgSettingsUI.py | 1 + src/Gui/Tree.cpp | 2 +- src/Gui/TreeParams.cpp | 44 +++++++++++++++++++++++ src/Gui/TreeParams.h | 13 +++++++ src/Gui/TreeParams.py | 2 ++ 7 files changed, 82 insertions(+), 10 deletions(-) diff --git a/src/Gui/PreferencePages/DlgSettingsUI.cpp b/src/Gui/PreferencePages/DlgSettingsUI.cpp index beed6daf0f..f9252436e2 100644 --- a/src/Gui/PreferencePages/DlgSettingsUI.cpp +++ b/src/Gui/PreferencePages/DlgSettingsUI.cpp @@ -92,50 +92,57 @@ DlgSettingsUI::DlgSettingsUI(QWidget* parent) ResizableColumn->setEntryName("ResizableColumn"); ResizableColumn->setParamGrpPath("TreeView"); + // Auto generated code (Tools/params_utils.py:433) + VisibilityIcon = new Gui::PrefCheckBox(this); + layoutTreeview->addWidget(VisibilityIcon, 3, 0); + VisibilityIcon->setChecked(Gui::TreeParams::defaultVisibilityIcon()); + VisibilityIcon->setEntryName("VisibilityIcon"); + VisibilityIcon->setParamGrpPath("TreeView"); + // Auto generated code (Tools/params_utils.py:433) HideColumn = new Gui::PrefCheckBox(this); - layoutTreeview->addWidget(HideColumn, 3, 0); + layoutTreeview->addWidget(HideColumn, 4, 0); HideColumn->setChecked(Gui::TreeParams::defaultHideColumn()); HideColumn->setEntryName("HideColumn"); HideColumn->setParamGrpPath("TreeView"); // Auto generated code (Tools/params_utils.py:433) HideScrollBar = new Gui::PrefCheckBox(this); - layoutTreeview->addWidget(HideScrollBar, 4, 0); + layoutTreeview->addWidget(HideScrollBar, 5, 0); HideScrollBar->setChecked(Gui::TreeParams::defaultHideScrollBar()); HideScrollBar->setEntryName("HideScrollBar"); HideScrollBar->setParamGrpPath("TreeView"); // Auto generated code (Tools/params_utils.py:433) HideHeaderView = new Gui::PrefCheckBox(this); - layoutTreeview->addWidget(HideHeaderView, 5, 0); + layoutTreeview->addWidget(HideHeaderView, 6, 0); HideHeaderView->setChecked(Gui::TreeParams::defaultHideHeaderView()); HideHeaderView->setEntryName("HideHeaderView"); HideHeaderView->setParamGrpPath("TreeView"); // Auto generated code (Tools/params_utils.py:433) labelIconSize = new QLabel(this); - layoutTreeview->addWidget(labelIconSize, 6, 0); + layoutTreeview->addWidget(labelIconSize, 7, 0); IconSize = new Gui::PrefSpinBox(this); - layoutTreeview->addWidget(IconSize, 6, 1); + layoutTreeview->addWidget(IconSize, 7, 1); IconSize->setValue(Gui::TreeParams::defaultIconSize()); IconSize->setEntryName("IconSize"); IconSize->setParamGrpPath("TreeView"); // Auto generated code (Tools/params_utils.py:433) labelFontSize = new QLabel(this); - layoutTreeview->addWidget(labelFontSize, 7, 0); + layoutTreeview->addWidget(labelFontSize, 8, 0); FontSize = new Gui::PrefSpinBox(this); - layoutTreeview->addWidget(FontSize, 7, 1); + layoutTreeview->addWidget(FontSize, 8, 1); FontSize->setValue(Gui::TreeParams::defaultFontSize()); FontSize->setEntryName("FontSize"); FontSize->setParamGrpPath("TreeView"); // Auto generated code (Tools/params_utils.py:433) labelItemSpacing = new QLabel(this); - layoutTreeview->addWidget(labelItemSpacing, 8, 0); + layoutTreeview->addWidget(labelItemSpacing, 9, 0); ItemSpacing = new Gui::PrefSpinBox(this); - layoutTreeview->addWidget(ItemSpacing, 8, 1); + layoutTreeview->addWidget(ItemSpacing, 9, 1); ItemSpacing->setValue(Gui::TreeParams::defaultItemSpacing()); ItemSpacing->setEntryName("ItemSpacing"); ItemSpacing->setParamGrpPath("TreeView"); @@ -442,6 +449,7 @@ void DlgSettingsUI::saveSettings() ItemBackground->onSave(); ItemBackgroundPadding->onSave(); ResizableColumn->onSave(); + VisibilityIcon->onSave(); HideColumn->onSave(); HideScrollBar->onSave(); HideHeaderView->onSave(); @@ -482,6 +490,7 @@ void DlgSettingsUI::loadSettings() ItemBackground->onRestore(); ItemBackgroundPadding->onRestore(); ResizableColumn->onRestore(); + VisibilityIcon->onRestore(); HideColumn->onRestore(); HideScrollBar->onRestore(); HideHeaderView->onRestore(); @@ -528,6 +537,8 @@ void DlgSettingsUI::retranslateUi() labelItemBackgroundPadding->setToolTip(ItemBackgroundPadding->toolTip()); ResizableColumn->setToolTip(QApplication::translate("TreeParams", Gui::TreeParams::docResizableColumn())); ResizableColumn->setText(QObject::tr("Resizable columns")); + VisibilityIcon->setToolTip(QApplication::translate("TreeParams", Gui::TreeParams::docVisibilityIcon())); + VisibilityIcon->setText(QObject::tr("Show visibility icon")); HideColumn->setToolTip(QApplication::translate("TreeParams", Gui::TreeParams::docHideColumn())); HideColumn->setText(QObject::tr("Hide extra column")); HideScrollBar->setToolTip(QApplication::translate("TreeParams", Gui::TreeParams::docHideScrollBar())); diff --git a/src/Gui/PreferencePages/DlgSettingsUI.h b/src/Gui/PreferencePages/DlgSettingsUI.h index 362809cc5d..af4dfab452 100644 --- a/src/Gui/PreferencePages/DlgSettingsUI.h +++ b/src/Gui/PreferencePages/DlgSettingsUI.h @@ -78,6 +78,7 @@ private: QLabel *labelItemBackgroundPadding = nullptr; Gui::PrefSpinBox *ItemBackgroundPadding = nullptr; Gui::PrefCheckBox *ResizableColumn = nullptr; + Gui::PrefCheckBox *VisibilityIcon = nullptr; Gui::PrefCheckBox *HideColumn = nullptr; Gui::PrefCheckBox *HideScrollBar = nullptr; Gui::PrefCheckBox *HideHeaderView = nullptr; diff --git a/src/Gui/PreferencePages/DlgSettingsUI.py b/src/Gui/PreferencePages/DlgSettingsUI.py index 8345645157..77da4e25cf 100644 --- a/src/Gui/PreferencePages/DlgSettingsUI.py +++ b/src/Gui/PreferencePages/DlgSettingsUI.py @@ -48,6 +48,7 @@ ParamGroup = ( 'ItemBackground', 'ItemBackgroundPadding', 'ResizableColumn', + 'VisibilityIcon', 'HideColumn', 'HideScrollBar', 'HideHeaderView', diff --git a/src/Gui/Tree.cpp b/src/Gui/Tree.cpp index 9afdb6a3ff..03c1a5b462 100644 --- a/src/Gui/Tree.cpp +++ b/src/Gui/Tree.cpp @@ -94,7 +94,7 @@ static bool _DraggingActive; static bool _DragEventFilter; static bool isVisibilityIconEnabled() { - return true; + return TreeParams::getVisibilityIcon(); } static bool isSelectionCheckBoxesEnabled() { diff --git a/src/Gui/TreeParams.cpp b/src/Gui/TreeParams.cpp index a83548fa4e..09016832ee 100644 --- a/src/Gui/TreeParams.cpp +++ b/src/Gui/TreeParams.cpp @@ -78,6 +78,7 @@ public: long ColumnSize1; long ColumnSize2; bool TreeToolTipIcon; + bool VisibilityIcon; // Auto generated code (Tools/params_utils.py:203) TreeParamsP() { @@ -156,6 +157,8 @@ public: funcs["ColumnSize2"] = &TreeParamsP::updateColumnSize2; TreeToolTipIcon = handle->GetBool("TreeToolTipIcon", false); funcs["TreeToolTipIcon"] = &TreeParamsP::updateTreeToolTipIcon; + VisibilityIcon = handle->GetBool("VisibilityIcon", false); + funcs["VisibilityIcon"] = &TreeParamsP::updateVisibilityIcon; } // Auto generated code (Tools/params_utils.py:217) @@ -389,6 +392,14 @@ public: static void updateTreeToolTipIcon(TreeParamsP *self) { self->TreeToolTipIcon = self->handle->GetBool("TreeToolTipIcon", false); } + // Auto generated code (Tools/params_utils.py:296) + static void updateVisibilityIcon(TreeParamsP *self) { + auto v = self->handle->GetBool("VisibilityIcon", false); + if (self->VisibilityIcon != v) { + self->VisibilityIcon = v; + TreeParams::onVisibilityIconChanged(); + } + } }; // Auto generated code (Tools/params_utils.py:256) @@ -1381,6 +1392,34 @@ void TreeParams::setTreeToolTipIcon(const bool &v) { void TreeParams::removeTreeToolTipIcon() { instance()->handle->RemoveBool("TreeToolTipIcon"); } + +// Auto generated code (Tools/params_utils.py:350) +const char *TreeParams::docVisibilityIcon() { + return QT_TRANSLATE_NOOP("TreeParams", +"If enabled, show an eye icon before the tree view items, showing the items visibility status. When clicked the visibility is toggled"); +} + +// Auto generated code (Tools/params_utils.py:358) +const bool & TreeParams::getVisibilityIcon() { + return instance()->VisibilityIcon; +} + +// Auto generated code (Tools/params_utils.py:366) +const bool & TreeParams::defaultVisibilityIcon() { + const static bool def = false; + return def; +} + +// Auto generated code (Tools/params_utils.py:375) +void TreeParams::setVisibilityIcon(const bool &v) { + instance()->handle->SetBool("VisibilityIcon",v); + instance()->VisibilityIcon = v; +} + +// Auto generated code (Tools/params_utils.py:384) +void TreeParams::removeVisibilityIcon() { + instance()->handle->RemoveBool("VisibilityIcon"); +} //[[[end]]] void TreeParams::onSyncSelectionChanged() { @@ -1482,3 +1521,8 @@ void TreeParams::onHideColumnChanged() for(auto tree : TreeWidget::Instances) tree->setColumnHidden(1, TreeParams::getHideColumn()); } + +void TreeParams::onVisibilityIconChanged() +{ + TreeWidget::updateVisibilityIcons(); +} diff --git a/src/Gui/TreeParams.h b/src/Gui/TreeParams.h index 3ca2b1aec7..6b6f685981 100644 --- a/src/Gui/TreeParams.h +++ b/src/Gui/TreeParams.h @@ -457,6 +457,19 @@ public: static void setTreeToolTipIcon(const bool &v); static const char *docTreeToolTipIcon(); //@} + + // Auto generated code (Tools/params_utils.py:138) + //@{ + /// Accessor for parameter VisibilityIcon + /// + /// If enabled, show an eye icon before the tree view items, showing the items visibility status. When clicked the visibility is toggled + static const bool & getVisibilityIcon(); + static const bool & defaultVisibilityIcon(); + static void removeVisibilityIcon(); + static void setVisibilityIcon(const bool &v); + static const char *docVisibilityIcon(); + static void onVisibilityIconChanged(); + //@} //[[[end]]] static void refreshTreeViews(); diff --git a/src/Gui/TreeParams.py b/src/Gui/TreeParams.py index c63d931a3a..a640753ca8 100644 --- a/src/Gui/TreeParams.py +++ b/src/Gui/TreeParams.py @@ -80,6 +80,8 @@ Params = [ ParamInt('ColumnSize1', 0), ParamInt('ColumnSize2', 0), ParamBool('TreeToolTipIcon', False, title='Show icon in tool tip'), + ParamBool('VisibilityIcon', False, on_change=True, title='Show visibility icon', + doc = "If enabled, show an eye icon before the tree view items, showing the items visibility status. When clicked the visibility is toggled"), ] def declare_begin():