QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgsmultirenderchecker.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmultirenderchecker.h
3  --------------------------------------
4  Date : 6.11.2014
5  Copyright : (C) 2014 Matthias Kuhn
6  Email : matthias at opengis dot ch
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSMULTIRENDERCHECKER_H
17 #define QGSMULTIRENDERCHECKER_H
18 
19 #include "qgis_core.h"
20 #include "qgsrenderchecker.h"
21 
22 class QgsLayout;
23 
56 class CORE_EXPORT QgsMultiRenderChecker
57 {
58  public:
59 
64 
65  virtual ~QgsMultiRenderChecker() = default;
66 
72  void setControlName( const QString &name );
73 
74  void setControlPathPrefix( const QString &prefix );
75 
82  void setRenderedImage( const QString &renderedImagePath ) { mRenderedImage = renderedImagePath; }
83 
89  void setExpectFail( bool expectFail ) { mExpectFail = expectFail; }
90 
96  void setMapSettings( const QgsMapSettings &mapSettings );
97 
105  void setColorTolerance( unsigned int colorTolerance ) { mColorTolerance = colorTolerance; }
106 
113  void setSizeTolerance( int xTolerance, int yTolerance ) { mMaxSizeDifferenceX = xTolerance; mMaxSizeDifferenceY = yTolerance; }
114 
128  bool runTest( const QString &testName, unsigned int mismatchCount = 0 );
129 
135  QString report() const;
136 
140  QString controlImagePath() const;
141 
146  static void drawBackground( QImage *image ) { QgsRenderChecker::drawBackground( image ); }
147 
148  private:
149  bool mResult = false;
150  QString mReport;
151  QString mRenderedImage;
152  QString mControlName;
153  QString mControlPathPrefix;
154  unsigned int mColorTolerance = 0;
155  int mMaxSizeDifferenceX = 0;
156  int mMaxSizeDifferenceY = 0;
157  QgsMapSettings mMapSettings;
158  bool mExpectFail = false;
159 
160  bool mIsCiRun = false;
161 };
162 
163 SIP_FEATURE( TESTS )
164 SIP_IF_FEATURE( TESTS )
165 
166 
174 class CORE_EXPORT QgsLayoutChecker : public QgsMultiRenderChecker
175 {
176  public:
177 
181  QgsLayoutChecker( const QString &testName, QgsLayout *layout );
182 
186  void setSize( QSize size ) { mSize = size; }
187 
202  bool testLayout( QString &report, int page = 0, int pixelDiff = 0, bool createReferenceImage = false );
203 
204  private:
205  QgsLayoutChecker() = delete;
206 
207  QString mTestName;
208  QgsLayout *mLayout = nullptr;
209  QSize mSize;
210  int mDotsPerMeter;
211 };
213 
214 SIP_END
215 
216 
217 #endif // QGSMULTIRENDERCHECKER_H
qgsrenderchecker.h
QgsMultiRenderChecker::drawBackground
static void drawBackground(QImage *image)
Draws a checkboard pattern for image backgrounds, so that opacity is visible without requiring a tran...
Definition: qgsmultirenderchecker.h:146
QgsMultiRenderChecker::setColorTolerance
void setColorTolerance(unsigned int colorTolerance)
Set tolerance for color components used by runTest() Default value is 0.
Definition: qgsmultirenderchecker.h:105
QgsMultiRenderChecker::setRenderedImage
void setRenderedImage(const QString &renderedImagePath)
Set the path to the rendered image.
Definition: qgsmultirenderchecker.h:82
QgsMultiRenderChecker::setExpectFail
void setExpectFail(bool expectFail)
Sets whether the comparison is expected to fail.
Definition: qgsmultirenderchecker.h:89
QgsRenderChecker::drawBackground
static void drawBackground(QImage *image)
Draws a checkboard pattern for image backgrounds, so that opacity is visible without requiring a tran...
Definition: qgsrenderchecker.cpp:97
QgsMultiRenderChecker
This class allows checking rendered images against comparison images.
Definition: qgsmultirenderchecker.h:56
SIP_IF_FEATURE
#define SIP_IF_FEATURE(feature)
Definition: qgis_sip.h:176
QgsLayout
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:50
QgsMultiRenderChecker::setSizeTolerance
void setSizeTolerance(int xTolerance, int yTolerance)
Sets the largest allowable difference in size between the rendered and the expected image.
Definition: qgsmultirenderchecker.h:113
QgsMapSettings
The QgsMapSettings class contains configuration for rendering of the map. The rendering itself is don...
Definition: qgsmapsettings.h:88
SIP_FEATURE
#define SIP_FEATURE(feature)
Definition: qgis_sip.h:171
SIP_END
#define SIP_END
Definition: qgis_sip.h:203