From 53adb99721d57ffb769fe61c9f148ee5b5d3ba28 Mon Sep 17 00:00:00 2001 From: Valentin Buira Date: Wed, 14 May 2025 13:29:40 +0200 Subject: [PATCH] Avoid needless extra method --- .../models/qgsmodelgraphicsscene.sip.in | 18 ++++---------- .../models/qgsmodelgraphicsscene.sip.in | 18 ++++---------- .../models/qgsmodelgraphicsscene.cpp | 11 +++------ .../processing/models/qgsmodelgraphicsscene.h | 15 ++++-------- tests/src/gui/testprocessinggui.cpp | 24 ++++++++++--------- 5 files changed, 28 insertions(+), 58 deletions(-) diff --git a/python/PyQt6/gui/auto_generated/processing/models/qgsmodelgraphicsscene.sip.in b/python/PyQt6/gui/auto_generated/processing/models/qgsmodelgraphicsscene.sip.in index 005642132a1..59d44fb19f8 100644 --- a/python/PyQt6/gui/auto_generated/processing/models/qgsmodelgraphicsscene.sip.in +++ b/python/PyQt6/gui/auto_generated/processing/models/qgsmodelgraphicsscene.sip.in @@ -87,19 +87,6 @@ Returns the current combination of flags set for the scene. virtual void mousePressEvent( QGraphicsSceneMouseEvent *event ); - QRectF modelBounds( double margin = 0.0 ) const; -%Docstring -Calculates the bounding rectangle of all components of the model. - -:param margin: optional margin (absolute value in scene coordinates) to - add around items. - -:return: model bounds, in scene units. - -.. versionadded:: 3.44 -%End - - void createItems( QgsProcessingModelAlgorithm *model, QgsProcessingContext &context ); %Docstring Populates the scene by creating items representing the specified @@ -191,7 +178,10 @@ Requests a complete rebuild of a model by emitting the according signal void updateBounds(); %Docstring -Updates the scene bounds of the model. +Updates the scene rect based on the bounds of the model. + +The bounding rectangle of the model is calculated off all components of +the model, with an additional margin arounds items. .. versionadded:: 3.44 %End diff --git a/python/gui/auto_generated/processing/models/qgsmodelgraphicsscene.sip.in b/python/gui/auto_generated/processing/models/qgsmodelgraphicsscene.sip.in index 20d2df68a1a..5a38610981a 100644 --- a/python/gui/auto_generated/processing/models/qgsmodelgraphicsscene.sip.in +++ b/python/gui/auto_generated/processing/models/qgsmodelgraphicsscene.sip.in @@ -87,19 +87,6 @@ Returns the current combination of flags set for the scene. virtual void mousePressEvent( QGraphicsSceneMouseEvent *event ); - QRectF modelBounds( double margin = 0.0 ) const; -%Docstring -Calculates the bounding rectangle of all components of the model. - -:param margin: optional margin (absolute value in scene coordinates) to - add around items. - -:return: model bounds, in scene units. - -.. versionadded:: 3.44 -%End - - void createItems( QgsProcessingModelAlgorithm *model, QgsProcessingContext &context ); %Docstring Populates the scene by creating items representing the specified @@ -191,7 +178,10 @@ Requests a complete rebuild of a model by emitting the according signal void updateBounds(); %Docstring -Updates the scene bounds of the model. +Updates the scene rect based on the bounds of the model. + +The bounding rectangle of the model is calculated off all components of +the model, with an additional margin arounds items. .. versionadded:: 3.44 %End diff --git a/src/gui/processing/models/qgsmodelgraphicsscene.cpp b/src/gui/processing/models/qgsmodelgraphicsscene.cpp index cbce70ed30a..7f2d776b1aa 100644 --- a/src/gui/processing/models/qgsmodelgraphicsscene.cpp +++ b/src/gui/processing/models/qgsmodelgraphicsscene.cpp @@ -63,11 +63,6 @@ void QgsModelGraphicsScene::mousePressEvent( QGraphicsSceneMouseEvent *event ) } void QgsModelGraphicsScene::updateBounds() -{ - setSceneRect( modelBounds( SCENE_COMPONENT_MARGIN ) ); -} - -QRectF QgsModelGraphicsScene::modelBounds( double margin ) const { //start with an empty rectangle QRectF bounds; @@ -81,12 +76,12 @@ QRectF QgsModelGraphicsScene::modelBounds( double margin ) const bounds = bounds.united( componentItem->sceneBoundingRect() ); } - if ( bounds.isValid() && margin > 0.0 ) + if ( bounds.isValid() ) { - bounds.adjust( -margin, -margin, margin, margin ); + bounds.adjust( -SCENE_COMPONENT_MARGIN, -SCENE_COMPONENT_MARGIN, SCENE_COMPONENT_MARGIN, SCENE_COMPONENT_MARGIN ); } - return bounds; + setSceneRect( bounds ); } QgsModelComponentGraphicItem *QgsModelGraphicsScene::createParameterGraphicItem( QgsProcessingModelAlgorithm *model, QgsProcessingModelParameter *param ) const diff --git a/src/gui/processing/models/qgsmodelgraphicsscene.h b/src/gui/processing/models/qgsmodelgraphicsscene.h index 72b48f1ceba..fd846bf8304 100644 --- a/src/gui/processing/models/qgsmodelgraphicsscene.h +++ b/src/gui/processing/models/qgsmodelgraphicsscene.h @@ -98,15 +98,6 @@ class GUI_EXPORT QgsModelGraphicsScene : public QGraphicsScene void mousePressEvent( QGraphicsSceneMouseEvent *event ) override; - /** - * Calculates the bounding rectangle of all components of the model. - * \param margin optional margin (absolute value in scene coordinates) to add around items. - * \returns model bounds, in scene units. - * \since QGIS 3.44 - */ - QRectF modelBounds( double margin = 0.0 ) const; - - /** * Populates the scene by creating items representing the specified \a model. */ @@ -191,8 +182,10 @@ class GUI_EXPORT QgsModelGraphicsScene : public QGraphicsScene void requestRebuildRequired(); /** - * Updates the scene bounds of the model. - * + * Updates the scene rect based on the bounds of the model. + + * The bounding rectangle of the model is calculated off all components of the model, with an additional margin arounds items. + * * \since QGIS 3.44 */ void updateBounds(); diff --git a/tests/src/gui/testprocessinggui.cpp b/tests/src/gui/testprocessinggui.cpp index ae7649ba3f2..ee9e30226e7 100644 --- a/tests/src/gui/testprocessinggui.cpp +++ b/tests/src/gui/testprocessinggui.cpp @@ -11456,14 +11456,15 @@ void TestProcessingGui::testModelGraphicsView() QVERIFY( !layerCommentItem ); //check model bounds - QRectF modelBounds = scene2.modelBounds( 50 ); - QGSCOMPARENEAR( modelBounds.height(), 624.4, 3 ); // Sligtly higher threeshold because of various font size can marginally change the bounding rect - QGSCOMPARENEAR( modelBounds.width(), 655.00, 0.01 ); - QGSCOMPARENEAR( modelBounds.left(), -252.0, 0.01 ); - QGSCOMPARENEAR( modelBounds.top(), -232.0, 0.01 ); + scene2.updateBounds(); + QRectF modelRect = scene2.sceneRect(); + QGSCOMPARENEAR( modelRect.height(), 624.4, 3 ); // Sligtly higher threeshold because of various font size can marginally change the bounding rect + QGSCOMPARENEAR( modelRect.width(), 655.00, 0.01 ); + QGSCOMPARENEAR( modelRect.left(), -252.0, 0.01 ); + QGSCOMPARENEAR( modelRect.top(), -232.0, 0.01 ); - // test model large modelBounds + // test model large modelRect QgsProcessingModelAlgorithm model2; QgsProcessingModelChildAlgorithm algc2; @@ -11483,11 +11484,12 @@ void TestProcessingGui::testModelGraphicsView() scene3.setModel( &model2 ); scene3.createItems( &model2, context ); - QRectF modelBounds2 = scene3.modelBounds( 50 ); - QGSCOMPARENEAR( modelBounds2.height(), 4505.4, 3 ); // Sligtly higher threeshold because of various font size can marginally change the bounding rect - QGSCOMPARENEAR( modelBounds2.width(), 4603.0, 0.01 ); - QGSCOMPARENEAR( modelBounds2.left(), -201.0, 0.01 ); - QGSCOMPARENEAR( modelBounds2.top(), -150.0, 0.01 ); + scene3.updateBounds(); + QRectF modelRect2 = scene3.sceneRect(); + QGSCOMPARENEAR( modelRect2.height(), 4505.4, 3 ); // Sligtly higher threeshold because of various font size can marginally change the bounding rect + QGSCOMPARENEAR( modelRect2.width(), 4603.0, 0.01 ); + QGSCOMPARENEAR( modelRect2.left(), -201.0, 0.01 ); + QGSCOMPARENEAR( modelRect2.top(), -150.0, 0.01 ); QgsModelGraphicsScene scene;