12 changes: 12 additions & 0 deletions python/core/symbology-ng/qgsellipsesymbollayerv2.sip
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ class QgsEllipseSymbolLayerV2 : QgsMarkerSymbolLayerV2
void setOutlineColor( const QColor& c );
QColor outlineColor() const;

void setSymbolWidthUnit( QgsSymbolV2::OutputUnit unit );
QgsSymbolV2::OutputUnit symbolWidthUnit() const;

void setSymbolHeightUnit( QgsSymbolV2::OutputUnit unit );
QgsSymbolV2::OutputUnit symbolHeightUnit() const;

void setOutlineWidthUnit( QgsSymbolV2::OutputUnit unit );
QgsSymbolV2::OutputUnit outlineWidthUnit() const;

void setOutputUnit( QgsSymbolV2::OutputUnit unit );
QgsSymbolV2::OutputUnit outputUnit() const;

QSet<QString> usedAttributes() const;

};
49 changes: 49 additions & 0 deletions python/core/symbology-ng/qgsfillsymbollayerv2.sip
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ class QgsSimpleFillSymbolLayerV2 : QgsFillSymbolLayerV2

void setOffset( QPointF offset );
QPointF offset();

void setBorderWidthUnit( QgsSymbolV2::OutputUnit unit );
QgsSymbolV2::OutputUnit borderWidthUnit() const;

void setOffsetUnit( QgsSymbolV2::OutputUnit unit );
QgsSymbolV2::OutputUnit offsetUnit() const;

void setOutputUnit( QgsSymbolV2::OutputUnit unit );
QgsSymbolV2::OutputUnit outputUnit() const;
};

/**Base class for polygon renderers generating texture images*/
Expand All @@ -62,6 +71,9 @@ class QgsImageFillSymbolLayer: QgsFillSymbolLayerV2

virtual QgsSymbolV2* subSymbol();
virtual bool setSubSymbol( QgsSymbolV2* symbol );

void setOutlineWidthUnit( QgsSymbolV2::OutputUnit unit );
QgsSymbolV2::OutputUnit outlineWidthUnit() const;
};

/**A class for svg fill patterns. The class automatically scales the pattern to
Expand Down Expand Up @@ -105,6 +117,16 @@ class QgsSVGFillSymbolLayer: QgsImageFillSymbolLayer
QColor svgOutlineColor() const;
void setSvgOutlineWidth( double w );
double svgOutlineWidth() const;

void setPatternWidthUnit( QgsSymbolV2::OutputUnit unit );
QgsSymbolV2::OutputUnit patternWidthUnit() const;

void setSvgOutlineWidthUnit( QgsSymbolV2::OutputUnit unit );
QgsSymbolV2::OutputUnit svgOutlineWidthUnit() const;

void setOutputUnit( QgsSymbolV2::OutputUnit unit );
QgsSymbolV2::OutputUnit outputUnit() const;

};

class QgsLinePatternFillSymbolLayer: QgsImageFillSymbolLayer
Expand Down Expand Up @@ -142,6 +164,18 @@ class QgsLinePatternFillSymbolLayer: QgsImageFillSymbolLayer
QColor color() const;
void setOffset( double offset );
double offset() const;

void setDistanceUnit( QgsSymbolV2::OutputUnit unit );
QgsSymbolV2::OutputUnit distanceUnit() const;

void setLineWidthUnit( QgsSymbolV2::OutputUnit unit );
QgsSymbolV2::OutputUnit lineWidthUnit() const;

void setOffsetUnit( QgsSymbolV2::OutputUnit unit );
QgsSymbolV2::OutputUnit offsetUnit() const;

void setOutputUnit( QgsSymbolV2::OutputUnit unit );
QgsSymbolV2::OutputUnit outputUnit() const;
};

class QgsPointPatternFillSymbolLayer : QgsImageFillSymbolLayer
Expand Down Expand Up @@ -183,6 +217,21 @@ class QgsPointPatternFillSymbolLayer : QgsImageFillSymbolLayer

bool setSubSymbol( QgsSymbolV2* symbol );
virtual QgsSymbolV2* subSymbol();

void setDistanceXUnit( QgsSymbolV2::OutputUnit unit );
QgsSymbolV2::OutputUnit distanceXUnit() const;

void setDistanceYUnit( QgsSymbolV2::OutputUnit unit );
QgsSymbolV2::OutputUnit distanceYUnit() const;

void setDisplacementXUnit( QgsSymbolV2::OutputUnit unit );
QgsSymbolV2::OutputUnit displacementXUnit() const;

void setDisplacementYUnit( QgsSymbolV2::OutputUnit unit );
QgsSymbolV2::OutputUnit displacementYUnit() const;

void setOutputUnit( QgsSymbolV2::OutputUnit unit );
QgsSymbolV2::OutputUnit outputUnit() const;
};

class QgsCentroidFillSymbolLayerV2 : QgsFillSymbolLayerV2
Expand Down
18 changes: 18 additions & 0 deletions python/core/symbology-ng/qgslinesymbollayerv2.sip
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,15 @@ class QgsSimpleLineSymbolLayerV2 : QgsLineSymbolLayerV2
double offset() const;
void setOffset( double offset );

QgsSymbolV2::OutputUnit offsetUnit() const;
void setOffsetUnit( QgsSymbolV2::OutputUnit unit );

bool useCustomDashPattern() const;
void setUseCustomDashPattern( bool b );

QgsSymbolV2::OutputUnit customDashPatternUnit() const;
void setCustomDashPatternUnit( QgsSymbolV2::OutputUnit unit );

QVector<qreal> customDashVector() const;
void setCustomDashVector( const QVector<qreal>& vector );
};
Expand Down Expand Up @@ -114,6 +120,15 @@ class QgsMarkerLineSymbolLayerV2 : QgsLineSymbolLayerV2
double offset() const;
void setOffset( double offset );

QgsSymbolV2::OutputUnit intervalUnit() const;
void setIntervalUnit( QgsSymbolV2::OutputUnit unit );

QgsSymbolV2::OutputUnit offsetUnit() const;
void setOffsetUnit( QgsSymbolV2::OutputUnit unit );

void setOutputUnit( QgsSymbolV2::OutputUnit unit );
QgsSymbolV2::OutputUnit outputUnit() const;

Placement placement() const;
void setPlacement( Placement p );

Expand Down Expand Up @@ -157,4 +172,7 @@ class QgsLineDecorationSymbolLayerV2 : QgsLineSymbolLayerV2
QgsSymbolLayerV2* clone() const /Factory/;

void toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const;

void setOutputUnit( QgsSymbolV2::OutputUnit unit );
QgsSymbolV2::OutputUnit outputUnit() const;
};
12 changes: 12 additions & 0 deletions python/core/symbology-ng/qgsmarkersymbollayerv2.sip
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ class QgsSimpleMarkerSymbolLayerV2 : QgsMarkerSymbolLayerV2
QColor borderColor() const;
void setBorderColor( QColor color );

double outlineWidth() const;
void setOutlineWidth( double w );

QgsSymbolV2::OutputUnit outlineWidthUnit() const;
void setOutlineWidthUnit( QgsSymbolV2::OutputUnit u );

protected:

void drawMarker( QPainter* p, QgsSymbolV2RenderContext& context );
Expand Down Expand Up @@ -92,6 +98,12 @@ class QgsSvgMarkerSymbolLayerV2 : QgsMarkerSymbolLayerV2

double outlineWidth() const;
void setOutlineWidth( double w );

void setOutlineWidthUnit( QgsSymbolV2::OutputUnit unit );
QgsSymbolV2::OutputUnit outlineWidthUnit() const;

void setOutputUnit( QgsSymbolV2::OutputUnit unit );
QgsSymbolV2::OutputUnit outputUnit() const;
};

class QgsFontMarkerSymbolLayerV2 : QgsMarkerSymbolLayerV2
Expand Down
28 changes: 28 additions & 0 deletions python/core/symbology-ng/qgssymbollayerv2.sip
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,31 @@ class QgsSymbolLayerV2
void setLocked( bool locked );
bool isLocked() const;

virtual void setOutputUnit( QgsSymbolV2::OutputUnit unit );
virtual QgsSymbolV2::OutputUnit outputUnit() const;

// used only with rending with symbol levels is turned on (0 = first pass, 1 = second, ...)
void setRenderingPass( int renderingPass );
int renderingPass() const;

// symbol layers normally only use additional attributes to provide data defined settings
virtual QSet<QString> usedAttributes() const;

virtual const QgsExpression* dataDefinedProperty( const QString& property ) const;
virtual QString dataDefinedPropertyString( const QString& property ) const;
virtual void setDataDefinedProperty( const QString& property, const QString& expressionString );
virtual void removeDataDefinedProperty( const QString& property );
virtual void removeDataDefinedProperties();

protected:
QgsSymbolLayerV2( QgsSymbolV2::SymbolType type, bool locked = false );

virtual void prepareExpressions( const QgsVectorLayer* vl );
virtual QgsExpression* expression( const QString& property );
/**Saves data defined properties to string map*/
void saveDataDefinedProperties( QgsStringMap& stringMap ) const;
/**Copies data defined properties of this layer to another symbol layer*/
void copyDataDefinedProperties( QgsSymbolLayerV2* destLayer ) const;
};

//////////////////////
Expand Down Expand Up @@ -130,6 +146,15 @@ class QgsMarkerSymbolLayerV2 : QgsSymbolLayerV2

virtual void writeSldMarker( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const;

void setOffsetUnit( QgsSymbolV2::OutputUnit unit );
QgsSymbolV2::OutputUnit offsetUnit() const;

void setSizeUnit( QgsSymbolV2::OutputUnit unit );
QgsSymbolV2::OutputUnit sizeUnit() const;

virtual void setOutputUnit( QgsSymbolV2::OutputUnit unit );
virtual QgsSymbolV2::OutputUnit outputUnit() const;

protected:
QgsMarkerSymbolLayerV2( bool locked = false );
};
Expand All @@ -149,6 +174,9 @@ class QgsLineSymbolLayerV2 : QgsSymbolLayerV2
virtual void setWidth( double width );
virtual double width() const;

void setWidthUnit( QgsSymbolV2::OutputUnit unit );
QgsSymbolV2::OutputUnit widthUnit() const;

void drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size );

protected:
Expand Down
27 changes: 25 additions & 2 deletions src/core/symbology-ng/qgsellipsesymbollayerv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ QgsEllipseSymbolLayerV2::QgsEllipseSymbolLayerV2(): mSymbolName( "circle" ), mSy
mPen.setJoinStyle( Qt::MiterJoin );
mBrush.setColor( mFillColor );
mBrush.setStyle( Qt::SolidPattern );
mOffset = QPointF( 0, 0 );

mAngle = 0;
}
Expand Down Expand Up @@ -83,6 +84,14 @@ QgsSymbolLayerV2* QgsEllipseSymbolLayerV2::create( const QgsStringMap& propertie
{
layer->setOutlineColor( QgsSymbolLayerV2Utils::decodeColor( properties["outline_color"] ) );
}
if ( properties.contains( "offset" ) )
{
layer->setOffset( QgsSymbolLayerV2Utils::decodePoint( properties["offset"] ) );
}
if ( properties.contains( "offset_unit" ) )
{
layer->setOffsetUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( properties["offset_unit"] ) );
}

//data defined properties
if ( properties.contains( "width_expression" ) )
Expand Down Expand Up @@ -113,6 +122,10 @@ QgsSymbolLayerV2* QgsEllipseSymbolLayerV2::create( const QgsStringMap& propertie
{
layer->setDataDefinedProperty( "symbol_name", properties["symbol_name_expression"] );
}
if ( properties.contains( "offset_expression" ) )
{
layer->setDataDefinedProperty( "offset", properties["offset_expression"] );
}

//compatibility with old project file format
if ( !properties["width_field"].isEmpty() )
Expand Down Expand Up @@ -183,6 +196,12 @@ void QgsEllipseSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2Rend
preparePath( symbolName, context, context.feature() );
}

//offset
double offsetX = 0;
double offsetY = 0;
markerOffset( context, offsetX, offsetY );
QPointF off( offsetX, offsetY );

QPainter* p = context.renderContext().painter();
if ( !p )
{
Expand All @@ -199,9 +218,11 @@ void QgsEllipseSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2Rend
{
rotation = mAngle;
}
if ( rotation )
off = _rotatedOffset( off, rotation );

QMatrix transform;
transform.translate( point.x(), point.y() );
transform.translate( point.x() + off.x(), point.y() + off.y() );
if ( !qgsDoubleNear( rotation, 0.0 ) )
{
transform.rotate( rotation );
Expand Down Expand Up @@ -362,6 +383,8 @@ QgsStringMap QgsEllipseSymbolLayerV2::properties() const
map["outline_width_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( mOutlineWidthUnit );
map["fill_color"] = QgsSymbolLayerV2Utils::encodeColor( mFillColor );
map["outline_color"] = QgsSymbolLayerV2Utils::encodeColor( mOutlineColor );
map["offset"] = QgsSymbolLayerV2Utils::encodePoint( mOffset );
map["offset_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( mOffsetUnit );
saveDataDefinedProperties( map );
return map;
}
Expand All @@ -370,7 +393,7 @@ bool QgsEllipseSymbolLayerV2::hasDataDefinedProperty() const
{
return ( dataDefinedProperty( "width" ) || dataDefinedProperty( "height" ) || dataDefinedProperty( "rotation" )
|| dataDefinedProperty( "outline_width" ) || dataDefinedProperty( "fill_color" ) || dataDefinedProperty( "outline_color" )
|| dataDefinedProperty( "symbol_name" ) );
|| dataDefinedProperty( "symbol_name" ) || dataDefinedProperty( "offset" ) );
}

void QgsEllipseSymbolLayerV2::preparePath( const QString& symbolName, QgsSymbolV2RenderContext& context, const QgsFeature* f )
Expand Down
32 changes: 0 additions & 32 deletions src/core/symbology-ng/qgsmarkersymbollayerv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,6 @@

#include <cmath>

// MSVC compiler doesn't have defined M_PI in math.h
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif

#define DEG2RAD(x) ((x)*M_PI/180)


static QPointF _rotatedOffset( const QPointF& offset, double angle )
{
angle = DEG2RAD( angle );
double c = cos( angle ), s = sin( angle );
return QPointF( offset.x() * c - offset.y() * s, offset.x() * s + offset.y() * c );
}

//////

QgsSimpleMarkerSymbolLayerV2::QgsSimpleMarkerSymbolLayerV2( QString name, QColor color, QColor borderColor, double size, double angle, QgsSymbolV2::ScaleMethod scaleMethod )
Expand Down Expand Up @@ -426,23 +411,6 @@ bool QgsSimpleMarkerSymbolLayerV2::preparePath( QString name )
return false;
}

void QgsSimpleMarkerSymbolLayerV2::markerOffset( QgsSymbolV2RenderContext& context, double& offsetX, double& offsetY )
{
offsetX = mOffset.x();
offsetY = mOffset.y();

QgsExpression* offsetExpression = expression( "offset" );
if ( offsetExpression )
{
QPointF offset = QgsSymbolLayerV2Utils::decodePoint( offsetExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString() );
offsetX = offset.x();
offsetY = offset.y();
}

offsetX *= QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit );
offsetY *= QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit );
}

void QgsSimpleMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context )
{
QgsRenderContext& rc = context.renderContext();
Expand Down
3 changes: 0 additions & 3 deletions src/core/symbology-ng/qgsmarkersymbollayerv2.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,6 @@ class CORE_EXPORT QgsSimpleMarkerSymbolLayerV2 : public QgsMarkerSymbolLayerV2
QBrush mSelBrush;
QImage mSelCache;
bool mUsingCache;

private:
void markerOffset( QgsSymbolV2RenderContext& context, double& offsetX, double& offsetY );
};

//////////
Expand Down
Loading