Skip to content

Commit 26dcf79

Browse files
committed
Fix tests
1 parent 8ca6d3e commit 26dcf79

File tree

8 files changed

+62
-27
lines changed

8 files changed

+62
-27
lines changed

python/core/layout/qgslayoutitemshape.sip

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class QgsLayoutItemShape : QgsLayoutItem
3636
virtual int type() const;
3737
virtual QString stringType() const;
3838

39+
virtual QString displayName() const;
40+
3941
QgsLayoutItemShape::Shape shapeType() const;
4042
%Docstring
4143
Returns the type of shape (e.g. rectangle, ellipse, etc).

src/core/layout/qgslayoutitemgroup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ void QgsLayoutItemGroup::attemptMove( const QgsLayoutPoint &point, bool useRefer
158158
QgsLayoutPoint deltaPos = mLayout->convertFromLayoutUnits( QPointF( deltaX, deltaY ), itemPos.units() );
159159
itemPos.setX( itemPos.x() + deltaPos.x() );
160160
itemPos.setY( itemPos.y() + deltaPos.y() );
161-
item->attemptMove( itemPos, includesFrame );
161+
item->attemptMove( itemPos, true, includesFrame );
162162

163163
if ( command )
164164
{

src/core/layout/qgslayoutitemshape.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,26 @@ QgsLayoutItemShape::QgsLayoutItemShape( QgsLayout *layout )
5454
#endif
5555
}
5656

57+
QString QgsLayoutItemShape::displayName() const
58+
{
59+
if ( !id().isEmpty() )
60+
{
61+
return id();
62+
}
63+
64+
switch ( mShape )
65+
{
66+
case Ellipse:
67+
return tr( "<Ellipse>" );
68+
case Rectangle:
69+
return tr( "<Rectangle>" );
70+
case Triangle:
71+
return tr( "<Triangle>" );
72+
}
73+
74+
return tr( "<Shape>" );
75+
}
76+
5777
void QgsLayoutItemShape::setShapeType( QgsLayoutItemShape::Shape type )
5878
{
5979
if ( type == mShape )

src/core/layout/qgslayoutitemshape.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ class CORE_EXPORT QgsLayoutItemShape : public QgsLayoutItem
5252
int type() const override { return QgsLayoutItemRegistry::LayoutShape; }
5353
QString stringType() const override { return QStringLiteral( "ItemShape" ); }
5454

55+
//Overridden to return shape type
56+
virtual QString displayName() const override;
57+
5558
/**
5659
* Returns the type of shape (e.g. rectangle, ellipse, etc).
5760
* \see setShapeType()

tests/src/core/testqgslayout.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -299,10 +299,10 @@ void TestQgsLayout::bounds()
299299
QGSCOMPARENEAR( layoutBounds.top(), 0.00000, 0.01 );
300300

301301
QRectF compositionBoundsNoPage = l.layoutBounds( true );
302-
QGSCOMPARENEAR( compositionBoundsNoPage.height(), 174.497475, 0.01 );
303-
QGSCOMPARENEAR( compositionBoundsNoPage.width(), 124.497475, 0.01 );
304-
QGSCOMPARENEAR( compositionBoundsNoPage.left(), 85.502525, 0.01 );
305-
QGSCOMPARENEAR( compositionBoundsNoPage.top(), 25.502525, 0.01 );
302+
QGSCOMPARENEAR( compositionBoundsNoPage.height(), 174.859607, 0.01 );
303+
QGSCOMPARENEAR( compositionBoundsNoPage.width(), 124.859607, 0.01 );
304+
QGSCOMPARENEAR( compositionBoundsNoPage.left(), 85.290393, 0.01 );
305+
QGSCOMPARENEAR( compositionBoundsNoPage.top(), 25.290393, 0.01 );
306306

307307
#if 0
308308
QRectF page1Bounds = composition->pageItemBounds( 0, true );
@@ -339,10 +339,10 @@ void TestQgsLayout::addItem()
339339
l.addLayoutItem( shape1 );
340340
QVERIFY( l.items().contains( shape1 ) );
341341
// bounds should be updated to include item
342-
QGSCOMPARENEAR( l.sceneRect().left(), 90, 0.001 );
343-
QGSCOMPARENEAR( l.sceneRect().top(), 50, 0.001 );
344-
QGSCOMPARENEAR( l.sceneRect().width(), 140, 0.001 );
345-
QGSCOMPARENEAR( l.sceneRect().height(), 70, 0.001 );
342+
QGSCOMPARENEAR( l.sceneRect().left(), 89.850, 0.001 );
343+
QGSCOMPARENEAR( l.sceneRect().top(), 49.85, 0.001 );
344+
QGSCOMPARENEAR( l.sceneRect().width(), 140.30, 0.001 );
345+
QGSCOMPARENEAR( l.sceneRect().height(), 70.3, 0.001 );
346346

347347
QgsLayoutItemShape *shape2 = new QgsLayoutItemShape( &l );
348348
shape2->attemptResize( QgsLayoutSize( 240, 170 ) );
@@ -351,17 +351,17 @@ void TestQgsLayout::addItem()
351351

352352
// don't use addLayoutItem - we want to manually trigger a bounds update
353353
l.addItem( shape2 );
354-
QGSCOMPARENEAR( l.sceneRect().left(), 90, 0.001 );
355-
QGSCOMPARENEAR( l.sceneRect().top(), 50, 0.001 );
356-
QGSCOMPARENEAR( l.sceneRect().width(), 140, 0.001 );
357-
QGSCOMPARENEAR( l.sceneRect().height(), 70, 0.001 );
354+
QGSCOMPARENEAR( l.sceneRect().left(), 89.85, 0.001 );
355+
QGSCOMPARENEAR( l.sceneRect().top(), 49.85, 0.001 );
356+
QGSCOMPARENEAR( l.sceneRect().width(), 140.3, 0.001 );
357+
QGSCOMPARENEAR( l.sceneRect().height(), 70.3, 0.001 );
358358

359359
l.updateBounds();
360360
// bounds should be updated to include item
361-
QGSCOMPARENEAR( l.sceneRect().left(), 30, 0.001 );
362-
QGSCOMPARENEAR( l.sceneRect().top(), 20, 0.001 );
363-
QGSCOMPARENEAR( l.sceneRect().width(), 240, 0.001 );
364-
QGSCOMPARENEAR( l.sceneRect().height(), 170, 0.001 );
361+
QGSCOMPARENEAR( l.sceneRect().left(), 29.85, 0.001 );
362+
QGSCOMPARENEAR( l.sceneRect().top(), 19.85, 0.001 );
363+
QGSCOMPARENEAR( l.sceneRect().width(), 240.3, 0.001 );
364+
QGSCOMPARENEAR( l.sceneRect().height(), 170.3, 0.001 );
365365
}
366366

367367
void TestQgsLayout::layoutItems()

tests/src/core/testqgslayoutitem.cpp

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "qgslayoutitemmap.h"
2727
#include "qgslayoutitemshape.h"
2828
#include "qgslayouteffect.h"
29+
#include "qgsfillsymbollayer.h"
2930
#include <QObject>
3031
#include <QPainter>
3132
#include <QImage>
@@ -1640,6 +1641,17 @@ void TestQgsLayoutItem::excludeFromExports()
16401641
QgsProject proj;
16411642
QgsLayout l( &proj );
16421643

1644+
std::unique_ptr< QgsLayoutItemPage > page( new QgsLayoutItemPage( &l ) );
1645+
page->setPageSize( QgsLayoutSize( 297, 210, QgsUnitTypes::LayoutMillimeters ) );
1646+
l.pageCollection()->addPage( page.release() );
1647+
1648+
QgsSimpleFillSymbolLayer *simpleFill = new QgsSimpleFillSymbolLayer();
1649+
std::unique_ptr< QgsFillSymbol > fillSymbol( new QgsFillSymbol() );
1650+
fillSymbol->changeSymbolLayer( 0, simpleFill );
1651+
simpleFill->setColor( Qt::transparent );
1652+
simpleFill->setStrokeColor( Qt::transparent );
1653+
l.pageCollection()->setPageStyleSymbol( fillSymbol.get() );
1654+
16431655
QgsLayoutItemShape *item = new QgsLayoutItemShape( &l );
16441656
l.addLayoutItem( item );
16451657

@@ -1653,17 +1665,14 @@ void TestQgsLayoutItem::excludeFromExports()
16531665
QVERIFY( !item->excludeFromExports() ); // should not change
16541666
QVERIFY( item->mEvaluatedExcludeFromExports );
16551667

1656-
item->setPos( 100, 100 );
1657-
item->setRect( 0, 0, 200, 200 );
1658-
l.setSceneRect( 0, 0, 400, 400 );
1659-
l.context().setFlag( QgsLayoutContext::FlagDebug, true );
1660-
QImage image( l.sceneRect().size().toSize(), QImage::Format_ARGB32 );
1661-
image.fill( 0 );
1662-
QPainter painter( &image );
1663-
l.render( &painter );
1664-
painter.end();
1668+
item->attemptMove( QgsLayoutPoint( 100, 100 ) );
1669+
item->attemptResize( QgsLayoutSize( 200, 200 ) );
1670+
l.updateBounds();
16651671

1666-
QVERIFY( renderCheck( QStringLiteral( "layoutitem_excluded" ), image, 0 ) );
1672+
QgsLayoutChecker checker( QStringLiteral( "layoutitem_excluded" ), &l );
1673+
checker.setControlPathPrefix( QStringLiteral( "layouts" ) );
1674+
checker.setSize( QSize( 400, 400 ) );
1675+
QVERIFY( checker.testLayout( mReport ) );
16671676
}
16681677

16691678
QgsLayoutItem *TestQgsLayoutItem::createCopyViaXml( QgsLayout *layout, QgsLayoutItem *original )

tests/src/core/testqgslayoutitemgroup.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "qgsapplication.h"
2626
#include "qgslogger.h"
2727
#include "qgsproject.h"
28+
#include "qgsfillsymbollayer.h"
2829

2930
#include <QObject>
3031
#include <QtTest/QSignalSpy>

0 commit comments

Comments
 (0)