Skip to content

Commit

Permalink
symbology-ng: fix data defined properties of centroid fill markers (f…
Browse files Browse the repository at this point in the history
…ixes #8318)
  • Loading branch information
jef-n committed Jul 22, 2013
1 parent 4e4bf8e commit 1d5712c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 40 deletions.
12 changes: 12 additions & 0 deletions src/core/symbology-ng/qgsfillsymbollayerv2.cpp
Expand Up @@ -1718,6 +1718,18 @@ bool QgsCentroidFillSymbolLayerV2::setSubSymbol( QgsSymbolV2* symbol )
return true;
}

QSet<QString> QgsCentroidFillSymbolLayerV2::usedAttributes() const
{
QSet<QString> attributes;

attributes.unite( QgsSymbolLayerV2::usedAttributes() );

if ( mMarker )
attributes.unite( mMarker->usedAttributes() );

return attributes;
}

QgsSymbolV2::OutputUnit QgsCentroidFillSymbolLayerV2::outputUnit() const
{
if ( mMarker )
Expand Down
2 changes: 2 additions & 0 deletions src/core/symbology-ng/qgsfillsymbollayerv2.h
Expand Up @@ -384,6 +384,8 @@ class CORE_EXPORT QgsCentroidFillSymbolLayerV2 : public QgsFillSymbolLayerV2
void setOutputUnit( QgsSymbolV2::OutputUnit unit ) { Q_UNUSED( unit ); }
QgsSymbolV2::OutputUnit outputUnit() const;

virtual QSet<QString> usedAttributes() const;

protected:
QgsMarkerSymbolV2* mMarker;
};
Expand Down
51 changes: 14 additions & 37 deletions src/core/symbology-ng/qgsmarkersymbollayerv2.cpp
Expand Up @@ -413,8 +413,7 @@ bool QgsSimpleMarkerSymbolLayerV2::preparePath( QString name )

void QgsSimpleMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context )
{
QgsRenderContext& rc = context.renderContext();
QPainter* p = rc.painter();
QPainter *p = context.renderContext().painter();
if ( !p )
{
return;
Expand Down Expand Up @@ -460,42 +459,20 @@ void QgsSimpleMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV
{
QMatrix transform;


bool hasDataDefinedRotation = context.renderHints() & QgsSymbolV2::DataDefinedRotation || angleExpression;
QgsExpression* sizeExpression = expression( "size" );
bool hasDataDefinedSize = context.renderHints() & QgsSymbolV2::DataDefinedSizeScale || sizeExpression;

// move to the desired position
transform.translate( point.x() + off.x(), point.y() + off.y() );

// resize if necessary
if ( hasDataDefinedSize )
{
double scaledSize = mSize;
if ( sizeExpression )
{
scaledSize = sizeExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toDouble();
}
scaledSize *= QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mSizeUnit );

switch ( mScaleMethod )
{
case QgsSymbolV2::ScaleArea:
scaledSize = sqrt( scaledSize );
break;
case QgsSymbolV2::ScaleDiameter:
break;
}

double half = scaledSize / 2.0;
transform.scale( half, half );
}
double size = mSize;
QgsExpression* sizeExpression = expression( "size" );

// rotate if necessary
if ( angle != 0 && hasDataDefinedRotation )
if ( sizeExpression )
{
transform.rotate( angle );
size = sizeExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toDouble();
}
size *= QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mSizeUnit );

double half = size / 2.0;
transform.scale( half, half );

QgsExpression* colorExpression = expression( "color" );
QgsExpression* colorBorderExpression = expression( "color_border" );
Expand Down Expand Up @@ -835,11 +812,9 @@ void QgsSvgMarkerSymbolLayerV2::stopRender( QgsSymbolV2RenderContext& context )

void QgsSvgMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context )
{
QPainter* p = context.renderContext().painter();
QPainter *p = context.renderContext().painter();
if ( !p )
{
return;
}

double size = mSize;
QgsExpression* sizeExpression = expression( "size" );
Expand Down Expand Up @@ -1167,13 +1142,15 @@ void QgsFontMarkerSymbolLayerV2::stopRender( QgsSymbolV2RenderContext& context )

void QgsFontMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context )
{
QPainter* p = context.renderContext().painter();
QPainter *p = context.renderContext().painter();
if ( !p )
return;

QColor penColor = context.selected() ? context.renderContext().selectionColor() : mColor;
penColor.setAlphaF( mColor.alphaF() * context.alpha() );
p->setPen( penColor );
p->setFont( mFont );


p->save();
double offsetX = mOffset.x() * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit );
double offsetY = mOffset.y() * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit );
Expand Down
6 changes: 3 additions & 3 deletions src/core/symbology-ng/qgssymbollayerv2.cpp
Expand Up @@ -96,7 +96,6 @@ void QgsSymbolLayerV2::prepareExpressions( const QgsVectorLayer* vl )

QSet<QString> QgsSymbolLayerV2::usedAttributes() const
{
QSet<QString> attributes;
QStringList columns;

QMap< QString, QgsExpression* >::const_iterator ddIt = mDataDefinedProperties.constBegin();
Expand All @@ -108,11 +107,13 @@ QSet<QString> QgsSymbolLayerV2::usedAttributes() const
}
}

QSet<QString> attributes;
QStringList::const_iterator it = columns.constBegin();
for ( ; it != columns.constEnd(); ++it )
{
attributes.insert( *it );
}

return attributes;
}

Expand All @@ -131,9 +132,8 @@ void QgsSymbolLayerV2::saveDataDefinedProperties( QgsStringMap& stringMap ) cons
void QgsSymbolLayerV2::copyDataDefinedProperties( QgsSymbolLayerV2* destLayer ) const
{
if ( !destLayer )
{
return;
}

destLayer->removeDataDefinedProperties();

QMap< QString, QgsExpression* >::const_iterator ddIt = mDataDefinedProperties.constBegin();
Expand Down

0 comments on commit 1d5712c

Please sign in to comment.