Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 7, 2017
1 parent 8ca6d3e commit 26dcf79
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 27 deletions.
2 changes: 2 additions & 0 deletions python/core/layout/qgslayoutitemshape.sip
Expand Up @@ -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).
Expand Down
2 changes: 1 addition & 1 deletion src/core/layout/qgslayoutitemgroup.cpp
Expand Up @@ -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 )
{
Expand Down
20 changes: 20 additions & 0 deletions src/core/layout/qgslayoutitemshape.cpp
Expand Up @@ -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 )
Expand Down
3 changes: 3 additions & 0 deletions src/core/layout/qgslayoutitemshape.h
Expand Up @@ -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()
Expand Down
32 changes: 16 additions & 16 deletions tests/src/core/testqgslayout.cpp
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 ) );
Expand All @@ -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()
Expand Down
29 changes: 19 additions & 10 deletions tests/src/core/testqgslayoutitem.cpp
Expand Up @@ -26,6 +26,7 @@
#include "qgslayoutitemmap.h"
#include "qgslayoutitemshape.h"
#include "qgslayouteffect.h"
#include "qgsfillsymbollayer.h"
#include <QObject>
#include <QPainter>
#include <QImage>
Expand Down Expand Up @@ -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 );

Expand All @@ -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 )
Expand Down
1 change: 1 addition & 0 deletions tests/src/core/testqgslayoutitemgroup.cpp
Expand Up @@ -25,6 +25,7 @@
#include "qgsapplication.h"
#include "qgslogger.h"
#include "qgsproject.h"
#include "qgsfillsymbollayer.h"

#include <QObject>
#include <QtTest/QSignalSpy>
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 26dcf79

Please sign in to comment.