Skip to content
Permalink
Browse files

Add a unit test

  • Loading branch information
nyalldawson committed Oct 23, 2017
1 parent 1bfed13 commit 272097b83afd4cfd855ffb41601d7576563dccca
Showing with 16 additions and 0 deletions.
  1. +16 −0 tests/src/core/testqgslayoutitem.cpp
@@ -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
{
@@ -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
@@ -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()

0 comments on commit 272097b

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