diff --git a/src/Gui/Tree.cpp b/src/Gui/Tree.cpp index 41bdcdebc0..6cd159c04d 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); @@ -522,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() @@ -902,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()); @@ -2769,7 +2789,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")); 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."),