Skip to content
Permalink
Browse files

Symbol rendering engine does not rely on guaranteed types

  • Loading branch information
m-kuhn committed Dec 4, 2015
1 parent 68b5209 commit 554b41d28a6d69e3fe1141554fec264dc7d90409
Showing with 81 additions and 16 deletions.
  1. +41 −0 src/core/symbology-ng/qgslinesymbollayerv2.h
  2. +40 −16 src/core/symbology-ng/qgssymbolv2.cpp
@@ -142,6 +142,9 @@ class CORE_EXPORT QgsMarkerLineSymbolLayerV2 : public QgsLineSymbolLayerV2

~QgsMarkerLineSymbolLayerV2();

/**
* Defines how/where the marker should be placed on the line
*/
enum Placement
{
Interval,
@@ -154,7 +157,22 @@ class CORE_EXPORT QgsMarkerLineSymbolLayerV2 : public QgsLineSymbolLayerV2

// static stuff

/**
* Create a new MarkerLineSymbolLayerV2
*
* @param properties A property map to deserialize saved information from properties()
*
* @return A new MarkerLineSymbolLayerV2
*/
static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() );

/**
* Create a new MarkerLineSymbolLayerV2 from SLD
*
* @param element An SLD XML DOM element
*
* @return A new MarkerLineSymbolLayerV2
*/
static QgsSymbolLayerV2* createFromSld( QDomElement &element );

// implemented from base classes
@@ -187,13 +205,36 @@ class CORE_EXPORT QgsMarkerLineSymbolLayerV2 : public QgsLineSymbolLayerV2

// new stuff

/**
* Shall the marker be rotated.
*
* @return True if the marker should be rotated.
*/
bool rotateMarker() const { return mRotateMarker; }

/**
* Shall the marker be rotated.
*/
void setRotateMarker( bool rotate ) { mRotateMarker = rotate; }

/**
* The interval between individual markers.
*/
double interval() const { return mInterval; }

/**
* The interval between individual markers.
*/
void setInterval( double interval ) { mInterval = interval; }

/**
* The placement of the markers.
*/
Placement placement() const { return mPlacement; }

/**
* The placement of the markers.
*/
void setPlacement( Placement p ) { mPlacement = p; }

/** Returns the offset along the line for the marker placement. For Interval placements, this is the distance
@@ -1273,15 +1273,20 @@ void QgsMarkerSymbolV2::renderPointUsingLayer( QgsMarkerSymbolLayerV2* layer, co
}
}

void QgsMarkerSymbolV2::renderPoint( const QPointF& point, const QgsFeature* f, QgsRenderContext& context, int layer, bool selected )
void QgsMarkerSymbolV2::renderPoint( const QPointF& point, const QgsFeature* f, QgsRenderContext& context, int layerIdx, bool selected )
{
QgsSymbolV2RenderContext symbolContext( context, outputUnit(), mAlpha, selected, mRenderHints, f, 0, mapUnitScale() );

if ( layer != -1 )
if ( layerIdx != -1 )
{
if ( layer >= 0 && layer < mLayers.count() )
if ( layerIdx >= 0 && layerIdx < mLayers.count() )
{
renderPointUsingLayer(( QgsMarkerSymbolLayerV2* ) mLayers[layer], point, symbolContext );
QgsMarkerSymbolLayerV2* markerLayer = dynamic_cast<QgsMarkerSymbolLayerV2*>( mLayers.at( layerIdx ) );

if ( markerLayer )
renderPointUsingLayer( markerLayer, point, symbolContext );
else
renderUsingLayer( mLayers.at( layerIdx ), symbolContext );
}
return;
}
@@ -1292,6 +1297,8 @@ void QgsMarkerSymbolV2::renderPoint( const QPointF& point, const QgsFeature* f,

if ( markerLayer )
renderPointUsingLayer( markerLayer, point, symbolContext );
else
renderUsingLayer( layer, symbolContext );
}
}

@@ -1459,24 +1466,34 @@ QgsDataDefined QgsLineSymbolV2::dataDefinedWidth() const
return QgsDataDefined( *symbolDD );
}

void QgsLineSymbolV2::renderPolyline( const QPolygonF& points, const QgsFeature* f, QgsRenderContext& context, int layer, bool selected )
void QgsLineSymbolV2::renderPolyline( const QPolygonF& points, const QgsFeature* f, QgsRenderContext& context, int layerIdx, bool selected )
{
//save old painter
QPainter* renderPainter = context.painter();
QgsSymbolV2RenderContext symbolContext( context, outputUnit(), mAlpha, selected, mRenderHints, f, 0, mapUnitScale() );

if ( layer != -1 )
if ( layerIdx != -1 )
{
if ( layer >= 0 && layer < mLayers.count() )
if ( layerIdx >= 0 && layerIdx < mLayers.count() )
{
renderPolylineUsingLayer(( QgsLineSymbolLayerV2* ) mLayers[layer], points, symbolContext );
QgsLineSymbolLayerV2* lineLayer = dynamic_cast<QgsLineSymbolLayerV2*>( mLayers.at( layerIdx ) );

if ( lineLayer )
renderPolylineUsingLayer( lineLayer, points, symbolContext );
else
renderUsingLayer( mLayers.at( layerIdx ), symbolContext );
}
return;
}

for ( QgsSymbolLayerV2List::iterator it = mLayers.begin(); it != mLayers.end(); ++it )
Q_FOREACH ( QgsSymbolLayerV2* symbolLayer, mLayers )
{
renderPolylineUsingLayer(( QgsLineSymbolLayerV2* ) * it, points, symbolContext );
QgsLineSymbolLayerV2* lineLayer = dynamic_cast<QgsLineSymbolLayerV2*>( symbolLayer );

if ( lineLayer )
renderPolylineUsingLayer( lineLayer, points, symbolContext );
else
renderUsingLayer( symbolLayer, symbolContext );
}

context.setPainter( renderPainter );
@@ -1523,22 +1540,29 @@ QgsFillSymbolV2::QgsFillSymbolV2( const QgsSymbolLayerV2List& layers )
mLayers.append( new QgsSimpleFillSymbolLayerV2() );
}

void QgsFillSymbolV2::renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, const QgsFeature* f, QgsRenderContext& context, int layer, bool selected )
void QgsFillSymbolV2::renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, const QgsFeature* f, QgsRenderContext& context, int layerIdx, bool selected )
{
QgsSymbolV2RenderContext symbolContext( context, outputUnit(), mAlpha, selected, mRenderHints, f, 0, mapUnitScale() );

if ( layer != -1 )
if ( layerIdx != -1 )
{
if ( layer >= 0 && layer < mLayers.count() )
if ( layerIdx >= 0 && layerIdx < mLayers.count() )
{
renderPolygonUsingLayer( mLayers[layer], points, rings, symbolContext );
QgsSymbolLayerV2* layer = mLayers.at( layerIdx );
if ( layer->type() == Fill || layer->type() == Line )
renderPolygonUsingLayer( layer, points, rings, symbolContext );
else
renderUsingLayer( layer, symbolContext );
}
return;
}

for ( QgsSymbolLayerV2List::iterator it = mLayers.begin(); it != mLayers.end(); ++it )
Q_FOREACH ( QgsSymbolLayerV2* layer, mLayers )
{
renderPolygonUsingLayer( *it, points, rings, symbolContext );
if ( layer->type() == Fill || layer->type() == Line )
renderPolygonUsingLayer( layer, points, rings, symbolContext );
else
renderUsingLayer( layer, symbolContext );
}
}

0 comments on commit 554b41d

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