Skip to content

Commit 4287ce4

Browse files
committedFeb 5, 2018
[layouts] Fix rotated items move when refreshing layout
Fixes #18037
1 parent 345dd0c commit 4287ce4

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed
 

‎src/core/layout/qgslayoutitem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ int QgsLayoutItem::page() const
487487

488488
QPointF QgsLayoutItem::pagePos() const
489489
{
490-
QPointF p = pos();
490+
QPointF p = positionAtReferencePoint( mReferencePoint );
491491

492492
if ( !mLayout )
493493
return p;

‎src/core/layout/qgslayoutpagecollection.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void QgsLayoutPageCollection::endPageSizeChange()
7777
{
7878
if ( !mBlockUndoCommands )
7979
item->beginCommand( QString() );
80-
item->attemptMove( it.value().second, false, false, it.value().first );
80+
item->attemptMove( it.value().second, true, false, it.value().first );
8181
if ( !mBlockUndoCommands )
8282
item->endCommand();
8383
}

‎tests/src/core/testqgslayoutitem.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,6 +1386,16 @@ void TestQgsLayoutItem::page()
13861386
QCOMPARE( item->page(), 2 );
13871387
QCOMPARE( item->pagePositionWithUnits(), QgsLayoutPoint( 5, 6, QgsUnitTypes::LayoutCentimeters ) );
13881388
QCOMPARE( item->positionWithUnits(), QgsLayoutPoint( 5, 38, QgsUnitTypes::LayoutCentimeters ) );
1389+
1390+
// non-top-left reference
1391+
item->setReferencePoint( QgsLayoutItem::Middle );
1392+
item->attemptMove( QgsLayoutPoint( 5, 6 ), true, false, 0 );
1393+
QCOMPARE( item->pagePos(), QPointF( 5, 6 ) );
1394+
QCOMPARE( item->pagePositionWithUnits(), QgsLayoutPoint( 5, 6 ) );
1395+
item->attemptMove( QgsLayoutPoint( 5, 6 ), true, false, 1 );
1396+
QCOMPARE( item->page(), 1 );
1397+
QCOMPARE( item->pagePos(), QPointF( 5, 6 ) );
1398+
QCOMPARE( item->pagePositionWithUnits(), QgsLayoutPoint( 5, 6, QgsUnitTypes::LayoutMillimeters ) );
13891399
}
13901400

13911401
void TestQgsLayoutItem::itemVariablesFunction()
@@ -1525,6 +1535,24 @@ void TestQgsLayoutItem::rotation()
15251535
QCOMPARE( item2->pos().x(), 7.0 );
15261536
QCOMPARE( item2->pos().y(), 16.0 );
15271537

1538+
// test that refresh rotation doesn't move item (#18037)
1539+
item2 = qgis::make_unique< TestItem >( &l );
1540+
item2->setReferencePoint( QgsLayoutItem::Middle );
1541+
item2->attemptMove( QgsLayoutPoint( 5.0, 8.0 ) );
1542+
item2->attemptResize( QgsLayoutSize( 10.0, 6.0 ) );
1543+
item2->setItemRotation( 45 );
1544+
QCOMPARE( item2->positionWithUnits().x(), 5.0 );
1545+
QCOMPARE( item2->positionWithUnits().y(), 8.0 );
1546+
QGSCOMPARENEAR( item2->pos().x(), 3.58, 0.01 );
1547+
QGSCOMPARENEAR( item2->pos().y(), 2.343146, 0.01 );
1548+
QCOMPARE( item2->rotation(), 45.0 );
1549+
item2->refresh();
1550+
QCOMPARE( item2->positionWithUnits().x(), 5.0 );
1551+
QCOMPARE( item2->positionWithUnits().y(), 8.0 );
1552+
QGSCOMPARENEAR( item2->pos().x(), 3.58, 0.01 );
1553+
QGSCOMPARENEAR( item2->pos().y(), 2.343146, 0.01 );
1554+
QCOMPARE( item2->rotation(), 45.0 );
1555+
15281556

15291557
//TODO also changing size?
15301558

0 commit comments

Comments
 (0)
Please sign in to comment.