From 2224d87e6e165a49c22ddd6a894dbe105cf2674a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Althaus?= Date: Tue, 5 Mar 2024 18:00:09 +0100 Subject: [PATCH] Fix #12780: An additional visibility icon is shown for features in groups The icons in the testStatus() function are taken by reference and modified inside. This seems to be used for caching when the same item occurs multiple times in the tree. This can be the case for groups. The visibility icon was added without taking the cached icon into consideration and so it was added a second time. The code is now moved into the if statement checking for this case. --- src/Gui/Tree.cpp | 59 ++++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 30 deletions(-) diff --git a/src/Gui/Tree.cpp b/src/Gui/Tree.cpp index 0c07f2682b..5ef4331f5c 100644 --- a/src/Gui/Tree.cpp +++ b/src/Gui/Tree.cpp @@ -5356,38 +5356,37 @@ void DocumentObjectItem::testStatus(bool resetStatus, QIcon& icon1, QIcon& icon2 icon.addPixmap(pxOff, QIcon::Normal, QIcon::Off); icon = object()->mergeColorfulOverlayIcons(icon); + + if (isVisibilityIconEnabled()) { + static QPixmap pxVisible, pxInvisible; + if (pxVisible.isNull()) { + pxVisible = BitmapFactory().pixmap("TreeItemVisible"); + } + if (pxInvisible.isNull()) { + pxInvisible = BitmapFactory().pixmap("TreeItemInvisible"); + } + + // Prepend the visibility pixmap to the final icon pixmaps and use these as the icon. + QIcon new_icon; + for (auto state: {QIcon::On, QIcon::Off}) { + QPixmap px_org = icon.pixmap(0xFFFF, 0xFFFF, QIcon::Normal, state); + + QPixmap px(2*px_org.width(), px_org.height()); + px.fill(Qt::transparent); + + QPainter pt; + pt.begin(&px); + pt.setPen(Qt::NoPen); + pt.drawPixmap(0, 0, px_org.width(), px_org.height(), (currentStatus & 1) ? pxVisible : pxInvisible); + pt.drawPixmap(px_org.width(), 0, px_org.width(), px_org.height(), px_org); + pt.end(); + + new_icon.addPixmap(px, QIcon::Normal, state); + } + icon = new_icon; + } } - if (isVisibilityIconEnabled()) { - static QPixmap pxVisible, pxInvisible; - if (pxVisible.isNull()) { - pxVisible = BitmapFactory().pixmap("TreeItemVisible"); - } - if (pxInvisible.isNull()) { - pxInvisible = BitmapFactory().pixmap("TreeItemInvisible"); - } - - // Prepend the visibility pixmap to the final icon pixmaps and use these as the icon. - QIcon new_icon; - for (auto state: {QIcon::On, QIcon::Off}) { - QPixmap px_org = icon.pixmap(0xFFFF, 0xFFFF, QIcon::Normal, state); - - QPixmap px(2*px_org.width(), px_org.height()); - px.fill(Qt::transparent); - - QPainter pt; - pt.begin(&px); - pt.setPen(Qt::NoPen); - pt.drawPixmap(0, 0, px_org.width(), px_org.height(), (currentStatus & 1) ? pxVisible : pxInvisible); - pt.drawPixmap(px_org.width(), 0, px_org.width(), px_org.height(), px_org); - pt.end(); - - new_icon.addPixmap(px, QIcon::Normal, state); - } - icon = new_icon; - } - - _Timing(2, setIcon); this->setIcon(0, icon); }