Merge pull request #1301 from ispyisail/fix/zoom-content-hidden-items

Fix #1281: Zoom to content includes hidden wire texts
This commit is contained in:
Laurent Trinques
2026-10-04 07:35:52 +02:00
committed by GitHub
3 changed files with 26 additions and 5 deletions
+22 -3
View File
@@ -929,7 +929,7 @@ bool Diagram::toPaintDevice(QPaintDevice &pix,
// determine la zone source = contenu du schema + marges // determine la zone source = contenu du schema + marges
QRectF source_area; QRectF source_area;
if (!use_border_) { if (!use_border_) {
source_area = itemsBoundingRect(); source_area = visibleItemsBoundingRect();
source_area.translate(-margin, -margin); source_area.translate(-margin, -margin);
source_area.setWidth (source_area.width () + 2.0 * margin); source_area.setWidth (source_area.width () + 2.0 * margin);
source_area.setHeight(source_area.height() + 2.0 * margin); source_area.setHeight(source_area.height() + 2.0 * margin);
@@ -997,7 +997,7 @@ QSize Diagram::imageSize() const
// determine la zone source = contenu du schema + marges // determine la zone source = contenu du schema + marges
qreal image_width, image_height; qreal image_width, image_height;
if (!use_border_) { if (!use_border_) {
QRectF items_rect = itemsBoundingRect(); QRectF items_rect = visibleItemsBoundingRect();
image_width = items_rect.width(); image_width = items_rect.width();
image_height = items_rect.height(); image_height = items_rect.height();
} else { } else {
@@ -2838,10 +2838,29 @@ void Diagram::adjustSceneRect()
{ {
QRectF old_rect = sceneRect(); QRectF old_rect = sceneRect();
setSceneRect(border_and_titleblock.borderAndTitleBlockRect().united( setSceneRect(border_and_titleblock.borderAndTitleBlockRect().united(
itemsBoundingRect())); visibleItemsBoundingRect()));
update(old_rect.united(sceneRect())); update(old_rect.united(sceneRect()));
} }
/**
@brief Diagram::visibleItemsBoundingRect
Same as QGraphicsScene::itemsBoundingRect(), but only counts items that
are shown. A hidden item keeps whatever position it last had: the text of
a single-line wire, and the wire texts hidden by "one text per potential",
are never positioned again and can sit far outside the drawing (#1281).
@return the bounding rect of the visible items, in scene coordinates
*/
QRectF Diagram::visibleItemsBoundingRect() const
{
QRectF rect;
const auto scene_items = items();
for (QGraphicsItem *item : scene_items) {
if (item->isVisible())
rect |= item->sceneBoundingRect();
}
return rect;
}
/** /**
@brief Diagram::applyProperties @brief Diagram::applyProperties
This method allows you to apply new rendering options while This method allows you to apply new rendering options while
+1
View File
@@ -258,6 +258,7 @@ class Diagram : public QGraphicsScene
bool toPaintDevice(QPaintDevice &, int = -1, int = -1, bool toPaintDevice(QPaintDevice &, int = -1, int = -1,
Qt::AspectRatioMode = Qt::KeepAspectRatio); Qt::AspectRatioMode = Qt::KeepAspectRatio);
QSize imageSize() const; QSize imageSize() const;
QRectF visibleItemsBoundingRect() const;
bool isEmpty() const; bool isEmpty() const;
+3 -2
View File
@@ -479,8 +479,9 @@ void DiagramView::zoomFit()
*/ */
void DiagramView::zoomContent() void DiagramView::zoomContent()
{ {
fitInView(m_diagram -> itemsBoundingRect(), Qt::KeepAspectRatio); const QRectF content = m_diagram->visibleItemsBoundingRect();
adjustGridToZoom(); if (!content.isNull())
zoomToRect(content);
} }
/** /**