Add View > Show to hide texts, shapes, pictures by kind (bugtracker #301)

A submenu under View (Affichage > Afficher) with one tick per kind:
symbol texts, wire texts, free texts, shapes, pictures, tables and
cross-references. Unticking one hides it on every folio of every open
project; the status bar says how many kinds are hidden. Session only,
not saved in the project.

Each item is tagged with its kind by its constructor (ShownKinds::tag),
so an item created while its kind is hidden starts hidden whatever
created it. A tag rather than type(): the cross-reference under a
contact's label is a plain QGraphicsTextItem.

Items that already hide themselves (wire text switched off, one text per
potential, a cross-reference snapped elsewhere) now go through
ShownKinds::setVisible(): the kind state can only veto a show, and
apply() re-shows only what it hid itself (hidden_key), never what an
item hid. Conductor::updateTextVisibility() replaces the same visibility
rule pasted in diagrampropertiesdialog.cpp and qetscriptapi.cpp.

Hidden items are not selectable (Qt), so Select All, copy and delete
skip them. Print, PDF and image export render the scene and leave them
out; the DXF export walks items itself and skips them through
ShownKinds::isHidden(). CrossRefItem::linkedChanged() keeps following
its slaves while hidden only by kind, so its label is right when shown.

Known limitation: QGraphicsScene::itemsBoundingRect() still counts hidden
items, so Zoom to fit and borderless image export keep their space.

Verified: tst_shownkinds (12 cases, two mutation checks) and ctest 55/55;
GUI hide/show of symbol texts, wire texts (incl. one text per potential),
free texts, shapes and cross-references returns pixel-identical folios;
with nothing hidden, --export-dxf of the 24 examples is byte-identical to
master (133 files) and --export-pdf renders identically (133 pages).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015FPuYPS4T7QuEwjNu22rXD
This commit is contained in:
ispyisail
2026-10-03 19:44:12 +13:00
parent 6144da0f91
commit 649f06b3b8
21 changed files with 530 additions and 24 deletions
+47
View File
@@ -16,6 +16,7 @@
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#include "qetdiagrameditor.h"
#include "shownkinds.h"
#ifdef QET_HAS_SCRIPTING
#include "scripting/qetscripting.h"
#include "scripting/scriptlibrary.h"
@@ -607,6 +608,36 @@ void QETDiagramEditor::setUpActions()
dv->setCellLinesShown(checked);
});
//Show or hide whole kinds of items on every folio (bugtracker #301)
m_shown_kinds_menu = new QMenu(tr("Afficher"), this);
const QList<QPair<ShownKinds::Kind, QString>> kinds {
{ShownKinds::SymbolTexts, tr("Textes des éléments")},
{ShownKinds::WireNumbers, tr("Textes des conducteurs")},
{ShownKinds::FreeTexts, tr("Champs de texte")},
{ShownKinds::Shapes, tr("Formes")},
{ShownKinds::Pictures, tr("Images")},
{ShownKinds::Tables, tr("Tableaux")},
{ShownKinds::CrossReferences, tr("Références croisées")}};
for (const auto &kind : kinds)
{
QAction *action = m_shown_kinds_menu->addAction(kind.second);
action->setCheckable(true);
action->setData(int(kind.first));
connect(action, &QAction::triggered, this, [kind](bool checked) {
ShownKinds::setShown(kind.first, checked);
for (QETProject *project : QETApp::registeredProjects())
for (Diagram *diagram : project->diagrams())
ShownKinds::apply(diagram, kind.first);
emit QETApp::instance()->shownKindsChanged();
});
}
m_hidden_kinds_label = new QLabel(this);
m_hidden_kinds_label->setToolTip(tr("Voir Affichage > Afficher"));
statusBar()->addPermanentWidget(m_hidden_kinds_label);
connect(QETApp::instance(), &QETApp::shownKindsChanged,
this, &QETDiagramEditor::updateShownKinds);
updateShownKinds();
//Edit current diagram properties
m_edit_diagram_properties = new QAction(QET::Icons::DialogInformation, tr("Propriétés du folio"), this);
ShortcutManager::instance().registerAction(m_edit_diagram_properties, "diagrameditor.edit_diagram_properties", tr("Éditeur de schémas"), Qt::CTRL | Qt::Key_L);
@@ -1458,6 +1489,7 @@ void QETDiagramEditor::setUpMenu()
menu_affichage -> addAction(m_draw_guides);
menu_affichage -> addAction(m_cell_rulers);
menu_affichage -> addAction(m_cell_lines);
menu_affichage -> addMenu(m_shown_kinds_menu);
menu_affichage -> addMenu(m_background_color_button->menu());
menu_affichage -> addSeparator();
menu_affichage -> addActions(m_zoom_actions_group.actions());
@@ -4140,6 +4172,21 @@ void QETDiagramEditor::updateScriptActions()
}
#endif
/**
@brief QETDiagramEditor::updateShownKinds
Tick the kinds shown in View > Show, and say in the status bar how many
are hidden, so that a hidden kind is never forgotten.
*/
void QETDiagramEditor::updateShownKinds()
{
for (QAction *action : m_shown_kinds_menu->actions())
action->setChecked(ShownKinds::isShown(ShownKinds::Kind(action->data().toInt())));
const int hidden = ShownKinds::hiddenCount();
m_hidden_kinds_label->setText(tr("%n type(s) d'objets masqué(s)", "", hidden));
m_hidden_kinds_label->setVisible(hidden > 0);
}
/**
@brief QETDiagramEditor::updateTextGridButton
Show the current text grid on its toolbar button and check it in its menu.