Skip to content

Commit 936d58b

Browse files
committedJun 8, 2011
Include QgsFeature pointer to symbol render context. Bindings not adapted yet
1 parent ebfef6f commit 936d58b

File tree

8 files changed

+39
-34
lines changed

8 files changed

+39
-34
lines changed
 

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,13 +273,13 @@ void QgsSVGFillSymbolLayer::renderPolygon( const QPolygonF& points, QList<QPolyg
273273
_renderPolygon( p, points, rings );
274274
if ( mOutline )
275275
{
276-
mOutline->renderPolyline( points, context.renderContext(), -1, selectFillBorder && context.selected() );
276+
mOutline->renderPolyline( points, context.feature(), context.renderContext(), -1, selectFillBorder && context.selected() );
277277
if ( rings )
278278
{
279279
QList<QPolygonF>::const_iterator ringIt = rings->constBegin();
280280
for ( ; ringIt != rings->constEnd(); ++ringIt )
281281
{
282-
mOutline->renderPolyline( *ringIt, context.renderContext(), -1, selectFillBorder && context.selected() );
282+
mOutline->renderPolyline( *ringIt, context.feature(), context.renderContext(), -1, selectFillBorder && context.selected() );
283283
}
284284
}
285285
}
@@ -419,7 +419,7 @@ void QgsCentroidFillSymbolLayerV2::renderPolygon( const QPolygonF& points, QList
419419
cx /= sum;
420420
cy /= sum;
421421

422-
mMarker->renderPoint( QPointF( cx, cy ), context.renderContext(), -1, context.selected() );
422+
mMarker->renderPoint( QPointF( cx, cy ), context.feature(), context.renderContext(), -1, context.selected() );
423423
}
424424

425425
QgsStringMap QgsCentroidFillSymbolLayerV2::properties() const

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ void QgsMarkerLineSymbolLayerV2::renderPolylineInterval( const QPolygonF& points
354354
// draw first marker
355355
if ( first )
356356
{
357-
mMarker->renderPoint( lastPt, rc, -1, context.selected() );
357+
mMarker->renderPoint( lastPt, context.feature(), rc, -1, context.selected() );
358358
first = false;
359359
}
360360

@@ -364,7 +364,7 @@ void QgsMarkerLineSymbolLayerV2::renderPolylineInterval( const QPolygonF& points
364364
// "c" is 1 for regular point or in interval (0,1] for begin of line segment
365365
lastPt += c * diff;
366366
lengthLeft -= painterUnitInterval;
367-
mMarker->renderPoint( lastPt, rc, -1, context.selected() );
367+
mMarker->renderPoint( lastPt, context.feature(), rc, -1, context.selected() );
368368
c = 1; // reset c (if wasn't 1 already)
369369
}
370370

@@ -473,7 +473,7 @@ void QgsMarkerLineSymbolLayerV2::renderPolylineVertex( const QPolygonF& points,
473473
mMarker->setAngle( origAngle + angle * 180 / M_PI );
474474
}
475475

476-
mMarker->renderPoint( points.at( i ), rc, -1, context.selected() );
476+
mMarker->renderPoint( points.at( i ), context.feature(), rc, -1, context.selected() );
477477
}
478478

479479
// restore original rotation
@@ -520,7 +520,7 @@ void QgsMarkerLineSymbolLayerV2::renderPolylineCentral( const QPolygonF& points,
520520
double origAngle = mMarker->angle();
521521
if ( mRotateMarker )
522522
mMarker->setAngle( origAngle + l.angle() * 180 / M_PI );
523-
mMarker->renderPoint( pt, context.renderContext(), -1, context.selected() );
523+
mMarker->renderPoint( pt, context.feature(), context.renderContext(), -1, context.selected() );
524524
if ( mRotateMarker )
525525
mMarker->setAngle( origAngle );
526526
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ void QgsFeatureRendererV2::renderFeature( QgsFeature& feature, QgsRenderContext&
202202
}
203203
QPointF pt;
204204
_getPoint( pt, context, geom->asWkb() );
205-
(( QgsMarkerSymbolV2* )symbol )->renderPoint( pt, context, layer, selected );
205+
(( QgsMarkerSymbolV2* )symbol )->renderPoint( pt, &feature, context, layer, selected );
206206

207207
//if ( drawVertexMarker )
208208
// renderVertexMarker( pt, context );
@@ -219,7 +219,7 @@ void QgsFeatureRendererV2::renderFeature( QgsFeature& feature, QgsRenderContext&
219219
}
220220
QPolygonF pts;
221221
_getLineString( pts, context, geom->asWkb() );
222-
(( QgsLineSymbolV2* )symbol )->renderPolyline( pts, context, layer, selected );
222+
(( QgsLineSymbolV2* )symbol )->renderPolyline( pts, &feature, context, layer, selected );
223223

224224
if ( drawVertexMarker )
225225
renderVertexMarkerPolyline( pts, context );
@@ -237,7 +237,7 @@ void QgsFeatureRendererV2::renderFeature( QgsFeature& feature, QgsRenderContext&
237237
QPolygonF pts;
238238
QList<QPolygonF> holes;
239239
_getPolygon( pts, holes, context, geom->asWkb() );
240-
(( QgsFillSymbolV2* )symbol )->renderPolygon( pts, ( holes.count() ? &holes : NULL ), context, layer, selected );
240+
(( QgsFillSymbolV2* )symbol )->renderPolygon( pts, ( holes.count() ? &holes : NULL ), &feature, context, layer, selected );
241241

242242
if ( drawVertexMarker )
243243
renderVertexMarkerPolygon( pts, ( holes.count() ? &holes : NULL ), context );
@@ -261,7 +261,7 @@ void QgsFeatureRendererV2::renderFeature( QgsFeature& feature, QgsRenderContext&
261261
for ( unsigned int i = 0; i < num; ++i )
262262
{
263263
ptr = _getPoint( pt, context, ptr );
264-
(( QgsMarkerSymbolV2* )symbol )->renderPoint( pt, context, layer, selected );
264+
(( QgsMarkerSymbolV2* )symbol )->renderPoint( pt, &feature, context, layer, selected );
265265

266266
//if ( drawVertexMarker )
267267
// renderVertexMarker( pt, context );
@@ -286,7 +286,7 @@ void QgsFeatureRendererV2::renderFeature( QgsFeature& feature, QgsRenderContext&
286286
for ( unsigned int i = 0; i < num; ++i )
287287
{
288288
ptr = _getLineString( pts, context, ptr );
289-
(( QgsLineSymbolV2* )symbol )->renderPolyline( pts, context, layer, selected );
289+
(( QgsLineSymbolV2* )symbol )->renderPolyline( pts, &feature, context, layer, selected );
290290

291291
if ( drawVertexMarker )
292292
renderVertexMarkerPolyline( pts, context );
@@ -312,7 +312,7 @@ void QgsFeatureRendererV2::renderFeature( QgsFeature& feature, QgsRenderContext&
312312
for ( unsigned int i = 0; i < num; ++i )
313313
{
314314
ptr = _getPolygon( pts, holes, context, ptr );
315-
(( QgsFillSymbolV2* )symbol )->renderPolygon( pts, ( holes.count() ? &holes : NULL ), context, layer, selected );
315+
(( QgsFillSymbolV2* )symbol )->renderPolygon( pts, ( holes.count() ? &holes : NULL ), &feature, context, layer, selected );
316316

317317
if ( drawVertexMarker )
318318
renderVertexMarkerPolygon( pts, ( holes.count() ? &holes : NULL ), context );

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -215,17 +215,17 @@ QImage QgsSymbolV2::bigSymbolPreviewImage()
215215
{
216216
QPolygonF poly;
217217
poly << QPointF( 0, 50 ) << QPointF( 99, 50 );
218-
static_cast<QgsLineSymbolV2*>( this )->renderPolyline( poly, context );
218+
static_cast<QgsLineSymbolV2*>( this )->renderPolyline( poly, 0, context );
219219
}
220220
else if ( mType == QgsSymbolV2::Fill )
221221
{
222222
QPolygonF polygon;
223223
polygon << QPointF( 20, 20 ) << QPointF( 80, 20 ) << QPointF( 80, 80 ) << QPointF( 20, 80 ) << QPointF( 20, 20 );
224-
static_cast<QgsFillSymbolV2*>( this )->renderPolygon( polygon, NULL, context );
224+
static_cast<QgsFillSymbolV2*>( this )->renderPolygon( polygon, NULL, 0, context );
225225
}
226226
else // marker
227227
{
228-
static_cast<QgsMarkerSymbolV2*>( this )->renderPoint( QPointF( 50, 50 ), context );
228+
static_cast<QgsMarkerSymbolV2*>( this )->renderPoint( QPointF( 50, 50 ), 0, context );
229229
}
230230

231231
stopRender( context );
@@ -267,8 +267,8 @@ QgsSymbolLayerV2List QgsSymbolV2::cloneLayers() const
267267

268268
////////////////////
269269

270-
QgsSymbolV2RenderContext::QgsSymbolV2RenderContext( QgsRenderContext& c, QgsSymbolV2::OutputUnit u, qreal alpha, bool selected, int renderHints )
271-
: mRenderContext( c ), mOutputUnit( u ), mAlpha( alpha ), mSelected( selected ), mRenderHints( renderHints )
270+
QgsSymbolV2RenderContext::QgsSymbolV2RenderContext( QgsRenderContext& c, QgsSymbolV2::OutputUnit u, qreal alpha, bool selected, int renderHints, const QgsFeature* f )
271+
: mRenderContext( c ), mOutputUnit( u ), mAlpha( alpha ), mSelected( selected ), mRenderHints( renderHints ), mFeature( 0 )
272272
{
273273

274274
}
@@ -402,9 +402,9 @@ double QgsMarkerSymbolV2::size()
402402
return maxSize;
403403
}
404404

405-
void QgsMarkerSymbolV2::renderPoint( const QPointF& point, QgsRenderContext& context, int layer, bool selected )
405+
void QgsMarkerSymbolV2::renderPoint( const QPointF& point, const QgsFeature* f, QgsRenderContext& context, int layer, bool selected )
406406
{
407-
QgsSymbolV2RenderContext symbolContext( context, mOutputUnit, mAlpha, selected, mRenderHints );
407+
QgsSymbolV2RenderContext symbolContext( context, mOutputUnit, mAlpha, selected, mRenderHints, f );
408408
if ( layer != -1 )
409409
{
410410
if ( layer >= 0 && layer < mLayers.count() )
@@ -471,9 +471,9 @@ double QgsLineSymbolV2::width()
471471
return maxWidth;
472472
}
473473

474-
void QgsLineSymbolV2::renderPolyline( const QPolygonF& points, QgsRenderContext& context, int layer, bool selected )
474+
void QgsLineSymbolV2::renderPolyline( const QPolygonF& points, const QgsFeature* f, QgsRenderContext& context, int layer, bool selected )
475475
{
476-
QgsSymbolV2RenderContext symbolContext( context, mOutputUnit, mAlpha, selected, mRenderHints );
476+
QgsSymbolV2RenderContext symbolContext( context, mOutputUnit, mAlpha, selected, mRenderHints, f );
477477
if ( layer != -1 )
478478
{
479479
if ( layer >= 0 && layer < mLayers.count() )
@@ -507,9 +507,9 @@ QgsFillSymbolV2::QgsFillSymbolV2( QgsSymbolLayerV2List layers )
507507
mLayers.append( new QgsSimpleFillSymbolLayerV2() );
508508
}
509509

510-
void QgsFillSymbolV2::renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsRenderContext& context, int layer, bool selected )
510+
void QgsFillSymbolV2::renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, const QgsFeature* f, QgsRenderContext& context, int layer, bool selected )
511511
{
512-
QgsSymbolV2RenderContext symbolContext( context, mOutputUnit, mAlpha, selected, mRenderHints );
512+
QgsSymbolV2RenderContext symbolContext( context, mOutputUnit, mAlpha, selected, mRenderHints, f );
513513
if ( layer != -1 )
514514
{
515515
if ( layer >= 0 && layer < mLayers.count() )

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class QPointF;
1414
class QPolygonF;
1515
//class
1616

17+
class QgsFeature;
1718
class QgsSymbolLayerV2;
1819
class QgsRenderContext;
1920

@@ -124,7 +125,7 @@ class CORE_EXPORT QgsSymbolV2
124125
class CORE_EXPORT QgsSymbolV2RenderContext
125126
{
126127
public:
127-
QgsSymbolV2RenderContext( QgsRenderContext& c, QgsSymbolV2::OutputUnit u , qreal alpha = 1.0, bool selected = false, int renderHints = 0 );
128+
QgsSymbolV2RenderContext( QgsRenderContext& c, QgsSymbolV2::OutputUnit u , qreal alpha = 1.0, bool selected = false, int renderHints = 0, const QgsFeature* f = 0 );
128129
~QgsSymbolV2RenderContext();
129130

130131
QgsRenderContext& renderContext() { return mRenderContext; }
@@ -144,6 +145,9 @@ class CORE_EXPORT QgsSymbolV2RenderContext
144145
//! @note added in 1.5
145146
void setRenderHints( int hints ) { mRenderHints = hints; }
146147

148+
void setFeature( const QgsFeature* f ){ mFeature = f; }
149+
const QgsFeature* feature() const { return mFeature; }
150+
147151
// Color used for selections
148152
static QColor selectionColor();
149153

@@ -159,6 +163,7 @@ class CORE_EXPORT QgsSymbolV2RenderContext
159163
qreal mAlpha;
160164
bool mSelected;
161165
int mRenderHints;
166+
const QgsFeature* mFeature; //current feature
162167
};
163168

164169

@@ -184,7 +189,7 @@ class CORE_EXPORT QgsMarkerSymbolV2 : public QgsSymbolV2
184189
void setSize( double size );
185190
double size();
186191

187-
void renderPoint( const QPointF& point, QgsRenderContext& context, int layer = -1, bool selected = false );
192+
void renderPoint( const QPointF& point, const QgsFeature* f, QgsRenderContext& context, int layer = -1, bool selected = false );
188193

189194
virtual QgsSymbolV2* clone() const;
190195
};
@@ -205,7 +210,7 @@ class CORE_EXPORT QgsLineSymbolV2 : public QgsSymbolV2
205210
void setWidth( double width );
206211
double width();
207212

208-
void renderPolyline( const QPolygonF& points, QgsRenderContext& context, int layer = -1, bool selected = false );
213+
void renderPolyline( const QPolygonF& points, const QgsFeature* f, QgsRenderContext& context, int layer = -1, bool selected = false );
209214

210215
virtual QgsSymbolV2* clone() const;
211216
};
@@ -223,7 +228,7 @@ class CORE_EXPORT QgsFillSymbolV2 : public QgsSymbolV2
223228

224229
QgsFillSymbolV2( QgsSymbolLayerV2List layers = QgsSymbolLayerV2List() );
225230
void setAngle( double angle );
226-
void renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsRenderContext& context, int layer = -1, bool selected = false );
231+
void renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, const QgsFeature* f, QgsRenderContext& context, int layer = -1, bool selected = false );
227232

228233
virtual QgsSymbolV2* clone() const;
229234
};

‎src/gui/qgsannotationitem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ void QgsAnnotationItem::drawMarkerSymbol( QPainter* p )
220220
if ( mMarkerSymbol )
221221
{
222222
mMarkerSymbol->startRender( renderContext );
223-
mMarkerSymbol->renderPoint( QPointF( 0, 0 ), renderContext );
223+
mMarkerSymbol->renderPoint( QPointF( 0, 0 ), 0, renderContext );
224224
mMarkerSymbol->stopRender( renderContext );
225225
}
226226
}

‎src/plugins/point_displacement_renderer/qgspointdisplacementrenderer.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ void QgsPointDisplacementRenderer::renderFeature( QgsFeature& feature, QgsRender
164164
{
165165
if ( mCenterSymbol )
166166
{
167-
mCenterSymbol->renderPoint( pt, context, layer, selected );
167+
mCenterSymbol->renderPoint( pt, &feature, context, layer, selected );
168168
}
169169
else
170170
{
@@ -173,7 +173,7 @@ void QgsPointDisplacementRenderer::renderFeature( QgsFeature& feature, QgsRender
173173
}
174174

175175
//draw symbols on the circle
176-
drawSymbols( context, symbolList, symbolPositions, selected );
176+
drawSymbols( feature, context, symbolList, symbolPositions, selected );
177177
//and also the labels
178178
drawLabels( pt, symbolContext, labelPositions, labelAttributeList );
179179
}
@@ -509,15 +509,15 @@ void QgsPointDisplacementRenderer::drawCircle( double radiusPainterUnits, QgsSym
509509
p->drawArc( QRectF( centerPoint.x() - radiusPainterUnits, centerPoint.y() - radiusPainterUnits, 2 * radiusPainterUnits, 2 * radiusPainterUnits ), 0, 5760 );
510510
}
511511

512-
void QgsPointDisplacementRenderer::drawSymbols( QgsRenderContext& context, const QList<QgsMarkerSymbolV2*>& symbolList, const QList<QPointF>& symbolPositions, bool selected )
512+
void QgsPointDisplacementRenderer::drawSymbols( QgsFeature& f, QgsRenderContext& context, const QList<QgsMarkerSymbolV2*>& symbolList, const QList<QPointF>& symbolPositions, bool selected )
513513
{
514514
QList<QPointF>::const_iterator symbolPosIt = symbolPositions.constBegin();
515515
QList<QgsMarkerSymbolV2*>::const_iterator symbolIt = symbolList.constBegin();
516516
for ( ; symbolPosIt != symbolPositions.constEnd() && symbolIt != symbolList.constEnd(); ++symbolPosIt, ++symbolIt )
517517
{
518518
if ( *symbolIt )
519519
{
520-
( *symbolIt )->renderPoint( *symbolPosIt, context, -1, selected );
520+
( *symbolIt )->renderPoint( *symbolPosIt, &f, context, -1, selected );
521521
}
522522
}
523523
}

‎src/plugins/point_displacement_renderer/qgspointdisplacementrenderer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ class QgsPointDisplacementRenderer: public QgsFeatureRendererV2
143143
//helper functions
144144
void calculateSymbolAndLabelPositions( const QPointF& centerPoint, int nPosition, double radius, double symbolDiagonal, QList<QPointF>& symbolPositions, QList<QPointF>& labelShifts ) const;
145145
void drawCircle( double radiusPainterUnits, QgsSymbolV2RenderContext& context, const QPointF& centerPoint, int nSymbols );
146-
void drawSymbols( QgsRenderContext& context, const QList<QgsMarkerSymbolV2*>& symbolList, const QList<QPointF>& symbolPositions, bool selected = false );
146+
void drawSymbols( QgsFeature& f, QgsRenderContext& context, const QList<QgsMarkerSymbolV2*>& symbolList, const QList<QPointF>& symbolPositions, bool selected = false );
147147
void drawLabels( const QPointF& centerPoint, QgsSymbolV2RenderContext& context, const QList<QPointF>& labelShifts, const QStringList& labelList );
148148
};
149149

0 commit comments

Comments
 (0)
Please sign in to comment.