QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsmultirenderchecker.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmultirenderchecker.cpp
3  --------------------------------------
4  Date : 6.11.2014
5  Copyright : (C) 2014 Matthias Kuhn
6  Email : matthias dot kuhn at gmx 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 #include "qgsmultirenderchecker.h"
17 
18 #include <QDebug>
19 
21  : mColorTolerance( 0 )
22 {
23 }
24 
25 void QgsMultiRenderChecker::setControlName( const QString& theName )
26 {
27  mControlName = theName;
28 }
29 
30 void QgsMultiRenderChecker::setControlPathPrefix( const QString& prefix )
31 {
32  mControlPathPrefix = prefix;
33 }
34 
36 {
37  mMapSettings = mapSettings;
38 }
39 
40 bool QgsMultiRenderChecker::runTest( const QString& theTestName, unsigned int theMismatchCount )
41 {
42  bool successful = false;
43 
44  const QString baseDir = controlImagePath();
45 
46  QStringList subDirs = QDir( baseDir ).entryList( QDir::Dirs | QDir::NoDotAndDotDot );
47 
48  if ( subDirs.count() == 0 )
49  {
50  subDirs << "";
51  }
52 
53  QVector<QgsDartMeasurement> dartMeasurements;
54 
55  Q_FOREACH ( const QString& suffix, subDirs )
56  {
57  qDebug() << "Checking subdir " << suffix;
58  bool result;
59  QgsRenderChecker checker;
60  checker.enableDashBuffering( true );
61  checker.setColorTolerance( mColorTolerance );
62  checker.setControlPathPrefix( mControlPathPrefix );
63  checker.setControlPathSuffix( suffix );
64  checker.setControlName( mControlName );
65  checker.setMapSettings( mMapSettings );
66 
67  if ( !mRenderedImage.isNull() )
68  {
69  checker.setRenderedImage( mRenderedImage );
70  result = checker.compareImages( theTestName, theMismatchCount, mRenderedImage );
71  }
72  else
73  {
74  result = checker.runTest( theTestName, theMismatchCount );
75  mRenderedImage = checker.renderedImage();
76  }
77 
78  successful |= result;
79 
80  dartMeasurements << checker.dartMeasurements();
81 
82  mReport += checker.report();
83  }
84 
85  if ( !successful )
86  {
87  Q_FOREACH ( const QgsDartMeasurement& measurement, dartMeasurements )
88  measurement.send();
89 
90  QgsDartMeasurement msg( "Image not accepted by test", QgsDartMeasurement::Text, "This may be caused because the test is supposed to fail or rendering inconsistencies."
91  "If this is a rendering inconsistency, please add another control image folder, add an anomaly image or increase the color tolerance." );
92  msg.send();
93  }
94 
95  return successful;
96 }
97 
99 {
100  QString myDataDir( TEST_DATA_DIR ); //defined in CmakeLists.txt
101  QString myControlImageDir = myDataDir + QDir::separator() + "control_images" +
102  QDir::separator() + mControlPathPrefix + QDir::separator() + mControlName + QDir::separator();
103  return myControlImageDir;
104 }