Skip to content

Commit

Permalink
An initial stage for displaying internal names in the tree view
Browse files Browse the repository at this point in the history
  • Loading branch information
KuzemkoA committed May 14, 2024
1 parent 869cb1f commit 344015f
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 7 deletions.
47 changes: 40 additions & 7 deletions src/Gui/Tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@


#include "PreCompiled.h"
#include "qdebug.h"

#ifndef _PreComp_
# include <QAction>
Expand Down Expand Up @@ -429,7 +430,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 All @@ -456,7 +457,15 @@ void TreeWidgetItemDelegate::paint(QPainter *painter,
} else if (!opt.state.testFlag(QStyle::State_Selected))
painter->fillRect(rect, _TreeItemBackground);
}

}
else if (index.column() == 2) {
auto ti = static_cast<QTreeWidgetItem*>(index.internalPointer());
if (ti->type() == TreeWidget::ObjectType)
{
auto item = static_cast<DocumentObjectItem*>(ti);
App::DocumentObject* obj = item->object()->getObject();
painter->drawText(rect, Qt::AlignLeft | Qt::AlignVCenter, QString::fromUtf8(obj->getNameInDocument()));
}
}

style->drawControl(QStyle::CE_ItemViewItem, &opt, painter, tree);
Expand Down Expand Up @@ -534,7 +543,7 @@ TreeWidget::TreeWidget(const char* name, QWidget* parent)
this->setDragEnabled(true);
this->setAcceptDrops(true);
this->setDragDropMode(QTreeWidget::InternalMove);
this->setColumnCount(2);
this->setColumnCount(3);
this->setItemDelegate(new TreeWidgetItemDelegate(this));

this->showHiddenAction = new QAction(this);
Expand Down Expand Up @@ -615,9 +624,12 @@ 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 @@ -656,7 +668,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 @@ -1048,18 +1061,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 @@ -1373,12 +1402,15 @@ void TreeWidget::setupResizableColumn(TreeWidget *tree) {
if(!tree || tree==inst) {
inst->header()->setSectionResizeMode(0, mode);
inst->header()->setSectionResizeMode(1, mode);
inst->header()->setSectionResizeMode(2, mode);
if (TreeParams::getResizableColumn()) {
QSignalBlocker blocker(inst);
if (TreeParams::getColumnSize1() > 0)
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 @@ -3193,6 +3225,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
79 changes: 79 additions & 0 deletions src/Gui/TreeParams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,13 @@ class TreeParamsP: public ParameterGrp::ObserverType {
unsigned long ItemBackground;
long ItemBackgroundPadding;
bool HideColumn;
bool ShowInternalNames;
bool HideScrollBar;
bool HideHeaderView;
bool ResizableColumn;
long ColumnSize1;
long ColumnSize2;
long ColumnSize3;
bool TreeToolTipIcon;
bool VisibilityIcon;

Expand Down Expand Up @@ -145,6 +147,8 @@ class TreeParamsP: public ParameterGrp::ObserverType {
funcs["ItemBackgroundPadding"] = &TreeParamsP::updateItemBackgroundPadding;
HideColumn = handle->GetBool("HideColumn", true);
funcs["HideColumn"] = &TreeParamsP::updateHideColumn;
ShowInternalNames = handle->GetBool("ShowInternalNames", true);
funcs["ShowInternalNames"] = &TreeParamsP::updateShowInternalNames;
HideScrollBar = handle->GetBool("HideScrollBar", true);
funcs["HideScrollBar"] = &TreeParamsP::updateHideScrollBar;
HideHeaderView = handle->GetBool("HideHeaderView", true);
Expand All @@ -155,6 +159,8 @@ class TreeParamsP: public ParameterGrp::ObserverType {
funcs["ColumnSize1"] = &TreeParamsP::updateColumnSize1;
ColumnSize2 = handle->GetInt("ColumnSize2", 0);
funcs["ColumnSize2"] = &TreeParamsP::updateColumnSize2;
ColumnSize3 = handle->GetInt("ColumnSize3", 0);
funcs["ColumnSize3"] = &TreeParamsP::updateColumnSize3;
TreeToolTipIcon = handle->GetBool("TreeToolTipIcon", false);
funcs["TreeToolTipIcon"] = &TreeParamsP::updateTreeToolTipIcon;
VisibilityIcon = handle->GetBool("VisibilityIcon", false);
Expand Down Expand Up @@ -365,6 +371,14 @@ class TreeParamsP: public ParameterGrp::ObserverType {
TreeParams::onHideColumnChanged();
}
}
// Auto generated code (Tools/params_utils.py:296)
static void updateShowInternalNames(TreeParamsP *self) {
auto v = self->handle->GetBool("ShowInternalNames", true);
if (self->ShowInternalNames != v) {
self->ShowInternalNames = v;
TreeParams::onShowInternalNamesChanged();
}
}
// Auto generated code (Tools/params_utils.py:288)
static void updateHideScrollBar(TreeParamsP *self) {
self->HideScrollBar = self->handle->GetBool("HideScrollBar", true);
Expand All @@ -390,6 +404,10 @@ class TreeParamsP: public ParameterGrp::ObserverType {
self->ColumnSize2 = self->handle->GetInt("ColumnSize2", 0);
}
// Auto generated code (Tools/params_utils.py:288)
static void updateColumnSize3(TreeParamsP *self) {
self->ColumnSize3 = self->handle->GetInt("ColumnSize3", 0);
}
// Auto generated code (Tools/params_utils.py:288)
static void updateTreeToolTipIcon(TreeParamsP *self) {
self->TreeToolTipIcon = self->handle->GetBool("TreeToolTipIcon", false);
}
Expand Down Expand Up @@ -1229,6 +1247,34 @@ void TreeParams::removeHideColumn() {
instance()->handle->RemoveBool("HideColumn");
}

// Auto generated code (Tools/params_utils.py:350)
const char *TreeParams::docShowInternalNames() {
return QT_TRANSLATE_NOOP("TreeParams",
"Show Internal Names column.");
}

// Auto generated code (Tools/params_utils.py:358)
const bool & TreeParams::getShowInternalNames() {
return instance()->ShowInternalNames;
}

// Auto generated code (Tools/params_utils.py:366)
const bool & TreeParams::defaultShowInternalNames() {
const static bool def = true;
return def;
}

// Auto generated code (Tools/params_utils.py:375)
void TreeParams::setShowInternalNames(const bool &v) {
instance()->handle->SetBool("ShowInternalNames",v);
instance()->ShowInternalNames = v;
}

// Auto generated code (Tools/params_utils.py:384)
void TreeParams::removeShowInternalNames() {
instance()->handle->RemoveBool("ShowInternalNames");
}

// Auto generated code (Tools/params_utils.py:350)
const char *TreeParams::docHideScrollBar() {
return QT_TRANSLATE_NOOP("TreeParams",
Expand Down Expand Up @@ -1367,6 +1413,33 @@ void TreeParams::removeColumnSize2() {
instance()->handle->RemoveInt("ColumnSize2");
}

// Auto generated code (Tools/params_utils.py:350)
const char *TreeParams::docColumnSize3() {
return "";
}

// Auto generated code (Tools/params_utils.py:358)
const long & TreeParams::getColumnSize3() {
return instance()->ColumnSize3;
}

// Auto generated code (Tools/params_utils.py:366)
const long & TreeParams::defaultColumnSize3() {
const static long def = 0;
return def;
}

// Auto generated code (Tools/params_utils.py:375)
void TreeParams::setColumnSize3(const long &v) {
instance()->handle->SetInt("ColumnSize3",v);
instance()->ColumnSize3 = v;
}

// Auto generated code (Tools/params_utils.py:384)
void TreeParams::removeColumnSize3() {
instance()->handle->RemoveInt("ColumnSize3");
}

// Auto generated code (Tools/params_utils.py:350)
const char *TreeParams::docTreeToolTipIcon() {
return "";
Expand Down Expand Up @@ -1523,6 +1596,12 @@ void TreeParams::onHideColumnChanged()
tree->setColumnHidden(1, TreeParams::getHideColumn());
}

void TreeParams::onShowInternalNamesChanged()
{
for(auto tree : TreeWidget::Instances)
tree->setColumnHidden(2, TreeParams::getShowInternalNames());
}

void TreeParams::onVisibilityIconChanged()
{
TreeWidget::updateVisibilityIcons();
Expand Down
23 changes: 23 additions & 0 deletions src/Gui/TreeParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,19 @@ class GuiExport TreeParams {
static void onHideColumnChanged();
//@}

// Auto generated code (Tools/params_utils.py:138)
//@{
/// Accessor for parameter ShowInternalNames
///
/// Show Internal Names column.
static const bool & getShowInternalNames();
static const bool & defaultShowInternalNames();
static void removeShowInternalNames();
static void setShowInternalNames(const bool &v);
static const char *docShowInternalNames();
static void onShowInternalNamesChanged();
//@}

// Auto generated code (Tools/params_utils.py:138)
//@{
/// Accessor for parameter HideScrollBar
Expand Down Expand Up @@ -448,6 +461,16 @@ class GuiExport TreeParams {
static const char *docColumnSize2();
//@}

// Auto generated code (Tools/params_utils.py:138)
//@{
/// Accessor for parameter ColumnSize3
static const long & getColumnSize3();
static const long & defaultColumnSize3();
static void removeColumnSize3();
static void setColumnSize3(const long &v);
static const char *docColumnSize3();
//@}

// Auto generated code (Tools/params_utils.py:138)
//@{
/// Accessor for parameter TreeToolTipIcon
Expand Down
3 changes: 3 additions & 0 deletions src/Gui/TreeParams.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@
doc = "Tree view item background padding."),
ParamBool('HideColumn', True, on_change=True, title="Hide extra column",
doc = "Hide extra tree view column for item description."),
ParamBool('ShowInternalNames', True, on_change=True, title="Show Internal Names",
doc = "Show Internal Names column."),
ParamBool('HideScrollBar', True, title="Hide scroll bar",
doc = "Hide tree view scroll bar in dock overlay."),
ParamBool('HideHeaderView', True, title="Hide header",
Expand All @@ -79,6 +81,7 @@
doc = "Allow tree view columns to be manually resized."),
ParamInt('ColumnSize1', 0),
ParamInt('ColumnSize2', 0),
ParamInt('ColumnSize3', 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"),

Check warning on line 87 in src/Gui/TreeParams.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Line too long (150/100) (line-too-long)
Expand Down

0 comments on commit 344015f

Please sign in to comment.