mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-05 02:24:13 +02:00
Zoom to content: count only visible items
itemsBoundingRect() also counts hidden items. 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, so Zoom to content zoomed out to include them. On photovoltaique.qet 14 such texts reach x = -729 and the zoom covered 2421x924 instead of 1135x648. Add Diagram::visibleItemsBoundingRect() and use it for Zoom to content, the scene rect and the borderless export. Zoom to content now goes through zoomToRect(), which re-centres after the scroll bars appear; before, the view could stay scrolled to the top-left with part of the content cut off. Fixes #1281 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+22
-3
@@ -929,7 +929,7 @@ bool Diagram::toPaintDevice(QPaintDevice &pix,
|
||||
// determine la zone source = contenu du schema + marges
|
||||
QRectF source_area;
|
||||
if (!use_border_) {
|
||||
source_area = itemsBoundingRect();
|
||||
source_area = visibleItemsBoundingRect();
|
||||
source_area.translate(-margin, -margin);
|
||||
source_area.setWidth (source_area.width () + 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
|
||||
qreal image_width, image_height;
|
||||
if (!use_border_) {
|
||||
QRectF items_rect = itemsBoundingRect();
|
||||
QRectF items_rect = visibleItemsBoundingRect();
|
||||
image_width = items_rect.width();
|
||||
image_height = items_rect.height();
|
||||
} else {
|
||||
@@ -2838,10 +2838,29 @@ void Diagram::adjustSceneRect()
|
||||
{
|
||||
QRectF old_rect = sceneRect();
|
||||
setSceneRect(border_and_titleblock.borderAndTitleBlockRect().united(
|
||||
itemsBoundingRect()));
|
||||
visibleItemsBoundingRect()));
|
||||
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
|
||||
This method allows you to apply new rendering options while
|
||||
|
||||
@@ -258,6 +258,7 @@ class Diagram : public QGraphicsScene
|
||||
bool toPaintDevice(QPaintDevice &, int = -1, int = -1,
|
||||
Qt::AspectRatioMode = Qt::KeepAspectRatio);
|
||||
QSize imageSize() const;
|
||||
QRectF visibleItemsBoundingRect() const;
|
||||
|
||||
bool isEmpty() const;
|
||||
|
||||
|
||||
@@ -479,8 +479,9 @@ void DiagramView::zoomFit()
|
||||
*/
|
||||
void DiagramView::zoomContent()
|
||||
{
|
||||
fitInView(m_diagram -> itemsBoundingRect(), Qt::KeepAspectRatio);
|
||||
adjustGridToZoom();
|
||||
const QRectF content = m_diagram->visibleItemsBoundingRect();
|
||||
if (!content.isNull())
|
||||
zoomToRect(content);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user