Files
qelectrotech-source-mirror/sources/shownkinds.h
T
ispyisail 649f06b3b8 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
2026-10-03 19:44:12 +13:00

77 lines
2.6 KiB
C++

/*
Copyright 2006-2026 The QElectroTech Team
This file is part of QElectroTech.
QElectroTech is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
QElectroTech is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SHOWNKINDS_H
#define SHOWNKINDS_H
class QGraphicsItem;
class QGraphicsScene;
/**
Show or hide whole kinds of folio items, View > Show (bugtracker #301):
symbol texts, wire numbers, free texts and so on.
Each item says which kind it is with a tag set by its constructor, so an
item created while its kind is hidden starts hidden, whichever way it was
created (load, paste, a text added to a symbol, a new cross-reference).
A tag and not type(): the cross-reference under a contact's label is a
plain QGraphicsTextItem.
Some items also hide themselves (a wire number switched off, one text
per potential, a cross-reference snapped elsewhere). They call
setVisible() here instead of QGraphicsItem::setVisible(), and the kind
state can only veto what they ask for: showing a kind again brings back
only what was hidden for it, never what an item hid itself.
The state is for the whole application and is not saved: it is a way of
looking at the folios, like the grid. Hidden items are left out of
printing and exports, and Qt does not select them, so nothing hidden is
copied, moved or deleted by accident.
This part knows nothing of Diagram, so it can be tested on a plain scene.
*/
namespace ShownKinds
{
enum Kind {
SymbolTexts,
WireNumbers,
FreeTexts,
Shapes,
Pictures,
Tables,
CrossReferences,
KindCount
};
/// QGraphicsItem::data() key holding an item's kind.
inline constexpr int data_key = 0x4b4e44; // "KND"
/// QGraphicsItem::data() key set while an item that wants to be
/// visible is hidden only because its kind is hidden.
inline constexpr int hidden_key = 0x4b4e48; // "KNH"
bool isShown(Kind kind);
void setShown(Kind kind, bool shown);
int hiddenCount();
void tag(QGraphicsItem *item, Kind kind);
void setVisible(QGraphicsItem *item, bool visible);
bool isHidden(const QGraphicsItem *item);
void apply(QGraphicsScene *scene, Kind kind);
}
#endif // SHOWNKINDS_H