Skip to content

Commit

Permalink
Add a unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 7, 2017
1 parent 1bfed13 commit 272097b
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/src/core/testqgslayoutitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class TestItem : public QgsLayoutItem
int type() const override { return QgsLayoutItemRegistry::LayoutItem + 101; }
QString stringType() const override { return QStringLiteral( "TestItemType" ); }

bool forceResize = false;

protected:
void draw( QgsRenderContext &context, const QStyleOptionGraphicsItem * = nullptr ) override
{
Expand All @@ -61,6 +63,14 @@ class TestItem : public QgsLayoutItem
painter->drawRect( rect() );
painter->restore();
}

QSizeF applyItemSizeConstraint( const QSizeF &targetSize ) override
{
if ( !forceResize )
return targetSize;

return QSizeF( 17, 27 );
}
};

//item with minimum size
Expand Down Expand Up @@ -753,6 +763,12 @@ void TestQgsLayoutItem::resize()
QCOMPARE( spySizeChanged.count(), 13 );

l.setUnits( QgsUnitTypes::LayoutMillimeters );

// try override item size in item
item->forceResize = true;
item->attemptResize( QgsLayoutSize( 10.0, 15.0, QgsUnitTypes::LayoutMillimeters ) );
QCOMPARE( item->rect().width(), 17.0 );
QCOMPARE( item->rect().height(), 27.0 );
}

void TestQgsLayoutItem::referencePoint()
Expand Down

0 comments on commit 272097b

Please sign in to comment.