Skip to content

Commit fb8f3e9

Browse files
committedJan 29, 2018
[layouts] Fix restoration of rotated item positions
Fixes #17982
1 parent 0be37ad commit fb8f3e9

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed
 

‎src/core/layout/qgslayoutitem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,9 +637,9 @@ bool QgsLayoutItem::readXml( const QDomElement &element, const QDomDocument &doc
637637
mUuid = element.attribute( QStringLiteral( "uuid" ), QUuid::createUuid().toString() );
638638
setId( element.attribute( QStringLiteral( "id" ) ) );
639639
mReferencePoint = static_cast< ReferencePoint >( element.attribute( QStringLiteral( "referencePoint" ) ).toInt() );
640+
setItemRotation( element.attribute( QStringLiteral( "itemRotation" ), QStringLiteral( "0" ) ).toDouble() );
640641
attemptMove( QgsLayoutPoint::decodePoint( element.attribute( QStringLiteral( "position" ) ) ) );
641642
attemptResize( QgsLayoutSize::decodeSize( element.attribute( QStringLiteral( "size" ) ) ) );
642-
setItemRotation( element.attribute( QStringLiteral( "itemRotation" ), QStringLiteral( "0" ) ).toDouble() );
643643

644644
mParentGroupUuid = element.attribute( QStringLiteral( "groupUuid" ) );
645645
if ( !mParentGroupUuid.isEmpty() )

‎tests/src/core/testqgslayoutitem.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ class TestQgsLayoutItem: public QObject
177177

178178
bool renderCheck( QString testName, QImage &image, int mismatchCount );
179179

180-
QgsLayoutItem *createCopyViaXml( QgsLayout *layout, QgsLayoutItem *original );
180+
std::unique_ptr< QgsLayoutItem > createCopyViaXml( QgsLayout *layout, QgsLayoutItem *original );
181181

182182
};
183183

@@ -248,7 +248,7 @@ void TestQgsLayoutItem::registry()
248248
QVERIFY( registry.itemTypes().isEmpty() );
249249
QVERIFY( !registry.createItem( 1, nullptr ) );
250250

251-
auto create = []( QgsLayout * layout )->QgsLayoutItem*
251+
auto create = []( QgsLayout * layout )->QgsLayoutItem *
252252
{
253253
return new TestItem( layout );
254254
};
@@ -1647,7 +1647,7 @@ void TestQgsLayoutItem::writeReadXmlProperties()
16471647

16481648
original->dataDefinedProperties().setProperty( QgsLayoutObject::TestProperty, QgsProperty::fromExpression( QStringLiteral( "10 + 40" ) ) );
16491649

1650-
original->setReferencePoint( QgsLayoutItem::Middle );
1650+
original->setReferencePoint( QgsLayoutItem::MiddleRight );
16511651
original->attemptResize( QgsLayoutSize( 6, 8, QgsUnitTypes::LayoutCentimeters ) );
16521652
original->attemptMove( QgsLayoutPoint( 0.05, 0.09, QgsUnitTypes::LayoutMeters ) );
16531653
original->setItemRotation( 45.0 );
@@ -1665,7 +1665,7 @@ void TestQgsLayoutItem::writeReadXmlProperties()
16651665
original->setExcludeFromExports( true );
16661666
original->setItemOpacity( 0.75 );
16671667

1668-
QgsLayoutItem *copy = createCopyViaXml( &l, original );
1668+
std::unique_ptr< QgsLayoutItem > copy = createCopyViaXml( &l, original );
16691669

16701670
QCOMPARE( copy->uuid(), original->uuid() );
16711671
QCOMPARE( copy->id(), original->id() );
@@ -1675,8 +1675,12 @@ void TestQgsLayoutItem::writeReadXmlProperties()
16751675
QCOMPARE( dd.propertyType(), QgsProperty::ExpressionBasedProperty );
16761676
QCOMPARE( copy->referencePoint(), original->referencePoint() );
16771677
QCOMPARE( copy->sizeWithUnits(), original->sizeWithUnits() );
1678-
QCOMPARE( copy->positionWithUnits(), original->positionWithUnits() );
1678+
QGSCOMPARENEAR( copy->positionWithUnits().x(), original->positionWithUnits().x(), 0.001 );
1679+
QGSCOMPARENEAR( copy->positionWithUnits().y(), original->positionWithUnits().y(), 0.001 );
1680+
QCOMPARE( copy->positionWithUnits().units(), original->positionWithUnits().units() );
16791681
QCOMPARE( copy->itemRotation(), original->itemRotation() );
1682+
QGSCOMPARENEAR( copy->pos().x(), original->pos().x(), 0.001 );
1683+
QGSCOMPARENEAR( copy->pos().y(), original->pos().y(), 0.001 );
16801684
QVERIFY( copy->isLocked() );
16811685
QCOMPARE( copy->zValue(), 55.0 );
16821686
QVERIFY( !copy->isVisible() );
@@ -1689,8 +1693,6 @@ void TestQgsLayoutItem::writeReadXmlProperties()
16891693
QCOMPARE( copy->blendMode(), QPainter::CompositionMode_Darken );
16901694
QVERIFY( copy->excludeFromExports( ) );
16911695
QCOMPARE( copy->itemOpacity(), 0.75 );
1692-
1693-
delete copy;
16941696
delete original;
16951697
}
16961698

@@ -1985,7 +1987,7 @@ void TestQgsLayoutItem::excludeFromExports()
19851987
QVERIFY( checker.testLayout( mReport ) );
19861988
}
19871989

1988-
QgsLayoutItem *TestQgsLayoutItem::createCopyViaXml( QgsLayout *layout, QgsLayoutItem *original )
1990+
std::unique_ptr<QgsLayoutItem> TestQgsLayoutItem::createCopyViaXml( QgsLayout *layout, QgsLayoutItem *original )
19891991
{
19901992
//save original item to xml
19911993
QDomImplementation DomImplementation;
@@ -1998,10 +2000,10 @@ QgsLayoutItem *TestQgsLayoutItem::createCopyViaXml( QgsLayout *layout, QgsLayout
19982000
original->writeXml( rootNode, doc, QgsReadWriteContext() );
19992001

20002002
//create new item and restore settings from xml
2001-
TestItem *copy = new TestItem( layout );
2003+
std::unique_ptr< TestItem > copy = qgis::make_unique< TestItem >( layout );
20022004
copy->readXml( rootNode.firstChildElement(), doc, QgsReadWriteContext() );
20032005

2004-
return copy;
2006+
return std::move( copy );
20052007
}
20062008

20072009
QGSTEST_MAIN( TestQgsLayoutItem )

0 commit comments

Comments
 (0)
Please sign in to comment.