Skip to content
Permalink
Browse files

Fix tests

  • Loading branch information
nyalldawson committed Oct 16, 2017
1 parent 8ca6d3e commit 26dcf792b042c9e0a567d608668c52fb6fd00154
@@ -36,6 +36,8 @@ class QgsLayoutItemShape : QgsLayoutItem
virtual int type() const;
virtual QString stringType() const;

virtual QString displayName() const;

QgsLayoutItemShape::Shape shapeType() const;
%Docstring
Returns the type of shape (e.g. rectangle, ellipse, etc).
@@ -158,7 +158,7 @@ void QgsLayoutItemGroup::attemptMove( const QgsLayoutPoint &point, bool useRefer
QgsLayoutPoint deltaPos = mLayout->convertFromLayoutUnits( QPointF( deltaX, deltaY ), itemPos.units() );
itemPos.setX( itemPos.x() + deltaPos.x() );
itemPos.setY( itemPos.y() + deltaPos.y() );
item->attemptMove( itemPos, includesFrame );
item->attemptMove( itemPos, true, includesFrame );

if ( command )
{
@@ -54,6 +54,26 @@ QgsLayoutItemShape::QgsLayoutItemShape( QgsLayout *layout )
#endif
}

QString QgsLayoutItemShape::displayName() const
{
if ( !id().isEmpty() )
{
return id();
}

switch ( mShape )
{
case Ellipse:
return tr( "<Ellipse>" );
case Rectangle:
return tr( "<Rectangle>" );
case Triangle:
return tr( "<Triangle>" );
}

return tr( "<Shape>" );
}

void QgsLayoutItemShape::setShapeType( QgsLayoutItemShape::Shape type )
{
if ( type == mShape )
@@ -52,6 +52,9 @@ class CORE_EXPORT QgsLayoutItemShape : public QgsLayoutItem
int type() const override { return QgsLayoutItemRegistry::LayoutShape; }
QString stringType() const override { return QStringLiteral( "ItemShape" ); }

//Overridden to return shape type
virtual QString displayName() const override;

/**
* Returns the type of shape (e.g. rectangle, ellipse, etc).
* \see setShapeType()
@@ -299,10 +299,10 @@ void TestQgsLayout::bounds()
QGSCOMPARENEAR( layoutBounds.top(), 0.00000, 0.01 );

QRectF compositionBoundsNoPage = l.layoutBounds( true );
QGSCOMPARENEAR( compositionBoundsNoPage.height(), 174.497475, 0.01 );
QGSCOMPARENEAR( compositionBoundsNoPage.width(), 124.497475, 0.01 );
QGSCOMPARENEAR( compositionBoundsNoPage.left(), 85.502525, 0.01 );
QGSCOMPARENEAR( compositionBoundsNoPage.top(), 25.502525, 0.01 );
QGSCOMPARENEAR( compositionBoundsNoPage.height(), 174.859607, 0.01 );
QGSCOMPARENEAR( compositionBoundsNoPage.width(), 124.859607, 0.01 );
QGSCOMPARENEAR( compositionBoundsNoPage.left(), 85.290393, 0.01 );
QGSCOMPARENEAR( compositionBoundsNoPage.top(), 25.290393, 0.01 );

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

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

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

l.updateBounds();
// bounds should be updated to include item
QGSCOMPARENEAR( l.sceneRect().left(), 30, 0.001 );
QGSCOMPARENEAR( l.sceneRect().top(), 20, 0.001 );
QGSCOMPARENEAR( l.sceneRect().width(), 240, 0.001 );
QGSCOMPARENEAR( l.sceneRect().height(), 170, 0.001 );
QGSCOMPARENEAR( l.sceneRect().left(), 29.85, 0.001 );
QGSCOMPARENEAR( l.sceneRect().top(), 19.85, 0.001 );
QGSCOMPARENEAR( l.sceneRect().width(), 240.3, 0.001 );
QGSCOMPARENEAR( l.sceneRect().height(), 170.3, 0.001 );
}

void TestQgsLayout::layoutItems()
@@ -26,6 +26,7 @@
#include "qgslayoutitemmap.h"
#include "qgslayoutitemshape.h"
#include "qgslayouteffect.h"
#include "qgsfillsymbollayer.h"
#include <QObject>
#include <QPainter>
#include <QImage>
@@ -1640,6 +1641,17 @@ void TestQgsLayoutItem::excludeFromExports()
QgsProject proj;
QgsLayout l( &proj );

std::unique_ptr< QgsLayoutItemPage > page( new QgsLayoutItemPage( &l ) );
page->setPageSize( QgsLayoutSize( 297, 210, QgsUnitTypes::LayoutMillimeters ) );
l.pageCollection()->addPage( page.release() );

QgsSimpleFillSymbolLayer *simpleFill = new QgsSimpleFillSymbolLayer();
std::unique_ptr< QgsFillSymbol > fillSymbol( new QgsFillSymbol() );
fillSymbol->changeSymbolLayer( 0, simpleFill );
simpleFill->setColor( Qt::transparent );
simpleFill->setStrokeColor( Qt::transparent );
l.pageCollection()->setPageStyleSymbol( fillSymbol.get() );

QgsLayoutItemShape *item = new QgsLayoutItemShape( &l );
l.addLayoutItem( item );

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

item->setPos( 100, 100 );
item->setRect( 0, 0, 200, 200 );
l.setSceneRect( 0, 0, 400, 400 );
l.context().setFlag( QgsLayoutContext::FlagDebug, true );
QImage image( l.sceneRect().size().toSize(), QImage::Format_ARGB32 );
image.fill( 0 );
QPainter painter( &image );
l.render( &painter );
painter.end();
item->attemptMove( QgsLayoutPoint( 100, 100 ) );
item->attemptResize( QgsLayoutSize( 200, 200 ) );
l.updateBounds();

QVERIFY( renderCheck( QStringLiteral( "layoutitem_excluded" ), image, 0 ) );
QgsLayoutChecker checker( QStringLiteral( "layoutitem_excluded" ), &l );
checker.setControlPathPrefix( QStringLiteral( "layouts" ) );
checker.setSize( QSize( 400, 400 ) );
QVERIFY( checker.testLayout( mReport ) );
}

QgsLayoutItem *TestQgsLayoutItem::createCopyViaXml( QgsLayout *layout, QgsLayoutItem *original )
@@ -25,6 +25,7 @@
#include "qgsapplication.h"
#include "qgslogger.h"
#include "qgsproject.h"
#include "qgsfillsymbollayer.h"

#include <QObject>
#include <QtTest/QSignalSpy>
Binary file not shown.

0 comments on commit 26dcf79

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