Skip to content

Commit

Permalink
fix(LayoutLegend): Correctly fix position while painting
Browse files Browse the repository at this point in the history
While painting, it happens that other code can modify current item
position, but this new position will be really used on the new draw,
not the current one. So we have to backup it early enough (at the very
beginning of paint) so we can translate to this new position at the
end of the paint method.

Fixes #37566 (Again)
  • Loading branch information
troopa81 authored and nyalldawson committed Sep 30, 2024
1 parent b9ad6ac commit b31dc5a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/core/layout/qgslayoutitemlegend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ void QgsLayoutItemLegend::paint( QPainter *painter, const QStyleOptionGraphicsIt
if ( !painter )
return;

const QPointF oldPos = pos();

ensureModelIsInitialized();

if ( mFilterAskedForUpdate )
Expand Down Expand Up @@ -157,8 +159,6 @@ void QgsLayoutItemLegend::paint( QPainter *painter, const QStyleOptionGraphicsIt
QgsLegendRenderer legendRenderer = createRenderer();
legendRenderer.setLegendSize( mForceResize && mSizeToContents ? QSize() : rect().size() );

const QPointF oldPos = pos();

//adjust box if width or height is too small
if ( mSizeToContents )
{
Expand Down
13 changes: 13 additions & 0 deletions tests/src/python/test_qgslayoutlegend.py
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,19 @@ def testReferencePoint(self):
)
)

# re-render with filtering to trigger mapHitTest which ends up by calling adjustBoxSize().
# These last change the box size and therefore position (because our reference point is lower left)
# So check that the legend position is according to what we expect (change also marker size
# so we are sure that it's size and position have correcly been updated)
legend.setLegendFilterByMapEnabled(True)
marker_symbol.setSize(10)

self.assertTrue(
self.render_layout_check(
'composer_legend_reference_point_newsize', layout
)
)

QgsProject.instance().clear()

def test_rulebased_child_filter(self):
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b31dc5a

Please sign in to comment.