Skip to content
Permalink
Browse files

[layouts] Fix legends do not respect reference point when auto sizing

Fixes #18269

(cherry-picked from 0f93e55)
  • Loading branch information
nyalldawson committed Mar 1, 2018
1 parent 3711a92 commit 6d9c55317d72ca6b4611edeb30e1b739b6e917b0
Showing with 24 additions and 3 deletions.
  1. +2 −2 src/core/layout/qgslayoutitemlegend.cpp
  2. +22 −1 tests/src/python/test_qgslayoutlegend.py
@@ -182,9 +182,9 @@ void QgsLayoutItemLegend::adjustBoxSize()
QgsDebugMsg( QString( "width = %1 height = %2" ).arg( size.width() ).arg( size.height() ) );
if ( size.isValid() )
{
QRectF targetRect = QRectF( pos().x(), pos().y(), size.width(), size.height() );
QgsLayoutSize newSize = mLayout->convertFromLayoutUnits( size, sizeWithUnits().units() );
//set new rect, respecting position mode and data defined size/position
attemptSetSceneRect( targetRect );
attemptResize( newSize );
}
}

@@ -26,7 +26,10 @@
QgsProject,
QgsLayoutObject,
QgsProperty,
QgsLayoutMeasurement)
QgsLayoutMeasurement,
QgsLayoutItem,
QgsLayoutPoint,
QgsLayoutSize)
from qgis.testing import (start_app,
unittest
)
@@ -84,6 +87,24 @@ def testInitialSizeSymbolMapUnits(self):
result, message = checker.testLayout()
self.assertTrue(result, message)

# resize with non-top-left reference point
legend.setResizeToContents(False)
legend.setReferencePoint(QgsLayoutItem.LowerRight)
legend.attemptMove(QgsLayoutPoint(120, 90))
legend.attemptResize(QgsLayoutSize(50, 60))

self.assertEqual(legend.positionWithUnits().x(), 120.0)
self.assertEqual(legend.positionWithUnits().y(), 90.0)
self.assertAlmostEqual(legend.pos().x(), 70, -1)
self.assertAlmostEqual(legend.pos().y(), 30, -1)

legend.setResizeToContents(True)
legend.updateLegend()
self.assertEqual(legend.positionWithUnits().x(), 120.0)
self.assertEqual(legend.positionWithUnits().y(), 90.0)
self.assertAlmostEqual(legend.pos().x(), 91, -1)
self.assertAlmostEqual(legend.pos().y(), 71, -1)

QgsProject.instance().removeMapLayers([point_layer.id()])

def testResizeWithMapContent(self):

0 comments on commit 6d9c553

Please sign in to comment.
You can’t perform that action at this time.