Skip to content

Commit edecc37

Browse files
committedNov 7, 2017
Start work on exporter for layouts
1 parent 9630a39 commit edecc37

20 files changed

+412
-54
lines changed
 

‎python/core/core_auto.sip

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@
158158
%Include composer/qgscomposertexttable.sip
159159
%Include composer/qgspaperitem.sip
160160
%Include layout/qgslayoutaligner.sip
161+
%Include layout/qgslayoutexporter.sip
161162
%Include layout/qgslayoutgridsettings.sip
162163
%Include layout/qgslayoutmeasurement.sip
163164
%Include layout/qgslayoutmeasurementconverter.sip

‎python/core/layout/qgslayout.sip

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ class QgsLayout : QGraphicsScene, QgsExpressionContextGenerator, QgsLayoutUndoOb
6262
:rtype: QgsLayoutModel
6363
%End
6464

65+
QgsLayoutExporter &exporter();
66+
%Docstring
67+
Returns the layout's exporter, which is used for rendering the layout and exporting
68+
to various formats.
69+
:rtype: QgsLayoutExporter
70+
%End
71+
6572
QString name() const;
6673
%Docstring
6774
Returns the layout's name.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/************************************************************************
2+
* This file has been generated automatically from *
3+
* *
4+
* src/core/layout/qgslayoutexporter.h *
5+
* *
6+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
7+
************************************************************************/
8+
9+
10+
11+
class QgsLayoutExporter
12+
{
13+
%Docstring
14+
Handles rendering and exports of layouts to various formats.
15+
.. versionadded:: 3.0
16+
%End
17+
18+
%TypeHeaderCode
19+
#include "qgslayoutexporter.h"
20+
%End
21+
public:
22+
23+
QgsLayoutExporter( QgsLayout *layout );
24+
%Docstring
25+
Constructor for QgsLayoutExporter, for the specified ``layout``.
26+
%End
27+
28+
void renderPage( QPainter *painter, int page );
29+
%Docstring
30+
Renders a full page to a destination ``painter``.
31+
32+
The ``page`` argument specifies the page number to render. Page numbers
33+
are 0 based, such that the first page in a layout is page 0.
34+
35+
.. seealso:: renderRect()
36+
%End
37+
38+
void renderRegion( QPainter *painter, const QRectF &region );
39+
%Docstring
40+
Renders a ``region`` from the layout to a ``painter``. This method can be used
41+
to render sections of pages rather than full pages.
42+
43+
.. seealso:: renderPage()
44+
%End
45+
46+
};
47+
48+
49+
50+
51+
/************************************************************************
52+
* This file has been generated automatically from *
53+
* *
54+
* src/core/layout/qgslayoutexporter.h *
55+
* *
56+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
57+
************************************************************************/

‎python/core/layout/qgslayoutitem.sip

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -589,14 +589,6 @@ class QgsLayoutItem : QgsLayoutObject, QGraphicsRectItem, QgsLayoutUndoObjectInt
589589
Draws the background for the item.
590590
%End
591591

592-
bool isPreviewRender( QPainter *painter ) const;
593-
%Docstring
594-
Returns true if the render to the specified ``painter`` is a preview render,
595-
i.e. is being rendered inside a QGraphicsView widget as opposed to a destination
596-
device (such as an image).
597-
:rtype: bool
598-
%End
599-
600592
virtual void setFixedSize( const QgsLayoutSize &size );
601593
%Docstring
602594
Sets a fixed ``size`` for the layout item, which prevents it from being freely

‎python/core/layout/qgslayoututils.sip

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,15 @@ class QgsLayoutUtils
7272
:rtype: float
7373
%End
7474

75+
76+
static bool isPreviewRender( QPainter *painter );
77+
%Docstring
78+
Returns true if the render to the specified ``painter`` is a preview render,
79+
i.e. is being rendered inside a QGraphicsView widget as opposed to a destination
80+
device (such as an image).
81+
:rtype: bool
82+
%End
83+
7584
};
7685

7786
/************************************************************************

‎python/core/qgsmultirenderchecker.sip

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,44 @@ class QgsCompositionChecker : QgsMultiRenderChecker
152152

153153
};
154154

155+
class QgsLayoutChecker : QgsMultiRenderChecker
156+
{
157+
%Docstring
158+
Renders a layout to an image and compares with an expected output
159+
.. versionadded:: 3.0
160+
%End
161+
162+
%TypeHeaderCode
163+
#include "qgsmultirenderchecker.h"
164+
%End
165+
public:
166+
167+
QgsLayoutChecker( const QString &testName, QgsLayout *layout );
168+
%Docstring
169+
Constructor for QgsLayoutChecker.
170+
%End
171+
172+
void setSize( QSize size );
173+
%Docstring
174+
Sets the output (reference) image ``size``.
175+
%End
176+
177+
bool runTest( QString &report, int page = 0, int pixelDiff = 0 );
178+
%Docstring
179+
Runs a render check on the layout, adding results to the specified ``report``.
180+
181+
The maximum number of allowable pixels differing from the reference image is
182+
specified via the ``pixelDiff`` argument.
183+
184+
The page number is specified via ``page``, where 0 corresponds to the first
185+
page in the layout.
186+
187+
Returns false if the rendered layout differs from the expected reference image.
188+
:rtype: bool
189+
%End
190+
191+
};
192+
155193
%End
156194

157195

‎src/core/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ SET(QGIS_CORE_SRCS
363363
layout/qgslayoutaligner.cpp
364364
layout/qgslayoutcontext.cpp
365365
layout/qgslayouteffect.cpp
366+
layout/qgslayoutexporter.cpp
366367
layout/qgslayoutgridsettings.cpp
367368
layout/qgslayoutguidecollection.cpp
368369
layout/qgslayoutitem.cpp
@@ -975,6 +976,7 @@ SET(QGIS_CORE_HDRS
975976
composer/qgspaperitem.h
976977

977978
layout/qgslayoutaligner.h
979+
layout/qgslayoutexporter.h
978980
layout/qgslayoutgridsettings.h
979981
layout/qgslayoutitemundocommand.h
980982
layout/qgslayoutmeasurement.h

‎src/core/layout/qgslayout.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ QgsLayout::QgsLayout( QgsProject *project )
3131
, mGridSettings( this )
3232
, mPageCollection( new QgsLayoutPageCollection( this ) )
3333
, mUndoStack( new QgsLayoutUndoStack( this ) )
34+
, mExporter( QgsLayoutExporter( this ) )
3435
{
3536
// just to make sure - this should be the default, but maybe it'll change in some future Qt version...
3637
setBackgroundBrush( Qt::NoBrush );
@@ -87,6 +88,11 @@ QgsLayoutModel *QgsLayout::itemsModel()
8788
return mItemsModel.get();
8889
}
8990

91+
QgsLayoutExporter &QgsLayout::exporter()
92+
{
93+
return mExporter;
94+
}
95+
9096
QList<QgsLayoutItem *> QgsLayout::selectedLayoutItems( const bool includeLockedItems )
9197
{
9298
QList<QgsLayoutItem *> layoutItemList;

‎src/core/layout/qgslayout.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "qgslayoutgridsettings.h"
2626
#include "qgslayoutguidecollection.h"
2727
#include "qgslayoutundostack.h"
28+
#include "qgslayoutexporter.h"
2829

2930
class QgsLayoutItemMap;
3031
class QgsLayoutModel;
@@ -83,6 +84,12 @@ class CORE_EXPORT QgsLayout : public QGraphicsScene, public QgsExpressionContext
8384
*/
8485
QgsLayoutModel *itemsModel();
8586

87+
/**
88+
* Returns the layout's exporter, which is used for rendering the layout and exporting
89+
* to various formats.
90+
*/
91+
QgsLayoutExporter &exporter();
92+
8693
/**
8794
* Returns the layout's name.
8895
* \see setName()
@@ -517,6 +524,7 @@ class CORE_EXPORT QgsLayout : public QGraphicsScene, public QgsExpressionContext
517524

518525
std::unique_ptr< QgsLayoutPageCollection > mPageCollection;
519526
std::unique_ptr< QgsLayoutUndoStack > mUndoStack;
527+
QgsLayoutExporter mExporter;
520528

521529
bool mBlockUndoCommands = false;
522530

‎src/core/layout/qgslayoutexporter.cpp

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/***************************************************************************
2+
qgslayoutexporter.cpp
3+
-------------------
4+
begin : October 2017
5+
copyright : (C) 2017 by Nyall Dawson
6+
email : nyall dot dawson at gmail dot com
7+
***************************************************************************/
8+
/***************************************************************************
9+
* *
10+
* This program is free software; you can redistribute it and/or modify *
11+
* it under the terms of the GNU General Public License as published by *
12+
* the Free Software Foundation; either version 2 of the License, or *
13+
* (at your option) any later version. *
14+
* *
15+
***************************************************************************/
16+
17+
#include "qgslayoutexporter.h"
18+
#include "qgslayout.h"
19+
20+
QgsLayoutExporter::QgsLayoutExporter( QgsLayout *layout )
21+
: mLayout( layout )
22+
{
23+
24+
}
25+
26+
void QgsLayoutExporter::renderPage( QPainter *painter, int page )
27+
{
28+
if ( !mLayout )
29+
return;
30+
31+
if ( mLayout->pageCollection()->pageCount() <= page || page < 0 )
32+
{
33+
return;
34+
}
35+
36+
QgsLayoutItemPage *pageItem = mLayout->pageCollection()->page( page );
37+
if ( !pageItem )
38+
{
39+
return;
40+
}
41+
42+
QRectF paperRect = QRectF( pageItem->pos().x(), pageItem->pos().y(), pageItem->rect().width(), pageItem->rect().height() );
43+
renderRegion( painter, paperRect );
44+
}
45+
46+
void QgsLayoutExporter::renderRegion( QPainter *painter, const QRectF &region )
47+
{
48+
QPaintDevice *paintDevice = painter->device();
49+
if ( !paintDevice || !mLayout )
50+
{
51+
return;
52+
}
53+
54+
#if 0 //TODO
55+
setSnapLinesVisible( false );
56+
#endif
57+
58+
mLayout->render( painter, QRectF( 0, 0, paintDevice->width(), paintDevice->height() ), region );
59+
60+
#if 0 // TODO
61+
setSnapLinesVisible( true );
62+
#endif
63+
}
64+

‎src/core/layout/qgslayoutexporter.h

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/***************************************************************************
2+
qgslayoutexporter.h
3+
-------------------
4+
begin : October 2017
5+
copyright : (C) 2017 by Nyall Dawson
6+
email : nyall dot dawson at gmail dot com
7+
***************************************************************************/
8+
/***************************************************************************
9+
* *
10+
* This program is free software; you can redistribute it and/or modify *
11+
* it under the terms of the GNU General Public License as published by *
12+
* the Free Software Foundation; either version 2 of the License, or *
13+
* (at your option) any later version. *
14+
* *
15+
***************************************************************************/
16+
#ifndef QGSLAYOUTEXPORTER_H
17+
#define QGSLAYOUTEXPORTER_H
18+
19+
#include "qgis_core.h"
20+
#include <QPointer>
21+
22+
class QgsLayout;
23+
class QPainter;
24+
25+
/**
26+
* \ingroup core
27+
* \class QgsLayoutExporter
28+
* \brief Handles rendering and exports of layouts to various formats.
29+
* \since QGIS 3.0
30+
*/
31+
class CORE_EXPORT QgsLayoutExporter
32+
{
33+
34+
public:
35+
36+
/**
37+
* Constructor for QgsLayoutExporter, for the specified \a layout.
38+
*/
39+
QgsLayoutExporter( QgsLayout *layout );
40+
41+
/**
42+
* Renders a full page to a destination \a painter.
43+
*
44+
* The \a page argument specifies the page number to render. Page numbers
45+
* are 0 based, such that the first page in a layout is page 0.
46+
*
47+
* \see renderRect()
48+
*/
49+
void renderPage( QPainter *painter, int page );
50+
51+
/**
52+
* Renders a \a region from the layout to a \a painter. This method can be used
53+
* to render sections of pages rather than full pages.
54+
*
55+
* \see renderPage()
56+
*/
57+
void renderRegion( QPainter *painter, const QRectF &region );
58+
59+
private:
60+
61+
QPointer< QgsLayout > mLayout;
62+
};
63+
64+
#endif //QGSLAYOUTEXPORTER_H
65+
66+
67+

‎src/core/layout/qgslayoutitem.cpp

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ bool QgsLayoutItem::shouldBlockUndoCommands() const
433433

434434
bool QgsLayoutItem::shouldDrawItem( QPainter *painter ) const
435435
{
436-
if ( isPreviewRender( painter ) )
436+
if ( QgsLayoutUtils::isPreviewRender( painter ) )
437437
{
438438
//preview mode so OK to draw item
439439
return true;
@@ -767,31 +767,6 @@ void QgsLayoutItem::drawBackground( QgsRenderContext &context )
767767
p->restore();
768768
}
769769

770-
bool QgsLayoutItem::isPreviewRender( QPainter *painter ) const
771-
{
772-
if ( !painter || !painter->device() )
773-
return false;
774-
775-
// if rendering to a QGraphicsView, we are in preview mode
776-
QPaintDevice *device = painter->device();
777-
if ( dynamic_cast< QPixmap * >( device ) )
778-
return true;
779-
780-
QObject *obj = dynamic_cast< QObject *>( device );
781-
if ( !obj )
782-
return false;
783-
784-
const QMetaObject *mo = obj->metaObject();
785-
while ( mo )
786-
{
787-
if ( mo->className() == QStringLiteral( "QGraphicsView" ) )
788-
return true;
789-
790-
mo = mo->superClass();
791-
}
792-
return false;
793-
}
794-
795770
void QgsLayoutItem::setFixedSize( const QgsLayoutSize &size )
796771
{
797772
mFixedSize = size;

‎src/core/layout/qgslayoutitem.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -583,13 +583,6 @@ class CORE_EXPORT QgsLayoutItem : public QgsLayoutObject, public QGraphicsRectIt
583583
*/
584584
virtual void drawBackground( QgsRenderContext &context );
585585

586-
/**
587-
* Returns true if the render to the specified \a painter is a preview render,
588-
* i.e. is being rendered inside a QGraphicsView widget as opposed to a destination
589-
* device (such as an image).
590-
*/
591-
bool isPreviewRender( QPainter *painter ) const;
592-
593586
/**
594587
* Sets a fixed \a size for the layout item, which prevents it from being freely
595588
* resized. Set an empty size if item can be freely resized.

‎src/core/layout/qgslayoutitempage.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,7 @@ void QgsLayoutItemPage::draw( QgsRenderContext &context, const QStyleOptionGraph
178178
QPainter *painter = context.painter();
179179
painter->save();
180180

181-
#if 0 //TODO
182-
if ( mComposition->plotStyle() == QgsComposition::Preview )
183-
#endif
181+
if ( QgsLayoutUtils::isPreviewRender( context.painter() ) )
184182
{
185183
//if in preview mode, draw page border and shadow so that it's
186184
//still possible to tell where pages with a transparent style begin and end
@@ -256,6 +254,9 @@ void QgsLayoutItemPageGrid::paint( QPainter *painter, const QStyleOptionGraphics
256254
if ( !mLayout )
257255
return;
258256

257+
if ( !QgsLayoutUtils::isPreviewRender( painter ) )
258+
return;
259+
259260
const QgsLayoutContext &context = mLayout->context();
260261
const QgsLayoutGridSettings &grid = mLayout->gridSettings();
261262

‎src/core/layout/qgslayoututils.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,28 @@ double QgsLayoutUtils::relativePosition( const double position, const double bef
109109
//return linearly scaled position
110110
return m * position + c;
111111
}
112+
113+
bool QgsLayoutUtils::isPreviewRender( QPainter *painter )
114+
{
115+
if ( !painter || !painter->device() )
116+
return false;
117+
118+
// if rendering to a QGraphicsView, we are in preview mode
119+
QPaintDevice *device = painter->device();
120+
if ( dynamic_cast< QPixmap * >( device ) )
121+
return true;
122+
123+
QObject *obj = dynamic_cast< QObject *>( device );
124+
if ( !obj )
125+
return false;
126+
127+
const QMetaObject *mo = obj->metaObject();
128+
while ( mo )
129+
{
130+
if ( mo->className() == QStringLiteral( "QGraphicsView" ) )
131+
return true;
132+
133+
mo = mo->superClass();
134+
}
135+
return false;
136+
}

‎src/core/layout/qgslayoututils.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ class CORE_EXPORT QgsLayoutUtils
8181
*/
8282
static double relativePosition( const double position, const double beforeMin, const double beforeMax, const double afterMin, const double afterMax );
8383

84+
85+
/**
86+
* Returns true if the render to the specified \a painter is a preview render,
87+
* i.e. is being rendered inside a QGraphicsView widget as opposed to a destination
88+
* device (such as an image).
89+
*/
90+
static bool isPreviewRender( QPainter *painter );
91+
8492
};
8593

8694
#endif //QGSLAYOUTUTILS_H

‎src/core/qgsmultirenderchecker.cpp

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include "qgsmultirenderchecker.h"
1717
#include "qgscomposition.h"
18+
#include "qgslayout.h"
1819
#include <QDebug>
1920

2021
void QgsMultiRenderChecker::setControlName( const QString &name )
@@ -170,6 +171,70 @@ bool QgsCompositionChecker::testComposition( QString &checkedReport, int page, i
170171
return testResult;
171172
}
172173

174+
175+
176+
//
177+
// QgsLayoutChecker
178+
//
179+
180+
QgsLayoutChecker::QgsLayoutChecker( const QString &testName, QgsLayout *layout )
181+
: QgsMultiRenderChecker()
182+
, mTestName( testName )
183+
, mLayout( layout )
184+
, mSize( 1122, 794 )
185+
, mDotsPerMeter( 96 / 25.4 * 1000 )
186+
{
187+
// Qt has some slight render inconsistencies on the whole image sometimes
188+
setColorTolerance( 5 );
189+
}
190+
191+
bool QgsLayoutChecker::runTest( QString &checkedReport, int page, int pixelDiff )
192+
{
193+
if ( !mLayout )
194+
{
195+
return false;
196+
}
197+
198+
setControlName( "expected_" + mTestName );
199+
200+
#if 0
201+
//fake mode to generate expected image
202+
//assume 96 dpi and size of the control image 1122 * 794
203+
QImage newImage( QSize( 1122, 794 ), QImage::Format_RGB32 );
204+
mComposition->setPlotStyle( QgsComposition::Print );
205+
newImage.setDotsPerMeterX( 96 / 25.4 * 1000 );
206+
newImage.setDotsPerMeterY( 96 / 25.4 * 1000 );
207+
drawBackground( &newImage );
208+
QPainter expectedPainter( &newImage );
209+
//QRectF sourceArea( 0, 0, mComposition->paperWidth(), mComposition->paperHeight() );
210+
//QRectF targetArea( 0, 0, 3507, 2480 );
211+
mComposition->renderPage( &expectedPainter, page );
212+
expectedPainter.end();
213+
newImage.save( controlImagePath() + QDir::separator() + "expected_" + mTestName + ".png", "PNG" );
214+
return true;
215+
#endif //0
216+
217+
QImage outputImage( mSize, QImage::Format_RGB32 );
218+
outputImage.setDotsPerMeterX( mDotsPerMeter );
219+
outputImage.setDotsPerMeterY( mDotsPerMeter );
220+
drawBackground( &outputImage );
221+
QPainter p( &outputImage );
222+
mLayout->exporter().renderPage( &p, page );
223+
p.end();
224+
225+
QString renderedFilePath = QDir::tempPath() + '/' + QFileInfo( mTestName ).baseName() + "_rendered.png";
226+
outputImage.save( renderedFilePath, "PNG" );
227+
228+
setRenderedImage( renderedFilePath );
229+
230+
bool testResult = runTest( mTestName, pixelDiff );
231+
232+
checkedReport += report();
233+
234+
return testResult;
235+
}
236+
237+
173238
///@endcond
174239

175240
#endif

‎src/core/qgsmultirenderchecker.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,48 @@ class CORE_EXPORT QgsCompositionChecker : public QgsMultiRenderChecker
165165
QSize mSize;
166166
int mDotsPerMeter;
167167
};
168+
169+
/**
170+
* \ingroup core
171+
* \class QgsLayoutChecker
172+
* Renders a layout to an image and compares with an expected output
173+
* \since QGIS 3.0
174+
*/
175+
class CORE_EXPORT QgsLayoutChecker : public QgsMultiRenderChecker
176+
{
177+
public:
178+
179+
/**
180+
* Constructor for QgsLayoutChecker.
181+
*/
182+
QgsLayoutChecker( const QString &testName, QgsLayout *layout );
183+
184+
/**
185+
* Sets the output (reference) image \a size.
186+
*/
187+
void setSize( QSize size ) { mSize = size; }
188+
189+
/**
190+
* Runs a render check on the layout, adding results to the specified \a report.
191+
*
192+
* The maximum number of allowable pixels differing from the reference image is
193+
* specified via the \a pixelDiff argument.
194+
*
195+
* The page number is specified via \a page, where 0 corresponds to the first
196+
* page in the layout.
197+
*
198+
* Returns false if the rendered layout differs from the expected reference image.
199+
*/
200+
bool runTest( QString &report, int page = 0, int pixelDiff = 0 );
201+
202+
private:
203+
QgsLayoutChecker() = delete;
204+
205+
QString mTestName;
206+
QgsLayout *mLayout = nullptr;
207+
QSize mSize;
208+
int mDotsPerMeter;
209+
};
168210
///@endcond
169211

170212
SIP_END

‎src/gui/layout/qgslayoutmousehandles.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,11 @@ void QgsLayoutMouseHandles::paint( QPainter *painter, const QStyleOptionGraphics
5757
Q_UNUSED( itemStyle );
5858
Q_UNUSED( pWidget );
5959

60-
//TODO
61-
#if 0
62-
if ( mLayout->plotStyle() != QgsComposition::Preview )
60+
if ( !QgsLayoutUtils::isPreviewRender( painter ) )
6361
{
64-
//don't draw selection handles in composition outputs
62+
//don't draw selection handles in layout outputs
6563
return;
6664
}
67-
#endif
6865

6966
if ( mLayout->context().boundingBoxesVisible() )
7067
{

‎tests/src/gui/testqgslayoutview.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "qgslayoutitemshape.h"
2727
#include "qgsproject.h"
2828
#include "qgsgui.h"
29+
#include "qgslayoututils.h"
2930
#include <QtTest/QSignalSpy>
3031
#include <QSvgGenerator>
3132
#include <QPrinter>
@@ -344,7 +345,7 @@ class TestViewItem : public QgsLayoutItem
344345
void paint( QPainter *painter, const QStyleOptionGraphicsItem *, QWidget * ) override
345346
{
346347
mDrawn = true;
347-
mPreview = isPreviewRender( painter );
348+
mPreview = QgsLayoutUtils::isPreviewRender( painter );
348349
}
349350
void draw( QgsRenderContext &, const QStyleOptionGraphicsItem * ) override
350351
{
@@ -369,18 +370,18 @@ void TestQgsLayoutView::isPreviewRender()
369370

370371

371372
// render to image
372-
QVERIFY( !item->isPreviewRender( nullptr ) );
373+
QVERIFY( !QgsLayoutUtils::isPreviewRender( nullptr ) );
373374
QImage im = QImage( 250, 250, QImage::Format_RGB32 );
374375
QPainter painter;
375376
QVERIFY( painter.begin( &im ) );
376-
QVERIFY( !item->isPreviewRender( &painter ) );
377+
QVERIFY( !QgsLayoutUtils::isPreviewRender( &painter ) );
377378
painter.end();
378379

379380
// render to svg
380381
QSvgGenerator generator;
381382
generator.setFileName( QDir::tempPath() + "/layout_text.svg" );
382383
QVERIFY( painter.begin( &generator ) );
383-
QVERIFY( !item->isPreviewRender( &painter ) );
384+
QVERIFY( !QgsLayoutUtils::isPreviewRender( &painter ) );
384385
painter.end();
385386

386387
// render to pdf
@@ -389,7 +390,7 @@ void TestQgsLayoutView::isPreviewRender()
389390
printer.setOutputFormat( QPrinter::PdfFormat );
390391
printer.setOutputFileName( QDir::tempPath() + "/layout_text.pdf" );
391392
QVERIFY( painter.begin( &printer ) );
392-
QVERIFY( !item->isPreviewRender( &painter ) );
393+
QVERIFY( !QgsLayoutUtils::isPreviewRender( &painter ) );
393394
painter.end();
394395

395396
// render in view - kinda gross!

0 commit comments

Comments
 (0)
Please sign in to comment.