Skip to content
Permalink
Browse files

Include QgsFeature pointer to symbol render context. Bindings not ada…

…pted yet
  • Loading branch information
mhugent committed Jun 8, 2011
1 parent ebfef6f commit 936d58bd569c79583aaa5da1abe1ce8cc9feeebe
@@ -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() );
}
}
}
@@ -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
@@ -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;
}

@@ -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)
}

@@ -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
@@ -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 );
}
@@ -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 );
@@ -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 );
@@ -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 );
@@ -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 );
@@ -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 );
@@ -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 );
@@ -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 );
@@ -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 )
{

}
@@ -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() )
@@ -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() )
@@ -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() )
@@ -14,6 +14,7 @@ class QPointF;
class QPolygonF;
//class

class QgsFeature;
class QgsSymbolLayerV2;
class QgsRenderContext;

@@ -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; }
@@ -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();

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


@@ -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;
};
@@ -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;
};
@@ -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;
};
@@ -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 );
}
}
@@ -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
{
@@ -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 );
}
@@ -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 );
}
}
}
@@ -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 );
};

0 comments on commit 936d58b

Please sign in to comment.
You can’t perform that action at this time.