From eeb02d4db1aa31cb7c49bf45a52bef4f63b8c85f Mon Sep 17 00:00:00 2001 From: Paddle Date: Tue, 30 May 2023 16:56:41 +0200 Subject: [PATCH 1/3] Core: Tree: Remove useless "Application" root item. --- src/Gui/Tree.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Gui/Tree.cpp b/src/Gui/Tree.cpp index 41bdcdebc0..20d2bf89e6 100644 --- a/src/Gui/Tree.cpp +++ b/src/Gui/Tree.cpp @@ -400,7 +400,6 @@ TreeWidget::TreeWidget(const char* name, QWidget* parent) this->setAcceptDrops(true); this->setDropIndicatorShown(false); this->setDragDropMode(QTreeWidget::InternalMove); - this->setRootIsDecorated(false); this->setColumnCount(2); this->setItemDelegate(new TreeWidgetEditDelegate(this)); @@ -487,8 +486,7 @@ TreeWidget::TreeWidget(const char* name, QWidget* parent) }); // Add the first main label - this->rootItem = new QTreeWidgetItem(this); - this->rootItem->setFlags(Qt::ItemIsEnabled); + this->rootItem = invisibleRootItem(); this->expandItem(this->rootItem); this->setSelectionMode(QAbstractItemView::ExtendedSelection); @@ -2769,7 +2767,6 @@ void TreeWidget::setupText() { this->headerItem()->setText(0, tr("Labels & Attributes")); this->headerItem()->setText(1, tr("Description")); - this->rootItem->setText(0, tr("Application")); this->showHiddenAction->setText(tr("Show items hidden in tree view")); this->showHiddenAction->setStatusTip(tr("Show items that are marked as 'hidden' in the tree view")); From 020cd97206c628a6e3329f4623c84e524b154f61 Mon Sep 17 00:00:00 2001 From: Paddle Date: Tue, 30 May 2023 16:58:41 +0200 Subject: [PATCH 2/3] Core: Tree: Change the default of the preference to hide the seldomly used 'Description' colum. On top of that the headers are now hidden if the description column is hidden. --- src/Gui/Tree.cpp | 1 + src/Gui/TreeParams.cpp | 6 +++--- src/Gui/TreeParams.py | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Gui/Tree.cpp b/src/Gui/Tree.cpp index 20d2bf89e6..8e364692c4 100644 --- a/src/Gui/Tree.cpp +++ b/src/Gui/Tree.cpp @@ -520,6 +520,7 @@ TreeWidget::TreeWidget(const char* name, QWidget* parent) documentPartialPixmap.reset(new QPixmap(icon.pixmap(documentPixmap->size(), QIcon::Disabled))); } setColumnHidden(1, TreeParams::getHideColumn()); + header()->setVisible(!TreeParams::getHideColumn()); } TreeWidget::~TreeWidget() diff --git a/src/Gui/TreeParams.cpp b/src/Gui/TreeParams.cpp index a2db6299c2..2b068655b1 100644 --- a/src/Gui/TreeParams.cpp +++ b/src/Gui/TreeParams.cpp @@ -142,7 +142,7 @@ public: funcs["ItemBackground"] = &TreeParamsP::updateItemBackground; ItemBackgroundPadding = handle->GetInt("ItemBackgroundPadding", 10); funcs["ItemBackgroundPadding"] = &TreeParamsP::updateItemBackgroundPadding; - HideColumn = handle->GetBool("HideColumn", false); + HideColumn = handle->GetBool("HideColumn", true); funcs["HideColumn"] = &TreeParamsP::updateHideColumn; HideScrollBar = handle->GetBool("HideScrollBar", true); funcs["HideScrollBar"] = &TreeParamsP::updateHideScrollBar; @@ -356,7 +356,7 @@ public: } // Auto generated code (Tools/params_utils.py:244) static void updateHideColumn(TreeParamsP *self) { - auto v = self->handle->GetBool("HideColumn", false); + auto v = self->handle->GetBool("HideColumn", true); if (self->HideColumn != v) { self->HideColumn = v; TreeParams::onHideColumnChanged(); @@ -1203,7 +1203,7 @@ const bool & TreeParams::getHideColumn() { // Auto generated code (Tools/params_utils.py:300) const bool & TreeParams::defaultHideColumn() { - const static bool def = false; + const static bool def = true; return def; } diff --git a/src/Gui/TreeParams.py b/src/Gui/TreeParams.py index e7163f573f..64490d3ceb 100644 --- a/src/Gui/TreeParams.py +++ b/src/Gui/TreeParams.py @@ -69,7 +69,7 @@ Params = [ doc = "Tree view item background. Only effecitve in overlay."), ParamInt('ItemBackgroundPadding', 10, on_change=True, title="Item background padding", proxy=ParamSpinBox(0, 100, 1), doc = "Tree view item background padding."), - ParamBool('HideColumn', False, on_change=True, title="Hide extra column", + ParamBool('HideColumn', True, on_change=True, title="Hide extra column", doc = "Hide extra tree view column for item description."), ParamBool('HideScrollBar', True, title="Hide scroll bar", doc = "Hide tree view scroll bar in dock overlay."), From 9a39b6c185de0e5c0acbf93cda1a8609937fbd71 Mon Sep 17 00:00:00 2001 From: Paddle Date: Fri, 2 Jun 2023 10:50:25 +0200 Subject: [PATCH 3/3] Add 'Tree settings' menu to the tree contextual menu. Also adds 'Show description column' setting in it. --- src/Gui/Tree.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Gui/Tree.cpp b/src/Gui/Tree.cpp index 8e364692c4..6cd159c04d 100644 --- a/src/Gui/Tree.cpp +++ b/src/Gui/Tree.cpp @@ -901,6 +901,27 @@ void TreeWidget::contextMenuEvent(QContextMenuEvent* e) subMenu.addActions(subMenuGroup.actions()); } + // add a submenu to present the settings of the tree. + QMenu settingsMenu; + settingsMenu.setTitle(tr("Tree settings")); + contextMenu.addSeparator(); + contextMenu.addMenu(&settingsMenu); + + QAction* action = new QAction(tr("Show description column"), this); + action->setStatusTip(tr("Show an extra tree view column for item description. The item's description can be set by pressing F2 (or your OS's edit button) or by editing the 'label2' property.")); + action->setCheckable(true); + + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/TreeView"); + action->setChecked(!hGrp->GetBool("HideColumn", true)); + + settingsMenu.addAction(action); + QObject::connect(action, &QAction::triggered, this, [this, action, hGrp]() { + bool show = action->isChecked(); + hGrp->SetBool("HideColumn", !show); + setColumnHidden(1, !show); + header()->setVisible(show); + }); + if (contextMenu.actions().count() > 0) { try { contextMenu.exec(QCursor::pos());