QGIS API Documentation  3.6.0-Noosa (5873452)
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 
55 class CORE_EXPORT QgsMultiRenderChecker
56 {
57  public:
58 
62  QgsMultiRenderChecker() = default;
63 
64  virtual ~QgsMultiRenderChecker() = default;
65 
71  void setControlName( const QString &name );
72 
73  void setControlPathPrefix( const QString &prefix );
74 
81  void setRenderedImage( const QString &renderedImagePath ) { mRenderedImage = renderedImagePath; }
82 
88  void setMapSettings( const QgsMapSettings &mapSettings );
89 
97  void setColorTolerance( unsigned int colorTolerance ) { mColorTolerance = colorTolerance; }
98 
105  void setSizeTolerance( int xTolerance, int yTolerance ) { mMaxSizeDifferenceX = xTolerance; mMaxSizeDifferenceY = yTolerance; }
106 
120  bool runTest( const QString &testName, unsigned int mismatchCount = 0 );
121 
125  QString report() const { return mReport; }
126 
130  QString controlImagePath() const;
131 
136  static void drawBackground( QImage *image ) { QgsRenderChecker::drawBackground( image ); }
137 
138  private:
139  QString mReport;
140  QString mRenderedImage;
141  QString mControlName;
142  QString mControlPathPrefix;
143  unsigned int mColorTolerance = 0;
144  int mMaxSizeDifferenceX = 0;
145  int mMaxSizeDifferenceY = 0;
146  QgsMapSettings mMapSettings;
147 };
148 
149 SIP_FEATURE( TESTS )
150 SIP_IF_FEATURE( TESTS )
151 
152 
160 class CORE_EXPORT QgsLayoutChecker : public QgsMultiRenderChecker
161 {
162  public:
163 
167  QgsLayoutChecker( const QString &testName, QgsLayout *layout );
168 
172  void setSize( QSize size ) { mSize = size; }
173 
188  bool testLayout( QString &report, int page = 0, int pixelDiff = 0, bool createReferenceImage = false );
189 
190  private:
191  QgsLayoutChecker() = delete;
192 
193  QString mTestName;
194  QgsLayout *mLayout = nullptr;
195  QSize mSize;
196  int mDotsPerMeter;
197 };
199 
200 SIP_END
201 
202 
203 #endif // QGSMULTIRENDERCHECKER_H
void setColorTolerance(unsigned int colorTolerance)
Set tolerance for color components used by runTest() Default value is 0.
void setSizeTolerance(int xTolerance, int yTolerance)
Sets the largest allowable difference in size between the rendered and the expected image...
QString report() const
Returns a report for this test.
The QgsMapSettings class contains configuration for rendering of the map.
This class allows checking rendered images against comparison images.
#define SIP_END
Definition: qgis_sip.h:182
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:49
#define SIP_IF_FEATURE(feature)
Definition: qgis_sip.h:155
static void drawBackground(QImage *image)
Draws a checkboard pattern for image backgrounds, so that opacity is visible without requiring a tran...
#define SIP_FEATURE(feature)
Definition: qgis_sip.h:150
static void drawBackground(QImage *image)
Draws a checkboard pattern for image backgrounds, so that opacity is visible without requiring a tran...
void setRenderedImage(const QString &renderedImagePath)
Set the path to the rendered image.