Skip to content
Permalink
Browse files

[FEATURE]: rotation for svg fills

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15139 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent
mhugent committed Feb 8, 2011
1 parent 98b631c commit ebbaa6fbfce6b95ff664ac281ab546cae5da7094
@@ -589,6 +589,9 @@ public:

void drawPreviewIcon(QgsSymbolV2RenderContext& context, QSize size);

void setAngle( double angle );
double angle() const;

protected:
QgsFillSymbolLayerV2(bool locked = false);
};
@@ -785,6 +788,7 @@ class QgsFillSymbolV2 : QgsSymbolV2
public:
QgsFillSymbolV2(QgsSymbolLayerV2List layers /Transfer/ = QgsSymbolLayerV2List());

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

virtual QgsSymbolV2* clone() const /Factory/;
@@ -116,17 +116,20 @@ QgsSymbolLayerV2* QgsSimpleFillSymbolLayerV2::clone() const

//QgsSVGFillSymbolLayer

QgsSVGFillSymbolLayer::QgsSVGFillSymbolLayer( const QString& svgFilePath, double width ): mPatternWidth( width ), mOutline( 0 )
QgsSVGFillSymbolLayer::QgsSVGFillSymbolLayer( const QString& svgFilePath, double width, double angle ): mPatternWidth( width ), mOutline( 0 )
{
setSvgFilePath( svgFilePath );
mOutlineWidth = 0.3;
mAngle = angle;
setSubSymbol( new QgsLineSymbolV2() );
}

QgsSVGFillSymbolLayer::QgsSVGFillSymbolLayer( const QByteArray& svgData, double width ): mPatternWidth( width ), mSvgData( svgData ), mOutline( 0 )
QgsSVGFillSymbolLayer::QgsSVGFillSymbolLayer( const QByteArray& svgData, double width, double angle ): mPatternWidth( width ),
mSvgData( svgData ), mOutline( 0 )
{
storeViewBox();
mOutlineWidth = 0.3;
mAngle = angle;
setSubSymbol( new QgsLineSymbolV2() );
}

@@ -151,6 +154,7 @@ QgsSymbolLayerV2* QgsSVGFillSymbolLayer::create( const QgsStringMap& properties
QByteArray data;
double width = 20;
QString svgFilePath;
double angle = 0.0;


if ( properties.contains( "width" ) )
@@ -163,10 +167,14 @@ QgsSymbolLayerV2* QgsSVGFillSymbolLayer::create( const QgsStringMap& properties
QString savePath = QgsSvgMarkerSymbolLayerV2::symbolNameToPath( svgName );
svgFilePath = ( savePath.isEmpty() ? svgName : savePath );
}
if ( properties.contains( "angle" ) )
{
angle = properties["angle"].toDouble();
}

if ( !svgFilePath.isEmpty() )
{
return new QgsSVGFillSymbolLayer( svgFilePath, width );
return new QgsSVGFillSymbolLayer( svgFilePath, width, angle );
}
else
{
@@ -175,7 +183,7 @@ QgsSymbolLayerV2* QgsSVGFillSymbolLayer::create( const QgsStringMap& properties
data = QByteArray::fromHex( properties["data"].toLocal8Bit() );
}

return new QgsSVGFillSymbolLayer( data, width );
return new QgsSVGFillSymbolLayer( data, width, angle );
}
}

@@ -205,6 +213,7 @@ void QgsSVGFillSymbolLayer::startRender( QgsSymbolV2RenderContext& context )
{
return;
}

r.render( &p );

if ( context.alpha() < 1.0 )
@@ -246,7 +255,19 @@ void QgsSVGFillSymbolLayer::renderPolygon( const QPolygonF& points, QList<QPolyg
p->setBrush( QBrush( selColor ) );
_renderPolygon( p, points, rings );
}
p->setBrush( mBrush );

if ( doubleNear( mAngle, 0.0 ) )
{
p->setBrush( mBrush );
}
else
{
QTransform t;
t.rotate( mAngle );
QBrush rotatedBrush = mBrush;
rotatedBrush.setTransform( t );
p->setBrush( rotatedBrush );
}
_renderPolygon( p, points, rings );
if ( mOutline )
{
@@ -275,6 +296,7 @@ QgsStringMap QgsSVGFillSymbolLayer::properties() const
}

map.insert( "width", QString::number( mPatternWidth ) );
map.insert( "angle", QString::number( mAngle ) );
return map;
}

@@ -283,11 +305,11 @@ QgsSymbolLayerV2* QgsSVGFillSymbolLayer::clone() const
QgsSymbolLayerV2* clonedLayer = 0;
if ( !mSvgFilePath.isEmpty() )
{
clonedLayer = new QgsSVGFillSymbolLayer( mSvgFilePath, mPatternWidth );
clonedLayer = new QgsSVGFillSymbolLayer( mSvgFilePath, mPatternWidth, mAngle );
}
else
{
clonedLayer = new QgsSVGFillSymbolLayer( mSvgData, mPatternWidth );
clonedLayer = new QgsSVGFillSymbolLayer( mSvgData, mPatternWidth, mAngle );
}

if ( mOutline )
@@ -72,8 +72,8 @@ class CORE_EXPORT QgsSimpleFillSymbolLayerV2 : public QgsFillSymbolLayerV2
class CORE_EXPORT QgsSVGFillSymbolLayer: public QgsFillSymbolLayerV2
{
public:
QgsSVGFillSymbolLayer( const QString& svgFilePath = "", double width = 20 );
QgsSVGFillSymbolLayer( const QByteArray& svgData, double width = 20 );
QgsSVGFillSymbolLayer( const QString& svgFilePath = "", double width = 20, double rotation = 0.0 );
QgsSVGFillSymbolLayer( const QByteArray& svgData, double width = 20, double rotation = 0.0 );
~QgsSVGFillSymbolLayer();

static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() );
@@ -91,7 +91,7 @@ class CORE_EXPORT QgsSVGFillSymbolLayer: public QgsFillSymbolLayerV2

QgsSymbolLayerV2* clone() const;

//gettersn and setters
//getters and setters
void setSvgFilePath( const QString& svgPath );
QString svgFilePath() const { return mSvgFilePath; }
void setPatternWidth( double width ) { mPatternWidth = width;}
@@ -53,6 +53,12 @@ QgsSymbolV2* QgsSingleSymbolRendererV2::symbolForFeature( QgsFeature& feature )
if ( mSizeScaleFieldIdx != -1 )
lineSymbol->setWidth( sizeScale * mOrigSize );
}
else if ( mTempSymbol->type() == QgsSymbolV2::Fill )
{
QgsFillSymbolV2* fillSymbol = static_cast<QgsFillSymbolV2*>( mTempSymbol );
if ( mRotationFieldIdx != -1 )
fillSymbol->setAngle( rotation );
}

return mTempSymbol;
}
@@ -120,10 +120,15 @@ class CORE_EXPORT QgsFillSymbolLayerV2 : public QgsSymbolLayerV2

void drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size );

void setAngle( double angle ) { mAngle = angle; }
double angle() const { return mAngle; }

protected:
QgsFillSymbolLayerV2( bool locked = false );
/**Default method to render polygon*/
void _renderPolygon( QPainter* p, const QPolygonF& points, const QList<QPolygonF>* rings );

double mAngle;
};

class QgsSymbolLayerV2Widget;
@@ -512,3 +512,12 @@ QgsSymbolV2* QgsFillSymbolV2::clone() const
cloneSymbol->setAlpha( mAlpha );
return cloneSymbol;
}

void QgsFillSymbolV2::setAngle( double angle )
{
for ( QgsSymbolLayerV2List::iterator it = mLayers.begin(); it != mLayers.end(); ++it )
{
QgsFillSymbolLayerV2* layer = ( QgsFillSymbolLayerV2* ) * it;
layer->setAngle( angle );
}
}
@@ -202,7 +202,7 @@ class CORE_EXPORT QgsFillSymbolV2 : public QgsSymbolV2
{
public:
QgsFillSymbolV2( QgsSymbolLayerV2List layers = QgsSymbolLayerV2List() );

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

virtual QgsSymbolV2* clone() const;
@@ -678,6 +678,7 @@ void QgsSVGFillSymbolLayerWidget::setSymbolLayer( QgsSymbolLayerV2* layer )
double width = mLayer->patternWidth();
mTextureWidthSpinBox->setValue( width );
mSVGLineEdit->setText( mLayer->svgFilePath() );
mRotationSpinBox->setValue( mLayer->angle() );
}
updateOutlineIcon();
}
@@ -745,6 +746,15 @@ void QgsSVGFillSymbolLayerWidget::on_mChangeOutlinePushButton_clicked()
emit changed();
}

void QgsSVGFillSymbolLayerWidget::on_mRotationSpinBox_valueChanged( double d )
{
if ( mLayer )
{
mLayer->setAngle( d );
}
emit changed();
}

void QgsSVGFillSymbolLayerWidget::updateOutlineIcon()
{
if ( mLayer )
@@ -247,6 +247,7 @@ class GUI_EXPORT QgsSVGFillSymbolLayerWidget : public QgsSymbolLayerV2Widget, pr
void on_mSVGLineEdit_textChanged( const QString & text );
void setFile( const QModelIndex& item );
void on_mChangeOutlinePushButton_clicked();
void on_mRotationSpinBox_valueChanged( double d );
};

//////////
@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>211</width>
<height>199</height>
<width>185</width>
<height>221</height>
</rect>
</property>
<property name="windowTitle">
@@ -33,6 +33,24 @@
</layout>
</item>
<item row="1" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="mRotationLabel">
<property name="text">
<string>Rotation</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="mRotationSpinBox">
<property name="maximum">
<double>360.000000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="mOutlineLabel">
@@ -50,7 +68,7 @@
</item>
</layout>
</item>
<item row="2" column="0">
<item row="3" column="0">
<widget class="QListView" name="mSvgListView">
<property name="flow">
<enum>QListView::LeftToRight</enum>
@@ -66,7 +84,7 @@
</property>
</widget>
</item>
<item row="3" column="0">
<item row="4" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLineEdit" name="mSVGLineEdit"/>

0 comments on commit ebbaa6f

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