QGIS API Documentation  3.23.0-Master (7c4a6de034)
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 
63  QgsMultiRenderChecker() = default;
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 setMapSettings( const QgsMapSettings &mapSettings );
90 
98  void setColorTolerance( unsigned int colorTolerance ) { mColorTolerance = colorTolerance; }
99 
106  void setSizeTolerance( int xTolerance, int yTolerance ) { mMaxSizeDifferenceX = xTolerance; mMaxSizeDifferenceY = yTolerance; }
107 
121  bool runTest( const QString &testName, unsigned int mismatchCount = 0 );
122 
126  QString report() const { return mReport; }
127 
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 SIP_FEATURE( TESTS )
151 SIP_IF_FEATURE( TESTS )
152 
153 
161 class CORE_EXPORT QgsLayoutChecker : public QgsMultiRenderChecker
162 {
163  public:
164 
168  QgsLayoutChecker( const QString &testName, QgsLayout *layout );
169 
173  void setSize( QSize size ) { mSize = size; }
174 
189  bool testLayout( QString &report, int page = 0, int pixelDiff = 0, bool createReferenceImage = false );
190 
191  private:
192  QgsLayoutChecker() = delete;
193 
194  QString mTestName;
195  QgsLayout *mLayout = nullptr;
196  QSize mSize;
197  int mDotsPerMeter;
198 };
200 
201 SIP_END
202 
203 
204 #endif // QGSMULTIRENDERCHECKER_H
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:51
The QgsMapSettings class contains configuration for rendering of the map.
This class allows checking rendered images against comparison images.
void setRenderedImage(const QString &renderedImagePath)
Set the path to the rendered image.
static void drawBackground(QImage *image)
Draws a checkboard pattern for image backgrounds, so that opacity is visible without requiring a tran...
virtual ~QgsMultiRenderChecker()=default
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.
QgsMultiRenderChecker()=default
Constructor for QgsMultiRenderChecker.
static void drawBackground(QImage *image)
Draws a checkboard pattern for image backgrounds, so that opacity is visible without requiring a tran...
#define SIP_IF_FEATURE(feature)
Definition: qgis_sip.h:167
#define SIP_FEATURE(feature)
Definition: qgis_sip.h:162
#define SIP_END
Definition: qgis_sip.h:194