Skip to content

Commit fe9461b

Browse files
committedSep 8, 2015
Add methods for retrieving extra parameters from symbol render
1 parent b8ad58c commit fe9461b

File tree

11 files changed

+231
-7
lines changed

11 files changed

+231
-7
lines changed
 

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,15 @@ class QgsFeatureRendererV2
263263
*/
264264
void setForceRasterRender( bool forceRaster );
265265

266+
/** Returns the result of the feature rendering operation. This should only be
267+
* called immediately after a rendering operation (eg calling renderFeature).
268+
* @note added in QGIS 2.12
269+
* @note this is a temporary method until QGIS 3.0. For QGIS 3.0 renderFeature
270+
* will return a QgsRenderResult object
271+
*/
272+
// TODO - QGIS 3.0. Remove and make renderFeature return a QgsRenderResult
273+
const QgsRenderResult& renderResult() const;
274+
266275
protected:
267276
QgsFeatureRendererV2( QString type );
268277

@@ -291,6 +300,16 @@ class QgsFeatureRendererV2
291300
*/
292301
void copyPaintEffect( QgsFeatureRendererV2 *destRenderer ) const;
293302

303+
/** Sets the result of the symbol rendering operation. Subclasses should call
304+
* this method after rendering a feature and update the render result to reflect
305+
* to actual result of the feature render.
306+
* @note added in QGIS 2.12
307+
* @note this is a temporary method until QGIS 3.0. For QGIS 3.0 the renderFeature method
308+
* will return a QgsRenderResult object
309+
*/
310+
// TODO - QGIS 3.0. Remove and make renderPoint, etc return a QgsRenderResult
311+
void setRenderResult( const QgsRenderResult& result );
312+
294313
private:
295314
QgsFeatureRendererV2( const QgsFeatureRendererV2 & );
296315
QgsFeatureRendererV2 & operator=( const QgsFeatureRendererV2 & );

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,15 @@ class QgsSymbolLayerV2
260260
*/
261261
void setPaintEffect( QgsPaintEffect* effect /Transfer/);
262262

263+
/** Returns the result of the symbol rendering operation. This should only be
264+
* called immediately after a rendering operation (eg calling renderPoint).
265+
* @note added in QGIS 2.12
266+
* @note this is a temporary method until QGIS 3.0. For QGIS 3.0 the render methods
267+
* will return a QgsRenderResult object
268+
*/
269+
// TODO - QGIS 3.0. Remove and make renderPoint, etc return a QgsRenderResult
270+
const QgsRenderResult& renderResult() const;
271+
263272
protected:
264273
QgsSymbolLayerV2( QgsSymbolV2::SymbolType type, bool locked = false );
265274

@@ -306,6 +315,16 @@ class QgsSymbolLayerV2
306315
*/
307316
void copyPaintEffect( QgsSymbolLayerV2* destLayer ) const;
308317

318+
/** Sets the result of the symbol rendering operation. Subclasses should call
319+
* this method after rendering a symbol and update the render result to reflect
320+
* to actual result of the symbol render.
321+
* @note added in QGIS 2.12
322+
* @note this is a temporary method until QGIS 3.0. For QGIS 3.0 the render methods
323+
* will return a QgsRenderResult object
324+
*/
325+
// TODO - QGIS 3.0. Remove and make renderPoint, etc return a QgsRenderResult
326+
void setRenderResult( const QgsRenderResult& result );
327+
309328
};
310329

311330
//////////////////////

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,39 @@
11

22
typedef QList<QgsSymbolLayerV2*> QgsSymbolLayerV2List;
33

4+
/** \ingroup core
5+
* \class QgsRenderResult
6+
* \brief A simple container for the results of a rendering operation
7+
* \note Added in version 2.12
8+
*/
9+
10+
class QgsRenderResult
11+
{
12+
%TypeHeaderCode
13+
#include <qgssymbolv2.h>
14+
%End
15+
public:
16+
17+
/** Constructor for QgsRenderResult
18+
* @param symbolRendered initial value for symbolRendered member
19+
*/
20+
QgsRenderResult( bool symbolRendered );
21+
22+
/** Bounds of rendered symbol shape.
23+
* @note only implemented for marker symbol types
24+
*/
25+
QRectF symbolBounds;
26+
27+
//! True if a symbol was rendered during the render operation
28+
bool symbolRendered;
29+
30+
/** Unites the render result with another QgsRenderResult object
31+
* @param other other render result
32+
*/
33+
void unite( const QgsRenderResult& other );
34+
};
35+
36+
437
class QgsSymbolV2
538
{
639
%TypeHeaderCode
@@ -163,6 +196,15 @@ class QgsSymbolV2
163196
void setLayer( const QgsVectorLayer* layer );
164197
const QgsVectorLayer* layer() const;
165198

199+
/** Returns the result of the symbol rendering operation. This should only be
200+
* called immediately after a rendering operation (eg calling renderPoint).
201+
* @note added in QGIS 2.12
202+
* @note this is a temporary method until QGIS 3.0. For QGIS 3.0 the render methods
203+
* will return a QgsRenderResult object
204+
*/
205+
// TODO - QGIS 3.0. Remove and make renderPoint, etc return a QgsRenderResult
206+
const QgsRenderResult& renderResult() const;
207+
166208
protected:
167209
QgsSymbolV2( SymbolType type, QgsSymbolLayerV2List layers /Transfer/ ); // can't be instantiated
168210

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

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -541,15 +541,18 @@ void QgsSimpleMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV
541541
}
542542
}
543543

544+
QgsRenderResult result( true );
544545
if ( mUsingCache )
545546
{
546547
//QgsDebugMsg( QString("XXX using cache") );
547548
// we will use cached image
548549
QImage &img = context.selected() ? mSelCache : mCache;
549550
double s = img.width() / context.renderContext().rasterScaleFactor();
550-
p->drawImage( QRectF( point.x() - s / 2.0 + off.x(),
551-
point.y() - s / 2.0 + off.y(),
552-
s, s ), img );
551+
QRectF imgRect( point.x() - s / 2.0 + off.x(),
552+
point.y() - s / 2.0 + off.y(),
553+
s, s );
554+
p->drawImage( imgRect, img );
555+
result.symbolBounds = imgRect;
553556
}
554557
else
555558
{
@@ -606,11 +609,25 @@ void QgsSimpleMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV
606609
p->setBrush( context.selected() ? mSelBrush : mBrush );
607610
p->setPen( context.selected() ? mSelPen : mPen );
608611

612+
QRectF boundingRect;
609613
if ( !mPolygon.isEmpty() )
610-
p->drawPolygon( transform.map( mPolygon ) );
614+
{
615+
QPolygonF transformed = transform.map( mPolygon );
616+
boundingRect = transformed.boundingRect();
617+
p->drawPolygon( transformed );
618+
619+
}
611620
else
612-
p->drawPath( transform.map( mPath ) );
621+
{
622+
QPainterPath transformed = transform.map( mPath );
623+
boundingRect = transformed.boundingRect();
624+
p->drawPath( transformed );
625+
}
626+
//adjust bounding rect for pen width
627+
result.symbolBounds = boundingRect.adjusted( -mPen.widthF() / 2.0, -mPen.widthF() / 2.0,
628+
mPen.widthF() / 2.0, mPen.widthF() / 2.0 );
613629
}
630+
setRenderResult( result );
614631
}
615632

616633

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ QgsFeatureRendererV2::QgsFeatureRendererV2( QString type )
218218
, mCurrentVertexMarkerSize( 3 )
219219
, mPaintEffect( 0 )
220220
, mForceRaster( false )
221+
, mRenderResult( QgsRenderResult( true ) )
221222
{
222223
mPaintEffect = QgsPaintEffectRegistry::defaultStack();
223224
mPaintEffect->setEnabled( false );
@@ -270,9 +271,13 @@ bool QgsFeatureRendererV2::renderFeature( QgsFeature& feature, QgsRenderContext&
270271
{
271272
QgsSymbolV2* symbol = symbolForFeature( feature, context );
272273
if ( symbol == NULL )
274+
{
275+
setRenderResult( QgsRenderResult( false ) );
273276
return false;
277+
}
274278

275279
renderFeatureWithSymbol( feature, symbol, context, layer, selected, drawVertexMarker );
280+
setRenderResult( symbol->renderResult() );
276281
return true;
277282
}
278283

@@ -810,3 +815,8 @@ void QgsFeatureRendererV2::convertSymbolRotation( QgsSymbolV2 * symbol, const QS
810815
s->setDataDefinedAngle( dd );
811816
}
812817
}
818+
819+
void QgsFeatureRendererV2::setRenderResult( const QgsRenderResult& result )
820+
{
821+
mRenderResult = result;
822+
}

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,15 @@ class CORE_EXPORT QgsFeatureRendererV2
311311
*/
312312
void setForceRasterRender( bool forceRaster ) { mForceRaster = forceRaster; }
313313

314+
/** Returns the result of the feature rendering operation. This should only be
315+
* called immediately after a rendering operation (eg calling renderFeature).
316+
* @note added in QGIS 2.12
317+
* @note this is a temporary method until QGIS 3.0. For QGIS 3.0 renderFeature
318+
* will return a QgsRenderResult object
319+
*/
320+
// TODO - QGIS 3.0. Remove and make renderFeature return a QgsRenderResult
321+
const QgsRenderResult& renderResult() const { return mRenderResult; }
322+
314323
protected:
315324
QgsFeatureRendererV2( QString type );
316325

@@ -361,8 +370,20 @@ class CORE_EXPORT QgsFeatureRendererV2
361370
*/
362371
static void convertSymbolRotation( QgsSymbolV2 * symbol, const QString & field );
363372

373+
/** Sets the result of the symbol rendering operation. Subclasses should call
374+
* this method after rendering a feature and update the render result to reflect
375+
* to actual result of the feature render.
376+
* @note added in QGIS 2.12
377+
* @note this is a temporary method until QGIS 3.0. For QGIS 3.0 the renderFeature method
378+
* will return a QgsRenderResult object
379+
*/
380+
// TODO - QGIS 3.0. Remove and make renderPoint, etc return a QgsRenderResult
381+
void setRenderResult( const QgsRenderResult& result );
382+
364383
private:
365384
Q_DISABLE_COPY( QgsFeatureRendererV2 )
385+
386+
QgsRenderResult mRenderResult;
366387
};
367388

368389
// for some reason SIP compilation fails if these lines are not included:

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,8 @@ bool QgsRuleBasedRendererV2::renderFeature( QgsFeature& feature,
815815
{
816816
Q_UNUSED( layer );
817817

818+
setRenderResult( QgsRenderResult( false ) );
819+
818820
int flags = ( selected ? FeatIsSelected : 0 ) | ( drawVertexMarker ? FeatDrawMarkers : 0 );
819821
mCurrentFeatures.append( FeatureToRender( feature, flags ) );
820822

@@ -873,6 +875,10 @@ void QgsRuleBasedRendererV2::stopRender( QgsRenderContext& context )
873875
{
874876
int flags = job->ftr.flags;
875877
renderFeatureWithSymbol( job->ftr.feat, job->symbol, context, i, flags & FeatIsSelected, flags & FeatDrawMarkers );
878+
879+
QgsRenderResult newRenderResult = job->symbol->renderResult();
880+
newRenderResult.unite( renderResult() );
881+
setRenderResult( newRenderResult );
876882
}
877883
}
878884
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ QgsSymbolLayerV2::QgsSymbolLayerV2( QgsSymbolV2::SymbolType type, bool locked )
334334
, mLocked( locked )
335335
, mRenderingPass( 0 )
336336
, mPaintEffect( 0 )
337+
, mRenderResult( QgsRenderResult( true ) )
337338
{
338339
mPaintEffect = QgsPaintEffectRegistry::defaultStack();
339340
mPaintEffect->setEnabled( false );
@@ -482,6 +483,11 @@ void QgsSymbolLayerV2::copyPaintEffect( QgsSymbolLayerV2 *destLayer ) const
482483
destLayer->setPaintEffect( mPaintEffect->clone() );
483484
}
484485

486+
void QgsSymbolLayerV2::setRenderResult( const QgsRenderResult& result )
487+
{
488+
mRenderResult = result;
489+
}
490+
485491
QgsMarkerSymbolLayerV2::QgsMarkerSymbolLayerV2( bool locked )
486492
: QgsSymbolLayerV2( QgsSymbolV2::Marker, locked )
487493
, mAngle( 0 )

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,15 @@ class CORE_EXPORT QgsSymbolLayerV2
247247
*/
248248
void setPaintEffect( QgsPaintEffect* effect );
249249

250+
/** Returns the result of the symbol rendering operation. This should only be
251+
* called immediately after a rendering operation (eg calling renderPoint).
252+
* @note added in QGIS 2.12
253+
* @note this is a temporary method until QGIS 3.0. For QGIS 3.0 the render methods
254+
* will return a QgsRenderResult object
255+
*/
256+
// TODO - QGIS 3.0. Remove and make renderPoint, etc return a QgsRenderResult
257+
const QgsRenderResult& renderResult() const { return mRenderResult; }
258+
250259
protected:
251260
QgsSymbolLayerV2( QgsSymbolV2::SymbolType type, bool locked = false );
252261

@@ -307,6 +316,16 @@ class CORE_EXPORT QgsSymbolLayerV2
307316
*/
308317
void copyPaintEffect( QgsSymbolLayerV2* destLayer ) const;
309318

319+
/** Sets the result of the symbol rendering operation. Subclasses should call
320+
* this method after rendering a symbol and update the render result to reflect
321+
* to actual result of the symbol render.
322+
* @note added in QGIS 2.12
323+
* @note this is a temporary method until QGIS 3.0. For QGIS 3.0 the render methods
324+
* will return a QgsRenderResult object
325+
*/
326+
// TODO - QGIS 3.0. Remove and make renderPoint, etc return a QgsRenderResult
327+
void setRenderResult( const QgsRenderResult& result );
328+
310329
static const QString EXPR_SIZE;
311330
static const QString EXPR_ANGLE;
312331
static const QString EXPR_NAME;
@@ -365,6 +384,10 @@ class CORE_EXPORT QgsSymbolLayerV2
365384
static const QString EXPR_OFFSET_ALONG_LINE;
366385
static const QString EXPR_HORIZONTAL_ANCHOR_POINT;
367386
static const QString EXPR_VERTICAL_ANCHOR_POINT;
387+
388+
private:
389+
390+
QgsRenderResult mRenderResult;
368391
};
369392

370393
//////////////////////

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ QgsSymbolV2::QgsSymbolV2( SymbolType type, QgsSymbolLayerV2List layers )
8181
, mRenderHints( 0 )
8282
, mClipFeaturesToExtent( true )
8383
, mLayer( 0 )
84+
, mRenderResult( QgsRenderResult( true ) )
8485
{
8586

8687
// check they're all correct symbol layers
@@ -831,6 +832,8 @@ void QgsMarkerSymbolV2::renderPointUsingLayer( QgsMarkerSymbolLayerV2* layer, co
831832
{
832833
layer->renderPoint( point, context );
833834
}
835+
836+
mRenderResult = layer->renderResult();
834837
}
835838

836839
void QgsMarkerSymbolV2::renderPoint( const QPointF& point, const QgsFeature* f, QgsRenderContext& context, int layer, bool selected )
@@ -846,10 +849,13 @@ void QgsMarkerSymbolV2::renderPoint( const QPointF& point, const QgsFeature* f,
846849
return;
847850
}
848851

852+
QgsRenderResult combinedResult( false );
849853
for ( QgsSymbolLayerV2List::iterator it = mLayers.begin(); it != mLayers.end(); ++it )
850854
{
851855
renderPointUsingLayer(( QgsMarkerSymbolLayerV2* ) * it, point, symbolContext );
856+
combinedResult.unite(( *it )->renderResult() );
852857
}
858+
mRenderResult = combinedResult;
853859
}
854860

855861
QgsSymbolV2* QgsMarkerSymbolV2::clone() const
@@ -1032,6 +1038,8 @@ void QgsLineSymbolV2::renderPolylineUsingLayer( QgsLineSymbolLayerV2 *layer, con
10321038
{
10331039
layer->renderPolyline( points, context );
10341040
}
1041+
1042+
mRenderResult = layer->renderResult();
10351043
}
10361044

10371045

@@ -1112,6 +1120,8 @@ void QgsFillSymbolV2::renderPolygonUsingLayer( QgsSymbolLayerV2* layer, const QP
11121120
(( QgsLineSymbolLayerV2* )layer )->renderPolygonOutline( points, rings, context );
11131121
}
11141122
}
1123+
1124+
mRenderResult = layer->renderResult();
11151125
}
11161126

11171127
QRectF QgsFillSymbolV2::polygonBounds( const QPolygonF& points, const QList<QPolygonF>* rings ) const

0 commit comments

Comments
 (0)
Please sign in to comment.