Skip to content

Commit

Permalink
Add initial variables fot toggle show internal names in tree wiev
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuzma30 committed Oct 26, 2023
1 parent 410d4f9 commit 3e3f42c
Show file tree
Hide file tree
Showing 3 changed files with 397 additions and 271 deletions.
35 changes: 29 additions & 6 deletions src/Gui/Tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ void TreeWidgetItemDelegate::paint(QPainter *painter,

// If the second column is not shown, we'll trim the color background when
// rendering as transparent overlay.
bool trimBG = TreeParams::getHideColumn();
bool trimBG = TreeParams::getHideColumn() || !TreeParams::getShowInternalNames();
QRect rect = opt.rect;

if (index.column() == 0) {
Expand Down Expand Up @@ -500,7 +500,7 @@ TreeWidget::TreeWidget(const char* name, QWidget* parent)
this->setAcceptDrops(true);
this->setDropIndicatorShown(false);
this->setDragDropMode(QTreeWidget::InternalMove);
this->setColumnCount(2);
this->setColumnCount(3);
this->setItemDelegate(new TreeWidgetItemDelegate(this));

this->showHiddenAction = new QAction(this);
Expand Down Expand Up @@ -581,8 +581,11 @@ TreeWidget::TreeWidget(const char* name, QWidget* parent)
setupResizableColumn(this);
this->header()->setStretchLastSection(false);
QObject::connect(this->header(), &QHeaderView::sectionResized, [](int idx, int, int newSize) {
if (idx)
if (idx==1)
TreeParams::setColumnSize2(newSize);
else
if (idx==2)
TreeParams::setColumnSize3(newSize);
else
TreeParams::setColumnSize1(newSize);
});
Expand Down Expand Up @@ -622,7 +625,8 @@ TreeWidget::TreeWidget(const char* name, QWidget* parent)
documentPartialPixmap = std::make_unique<QPixmap>(icon.pixmap(documentPixmap->size(), QIcon::Disabled));
}
setColumnHidden(1, TreeParams::getHideColumn());
header()->setVisible(!TreeParams::getHideColumn());
setColumnHidden(2, !TreeParams::getShowInternalNames());
header()->setVisible(!(TreeParams::getHideColumn() || !TreeParams::getShowInternalNames()));
}

TreeWidget::~TreeWidget()
Expand Down Expand Up @@ -1010,18 +1014,34 @@ void TreeWidget::contextMenuEvent(QContextMenuEvent* e)
contextMenu.addMenu(&settingsMenu);

QAction* action = new QAction(tr("Show description column"), this);
QAction* internalNameAction = new QAction(tr("Show internal name"), 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]() {
QObject::connect(action, &QAction::triggered, this, [this, action, internalNameAction, hGrp]() {
bool show = action->isChecked();
hGrp->SetBool("HideColumn", !show);
setColumnHidden(1, !show);
header()->setVisible(show);
header()->setVisible(action->isChecked()||internalNameAction->isChecked());
});


internalNameAction->setStatusTip(tr("Show an internal name column for items."));
internalNameAction->setCheckable(true);

internalNameAction->setChecked(hGrp->GetBool("ShowInternalNames", true));

settingsMenu.addAction(internalNameAction);

QObject::connect(internalNameAction, &QAction::triggered, this, [this, action, internalNameAction, hGrp]() {
bool show = internalNameAction->isChecked();
hGrp->SetBool("ShowInternalNames", show);
setColumnHidden(2, !show);
header()->setVisible(action->isChecked()||internalNameAction->isChecked());
});

if (contextMenu.actions().count() > 0) {
Expand Down Expand Up @@ -1341,6 +1361,8 @@ void TreeWidget::setupResizableColumn(TreeWidget *tree) {
inst->header()->resizeSection(0, TreeParams::getColumnSize1());
if (TreeParams::getColumnSize2() > 0)
inst->header()->resizeSection(1, TreeParams::getColumnSize2());
if (TreeParams::getColumnSize3() > 0)
inst->header()->resizeSection(2, TreeParams::getColumnSize3());
}
}
}
Expand Down Expand Up @@ -2952,6 +2974,7 @@ void TreeWidget::setupText()
{
this->headerItem()->setText(0, tr("Labels & Attributes"));
this->headerItem()->setText(1, tr("Description"));
this->headerItem()->setText(2, tr("Internal name"));

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"));
Expand Down
Loading

0 comments on commit 3e3f42c

Please sign in to comment.