Skip to content

Commit 8b37ea2

Browse files
committedMar 28, 2015
[FEATURE] Add option to symbology to prevent clipping of features
This option (located under the symbol advanced menu) disables the automatic clipping of lines/polygons to the canvas extent. In some cases this clipping results in unfavourable symbology (eg centroid fills where the centroid must always be the actual feature's centroid). (fix #9757)
1 parent 742f323 commit 8b37ea2

18 files changed

+230
-19
lines changed
 

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,8 @@ class QgsFeatureRendererV2
229229
void renderVertexMarkerPolygon( QPolygonF& pts, QList<QPolygonF>* rings, QgsRenderContext& context );
230230

231231
static const unsigned char* _getPoint( QPointF& pt, QgsRenderContext& context, const unsigned char* wkb );
232-
static const unsigned char* _getLineString( QPolygonF& pts, QgsRenderContext& context, const unsigned char* wkb );
233-
static const unsigned char* _getPolygon( QPolygonF& pts, QList<QPolygonF>& holes, QgsRenderContext& context, const unsigned char* wkb );
232+
static const unsigned char* _getLineString( QPolygonF& pts, QgsRenderContext& context, const unsigned char* wkb, bool clipToExtent = true );
233+
static const unsigned char* _getPolygon( QPolygonF& pts, QList<QPolygonF>& holes, QgsRenderContext& context, const unsigned char* wkb, bool clipToExtent = true );
234234

235235
void setScaleMethodToSymbol( QgsSymbolV2* symbol, int scaleMethod );
236236

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,26 @@ class QgsSymbolV2
130130
void setRenderHints( int hints );
131131
int renderHints() const;
132132

133+
/**Sets whether features drawn by the symbol should be clipped to the render context's
134+
* extent. If this option is enabled then features which are partially outside the extent
135+
* will be clipped. This speeds up rendering of the feature, but may have undesirable
136+
* side effects for certain symbol types.
137+
* @param clipFeaturesToExtent set to true to enable clipping (defaults to true)
138+
* @note added in QGIS 2.9
139+
* @see clipFeaturesToExtent
140+
*/
141+
void setClipFeaturesToExtent( bool clipFeaturesToExtent );
142+
143+
/**Returns whether features drawn by the symbol will be clipped to the render context's
144+
* extent. If this option is enabled then features which are partially outside the extent
145+
* will be clipped. This speeds up rendering of the feature, but may have undesirable
146+
* side effects for certain symbol types.
147+
* @returns true if features will be clipped
148+
* @note added in QGIS 2.9
149+
* @see setClipFeaturesToExtent
150+
*/
151+
double clipFeaturesToExtent() const;
152+
133153
QSet<QString> usedAttributes() const;
134154

135155
void setLayer( const QgsVectorLayer* layer );

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

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,21 @@ const unsigned char* QgsFeatureRendererV2::_getPoint( QPointF& pt, QgsRenderCont
5858
return wkbPtr;
5959
}
6060

61-
const unsigned char* QgsFeatureRendererV2::_getLineString( QPolygonF& pts, QgsRenderContext& context, const unsigned char* wkb )
61+
const unsigned char* QgsFeatureRendererV2::_getLineString( QPolygonF& pts, QgsRenderContext& context, const unsigned char* wkb, bool clipToExtent )
6262
{
63-
QgsConstWkbPtr wkbPtr( wkb );
63+
QgsConstWkbPtr wkbPtr( wkb + 1 );
6464
unsigned int wkbType, nPoints;
6565
wkbPtr >> wkbType >> nPoints;
6666

6767
bool hasZValue = wkbType == QGis::WKBLineString25D;
6868

69-
double x, y;
69+
double x = 0.0;
70+
double y = 0.0;
7071
const QgsCoordinateTransform* ct = context.coordinateTransform();
7172
const QgsMapToPixel& mtp = context.mapToPixel();
7273

7374
//apply clipping for large lines to achieve a better rendering performance
74-
if ( nPoints > 1 )
75+
if ( clipToExtent && nPoints > 1 )
7576
{
7677
const QgsRectangle& e = context.extent();
7778
double cw = e.width() / 10; double ch = e.height() / 10;
@@ -108,7 +109,7 @@ const unsigned char* QgsFeatureRendererV2::_getLineString( QPolygonF& pts, QgsRe
108109
return wkbPtr;
109110
}
110111

111-
const unsigned char* QgsFeatureRendererV2::_getPolygon( QPolygonF& pts, QList<QPolygonF>& holes, QgsRenderContext& context, const unsigned char* wkb )
112+
const unsigned char* QgsFeatureRendererV2::_getPolygon( QPolygonF& pts, QList<QPolygonF>& holes, QgsRenderContext& context, const unsigned char* wkb, bool clipToExtent )
112113
{
113114
QgsConstWkbPtr wkbPtr( wkb + 1 );
114115

@@ -152,7 +153,7 @@ const unsigned char* QgsFeatureRendererV2::_getPolygon( QPolygonF& pts, QList<QP
152153

153154
//clip close to view extent, if needed
154155
QRectF ptsRect = poly.boundingRect();
155-
if ( !context.extent().contains( ptsRect ) ) QgsClipper::trimPolygon( poly, clipRect );
156+
if ( clipToExtent && !context.extent().contains( ptsRect ) ) QgsClipper::trimPolygon( poly, clipRect );
156157

157158
//transform the QPolygonF to screen coordinates
158159
if ( ct )
@@ -271,7 +272,7 @@ void QgsFeatureRendererV2::renderFeatureWithSymbol( QgsFeature& feature, QgsSymb
271272
break;
272273
}
273274
QPolygonF pts;
274-
_getLineString( pts, context, geom->asWkb() );
275+
_getLineString( pts, context, geom->asWkb(), symbol->clipFeaturesToExtent() );
275276
(( QgsLineSymbolV2* )symbol )->renderPolyline( pts, &feature, context, layer, selected );
276277

277278
if ( drawVertexMarker )
@@ -289,7 +290,7 @@ void QgsFeatureRendererV2::renderFeatureWithSymbol( QgsFeature& feature, QgsSymb
289290
}
290291
QPolygonF pts;
291292
QList<QPolygonF> holes;
292-
_getPolygon( pts, holes, context, geom->asWkb() );
293+
_getPolygon( pts, holes, context, geom->asWkb(), symbol->clipFeaturesToExtent() );
293294
(( QgsFillSymbolV2* )symbol )->renderPolygon( pts, ( holes.count() ? &holes : NULL ), &feature, context, layer, selected );
294295

295296
if ( drawVertexMarker )
@@ -306,7 +307,7 @@ void QgsFeatureRendererV2::renderFeatureWithSymbol( QgsFeature& feature, QgsSymb
306307
break;
307308
}
308309

309-
QgsConstWkbPtr wkbPtr( geom->asWkb() + 5 );
310+
QgsConstWkbPtr wkbPtr( geom->asWkb() + 1 + sizeof( int ) );
310311
unsigned int num;
311312
wkbPtr >> num;
312313
const unsigned char* ptr = wkbPtr;
@@ -332,15 +333,15 @@ void QgsFeatureRendererV2::renderFeatureWithSymbol( QgsFeature& feature, QgsSymb
332333
break;
333334
}
334335

335-
QgsConstWkbPtr wkbPtr( geom->asWkb() + 5 );
336+
QgsConstWkbPtr wkbPtr( geom->asWkb() + 1 + sizeof( int ) );
336337
unsigned int num;
337338
wkbPtr >> num;
338339
const unsigned char* ptr = wkbPtr;
339340
QPolygonF pts;
340341

341342
for ( unsigned int i = 0; i < num; ++i )
342343
{
343-
ptr = QgsConstWkbPtr( _getLineString( pts, context, ptr ) );
344+
ptr = QgsConstWkbPtr( _getLineString( pts, context, ptr, symbol->clipFeaturesToExtent() ) );
344345
(( QgsLineSymbolV2* )symbol )->renderPolyline( pts, &feature, context, layer, selected );
345346

346347
if ( drawVertexMarker )
@@ -358,7 +359,7 @@ void QgsFeatureRendererV2::renderFeatureWithSymbol( QgsFeature& feature, QgsSymb
358359
break;
359360
}
360361

361-
QgsConstWkbPtr wkbPtr( geom->asWkb() + 5 );
362+
QgsConstWkbPtr wkbPtr( geom->asWkb() + 1 + sizeof( int ) );
362363
unsigned int num;
363364
wkbPtr >> num;
364365
const unsigned char* ptr = wkbPtr;
@@ -367,7 +368,7 @@ void QgsFeatureRendererV2::renderFeatureWithSymbol( QgsFeature& feature, QgsSymb
367368

368369
for ( unsigned int i = 0; i < num; ++i )
369370
{
370-
ptr = _getPolygon( pts, holes, context, ptr );
371+
ptr = _getPolygon( pts, holes, context, ptr, symbol->clipFeaturesToExtent() );
371372
(( QgsFillSymbolV2* )symbol )->renderPolygon( pts, ( holes.count() ? &holes : NULL ), &feature, context, layer, selected );
372373

373374
if ( drawVertexMarker )

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,8 @@ class CORE_EXPORT QgsFeatureRendererV2
251251
void renderVertexMarkerPolygon( QPolygonF& pts, QList<QPolygonF>* rings, QgsRenderContext& context );
252252

253253
static const unsigned char* _getPoint( QPointF& pt, QgsRenderContext& context, const unsigned char* wkb );
254-
static const unsigned char* _getLineString( QPolygonF& pts, QgsRenderContext& context, const unsigned char* wkb );
255-
static const unsigned char* _getPolygon( QPolygonF& pts, QList<QPolygonF>& holes, QgsRenderContext& context, const unsigned char* wkb );
254+
static const unsigned char* _getLineString( QPolygonF& pts, QgsRenderContext& context, const unsigned char* wkb, bool clipToExtent = true );
255+
static const unsigned char* _getPolygon( QPolygonF& pts, QList<QPolygonF>& holes, QgsRenderContext& context, const unsigned char* wkb, bool clipToExtent = true );
256256

257257
void setScaleMethodToSymbol( QgsSymbolV2* symbol, int scaleMethod );
258258

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,7 @@ QgsSymbolV2* QgsSymbolLayerV2Utils::loadSymbol( const QDomElement &element )
940940
symbol->setMapUnitScale( mapUnitScale );
941941
}
942942
symbol->setAlpha( element.attribute( "alpha", "1.0" ).toDouble() );
943+
symbol->setClipFeaturesToExtent( element.attribute( "clip_to_extent", "1" ).toInt() );
943944

944945
return symbol;
945946
}
@@ -993,6 +994,7 @@ QDomElement QgsSymbolLayerV2Utils::saveSymbol( QString name, QgsSymbolV2* symbol
993994
symEl.setAttribute( "type", _nameForSymbolType( symbol->type() ) );
994995
symEl.setAttribute( "name", name );
995996
symEl.setAttribute( "alpha", QString::number( symbol->alpha() ) );
997+
symEl.setAttribute( "clip_to_extent", symbol->clipFeaturesToExtent() ? "1" : "0" );
996998
QgsDebugMsg( "num layers " + QString::number( symbol->symbolLayerCount() ) );
997999

9981000
for ( int i = 0; i < symbol->symbolLayerCount(); i++ )

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ QgsSymbolV2::QgsSymbolV2( SymbolType type, QgsSymbolLayerV2List layers )
4040
, mLayers( layers )
4141
, mAlpha( 1.0 )
4242
, mRenderHints( 0 )
43+
, mClipFeaturesToExtent( true )
4344
, mLayer( 0 )
4445
{
4546

@@ -631,6 +632,7 @@ QgsSymbolV2* QgsMarkerSymbolV2::clone() const
631632
QgsSymbolV2* cloneSymbol = new QgsMarkerSymbolV2( cloneLayers() );
632633
cloneSymbol->setAlpha( mAlpha );
633634
cloneSymbol->setLayer( mLayer );
635+
cloneSymbol->setClipFeaturesToExtent( mClipFeaturesToExtent );
634636
return cloneSymbol;
635637
}
636638

@@ -728,6 +730,7 @@ QgsSymbolV2* QgsLineSymbolV2::clone() const
728730
QgsSymbolV2* cloneSymbol = new QgsLineSymbolV2( cloneLayers() );
729731
cloneSymbol->setAlpha( mAlpha );
730732
cloneSymbol->setLayer( mLayer );
733+
cloneSymbol->setClipFeaturesToExtent( mClipFeaturesToExtent );
731734
return cloneSymbol;
732735
}
733736

@@ -834,6 +837,7 @@ QgsSymbolV2* QgsFillSymbolV2::clone() const
834837
QgsSymbolV2* cloneSymbol = new QgsFillSymbolV2( cloneLayers() );
835838
cloneSymbol->setAlpha( mAlpha );
836839
cloneSymbol->setLayer( mLayer );
840+
cloneSymbol->setClipFeaturesToExtent( mClipFeaturesToExtent );
837841
return cloneSymbol;
838842
}
839843

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,26 @@ class CORE_EXPORT QgsSymbolV2
161161
void setRenderHints( int hints ) { mRenderHints = hints; }
162162
int renderHints() const { return mRenderHints; }
163163

164+
/**Sets whether features drawn by the symbol should be clipped to the render context's
165+
* extent. If this option is enabled then features which are partially outside the extent
166+
* will be clipped. This speeds up rendering of the feature, but may have undesirable
167+
* side effects for certain symbol types.
168+
* @param clipFeaturesToExtent set to true to enable clipping (defaults to true)
169+
* @note added in QGIS 2.9
170+
* @see clipFeaturesToExtent
171+
*/
172+
void setClipFeaturesToExtent( bool clipFeaturesToExtent ) { mClipFeaturesToExtent = clipFeaturesToExtent; }
173+
174+
/**Returns whether features drawn by the symbol will be clipped to the render context's
175+
* extent. If this option is enabled then features which are partially outside the extent
176+
* will be clipped. This speeds up rendering of the feature, but may have undesirable
177+
* side effects for certain symbol types.
178+
* @returns true if features will be clipped
179+
* @note added in QGIS 2.9
180+
* @see setClipFeaturesToExtent
181+
*/
182+
double clipFeaturesToExtent() const { return mClipFeaturesToExtent; }
183+
164184
QSet<QString> usedAttributes() const;
165185

166186
void setLayer( const QgsVectorLayer* layer ) { mLayer = layer; }
@@ -182,6 +202,7 @@ class CORE_EXPORT QgsSymbolV2
182202
qreal mAlpha;
183203

184204
int mRenderHints;
205+
bool mClipFeaturesToExtent;
185206

186207
const QgsVectorLayer* mLayer; //current vectorlayer
187208

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

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@
3535
#include <QMenu>
3636

3737

38-
QgsSymbolsListWidget::QgsSymbolsListWidget( QgsSymbolV2* symbol, QgsStyleV2* style, QMenu* menu, QWidget* parent ) : QWidget( parent )
38+
QgsSymbolsListWidget::QgsSymbolsListWidget( QgsSymbolV2* symbol, QgsStyleV2* style, QMenu* menu, QWidget* parent )
39+
: QWidget( parent )
40+
, mAdvancedMenu( 0 )
41+
, mClipFeaturesAction( 0 )
3942
{
4043
mSymbol = symbol;
4144
mStyle = style;
@@ -47,9 +50,17 @@ QgsSymbolsListWidget::QgsSymbolsListWidget( QgsSymbolV2* symbol, QgsStyleV2* sty
4750
btnAdvanced->hide(); // advanced button is hidden by default
4851
if ( menu ) // show it if there is a menu pointer
4952
{
50-
btnAdvanced->setMenu( menu );
53+
mAdvancedMenu = menu;
5154
btnAdvanced->show();
55+
btnAdvanced->setMenu( mAdvancedMenu );
5256
}
57+
else
58+
{
59+
btnAdvanced->setMenu( new QMenu( this ) );
60+
}
61+
mClipFeaturesAction = new QAction( tr( "Clip features to canvas extent" ), this );
62+
mClipFeaturesAction->setCheckable( true );
63+
connect( mClipFeaturesAction, SIGNAL( toggled( bool ) ), this, SLOT( clipFeaturesToggled( bool ) ) );
5364

5465
// populate the groups
5566
groupsCombo->addItem( "" );
@@ -163,6 +174,15 @@ void QgsSymbolsListWidget::openStyleManager()
163174
populateSymbolView();
164175
}
165176

177+
void QgsSymbolsListWidget::clipFeaturesToggled( bool checked )
178+
{
179+
if ( !mSymbol )
180+
return;
181+
182+
mSymbol->setClipFeaturesToExtent( checked );
183+
emit changed();
184+
}
185+
166186
void QgsSymbolsListWidget::setSymbolColor( const QColor& color )
167187
{
168188
mSymbol->setColor( color );
@@ -294,6 +314,21 @@ void QgsSymbolsListWidget::updateSymbolInfo()
294314
mTransparencySlider->setValue( transparency * 255 );
295315
displayTransparency( mSymbol->alpha() );
296316
mTransparencySlider->blockSignals( false );
317+
318+
if ( mSymbol->type() == QgsSymbolV2::Line || mSymbol->type() == QgsSymbolV2::Fill )
319+
{
320+
//add clip features option for line or fill symbols
321+
btnAdvanced->menu()->addAction( mClipFeaturesAction );
322+
}
323+
else
324+
{
325+
btnAdvanced->menu()->removeAction( mClipFeaturesAction );
326+
}
327+
btnAdvanced->setVisible( mAdvancedMenu || !btnAdvanced->menu()->isEmpty() );
328+
329+
mClipFeaturesAction->blockSignals( true );
330+
mClipFeaturesAction->setChecked( mSymbol->clipFeaturesToExtent() );
331+
mClipFeaturesAction->blockSignals( false );
297332
}
298333

299334
void QgsSymbolsListWidget::setSymbolFromStyle( const QModelIndex & index )

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,16 @@ class GUI_EXPORT QgsSymbolsListWidget : public QWidget, private Ui::SymbolsListW
4747
void on_groupsCombo_editTextChanged( const QString &text );
4848

4949
void openStyleManager();
50+
void clipFeaturesToggled( bool checked );
5051

5152
signals:
5253
void changed();
5354

5455
protected:
5556
QgsSymbolV2* mSymbol;
5657
QgsStyleV2* mStyle;
58+
QMenu* mAdvancedMenu;
59+
QAction* mClipFeaturesAction;
5760

5861
void populateSymbolView();
5962
void populateSymbols( QStringList symbols );

‎tests/src/core/testqgsstylev2.cpp

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,17 @@
2020
#include <QFileInfo>
2121

2222
//qgis includes...
23+
#include "qgsmultirenderchecker.h"
2324
#include <qgsapplication.h>
2425
#include "qgsconfig.h"
2526
#include "qgslogger.h"
2627
#include "qgsvectorcolorrampv2.h"
2728
#include "qgscptcityarchive.h"
29+
#include "qgsvectorlayer.h"
30+
#include "qgsmaplayerregistry.h"
31+
#include "qgslinesymbollayerv2.h"
32+
#include "qgsfillsymbollayerv2.h"
33+
#include "qgssinglesymbolrendererv2.h"
2834

2935
#include "qgsstylev2.h"
3036

@@ -40,10 +46,18 @@ class TestStyleV2 : public QObject
4046

4147
private:
4248

49+
QString mReport;
50+
4351
QgsStyleV2 *mStyle;
4452
QString mTestDataDir;
4553

54+
QgsMapSettings mMapSettings;
55+
QgsVectorLayer * mpPointsLayer;
56+
QgsVectorLayer * mpLinesLayer;
57+
QgsVectorLayer * mpPolysLayer;
58+
4659
bool testValidColor( QgsVectorColorRampV2 *ramp, double value, QColor expected );
60+
bool imageCheck( QgsMapSettings &ms, const QString &testName );
4761

4862
private slots:
4963

@@ -54,11 +68,14 @@ class TestStyleV2 : public QObject
5468
void cleanup() {}// will be called after every testfunction.
5569
// void initStyles();
5670

71+
void testCanvasClip();
5772
void testCreateColorRamps();
5873
void testLoadColorRamps();
5974
void testSaveLoad();
6075
void testParseColor();
6176
void testParseColorList();
77+
78+
6279
};
6380

6481
TestStyleV2::TestStyleV2()
@@ -96,6 +113,44 @@ void TestStyleV2::initTestCase()
96113

97114
// cpt-city ramp, small selection available in <testdir>/cpt-city
98115
QgsCptCityArchive::initArchives();
116+
117+
//
118+
//create a point layer that will be used in all tests...
119+
//
120+
QString myDataDir( TEST_DATA_DIR ); //defined in CmakeLists.txt
121+
mTestDataDir = myDataDir + QDir::separator();
122+
QString myPointsFileName = mTestDataDir + "points.shp";
123+
QFileInfo myPointFileInfo( myPointsFileName );
124+
mpPointsLayer = new QgsVectorLayer( myPointFileInfo.filePath(),
125+
myPointFileInfo.completeBaseName(), "ogr" );
126+
// Register the layer with the registry
127+
QgsMapLayerRegistry::instance()->addMapLayers(
128+
QList<QgsMapLayer *>() << mpPointsLayer );
129+
130+
//
131+
//create a poly layer that will be used in all tests...
132+
//
133+
QString myPolysFileName = mTestDataDir + "polys.shp";
134+
QFileInfo myPolyFileInfo( myPolysFileName );
135+
mpPolysLayer = new QgsVectorLayer( myPolyFileInfo.filePath(),
136+
myPolyFileInfo.completeBaseName(), "ogr" );
137+
// Register the layer with the registry
138+
QgsMapLayerRegistry::instance()->addMapLayers(
139+
QList<QgsMapLayer *>() << mpPolysLayer );
140+
141+
142+
//
143+
// Create a line layer that will be used in all tests...
144+
//
145+
QString myLinesFileName = mTestDataDir + "lines.shp";
146+
QFileInfo myLineFileInfo( myLinesFileName );
147+
mpLinesLayer = new QgsVectorLayer( myLineFileInfo.filePath(),
148+
myLineFileInfo.completeBaseName(), "ogr" );
149+
// Register the layer with the registry
150+
QgsMapLayerRegistry::instance()->addMapLayers(
151+
QList<QgsMapLayer *>() << mpLinesLayer );
152+
153+
mReport += "<h1>StyleV2 Tests</h1>\n";
99154
}
100155

101156
void TestStyleV2::cleanupTestCase()
@@ -104,6 +159,76 @@ void TestStyleV2::cleanupTestCase()
104159
// mStyle->save();
105160
delete mStyle;
106161
QgsApplication::exitQgis();
162+
163+
QString myReportFile = QDir::tempPath() + QDir::separator() + "qgistest.html";
164+
QFile myFile( myReportFile );
165+
if ( myFile.open( QIODevice::WriteOnly | QIODevice::Append ) )
166+
{
167+
QTextStream myQTextStream( &myFile );
168+
myQTextStream << mReport;
169+
myFile.close();
170+
//QDesktopServices::openUrl( "file:///" + myReportFile );
171+
}
172+
}
173+
174+
bool TestStyleV2::imageCheck( QgsMapSettings& ms, const QString& testName )
175+
{
176+
QgsMultiRenderChecker checker;
177+
checker.setControlName( "expected_" + testName );
178+
checker.setMapSettings( ms );
179+
bool result = checker.runTest( testName, 0 );
180+
mReport += checker.report();
181+
return result;
182+
}
183+
184+
void TestStyleV2::testCanvasClip()
185+
{
186+
//test rendering with and without clip to canvas enabled
187+
QgsMapSettings ms;
188+
QgsRectangle extent( -110.0, 25.0, -90, 40.0 );
189+
ms.setExtent( extent );
190+
ms.setFlag( QgsMapSettings::ForceVectorOutput );
191+
192+
//line
193+
mReport += "<h2>Line canvas clip</h2>\n";
194+
ms.setLayers( QStringList() << mpLinesLayer->id() );
195+
196+
QgsMarkerLineSymbolLayerV2* markerLine = new QgsMarkerLineSymbolLayerV2();
197+
markerLine->setPlacement( QgsMarkerLineSymbolLayerV2:: CentralPoint );
198+
QgsLineSymbolV2* lineSymbol = new QgsLineSymbolV2();
199+
lineSymbol->changeSymbolLayer( 0, markerLine );
200+
QgsSingleSymbolRendererV2* renderer = new QgsSingleSymbolRendererV2( lineSymbol );
201+
mpLinesLayer->setRendererV2( renderer );
202+
bool result;
203+
204+
lineSymbol->setClipFeaturesToExtent( true );
205+
result = imageCheck( ms, "stylev2_linecanvasclip" );
206+
QVERIFY( result );
207+
208+
lineSymbol->setClipFeaturesToExtent( false );
209+
result = imageCheck( ms, "stylev2_linecanvasclip_off" );
210+
QVERIFY( result );
211+
212+
//poly
213+
mReport += "<h2>Polygon canvas clip</h2>\n";
214+
ms.setLayers( QStringList() << mpPolysLayer->id() );
215+
216+
QgsCentroidFillSymbolLayerV2* centroidFill = new QgsCentroidFillSymbolLayerV2();
217+
QgsFillSymbolV2* fillSymbol = new QgsFillSymbolV2();
218+
fillSymbol->changeSymbolLayer( 0, centroidFill );
219+
renderer = new QgsSingleSymbolRendererV2( fillSymbol );
220+
mpPolysLayer->setRendererV2( renderer );
221+
222+
extent = QgsRectangle( -106.0, 29.0, -94, 36.0 );
223+
ms.setExtent( extent );
224+
225+
fillSymbol->setClipFeaturesToExtent( true );
226+
result = imageCheck( ms, "stylev2_polycanvasclip" );
227+
QVERIFY( result );
228+
229+
fillSymbol->setClipFeaturesToExtent( false );
230+
result = imageCheck( ms, "stylev2_polycanvasclip_off" );
231+
QVERIFY( result );
107232
}
108233

109234
bool TestStyleV2::testValidColor( QgsVectorColorRampV2 *ramp, double value, QColor expected )

0 commit comments

Comments
 (0)
Please sign in to comment.