Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix valgrind noise
  • Loading branch information
nyalldawson committed Oct 9, 2017
1 parent 02acbb4 commit f58947d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 22 deletions.
6 changes: 4 additions & 2 deletions src/core/layout/qgslayout.cpp
Expand Up @@ -46,11 +46,13 @@ QgsLayout::~QgsLayout()
// this class is deconstructed - to avoid segfaults
// when layout items access in destructor layout that isn't valid anymore

const QList<QGraphicsItem *> itemList = items();
for ( QGraphicsItem *item : itemList )
QList<QGraphicsItem *> itemList = items();
while ( !itemList.empty() )
{
QGraphicsItem *item = itemList.at( 0 );
if ( dynamic_cast< QgsLayoutItem * >( item ) && !dynamic_cast< QgsLayoutItemPage *>( item ) )
delete item;
itemList = items();
}

mItemsModel.reset(); // manually delete, so we can control order of destruction
Expand Down
24 changes: 11 additions & 13 deletions tests/src/core/testqgslayoutitem.cpp
Expand Up @@ -375,7 +375,7 @@ void TestQgsLayoutItem::positionWithUnits()
QgsProject p;
QgsLayout l( &p );

TestItem *item = new TestItem( &l );
std::unique_ptr< TestItem > item( new TestItem( &l ) );
item->attemptMove( QgsLayoutPoint( 60.0, 15.0, QgsUnitTypes::LayoutMillimeters ) );
QCOMPARE( item->positionWithUnits().x(), 60.0 );
QCOMPARE( item->positionWithUnits().y(), 15.0 );
Expand Down Expand Up @@ -690,8 +690,8 @@ void TestQgsLayoutItem::resize()

//resize test item (no restrictions), same units as layout
l.setUnits( QgsUnitTypes::LayoutMillimeters );
TestItem *item = new TestItem( &l );
QSignalSpy spySizeChanged( item, &QgsLayoutItem::sizePositionChanged );
std::unique_ptr< TestItem > item( new TestItem( &l ) );
QSignalSpy spySizeChanged( item.get(), &QgsLayoutItem::sizePositionChanged );

item->setRect( 0, 0, 55, 45 );
item->attemptMove( QgsLayoutPoint( 27, 29 ) );
Expand Down Expand Up @@ -754,7 +754,7 @@ void TestQgsLayoutItem::referencePoint()
QgsLayout l( &p );

//test setting/getting reference point
TestItem *item = new TestItem( &l );
std::unique_ptr< TestItem > item( new TestItem( &l ) );
item->setReferencePoint( QgsLayoutItem::LowerMiddle );
QCOMPARE( item->referencePoint(), QgsLayoutItem::LowerMiddle );

Expand Down Expand Up @@ -793,8 +793,7 @@ void TestQgsLayoutItem::referencePoint()
QCOMPARE( item->positionWithUnits().x(), 3.0 );
QCOMPARE( item->positionWithUnits().y(), 6.0 );

delete item;
item = new TestItem( &l );
item.reset( new TestItem( &l ) );

//test that setting item position is done relative to reference point
l.setUnits( QgsUnitTypes::LayoutMillimeters );
Expand Down Expand Up @@ -836,8 +835,7 @@ void TestQgsLayoutItem::referencePoint()
QCOMPARE( item->scenePos().x(), -1.0 );
QCOMPARE( item->scenePos().y(), -2.0 );

delete item;
item = new TestItem( &l );
item.reset( new TestItem( &l ) );

//test that resizing is done relative to reference point
item->attemptResize( QgsLayoutSize( 2, 4 ) );
Expand Down Expand Up @@ -922,7 +920,7 @@ void TestQgsLayoutItem::adjustPointForReference()
QgsProject p;
QgsLayout l( &p );

TestItem *item = new TestItem( &l );
std::unique_ptr< TestItem > item( new TestItem( &l ) );
QPointF result = item->adjustPointForReferencePosition( QPointF( 5, 7 ), QSizeF( 2, 4 ), QgsLayoutItem::UpperLeft );
QCOMPARE( result.x(), 5.0 );
QCOMPARE( result.y(), 7.0 );
Expand Down Expand Up @@ -1027,7 +1025,7 @@ void TestQgsLayoutItem::fixedSize()
QgsLayout l( &p );

l.setUnits( QgsUnitTypes::LayoutMillimeters );
FixedSizedItem *item = new FixedSizedItem( &l );
std::unique_ptr< FixedSizedItem > item( new FixedSizedItem( &l ) );
QCOMPARE( item->fixedSize().width(), 2.0 );
QCOMPARE( item->fixedSize().height(), 4.0 );
QCOMPARE( item->fixedSize().units(), QgsUnitTypes::LayoutInches );
Expand All @@ -1050,7 +1048,7 @@ void TestQgsLayoutItem::minSize()
QgsLayout l( &p );

l.setUnits( QgsUnitTypes::LayoutMillimeters );
MinSizedItem *item = new MinSizedItem( &l );
std::unique_ptr< MinSizedItem > item( new MinSizedItem( &l ) );
QCOMPARE( item->minimumSize().width(), 5.0 );
QCOMPARE( item->minimumSize().height(), 10.0 );
QCOMPARE( item->minimumSize().units(), QgsUnitTypes::LayoutCentimeters );
Expand All @@ -1073,7 +1071,7 @@ void TestQgsLayoutItem::minSize()
QGSCOMPARENEAR( item->rect().height(), 250.0, 4 * DBL_EPSILON );

//also need check that fixed size trumps min size
FixedMinSizedItem *fixedMinItem = new FixedMinSizedItem( &l );
std::unique_ptr< FixedMinSizedItem > fixedMinItem( new FixedMinSizedItem( &l ) );
QCOMPARE( fixedMinItem->minimumSize().width(), 5.0 );
QCOMPARE( fixedMinItem->minimumSize().height(), 9.0 );
QCOMPARE( fixedMinItem->minimumSize().units(), QgsUnitTypes::LayoutCentimeters );
Expand All @@ -1094,7 +1092,7 @@ void TestQgsLayoutItem::move()

//move test item, same units as layout
l.setUnits( QgsUnitTypes::LayoutMillimeters );
TestItem *item = new TestItem( &l );
std::unique_ptr< TestItem > item( new TestItem( &l ) );
item->setRect( 0, 0, 55, 45 );
item->setPos( 27, 29 );
item->attemptMove( QgsLayoutPoint( 60.0, 15.0, QgsUnitTypes::LayoutMillimeters ) );
Expand Down
2 changes: 0 additions & 2 deletions tests/src/core/testqgslayoutitemgroup.cpp
Expand Up @@ -320,7 +320,6 @@ void TestQgsLayoutItemGroup::moveGroup()
QList<QgsLayoutItem *> groupItems;
groupItems << item << item2;
QgsLayoutItemGroup *group = l.groupItems( groupItems );
l.addLayoutItem( group );

QCOMPARE( group->positionWithUnits().x(), 50.8 );
QCOMPARE( group->positionWithUnits().y(), 76.2 );
Expand Down Expand Up @@ -357,7 +356,6 @@ void TestQgsLayoutItemGroup::resizeGroup()
QList<QgsLayoutItem *> groupItems;
groupItems << item << item2;
QgsLayoutItemGroup *group = l.groupItems( groupItems );
l.addLayoutItem( group );

QCOMPARE( group->positionWithUnits().x(), 50.0 );
QCOMPARE( group->positionWithUnits().y(), 76.2 );
Expand Down
2 changes: 2 additions & 0 deletions tests/src/core/testqgslayoutmodel.cpp
Expand Up @@ -569,6 +569,7 @@ void TestQgsLayoutModel::setItemRemoved()
QCOMPARE( layout.itemsModel()->mItemsInScene.at( 0 ), item2 );
QCOMPARE( layout.itemsModel()->mItemsInScene.at( 1 ), item1 );
delete label;
delete item3;
}

void TestQgsLayoutModel::rebuildZListWithRemoved()
Expand Down Expand Up @@ -603,6 +604,7 @@ void TestQgsLayoutModel::rebuildZListWithRemoved()
QCOMPARE( layout.itemsModel()->mItemsInScene.size(), 2 );
QCOMPARE( layout.itemsModel()->mItemsInScene.at( 0 ), item2 );
QCOMPARE( layout.itemsModel()->mItemsInScene.at( 1 ), item1 );
delete item3;
}

void TestQgsLayoutModel::reorderUpWithRemoved()
Expand Down
10 changes: 5 additions & 5 deletions tests/src/core/testqgslayoutpage.cpp
Expand Up @@ -79,15 +79,15 @@ void TestQgsLayoutPage::itemType()
{
QgsProject p;
QgsLayout l( &p );
QgsLayoutItemPage *page = new QgsLayoutItemPage( &l );
std::unique_ptr< QgsLayoutItemPage > page( new QgsLayoutItemPage( &l ) );
QCOMPARE( page->type(), static_cast< int >( QgsLayoutItemRegistry::LayoutPage ) );
}

void TestQgsLayoutPage::pageSize()
{
QgsProject p;
QgsLayout l( &p );
QgsLayoutItemPage *page = new QgsLayoutItemPage( &l );
std::unique_ptr< QgsLayoutItemPage > page( new QgsLayoutItemPage( &l ) );
page->setPageSize( QgsLayoutSize( 270, 297, QgsUnitTypes::LayoutMeters ) );
QCOMPARE( page->pageSize().width(), 270.0 );
QCOMPARE( page->pageSize().height(), 297.0 );
Expand Down Expand Up @@ -137,7 +137,7 @@ void TestQgsLayoutPage::grid()
// test that grid follows page around
QgsProject p;
QgsLayout l( &p );
QgsLayoutItemPage *page = new QgsLayoutItemPage( &l );
std::unique_ptr< QgsLayoutItemPage > page( new QgsLayoutItemPage( &l ) );

// should have a grid
QVERIFY( page->mGrid.get() );
Expand Down Expand Up @@ -169,9 +169,9 @@ void TestQgsLayoutPage::hiddenPages()
{
QgsProject p;
QgsLayout l( &p );
QgsLayoutItemPage *page = new QgsLayoutItemPage( &l );
std::unique_ptr< QgsLayoutItemPage > page( new QgsLayoutItemPage( &l ) );
page->setPageSize( QgsLayoutSize( 297, 210, QgsUnitTypes::LayoutMillimeters ) );
l.pageCollection()->addPage( page );
l.pageCollection()->addPage( page.release() );

#if 0 //TODO
QgsSimpleFillSymbolLayer *simpleFill = new QgsSimpleFillSymbolLayer();
Expand Down

0 comments on commit f58947d

Please sign in to comment.