Skip to content

Commit fef8c1f

Browse files
committedApr 27, 2016
[FEATURE] add setting to control centroid fill point rendering
on all parts or a single part of multi-features (fixes #9199)
1 parent 77d95b0 commit fef8c1f

File tree

15 files changed

+314
-9
lines changed

15 files changed

+314
-9
lines changed
 

‎python/core/symbology-ng/qgsfillsymbollayerv2.sip

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,4 +893,11 @@ class QgsCentroidFillSymbolLayerV2 : QgsFillSymbolLayerV2
893893

894894
void setPointOnSurface( bool pointOnSurface );
895895
bool pointOnSurface() const;
896+
897+
/** Sets whether a point is drawn for all parts or only on the biggest part of multi-part features.
898+
* @note added in 2.16 */
899+
void setPointOnAllParts( bool pointOnAllParts );
900+
/** Returns whether a point is drawn for all parts or only on the biggest part of multi-part features.
901+
* @note added in 2.16 */
902+
bool pointOnAllParts() const;
896903
};

‎python/core/symbology-ng/qgssymbolv2.sip

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,24 @@ class QgsSymbolV2RenderContext
317317
//! @note added in 2.4
318318
const QgsFields* fields() const;
319319

320+
/** Part count of current geometry
321+
* @note added in QGIS 2.16
322+
*/
323+
int geometryPartCount() const;
324+
/** Sets the part count of current geometry
325+
* @note added in QGIS 2.16
326+
*/
327+
void setGeometryPartCount( int count );
328+
329+
/** Part number of current geometry
330+
* @note added in QGIS 2.16
331+
*/
332+
int geometryPartNum() const;
333+
/** Sets the part number of current geometry
334+
* @note added in QGIS 2.16
335+
*/
336+
void setGeometryPartNum( int num );
337+
320338
double outputLineWidth( double width ) const;
321339
double outputPixelSize( double size ) const;
322340

‎src/core/symbology-ng/qgsfillsymbollayerv2.cpp

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include "qgssymbollayerv2utils.h"
2020
#include "qgsdxfexport.h"
2121
#include "qgsexpression.h"
22+
#include "qgsgeometry.h"
23+
#include "qgsgeometrycollectionv2.h"
2224
#include "qgsrendercontext.h"
2325
#include "qgsproject.h"
2426
#include "qgssvgcache.h"
@@ -3384,7 +3386,7 @@ QSet<QString> QgsPointPatternFillSymbolLayer::usedAttributes() const
33843386
//////////////
33853387

33863388

3387-
QgsCentroidFillSymbolLayerV2::QgsCentroidFillSymbolLayerV2(): mMarker( nullptr ), mPointOnSurface( false )
3389+
QgsCentroidFillSymbolLayerV2::QgsCentroidFillSymbolLayerV2(): mMarker( nullptr ), mPointOnSurface( false ), mPointOnAllParts( true )
33883390
{
33893391
setSubSymbol( new QgsMarkerSymbolV2() );
33903392
}
@@ -3400,6 +3402,8 @@ QgsSymbolLayerV2* QgsCentroidFillSymbolLayerV2::create( const QgsStringMap& prop
34003402

34013403
if ( properties.contains( "point_on_surface" ) )
34023404
sl->setPointOnSurface( properties["point_on_surface"].toInt() != 0 );
3405+
if ( properties.contains( "point_on_all_parts" ) )
3406+
sl->setPointOnAllParts( properties["point_on_all_parts"].toInt() != 0 );
34033407

34043408
return sl;
34053409
}
@@ -3419,6 +3423,9 @@ void QgsCentroidFillSymbolLayerV2::startRender( QgsSymbolV2RenderContext& contex
34193423
{
34203424
mMarker->setAlpha( context.alpha() );
34213425
mMarker->startRender( context.renderContext(), context.fields() );
3426+
3427+
mCurrentFeatureId = -1;
3428+
mBiggestPartIndex = 0;
34223429
}
34233430

34243431
void QgsCentroidFillSymbolLayerV2::stopRender( QgsSymbolV2RenderContext& context )
@@ -3430,14 +3437,51 @@ void QgsCentroidFillSymbolLayerV2::renderPolygon( const QPolygonF& points, QList
34303437
{
34313438
Q_UNUSED( rings );
34323439

3433-
QPointF centroid = mPointOnSurface ? QgsSymbolLayerV2Utils::polygonPointOnSurface( points ) : QgsSymbolLayerV2Utils::polygonCentroid( points );
3434-
mMarker->renderPoint( centroid, context.feature(), context.renderContext(), -1, context.selected() );
3440+
if ( !mPointOnAllParts )
3441+
{
3442+
const QgsFeature* feature = context.feature();
3443+
if ( feature )
3444+
{
3445+
if ( feature->id() != mCurrentFeatureId )
3446+
{
3447+
mCurrentFeatureId = feature->id();
3448+
mBiggestPartIndex = 1;
3449+
3450+
if ( context.geometryPartCount() > 1 )
3451+
{
3452+
const QgsGeometry *geom = feature->constGeometry();
3453+
const QgsGeometryCollectionV2* geomCollection = dynamic_cast<const QgsGeometryCollectionV2*>( geom->geometry() );
3454+
3455+
double area = 0;
3456+
double areaBiggest = 0;
3457+
for ( int i = 0; i < context.geometryPartCount(); ++i )
3458+
{
3459+
area = geomCollection->geometryN( i )->area();
3460+
if ( area > areaBiggest )
3461+
{
3462+
areaBiggest = area;
3463+
mBiggestPartIndex = i + 1;
3464+
}
3465+
}
3466+
}
3467+
}
3468+
}
3469+
}
3470+
3471+
QgsDebugMsg( QString( "num: %1, count: %2" ).arg( context.geometryPartNum() ).arg( context.geometryPartCount() ) );
3472+
3473+
if ( mPointOnAllParts || ( context.geometryPartNum() == mBiggestPartIndex ) )
3474+
{
3475+
QPointF centroid = mPointOnSurface ? QgsSymbolLayerV2Utils::polygonPointOnSurface( points ) : QgsSymbolLayerV2Utils::polygonCentroid( points );
3476+
mMarker->renderPoint( centroid, context.feature(), context.renderContext(), -1, context.selected() );
3477+
}
34353478
}
34363479

34373480
QgsStringMap QgsCentroidFillSymbolLayerV2::properties() const
34383481
{
34393482
QgsStringMap map;
34403483
map["point_on_surface"] = QString::number( mPointOnSurface );
3484+
map["point_on_all_parts"] = QString::number( mPointOnAllParts );
34413485
return map;
34423486
}
34433487

@@ -3448,6 +3492,7 @@ QgsCentroidFillSymbolLayerV2* QgsCentroidFillSymbolLayerV2::clone() const
34483492
x->mColor = mColor;
34493493
x->setSubSymbol( mMarker->clone() );
34503494
x->setPointOnSurface( mPointOnSurface );
3495+
x->setPointOnAllParts( mPointOnAllParts );
34513496
copyPaintEffect( x );
34523497
return x;
34533498
}

‎src/core/symbology-ng/qgsfillsymbollayerv2.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,9 +1095,20 @@ class CORE_EXPORT QgsCentroidFillSymbolLayerV2 : public QgsFillSymbolLayerV2
10951095
void setPointOnSurface( bool pointOnSurface ) { mPointOnSurface = pointOnSurface; }
10961096
bool pointOnSurface() const { return mPointOnSurface; }
10971097

1098+
/** Sets whether a point is drawn for all parts or only on the biggest part of multi-part features.
1099+
* @note added in 2.16 */
1100+
void setPointOnAllParts( bool pointOnAllParts ) { mPointOnAllParts = pointOnAllParts; }
1101+
/** Returns whether a point is drawn for all parts or only on the biggest part of multi-part features.
1102+
* @note added in 2.16 */
1103+
bool pointOnAllParts() const { return mPointOnAllParts; }
1104+
10981105
protected:
10991106
QgsMarkerSymbolV2* mMarker;
11001107
bool mPointOnSurface;
1108+
bool mPointOnAllParts;
1109+
1110+
QgsFeatureId mCurrentFeatureId;
1111+
int mBiggestPartIndex;
11011112
};
11021113

11031114
#endif

‎src/core/symbology-ng/qgssymbolv2.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -733,11 +733,14 @@ void QgsSymbolV2::renderFeature( const QgsFeature& feature, QgsRenderContext& co
733733
deleteSegmentizedGeometry = true;
734734
}
735735

736+
mSymbolRenderContext->setGeometryPartCount( segmentizedGeometry->geometry()->partCount() );
737+
mSymbolRenderContext->setGeometryPartNum( 1 );
738+
736739
if ( mSymbolRenderContext->expressionContextScope() )
737740
{
738741
context.expressionContext().appendScope( mSymbolRenderContext->expressionContextScope() );
739742
QgsExpressionContextUtils::updateSymbolScope( this, mSymbolRenderContext->expressionContextScope() );
740-
mSymbolRenderContext->expressionContextScope()->setVariable( QgsExpressionContext::EXPR_GEOMETRY_PART_COUNT, segmentizedGeometry->geometry()->partCount() );
743+
mSymbolRenderContext->expressionContextScope()->setVariable( QgsExpressionContext::EXPR_GEOMETRY_PART_COUNT, mSymbolRenderContext->geometryPartCount() );
741744
mSymbolRenderContext->expressionContextScope()->setVariable( QgsExpressionContext::EXPR_GEOMETRY_PART_NUM, 1 );
742745
}
743746

@@ -833,6 +836,7 @@ void QgsSymbolV2::renderFeature( const QgsFeature& feature, QgsRenderContext& co
833836

834837
for ( int i = 0; i < mp->numGeometries(); ++i )
835838
{
839+
mSymbolRenderContext->setGeometryPartNum( i + 1 );
836840
mSymbolRenderContext->expressionContextScope()->setVariable( QgsExpressionContext::EXPR_GEOMETRY_PART_NUM, i + 1 );
837841

838842
const QgsPointV2* point = static_cast< const QgsPointV2* >( mp->geometryN( i ) );
@@ -868,6 +872,7 @@ void QgsSymbolV2::renderFeature( const QgsFeature& feature, QgsRenderContext& co
868872

869873
for ( unsigned int i = 0; i < num && wkbPtr; ++i )
870874
{
875+
mSymbolRenderContext->setGeometryPartNum( i + 1 );
871876
mSymbolRenderContext->expressionContextScope()->setVariable( QgsExpressionContext::EXPR_GEOMETRY_PART_NUM, i + 1 );
872877

873878
if ( geomCollection )
@@ -914,6 +919,7 @@ void QgsSymbolV2::renderFeature( const QgsFeature& feature, QgsRenderContext& co
914919

915920
for ( unsigned int i = 0; i < num && wkbPtr; ++i )
916921
{
922+
mSymbolRenderContext->setGeometryPartNum( i + 1 );
917923
mSymbolRenderContext->expressionContextScope()->setVariable( QgsExpressionContext::EXPR_GEOMETRY_PART_NUM, i + 1 );
918924

919925
if ( geomCollection )
@@ -1002,7 +1008,9 @@ QgsSymbolV2RenderContext::QgsSymbolV2RenderContext( QgsRenderContext& c, QgsSymb
10021008
mSelected( selected ),
10031009
mRenderHints( renderHints ),
10041010
mFeature( f ),
1005-
mFields( fields )
1011+
mFields( fields ),
1012+
mGeometryPartCount( 0 ),
1013+
mGeometryPartNum( 0 )
10061014
{
10071015
}
10081016

@@ -1440,6 +1448,8 @@ void QgsMarkerSymbolV2::renderPointUsingLayer( QgsMarkerSymbolLayerV2* layer, QP
14401448
void QgsMarkerSymbolV2::renderPoint( QPointF point, const QgsFeature* f, QgsRenderContext& context, int layerIdx, bool selected )
14411449
{
14421450
QgsSymbolV2RenderContext symbolContext( context, outputUnit(), mAlpha, selected, mRenderHints, f, nullptr, mapUnitScale() );
1451+
symbolContext.setGeometryPartCount( symbolRenderContext()->geometryPartCount() );
1452+
symbolContext.setGeometryPartNum( symbolRenderContext()->geometryPartNum() );
14431453

14441454
if ( layerIdx != -1 )
14451455
{
@@ -1646,6 +1656,8 @@ void QgsLineSymbolV2::renderPolyline( const QPolygonF& points, const QgsFeature*
16461656
//save old painter
16471657
QPainter* renderPainter = context.painter();
16481658
QgsSymbolV2RenderContext symbolContext( context, outputUnit(), mAlpha, selected, mRenderHints, f, nullptr, mapUnitScale() );
1659+
symbolContext.setGeometryPartCount( symbolRenderContext()->geometryPartCount() );
1660+
symbolContext.setGeometryPartNum( symbolRenderContext()->geometryPartNum() );
16491661

16501662
if ( layerIdx != -1 )
16511663
{
@@ -1723,6 +1735,8 @@ QgsFillSymbolV2::QgsFillSymbolV2( const QgsSymbolLayerV2List& layers )
17231735
void QgsFillSymbolV2::renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, const QgsFeature* f, QgsRenderContext& context, int layerIdx, bool selected )
17241736
{
17251737
QgsSymbolV2RenderContext symbolContext( context, outputUnit(), mAlpha, selected, mRenderHints, f, nullptr, mapUnitScale() );
1738+
symbolContext.setGeometryPartCount( symbolRenderContext()->geometryPartCount() );
1739+
symbolContext.setGeometryPartNum( symbolRenderContext()->geometryPartNum() );
17261740

17271741
if ( layerIdx != -1 )
17281742
{

‎src/core/symbology-ng/qgssymbolv2.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,24 @@ class CORE_EXPORT QgsSymbolV2RenderContext
379379
//! @note added in 2.4
380380
const QgsFields* fields() const { return mFields; }
381381

382+
/** Part count of current geometry
383+
* @note added in QGIS 2.16
384+
*/
385+
int geometryPartCount() const { return mGeometryPartCount; }
386+
/** Sets the part count of current geometry
387+
* @note added in QGIS 2.16
388+
*/
389+
void setGeometryPartCount( int count ) { mGeometryPartCount = count; }
390+
391+
/** Part number of current geometry
392+
* @note added in QGIS 2.16
393+
*/
394+
int geometryPartNum() const { return mGeometryPartNum; }
395+
/** Sets the part number of current geometry
396+
* @note added in QGIS 2.16
397+
*/
398+
void setGeometryPartNum( int num ) { mGeometryPartNum = num; }
399+
382400
double outputLineWidth( double width ) const;
383401
double outputPixelSize( double size ) const;
384402

@@ -410,6 +428,8 @@ class CORE_EXPORT QgsSymbolV2RenderContext
410428
int mRenderHints;
411429
const QgsFeature* mFeature; //current feature
412430
const QgsFields* mFields;
431+
int mGeometryPartCount;
432+
int mGeometryPartNum;
413433

414434

415435
QgsSymbolV2RenderContext( const QgsSymbolV2RenderContext& rh );

‎src/gui/symbology-ng/qgssymbollayerv2widget.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2737,9 +2737,8 @@ void QgsCentroidFillSymbolLayerV2Widget::setSymbolLayer( QgsSymbolLayerV2* layer
27372737
mLayer = static_cast<QgsCentroidFillSymbolLayerV2*>( layer );
27382738

27392739
// set values
2740-
mDrawInsideCheckBox->blockSignals( true );
2741-
mDrawInsideCheckBox->setChecked( mLayer->pointOnSurface() );
2742-
mDrawInsideCheckBox->blockSignals( false );
2740+
whileBlocking( mDrawInsideCheckBox )->setChecked( mLayer->pointOnSurface() );
2741+
whileBlocking( mDrawAllPartsCheckBox )->setChecked( mLayer->pointOnAllParts() );
27432742
}
27442743

27452744
QgsSymbolLayerV2* QgsCentroidFillSymbolLayerV2Widget::symbolLayer()
@@ -2753,6 +2752,12 @@ void QgsCentroidFillSymbolLayerV2Widget::on_mDrawInsideCheckBox_stateChanged( in
27532752
emit changed();
27542753
}
27552754

2755+
void QgsCentroidFillSymbolLayerV2Widget::on_mDrawAllPartsCheckBox_stateChanged( int state )
2756+
{
2757+
mLayer->setPointOnAllParts( state == Qt::Checked );
2758+
emit changed();
2759+
}
2760+
27562761
///////////////
27572762

27582763
QgsRasterFillSymbolLayerWidget::QgsRasterFillSymbolLayerWidget( const QgsVectorLayer *vl, QWidget *parent )

‎src/gui/symbology-ng/qgssymbollayerv2widget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,7 @@ class GUI_EXPORT QgsCentroidFillSymbolLayerV2Widget : public QgsSymbolLayerV2Wid
627627

628628
private slots:
629629
void on_mDrawInsideCheckBox_stateChanged( int state );
630+
void on_mDrawAllPartsCheckBox_stateChanged( int state );
630631

631632
};
632633

‎src/ui/symbollayer/widget_centroidfill.ui

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
</property>
1616
<layout class="QVBoxLayout" name="verticalLayout">
1717
<item>
18-
<layout class="QHBoxLayout" name="horizontalLayout">
18+
<layout class="QHBoxLayout" name="horizontalLayout_1">
1919
<item>
2020
<widget class="QCheckBox" name="mDrawInsideCheckBox">
2121
<property name="text">
@@ -41,6 +41,20 @@
4141
</item>
4242
</layout>
4343
</item>
44+
<item>
45+
<layout class="QHBoxLayout" name="horizontalLayout">
46+
<item>
47+
<widget class="QCheckBox" name="mDrawAllPartsCheckBox">
48+
<property name="text">
49+
<string>Draw point on every part of multi-part features</string>
50+
</property>
51+
<property name="toolTip">
52+
<string>When unchecked, a single point will be drawn on the biggest part of multi-part features</string>
53+
</property>
54+
</widget>
55+
</item>
56+
</layout>
57+
</item>
4458
<item>
4559
<spacer>
4660
<property name="orientation">

‎tests/src/core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ ADD_QGIS_TEST(invertedpolygontest testqgsinvertedpolygonrenderer.cpp )
145145
ADD_QGIS_TEST(labelingenginev2 testqgslabelingenginev2.cpp)
146146
ADD_QGIS_TEST(layertree testqgslayertree.cpp)
147147
ADD_QGIS_TEST(legendrenderertest testqgslegendrenderer.cpp )
148+
ADD_QGIS_TEST(centroidfillsymboltest testqgscentroidfillsymbol.cpp )
148149
ADD_QGIS_TEST(linefillsymboltest testqgslinefillsymbol.cpp )
149150
ADD_QGIS_TEST(maplayerstylemanager testqgsmaplayerstylemanager.cpp )
150151
ADD_QGIS_TEST(maplayertest testqgsmaplayer.cpp)
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
/***************************************************************************
2+
TestQgsCentroidFillSymbol.cpp
3+
-------------------------
4+
Date : Apr 2015
5+
Copyright : (C) 2015 by Mathieu Pellerin
6+
Email : nirvn dot asia at gmail dot com
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+
#include <QtTest/QtTest>
16+
#include <QObject>
17+
#include <QString>
18+
#include <QStringList>
19+
#include <QApplication>
20+
#include <QFileInfo>
21+
#include <QDir>
22+
#include <QDesktopServices>
23+
24+
//qgis includes...
25+
#include <qgsmaprenderer.h>
26+
#include <qgsmaplayer.h>
27+
#include <qgsvectorlayer.h>
28+
#include <qgsapplication.h>
29+
#include <qgsproviderregistry.h>
30+
#include <qgsmaplayerregistry.h>
31+
#include <qgssymbolv2.h>
32+
#include <qgssinglesymbolrendererv2.h>
33+
#include <qgsfillsymbollayerv2.h>
34+
35+
//qgis test includes
36+
#include "qgsrenderchecker.h"
37+
38+
/** \ingroup UnitTests
39+
* This is a unit test for line fill symbol types.
40+
*/
41+
class TestQgsCentroidFillSymbol : public QObject
42+
{
43+
Q_OBJECT
44+
45+
public:
46+
TestQgsCentroidFillSymbol()
47+
: mTestHasError( false )
48+
, mpPolysLayer( 0 )
49+
, mCentroidFill( 0 )
50+
, mFillSymbol( 0 )
51+
, mSymbolRenderer( 0 )
52+
{}
53+
54+
private slots:
55+
void initTestCase();// will be called before the first testfunction is executed.
56+
void cleanupTestCase();// will be called after the last testfunction was executed.
57+
void init() {} // will be called before each testfunction is executed.
58+
void cleanup() {} // will be called after every testfunction.
59+
60+
void centroidFillSymbol();
61+
void centroidFillSymbolPartBiggest();
62+
63+
private:
64+
bool mTestHasError;
65+
66+
bool imageCheck( const QString& theType );
67+
QgsMapSettings mMapSettings;
68+
QgsVectorLayer * mpPolysLayer;
69+
QgsCentroidFillSymbolLayerV2* mCentroidFill;
70+
QgsFillSymbolV2* mFillSymbol;
71+
QgsSingleSymbolRendererV2* mSymbolRenderer;
72+
QString mTestDataDir;
73+
QString mReport;
74+
};
75+
76+
77+
void TestQgsCentroidFillSymbol::initTestCase()
78+
{
79+
mTestHasError = false;
80+
// init QGIS's paths - true means that all path will be inited from prefix
81+
QgsApplication::init();
82+
QgsApplication::initQgis();
83+
QgsApplication::showSettings();
84+
85+
//create some objects that will be used in all tests...
86+
QString myDataDir( TEST_DATA_DIR ); //defined in CmakeLists.txt
87+
mTestDataDir = myDataDir + '/';
88+
89+
//
90+
//create a poly layer that will be used in all tests...
91+
//
92+
QString myPolysFileName = mTestDataDir + "polys.shp";
93+
QFileInfo myPolyFileInfo( myPolysFileName );
94+
mpPolysLayer = new QgsVectorLayer( myPolyFileInfo.filePath(),
95+
myPolyFileInfo.completeBaseName(), "ogr" );
96+
97+
QgsVectorSimplifyMethod simplifyMethod;
98+
simplifyMethod.setSimplifyHints( QgsVectorSimplifyMethod::NoSimplification );
99+
mpPolysLayer->setSimplifyMethod( simplifyMethod );
100+
101+
// Register the layer with the registry
102+
QgsMapLayerRegistry::instance()->addMapLayers(
103+
QList<QgsMapLayer *>() << mpPolysLayer );
104+
105+
//setup gradient fill
106+
mCentroidFill = new QgsCentroidFillSymbolLayerV2();
107+
mFillSymbol = new QgsFillSymbolV2();
108+
mFillSymbol->changeSymbolLayer( 0, mCentroidFill );
109+
mSymbolRenderer = new QgsSingleSymbolRendererV2( mFillSymbol );
110+
mpPolysLayer->setRendererV2( mSymbolRenderer );
111+
112+
// We only need maprender instead of mapcanvas
113+
// since maprender does not require a qui
114+
// and is more light weight
115+
//
116+
mMapSettings.setLayers( QStringList() << mpPolysLayer->id() );
117+
mReport += "<h1>Centroid Fill Symbol Tests</h1>\n";
118+
119+
}
120+
void TestQgsCentroidFillSymbol::cleanupTestCase()
121+
{
122+
QString myReportFile = QDir::tempPath() + "/qgistest.html";
123+
QFile myFile( myReportFile );
124+
if ( myFile.open( QIODevice::WriteOnly | QIODevice::Append ) )
125+
{
126+
QTextStream myQTextStream( &myFile );
127+
myQTextStream << mReport;
128+
myFile.close();
129+
}
130+
131+
QgsApplication::exitQgis();
132+
}
133+
134+
void TestQgsCentroidFillSymbol::centroidFillSymbol()
135+
{
136+
mReport += "<h2>Line fill symbol renderer test</h2>\n";
137+
138+
QVERIFY( imageCheck( "symbol_centroidfill" ) );
139+
}
140+
141+
void TestQgsCentroidFillSymbol::centroidFillSymbolPartBiggest()
142+
{
143+
mCentroidFill->setPointOnAllParts( false );
144+
145+
QVERIFY( imageCheck( "symbol_centroidfill_part_biggest" ) );
146+
}
147+
148+
//
149+
// Private helper functions not called directly by CTest
150+
//
151+
152+
153+
bool TestQgsCentroidFillSymbol::imageCheck( const QString& theTestType )
154+
{
155+
//use the QgsRenderChecker test utility class to
156+
//ensure the rendered output matches our control image
157+
mMapSettings.setExtent( mpPolysLayer->extent() );
158+
mMapSettings.setOutputDpi( 96 );
159+
QgsRenderChecker myChecker;
160+
myChecker.setControlPathPrefix( "symbol_centroidfill" );
161+
myChecker.setControlName( "expected_" + theTestType );
162+
myChecker.setMapSettings( mMapSettings );
163+
bool myResultFlag = myChecker.runTest( theTestType );
164+
mReport += myChecker.report();
165+
return myResultFlag;
166+
}
167+
168+
QTEST_MAIN( TestQgsCentroidFillSymbol )
169+
#include "testqgscentroidfillsymbol.moc"

0 commit comments

Comments
 (0)
Please sign in to comment.