|
32 | 32 | #include <qgsfield.h>
|
33 | 33 | #include <qgis.h> //defines GEOWkt
|
34 | 34 | #include <qgsmaprenderer.h>
|
| 35 | +#include "qgsmaprenderersequentialjob.h" |
35 | 36 | #include <qgsmaplayer.h>
|
36 | 37 | #include <qgsvectorlayer.h>
|
37 | 38 | #include <qgsapplication.h>
|
@@ -72,6 +73,12 @@ class TestQgsMapRenderer : public QObject
|
72 | 73 | /** This method tests render perfomance */
|
73 | 74 | void performanceTest();
|
74 | 75 |
|
| 76 | + /** This unit test checks if rendering of adjacent tiles (e.g. to render images for tile caches) |
| 77 | + * does not result in border effects |
| 78 | + */ |
| 79 | + void testFourAdjacentTiles_data(); |
| 80 | + void testFourAdjacentTiles(); |
| 81 | + |
75 | 82 | private:
|
76 | 83 | QString mEncoding;
|
77 | 84 | QgsVectorFileWriter::WriterError mError;
|
@@ -211,6 +218,121 @@ void TestQgsMapRenderer::performanceTest()
|
211 | 218 | QVERIFY( myResultFlag );
|
212 | 219 | }
|
213 | 220 |
|
| 221 | +void TestQgsMapRenderer::testFourAdjacentTiles_data() |
| 222 | +{ |
| 223 | + QTest::addColumn<QStringList>( "bboxList" ); |
| 224 | + QTest::addColumn<QString>( "controlName" ); |
| 225 | + QTest::addColumn<QString>( "shapeFile" ); |
| 226 | + QTest::addColumn<QString>( "qmlFile" ); |
| 227 | + |
| 228 | + QString shapeFile = TEST_DATA_DIR + QString( "/france_parts.shp" ); |
| 229 | + QString qmlFile = TEST_DATA_DIR + QString( "/adjacent_tiles/line_pattern_30_degree.qml" ); |
| 230 | + QString controlName = "expected_adjacent_line_fill"; |
| 231 | + |
| 232 | + QStringList bboxList1; |
| 233 | + bboxList1 << "-1.5,48,-0.5,49"; |
| 234 | + bboxList1 << "-0.5,48,0.5,49"; |
| 235 | + bboxList1 << "-1.5,47,-0.5,48"; |
| 236 | + bboxList1 << "-0.5,47,0.5,48"; |
| 237 | + |
| 238 | + QTest::newRow( "adjacent_line_fill" ) << bboxList1 << controlName << shapeFile << qmlFile; |
| 239 | + |
| 240 | + qmlFile = TEST_DATA_DIR + QString( "/adjacent_tiles/point_pattern_simple_marker.qml" ); |
| 241 | + controlName = "expected_adjacent_marker_fill"; |
| 242 | + |
| 243 | + QTest::newRow( "adjacent_marker_fill" ) << bboxList1 << controlName << shapeFile << qmlFile; |
| 244 | + |
| 245 | + shapeFile = TEST_DATA_DIR + QString( "/lines.shp" ); |
| 246 | + qmlFile = TEST_DATA_DIR + QString( "/adjacent_tiles/simple_line_dashed.qml" ); |
| 247 | + controlName = "expected_adjacent_dashed_line"; |
| 248 | + |
| 249 | + QStringList bboxList2; |
| 250 | + bboxList2 << "-105,35,-95,45"; |
| 251 | + bboxList2 << "-95,35,-85,45"; |
| 252 | + bboxList2 << "-105,25,-95,35"; |
| 253 | + bboxList2 << "-95,25,-85,35"; |
| 254 | + |
| 255 | + QTest::newRow( "adjacent_dashed_line" ) << bboxList2 << controlName << shapeFile << qmlFile; |
| 256 | +} |
| 257 | + |
| 258 | +void TestQgsMapRenderer::testFourAdjacentTiles() |
| 259 | +{ |
| 260 | + QFETCH( QStringList, bboxList ); |
| 261 | + QFETCH( QString, controlName ); |
| 262 | + QFETCH( QString, shapeFile ); |
| 263 | + QFETCH( QString, qmlFile ); |
| 264 | + |
| 265 | + QVERIFY( bboxList.size() == 4 ); |
| 266 | + |
| 267 | + //create maplayer, set QML and add to maplayer registry |
| 268 | + QgsVectorLayer* vectorLayer = new QgsVectorLayer( shapeFile, "testshape", "ogr" ); |
| 269 | + |
| 270 | + //todo: read QML |
| 271 | + QFile symbologyFile( qmlFile ); |
| 272 | + if ( !symbologyFile.open( QIODevice::ReadOnly ) ) |
| 273 | + { |
| 274 | + QFAIL( "Open symbology file failed" ); |
| 275 | + } |
| 276 | + |
| 277 | + QDomDocument qmlDoc; |
| 278 | + if ( !qmlDoc.setContent( &symbologyFile ) ) |
| 279 | + { |
| 280 | + QFAIL( "QML file not valid" ); |
| 281 | + } |
| 282 | + |
| 283 | + QString errorMsg; |
| 284 | + if ( !vectorLayer->readSymbology( qmlDoc.documentElement(), errorMsg ) ) |
| 285 | + { |
| 286 | + QFAIL( errorMsg.toLocal8Bit().data() ); |
| 287 | + } |
| 288 | + |
| 289 | + QgsMapLayerRegistry::instance()->addMapLayers( QList<QgsMapLayer*>() << vectorLayer ); |
| 290 | + |
| 291 | + QImage globalImage( 512, 512, QImage::Format_ARGB32_Premultiplied ); |
| 292 | + globalImage.fill( Qt::white ); |
| 293 | + QPainter globalPainter( &globalImage ); |
| 294 | + |
| 295 | + for ( int i = 0; i < 4; ++i ) |
| 296 | + { |
| 297 | + QgsMapSettings mapSettings; |
| 298 | + |
| 299 | + //extent |
| 300 | + QStringList rectCoords = bboxList.at( i ).split( "," ); |
| 301 | + if ( rectCoords.size() != 4 ) |
| 302 | + { |
| 303 | + QFAIL( "bbox string invalid" ); |
| 304 | + } |
| 305 | + QgsRectangle rect( rectCoords[0].toDouble(), rectCoords[1].toDouble(), rectCoords[2].toDouble(), rectCoords[3].toDouble() ); |
| 306 | + mapSettings.setExtent( rect ); |
| 307 | + mapSettings.setOutputSize( QSize( 256, 256 ) ); |
| 308 | + mapSettings.setLayers( QStringList() << vectorLayer->id() ); |
| 309 | + mapSettings.setFlags( QgsMapSettings::RenderMapTile ); |
| 310 | + mapSettings.setOutputDpi( 96 ); |
| 311 | + |
| 312 | + QgsMapRendererSequentialJob renderJob( mapSettings ); |
| 313 | + renderJob.start(); |
| 314 | + renderJob.waitForFinished(); |
| 315 | + QImage img = renderJob.renderedImage(); |
| 316 | + int globalImageX = ( i % 2 ) * 256; |
| 317 | + int globalImageY = ( i < 2 ) ? 0 : 256; |
| 318 | + globalPainter.drawImage( globalImageX, globalImageY, img ); |
| 319 | + } |
| 320 | + |
| 321 | + QgsMapLayerRegistry::instance()->removeMapLayers( QStringList() << vectorLayer->id() ); |
| 322 | + |
| 323 | + QString renderedImagePath = QDir::tempPath() + "/" + QTest::currentDataTag() + QString( ".png" ); |
| 324 | + globalImage.save( renderedImagePath ); |
| 325 | + |
| 326 | + QgsRenderChecker checker; |
| 327 | + |
| 328 | + checker.setControlPathPrefix( "adjacent_tiles" ); |
| 329 | + checker.setControlName( controlName ); |
| 330 | + bool result = checker.compareImages( QTest::currentDataTag(), 100, renderedImagePath ); |
| 331 | + mReport += checker.report(); |
| 332 | + QVERIFY( result ); |
| 333 | +} |
| 334 | + |
| 335 | + |
214 | 336 | QTEST_MAIN( TestQgsMapRenderer )
|
215 | 337 | #include "testqgsmaprenderer.moc"
|
216 | 338 |
|
|
0 commit comments