Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Displaying internal names in the tree view #14081

Closed
wants to merge 5 commits into from

Conversation

Kuzma30
Copy link
Contributor

@Kuzma30 Kuzma30 commented May 17, 2024

More info here
#5547 (comment)

@github-actions github-actions bot added the Core Issue or PR touches core sections (App, Gui, Base) of FreeCAD label May 17, 2024
@maxwxyz
Copy link
Collaborator

maxwxyz commented May 17, 2024

@Kuzma30 could you add some before/after screenshots?

@Kuzma30
Copy link
Contributor Author

Kuzma30 commented May 17, 2024

@Kuzma30 could you add some before/after screenshots?
"Before"
#14003 (comment)
"After"
#5547 (comment)

@FEA-eng
Copy link
Contributor

FEA-eng commented May 20, 2024

Very good idea and works well (I tested it). I just wonder if it should be enabled by default.

@Kuzma30
Copy link
Contributor Author

Kuzma30 commented May 21, 2024

Need rework after merge a09dcd9

@yorikvanhavre
Copy link
Member

I would say it shouldn't be enabled by default, most users will probably want it off

@Kuzma30
Copy link
Contributor Author

Kuzma30 commented May 21, 2024

Very strange situation:
With a09dcd9 applied (it must work for any column count) and

void TreeWidget::drawRow(QPainter* painter, const QStyleOptionViewItem& options, const QModelIndex& index) const
{
    QTreeWidget::drawRow(painter, options, index);
    // QTreeWidgetItem * item = itemFromIndex(index);
    // if (!isVisibilityIconEnabled() && item->type() == ObjectType && !(static_cast<DocumentObjectItem*>(item)->previousStatus & 1)) {
    //    QStyleOptionViewItem opt(options);
    //    opt.state ^= QStyle::State_Enabled;
    //    // Set color for all states, not just Inactive
    //    QColor c = opt.palette.color(QPalette::Disabled, QPalette::Dark);
    //    opt.palette.setColor(QPalette::Disabled, QPalette::Text, c);
    //    opt.palette.setColor(QPalette::Disabled, QPalette::HighlightedText, c);

    //    // Optionally, set colors for Active and Inactive states
    //    opt.palette.setColor(QPalette::Inactive, QPalette::Text, c);
    //    opt.palette.setColor(QPalette::Inactive, QPalette::HighlightedText, c);
    //    opt.palette.setColor(QPalette::Active, QPalette::Text, c);
    //    opt.palette.setColor(QPalette::Active, QPalette::HighlightedText, c);
    //    QTreeWidget::drawRow(painter, opt, index);
    // }
    // else {
    //    QTreeWidget::drawRow(painter, options, index);
    // }
}

I get
Знімок екрана з 2024-05-21 06-52-40

Its only work with drawRow modification. But with this modification it also work without a09dcd9

@Kuzma30
Copy link
Contributor Author

Kuzma30 commented May 21, 2024

I change adding 3 column logic. Now full patch

From 9283a9dc4c38acc2244425333371a4147ff0703c Mon Sep 17 00:00:00 2001
From: Kuzma30 <kuzemkoa@gmail.com>
Date: Tue, 21 May 2024 09:45:23 +0000
Subject: [PATCH 3/3] Displaying internal names in the tree view

---
 src/3rdParty/OndselSolver |  2 +-
 src/Gui/Tree.cpp          | 44 +++++++++++++++++-----
 src/Gui/TreeParams.cpp    | 79 +++++++++++++++++++++++++++++++++++++++
 src/Gui/TreeParams.h      | 23 ++++++++++++
 src/Gui/TreeParams.py     |  3 ++
 5 files changed, 140 insertions(+), 11 deletions(-)

diff --git a/src/3rdParty/OndselSolver b/src/3rdParty/OndselSolver
index 1c135304f6..2d71435110 160000
--- a/src/3rdParty/OndselSolver
+++ b/src/3rdParty/OndselSolver
@@ -1 +1 @@
-Subproject commit 1c135304f632abcfb6e9d47100b803ac81cf078c
+Subproject commit 2d71435110f2232cffa9c33a436ad63dd8036ce1
diff --git a/src/Gui/Tree.cpp b/src/Gui/Tree.cpp
index 9062db63f8..d0687d537a 100644
--- a/src/Gui/Tree.cpp
+++ b/src/Gui/Tree.cpp
@@ -217,6 +217,7 @@ public:
     bool itemHidden;
     std::string label;
     std::string label2;
+    std::string internalName;
 
     using Connection = boost::signals2::scoped_connection;
 
@@ -245,6 +246,7 @@ public:
         itemHidden = !viewObject->showInTree();
         label = viewObject->getObject()->Label.getValue();
         label2 = viewObject->getObject()->Label2.getValue();
+        internalName = viewObject->getObject()->getNameInDocument();
     }
 
     void insertItem(DocumentObjectItem* item)
@@ -429,7 +431,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) {
@@ -456,9 +458,7 @@ void TreeWidgetItemDelegate::paint(QPainter *painter,
             } else if (!opt.state.testFlag(QStyle::State_Selected))
                 painter->fillRect(rect, _TreeItemBackground);
         }
-
     }
-
     style->drawControl(QStyle::CE_ItemViewItem, &opt, painter, tree);
 }
 
@@ -534,7 +534,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);
@@ -615,10 +615,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
-            TreeParams::setColumnSize1(newSize);
+        else if (idx == 2)
+                TreeParams::setColumnSize3(newSize);
+            else
+                TreeParams::setColumnSize1(newSize);
     });
 
     // Add the first main label
@@ -656,7 +658,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()
@@ -1048,6 +1051,7 @@ 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);
 
@@ -1055,11 +1059,26 @@ void TreeWidget::contextMenuEvent(QContextMenuEvent* e)
     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) {
@@ -1373,12 +1392,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());
             }
         }
     }
@@ -3193,6 +3215,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"));
@@ -3788,6 +3811,7 @@ bool DocumentItem::createNewItem(const Gui::ViewProviderDocumentObject& obj,
     item->setText(0, QString::fromUtf8(data->label.c_str()));
     if (!data->label2.empty())
         item->setText(1, QString::fromUtf8(data->label2.c_str()));
+    item->setText(2, QString::fromUtf8(data->internalName.c_str()));
     if (!obj.showInTree() && !showHidden())
         item->setHidden(true);
     item->testStatus(true);
diff --git a/src/Gui/TreeParams.cpp b/src/Gui/TreeParams.cpp
index acbe950640..44c07c1468 100644
--- a/src/Gui/TreeParams.cpp
+++ b/src/Gui/TreeParams.cpp
@@ -72,11 +72,13 @@ public:
     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;
 
@@ -145,6 +147,8 @@ public:
         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);
@@ -155,6 +159,8 @@ public:
         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);
@@ -365,6 +371,14 @@ public:
             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);
@@ -390,6 +404,10 @@ public:
         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);
     }
@@ -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",
@@ -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 "";
@@ -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();
diff --git a/src/Gui/TreeParams.h b/src/Gui/TreeParams.h
index 50792491ba..2c566a078d 100644
--- a/src/Gui/TreeParams.h
+++ b/src/Gui/TreeParams.h
@@ -391,6 +391,19 @@ public:
     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
@@ -448,6 +461,16 @@ public:
     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
diff --git a/src/Gui/TreeParams.py b/src/Gui/TreeParams.py
index a640753ca8..e751949688 100644
--- a/src/Gui/TreeParams.py
+++ b/src/Gui/TreeParams.py
@@ -71,6 +71,8 @@ Params = [
         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",
@@ -79,6 +81,7 @@ Params = [
         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"),
-- 
2.43.0

@yorikvanhavre
Please test and rewiev. If it OK, I'll recreate pull request.

@FEA-eng
Copy link
Contributor

FEA-eng commented May 21, 2024

I would say it shouldn't be enabled by default, most users will probably want it off

Yes, it should be disabled by default as it’s not needed in most cases and becomes useful when digging a bit deeper.

@Kuzma30
Copy link
Contributor Author

Kuzma30 commented May 23, 2024

Recreate in #14237

@Kuzma30 Kuzma30 closed this May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Core Issue or PR touches core sections (App, Gui, Base) of FreeCAD
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants