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 github-actions[bot] committed Sep 30, 2024
1 parent be4300f commit 4af24e5
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 @@ -105,6 +105,8 @@ void QgsLayoutItemLegend::paint( QPainter *painter, const QStyleOptionGraphicsIt
if ( !painter )
return;

const QPointF oldPos = pos();

ensureModelIsInitialized();

if ( mFilterAskedForUpdate )
Expand Down Expand Up @@ -156,8 +158,6 @@ void QgsLayoutItemLegend::paint( QPainter *painter, const QStyleOptionGraphicsIt
QgsLegendRenderer legendRenderer( mLegendModel.get(), mSettings );
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 @@ -1054,6 +1054,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 4af24e5

Please sign in to comment.