QGIS API Documentation  3.0.2-Girona (307d082)
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 
53 class CORE_EXPORT QgsMultiRenderChecker
54 {
55  public:
56 
60  QgsMultiRenderChecker() = default;
61 
62  virtual ~QgsMultiRenderChecker() = default;
63 
69  void setControlName( const QString &name );
70 
71  void setControlPathPrefix( const QString &prefix );
72 
79  void setRenderedImage( const QString &renderedImagePath ) { mRenderedImage = renderedImagePath; }
80 
86  void setMapSettings( const QgsMapSettings &mapSettings );
87 
95  void setColorTolerance( unsigned int colorTolerance ) { mColorTolerance = colorTolerance; }
96 
103  void setSizeTolerance( int xTolerance, int yTolerance ) { mMaxSizeDifferenceX = xTolerance; mMaxSizeDifferenceY = yTolerance; }
104 
118  bool runTest( const QString &testName, unsigned int mismatchCount = 0 );
119 
125  QString report() const { return mReport; }
126 
131  QString controlImagePath() const;
132 
137  static void drawBackground( QImage *image ) { QgsRenderChecker::drawBackground( image ); }
138 
139  private:
140  QString mReport;
141  QString mRenderedImage;
142  QString mControlName;
143  QString mControlPathPrefix;
144  unsigned int mColorTolerance = 0;
145  int mMaxSizeDifferenceX = 0;
146  int mMaxSizeDifferenceY = 0;
147  QgsMapSettings mMapSettings;
148 };
149 
150 #ifdef ENABLE_TESTS
151 SIP_FEATURE( TESTS )
152 SIP_IF_FEATURE( TESTS )
153 
154 
162 class CORE_EXPORT QgsLayoutChecker : public QgsMultiRenderChecker
163 {
164  public:
165 
169  QgsLayoutChecker( const QString &testName, QgsLayout *layout );
170 
174  void setSize( QSize size ) { mSize = size; }
175 
190  bool testLayout( QString &report, int page = 0, int pixelDiff = 0, bool createReferenceImage = false );
191 
192  private:
193  QgsLayoutChecker() = delete;
194 
195  QString mTestName;
196  QgsLayout *mLayout = nullptr;
197  QSize mSize;
198  int mDotsPerMeter;
199 };
201 
202 SIP_END
203 #endif
204 
205 
206 #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:175
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.