Skip to content

Commit

Permalink
Added a basic rendering test
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Mar 27, 2020
1 parent 6a107c8 commit 3c33bf7
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 15 deletions.
Expand Up @@ -171,6 +171,14 @@ Sets list of styles of the renderer
QList<QgsVectorTileBasicRendererStyle> styles() const;
%Docstring
Returns list of styles of the renderer
%End

static QList<QgsVectorTileBasicRendererStyle> simpleStyle(
const QColor &polygonFillColor, const QColor &polygonStrokeColor, double polygonStrokeWidth,
const QColor &lineStrokeColor, double lineStrokeWidth,
const QColor &pointFillColor, const QColor &pointStrokeColor, double pointSize );
%Docstring
Sets a default style to render all layers with the given fill/stroke colors, stroke widths and marker sizes
%End

};
Expand Down
58 changes: 43 additions & 15 deletions src/core/vectortile/qgsvectortilebasicrenderer.cpp
Expand Up @@ -16,7 +16,9 @@
#include "qgsvectortilebasicrenderer.h"

#include "qgsexpressioncontextutils.h"
#include "qgsfillsymbollayer.h"
#include "qgslinesymbollayer.h"
#include "qgsmarkersymbollayer.h"
#include "qgssymbollayerutils.h"
#include "qgsvectortileutils.h"

Expand Down Expand Up @@ -229,30 +231,56 @@ QList<QgsVectorTileBasicRendererStyle> QgsVectorTileBasicRenderer::styles() cons

void QgsVectorTileBasicRenderer::setDefaultStyle()
{
QColor color = Qt::blue;
QColor polygonColor = color;
polygonColor.setAlpha( 100 );
QColor pointColor = Qt::red;

QgsFillSymbol *polygonSymbol = static_cast<QgsFillSymbol *>( QgsLineSymbol::defaultSymbol( QgsWkbTypes::PolygonGeometry ) );
polygonSymbol->setColor( polygonColor );

QgsLineSymbol *lineSymbol = static_cast<QgsLineSymbol *>( QgsLineSymbol::defaultSymbol( QgsWkbTypes::LineGeometry ) );
lineSymbol->setColor( color );
QColor polygonFillColor = Qt::blue;
QColor polygonStrokeColor = polygonFillColor;
polygonFillColor.setAlpha( 100 );
double polygonStrokeWidth = DEFAULT_LINE_WIDTH;

QColor lineStrokeColor = Qt::blue;
double lineStrokeWidth = DEFAULT_LINE_WIDTH;

QColor pointFillColor = Qt::red;
QColor pointStrokeColor = pointFillColor;
pointFillColor.setAlpha( 100 );
double pointSize = DEFAULT_POINT_SIZE;

setStyles( simpleStyle( polygonFillColor, polygonStrokeColor, polygonStrokeWidth,
lineStrokeColor, lineStrokeWidth,
pointFillColor, pointStrokeColor, pointSize ) );
}

QgsMarkerSymbol *pointSymbol = static_cast<QgsMarkerSymbol *>( QgsLineSymbol::defaultSymbol( QgsWkbTypes::PointGeometry ) );
pointSymbol->setColor( pointColor );
QList<QgsVectorTileBasicRendererStyle> QgsVectorTileBasicRenderer::simpleStyle(
const QColor &polygonFillColor, const QColor &polygonStrokeColor, double polygonStrokeWidth,
const QColor &lineStrokeColor, double lineStrokeWidth,
const QColor &pointFillColor, const QColor &pointStrokeColor, double pointSize )
{
QgsSimpleFillSymbolLayer *fillSymbolLayer = new QgsSimpleFillSymbolLayer();
fillSymbolLayer->setFillColor( polygonFillColor );
fillSymbolLayer->setStrokeColor( polygonStrokeColor );
fillSymbolLayer->setStrokeWidth( polygonStrokeWidth );
QgsFillSymbol *fillSymbol = new QgsFillSymbol( QgsSymbolLayerList() << fillSymbolLayer );

QgsSimpleLineSymbolLayer *lineSymbolLayer = new QgsSimpleLineSymbolLayer;
lineSymbolLayer->setColor( lineStrokeColor );
lineSymbolLayer->setWidth( lineStrokeWidth );
QgsLineSymbol *lineSymbol = new QgsLineSymbol( QgsSymbolLayerList() << lineSymbolLayer );

QgsSimpleMarkerSymbolLayer *markerSymbolLayer = new QgsSimpleMarkerSymbolLayer;
markerSymbolLayer->setFillColor( pointFillColor );
markerSymbolLayer->setStrokeColor( pointStrokeColor );
markerSymbolLayer->setSize( pointSize );
QgsMarkerSymbol *markerSymbol = new QgsMarkerSymbol( QgsSymbolLayerList() << markerSymbolLayer );

QgsVectorTileBasicRendererStyle st1( "polygons", QString(), QgsWkbTypes::PolygonGeometry );
st1.setSymbol( polygonSymbol );
st1.setSymbol( fillSymbol );

QgsVectorTileBasicRendererStyle st2( "lines", QString(), QgsWkbTypes::LineGeometry );
st2.setSymbol( lineSymbol );

QgsVectorTileBasicRendererStyle st3( "points", QString(), QgsWkbTypes::PointGeometry );
st3.setSymbol( pointSymbol );
st3.setSymbol( markerSymbol );

QList<QgsVectorTileBasicRendererStyle> lst;
lst << st1 << st2 << st3;
setStyles( lst );
return lst;
}
6 changes: 6 additions & 0 deletions src/core/vectortile/qgsvectortilebasicrenderer.h
Expand Up @@ -142,6 +142,12 @@ class CORE_EXPORT QgsVectorTileBasicRenderer : public QgsVectorTileRenderer
//! Returns list of styles of the renderer
QList<QgsVectorTileBasicRendererStyle> styles() const;

//! Sets a default style to render all layers with the given fill/stroke colors, stroke widths and marker sizes
static QList<QgsVectorTileBasicRendererStyle> simpleStyle(
const QColor &polygonFillColor, const QColor &polygonStrokeColor, double polygonStrokeWidth,
const QColor &lineStrokeColor, double lineStrokeWidth,
const QColor &pointFillColor, const QColor &pointStrokeColor, double pointSize );

private:
void setDefaultStyle();

Expand Down
31 changes: 31 additions & 0 deletions tests/src/core/testqgsvectortilelayer.cpp
Expand Up @@ -20,6 +20,7 @@
//qgis includes...
#include "qgsapplication.h"
#include "qgsproject.h"
#include "qgsrenderchecker.h"
#include "qgstiles.h"
#include "qgsvectortilelayer.h"

Expand All @@ -37,6 +38,10 @@ class TestQgsVectorTileLayer : public QObject
private:
QString mDataDir;
QgsVectorTileLayer *mLayer = nullptr;
QString mReport;
QgsMapSettings *mMapSettings = nullptr;

bool imageCheck( const QString &testType, QgsVectorTileLayer *layer, QgsRectangle extent );

private slots:
void initTestCase();// will be called before the first testfunction is executed.
Expand All @@ -45,6 +50,7 @@ class TestQgsVectorTileLayer : public QObject
void cleanup() {} // will be called after every testfunction.

void test_basic();
void test_render();
};


Expand All @@ -66,6 +72,9 @@ void TestQgsVectorTileLayer::initTestCase()

QgsProject::instance()->addMapLayer( mLayer );

mMapSettings = new QgsMapSettings();
mMapSettings->setLayers( QList<QgsMapLayer *>() << mLayer );

}

void TestQgsVectorTileLayer::cleanupTestCase()
Expand All @@ -84,5 +93,27 @@ void TestQgsVectorTileLayer::test_basic()
}


bool TestQgsVectorTileLayer::imageCheck( const QString &testType, QgsVectorTileLayer *layer, QgsRectangle extent )
{
mReport += "<h2>" + testType + "</h2>\n";
mMapSettings->setExtent( extent );
mMapSettings->setDestinationCrs( layer->crs() );
mMapSettings->setOutputDpi( 96 );
QgsRenderChecker myChecker;
myChecker.setControlPathPrefix( QStringLiteral( "vector_tile" ) );
myChecker.setControlName( "expected_" + testType );
myChecker.setMapSettings( *mMapSettings );
myChecker.setColorTolerance( 15 );
bool myResultFlag = myChecker.runTest( testType, 0 );
mReport += myChecker.report();
return myResultFlag;
}

void TestQgsVectorTileLayer::test_render()
{
QVERIFY( imageCheck( "render_test_basic", mLayer, mLayer->extent() ) );
}


QGSTEST_MAIN( TestQgsVectorTileLayer )
#include "testqgsvectortilelayer.moc"
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3c33bf7

Please sign in to comment.