Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Include QgsFeature pointer to symbol render context. Bindings not ada…
…pted yet
  • Loading branch information
mhugent committed Jun 8, 2011
1 parent ebfef6f commit 936d58b
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 34 deletions.
6 changes: 3 additions & 3 deletions src/core/symbology-ng/qgsfillsymbollayerv2.cpp
Expand Up @@ -273,13 +273,13 @@ void QgsSVGFillSymbolLayer::renderPolygon( const QPolygonF& points, QList<QPolyg
_renderPolygon( p, points, rings );
if ( mOutline )
{
mOutline->renderPolyline( points, context.renderContext(), -1, selectFillBorder && context.selected() );
mOutline->renderPolyline( points, context.feature(), context.renderContext(), -1, selectFillBorder && context.selected() );
if ( rings )
{
QList<QPolygonF>::const_iterator ringIt = rings->constBegin();
for ( ; ringIt != rings->constEnd(); ++ringIt )
{
mOutline->renderPolyline( *ringIt, context.renderContext(), -1, selectFillBorder && context.selected() );
mOutline->renderPolyline( *ringIt, context.feature(), context.renderContext(), -1, selectFillBorder && context.selected() );
}
}
}
Expand Down Expand Up @@ -419,7 +419,7 @@ void QgsCentroidFillSymbolLayerV2::renderPolygon( const QPolygonF& points, QList
cx /= sum;
cy /= sum;

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

QgsStringMap QgsCentroidFillSymbolLayerV2::properties() const
Expand Down
8 changes: 4 additions & 4 deletions src/core/symbology-ng/qgslinesymbollayerv2.cpp
Expand Up @@ -354,7 +354,7 @@ void QgsMarkerLineSymbolLayerV2::renderPolylineInterval( const QPolygonF& points
// draw first marker
if ( first )
{
mMarker->renderPoint( lastPt, rc, -1, context.selected() );
mMarker->renderPoint( lastPt, context.feature(), rc, -1, context.selected() );
first = false;
}

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

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

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

// restore original rotation
Expand Down Expand Up @@ -520,7 +520,7 @@ void QgsMarkerLineSymbolLayerV2::renderPolylineCentral( const QPolygonF& points,
double origAngle = mMarker->angle();
if ( mRotateMarker )
mMarker->setAngle( origAngle + l.angle() * 180 / M_PI );
mMarker->renderPoint( pt, context.renderContext(), -1, context.selected() );
mMarker->renderPoint( pt, context.feature(), context.renderContext(), -1, context.selected() );
if ( mRotateMarker )
mMarker->setAngle( origAngle );
}
Expand Down
12 changes: 6 additions & 6 deletions src/core/symbology-ng/qgsrendererv2.cpp
Expand Up @@ -202,7 +202,7 @@ void QgsFeatureRendererV2::renderFeature( QgsFeature& feature, QgsRenderContext&
}
QPointF pt;
_getPoint( pt, context, geom->asWkb() );
(( QgsMarkerSymbolV2* )symbol )->renderPoint( pt, context, layer, selected );
(( QgsMarkerSymbolV2* )symbol )->renderPoint( pt, &feature, context, layer, selected );

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

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

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

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

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

if ( drawVertexMarker )
renderVertexMarkerPolygon( pts, ( holes.count() ? &holes : NULL ), context );
Expand Down
22 changes: 11 additions & 11 deletions src/core/symbology-ng/qgssymbolv2.cpp
Expand Up @@ -215,17 +215,17 @@ QImage QgsSymbolV2::bigSymbolPreviewImage()
{
QPolygonF poly;
poly << QPointF( 0, 50 ) << QPointF( 99, 50 );
static_cast<QgsLineSymbolV2*>( this )->renderPolyline( poly, context );
static_cast<QgsLineSymbolV2*>( this )->renderPolyline( poly, 0, context );
}
else if ( mType == QgsSymbolV2::Fill )
{
QPolygonF polygon;
polygon << QPointF( 20, 20 ) << QPointF( 80, 20 ) << QPointF( 80, 80 ) << QPointF( 20, 80 ) << QPointF( 20, 20 );
static_cast<QgsFillSymbolV2*>( this )->renderPolygon( polygon, NULL, context );
static_cast<QgsFillSymbolV2*>( this )->renderPolygon( polygon, NULL, 0, context );
}
else // marker
{
static_cast<QgsMarkerSymbolV2*>( this )->renderPoint( QPointF( 50, 50 ), context );
static_cast<QgsMarkerSymbolV2*>( this )->renderPoint( QPointF( 50, 50 ), 0, context );
}

stopRender( context );
Expand Down Expand Up @@ -267,8 +267,8 @@ QgsSymbolLayerV2List QgsSymbolV2::cloneLayers() const

////////////////////

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

}
Expand Down Expand Up @@ -402,9 +402,9 @@ double QgsMarkerSymbolV2::size()
return maxSize;
}

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

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

void QgsFillSymbolV2::renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsRenderContext& context, int layer, bool selected )
void QgsFillSymbolV2::renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, const QgsFeature* f, QgsRenderContext& context, int layer, bool selected )
{
QgsSymbolV2RenderContext symbolContext( context, mOutputUnit, mAlpha, selected, mRenderHints );
QgsSymbolV2RenderContext symbolContext( context, mOutputUnit, mAlpha, selected, mRenderHints, f );
if ( layer != -1 )
{
if ( layer >= 0 && layer < mLayers.count() )
Expand Down
13 changes: 9 additions & 4 deletions src/core/symbology-ng/qgssymbolv2.h
Expand Up @@ -14,6 +14,7 @@ class QPointF;
class QPolygonF;
//class

class QgsFeature;
class QgsSymbolLayerV2;
class QgsRenderContext;

Expand Down Expand Up @@ -124,7 +125,7 @@ class CORE_EXPORT QgsSymbolV2
class CORE_EXPORT QgsSymbolV2RenderContext
{
public:
QgsSymbolV2RenderContext( QgsRenderContext& c, QgsSymbolV2::OutputUnit u , qreal alpha = 1.0, bool selected = false, int renderHints = 0 );
QgsSymbolV2RenderContext( QgsRenderContext& c, QgsSymbolV2::OutputUnit u , qreal alpha = 1.0, bool selected = false, int renderHints = 0, const QgsFeature* f = 0 );
~QgsSymbolV2RenderContext();

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

void setFeature( const QgsFeature* f ){ mFeature = f; }
const QgsFeature* feature() const { return mFeature; }

// Color used for selections
static QColor selectionColor();

Expand All @@ -159,6 +163,7 @@ class CORE_EXPORT QgsSymbolV2RenderContext
qreal mAlpha;
bool mSelected;
int mRenderHints;
const QgsFeature* mFeature; //current feature
};


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

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

virtual QgsSymbolV2* clone() const;
};
Expand All @@ -205,7 +210,7 @@ class CORE_EXPORT QgsLineSymbolV2 : public QgsSymbolV2
void setWidth( double width );
double width();

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

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

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

virtual QgsSymbolV2* clone() const;
};
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsannotationitem.cpp
Expand Up @@ -220,7 +220,7 @@ void QgsAnnotationItem::drawMarkerSymbol( QPainter* p )
if ( mMarkerSymbol )
{
mMarkerSymbol->startRender( renderContext );
mMarkerSymbol->renderPoint( QPointF( 0, 0 ), renderContext );
mMarkerSymbol->renderPoint( QPointF( 0, 0 ), 0, renderContext );
mMarkerSymbol->stopRender( renderContext );
}
}
Expand Down
Expand Up @@ -164,7 +164,7 @@ void QgsPointDisplacementRenderer::renderFeature( QgsFeature& feature, QgsRender
{
if ( mCenterSymbol )
{
mCenterSymbol->renderPoint( pt, context, layer, selected );
mCenterSymbol->renderPoint( pt, &feature, context, layer, selected );
}
else
{
Expand All @@ -173,7 +173,7 @@ void QgsPointDisplacementRenderer::renderFeature( QgsFeature& feature, QgsRender
}

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

void QgsPointDisplacementRenderer::drawSymbols( QgsRenderContext& context, const QList<QgsMarkerSymbolV2*>& symbolList, const QList<QPointF>& symbolPositions, bool selected )
void QgsPointDisplacementRenderer::drawSymbols( QgsFeature& f, QgsRenderContext& context, const QList<QgsMarkerSymbolV2*>& symbolList, const QList<QPointF>& symbolPositions, bool selected )
{
QList<QPointF>::const_iterator symbolPosIt = symbolPositions.constBegin();
QList<QgsMarkerSymbolV2*>::const_iterator symbolIt = symbolList.constBegin();
for ( ; symbolPosIt != symbolPositions.constEnd() && symbolIt != symbolList.constEnd(); ++symbolPosIt, ++symbolIt )
{
if ( *symbolIt )
{
( *symbolIt )->renderPoint( *symbolPosIt, context, -1, selected );
( *symbolIt )->renderPoint( *symbolPosIt, &f, context, -1, selected );
}
}
}
Expand Down
Expand Up @@ -143,7 +143,7 @@ class QgsPointDisplacementRenderer: public QgsFeatureRendererV2
//helper functions
void calculateSymbolAndLabelPositions( const QPointF& centerPoint, int nPosition, double radius, double symbolDiagonal, QList<QPointF>& symbolPositions, QList<QPointF>& labelShifts ) const;
void drawCircle( double radiusPainterUnits, QgsSymbolV2RenderContext& context, const QPointF& centerPoint, int nSymbols );
void drawSymbols( QgsRenderContext& context, const QList<QgsMarkerSymbolV2*>& symbolList, const QList<QPointF>& symbolPositions, bool selected = false );
void drawSymbols( QgsFeature& f, QgsRenderContext& context, const QList<QgsMarkerSymbolV2*>& symbolList, const QList<QPointF>& symbolPositions, bool selected = false );
void drawLabels( const QPointF& centerPoint, QgsSymbolV2RenderContext& context, const QList<QPointF>& labelShifts, const QStringList& labelList );
};

Expand Down

0 comments on commit 936d58b

Please sign in to comment.