Skip to content

Commit 04af2f9

Browse files
author
mhugent
committedFeb 8, 2011
[FEATURE]: rotation for svg fills
git-svn-id: http://svn.osgeo.org/qgis/trunk@15139 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 6a2c261 commit 04af2f9

File tree

10 files changed

+90
-15
lines changed

10 files changed

+90
-15
lines changed
 

‎python/core/symbology-ng-core.sip

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,9 @@ public:
589589

590590
void drawPreviewIcon(QgsSymbolV2RenderContext& context, QSize size);
591591

592+
void setAngle( double angle );
593+
double angle() const;
594+
592595
protected:
593596
QgsFillSymbolLayerV2(bool locked = false);
594597
};
@@ -785,6 +788,7 @@ class QgsFillSymbolV2 : QgsSymbolV2
785788
public:
786789
QgsFillSymbolV2(QgsSymbolLayerV2List layers /Transfer/ = QgsSymbolLayerV2List());
787790

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

790794
virtual QgsSymbolV2* clone() const /Factory/;

‎src/core/symbology-ng/qgsfillsymbollayerv2.cpp

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,17 +116,20 @@ QgsSymbolLayerV2* QgsSimpleFillSymbolLayerV2::clone() const
116116

117117
//QgsSVGFillSymbolLayer
118118

119-
QgsSVGFillSymbolLayer::QgsSVGFillSymbolLayer( const QString& svgFilePath, double width ): mPatternWidth( width ), mOutline( 0 )
119+
QgsSVGFillSymbolLayer::QgsSVGFillSymbolLayer( const QString& svgFilePath, double width, double angle ): mPatternWidth( width ), mOutline( 0 )
120120
{
121121
setSvgFilePath( svgFilePath );
122122
mOutlineWidth = 0.3;
123+
mAngle = angle;
123124
setSubSymbol( new QgsLineSymbolV2() );
124125
}
125126

126-
QgsSVGFillSymbolLayer::QgsSVGFillSymbolLayer( const QByteArray& svgData, double width ): mPatternWidth( width ), mSvgData( svgData ), mOutline( 0 )
127+
QgsSVGFillSymbolLayer::QgsSVGFillSymbolLayer( const QByteArray& svgData, double width, double angle ): mPatternWidth( width ),
128+
mSvgData( svgData ), mOutline( 0 )
127129
{
128130
storeViewBox();
129131
mOutlineWidth = 0.3;
132+
mAngle = angle;
130133
setSubSymbol( new QgsLineSymbolV2() );
131134
}
132135

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

155159

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

167175
if ( !svgFilePath.isEmpty() )
168176
{
169-
return new QgsSVGFillSymbolLayer( svgFilePath, width );
177+
return new QgsSVGFillSymbolLayer( svgFilePath, width, angle );
170178
}
171179
else
172180
{
@@ -175,7 +183,7 @@ QgsSymbolLayerV2* QgsSVGFillSymbolLayer::create( const QgsStringMap& properties
175183
data = QByteArray::fromHex( properties["data"].toLocal8Bit() );
176184
}
177185

178-
return new QgsSVGFillSymbolLayer( data, width );
186+
return new QgsSVGFillSymbolLayer( data, width, angle );
179187
}
180188
}
181189

@@ -205,6 +213,7 @@ void QgsSVGFillSymbolLayer::startRender( QgsSymbolV2RenderContext& context )
205213
{
206214
return;
207215
}
216+
208217
r.render( &p );
209218

210219
if ( context.alpha() < 1.0 )
@@ -246,7 +255,19 @@ void QgsSVGFillSymbolLayer::renderPolygon( const QPolygonF& points, QList<QPolyg
246255
p->setBrush( QBrush( selColor ) );
247256
_renderPolygon( p, points, rings );
248257
}
249-
p->setBrush( mBrush );
258+
259+
if ( doubleNear( mAngle, 0.0 ) )
260+
{
261+
p->setBrush( mBrush );
262+
}
263+
else
264+
{
265+
QTransform t;
266+
t.rotate( mAngle );
267+
QBrush rotatedBrush = mBrush;
268+
rotatedBrush.setTransform( t );
269+
p->setBrush( rotatedBrush );
270+
}
250271
_renderPolygon( p, points, rings );
251272
if ( mOutline )
252273
{
@@ -275,6 +296,7 @@ QgsStringMap QgsSVGFillSymbolLayer::properties() const
275296
}
276297

277298
map.insert( "width", QString::number( mPatternWidth ) );
299+
map.insert( "angle", QString::number( mAngle ) );
278300
return map;
279301
}
280302

@@ -283,11 +305,11 @@ QgsSymbolLayerV2* QgsSVGFillSymbolLayer::clone() const
283305
QgsSymbolLayerV2* clonedLayer = 0;
284306
if ( !mSvgFilePath.isEmpty() )
285307
{
286-
clonedLayer = new QgsSVGFillSymbolLayer( mSvgFilePath, mPatternWidth );
308+
clonedLayer = new QgsSVGFillSymbolLayer( mSvgFilePath, mPatternWidth, mAngle );
287309
}
288310
else
289311
{
290-
clonedLayer = new QgsSVGFillSymbolLayer( mSvgData, mPatternWidth );
312+
clonedLayer = new QgsSVGFillSymbolLayer( mSvgData, mPatternWidth, mAngle );
291313
}
292314

293315
if ( mOutline )

‎src/core/symbology-ng/qgsfillsymbollayerv2.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ class CORE_EXPORT QgsSimpleFillSymbolLayerV2 : public QgsFillSymbolLayerV2
7272
class CORE_EXPORT QgsSVGFillSymbolLayer: public QgsFillSymbolLayerV2
7373
{
7474
public:
75-
QgsSVGFillSymbolLayer( const QString& svgFilePath = "", double width = 20 );
76-
QgsSVGFillSymbolLayer( const QByteArray& svgData, double width = 20 );
75+
QgsSVGFillSymbolLayer( const QString& svgFilePath = "", double width = 20, double rotation = 0.0 );
76+
QgsSVGFillSymbolLayer( const QByteArray& svgData, double width = 20, double rotation = 0.0 );
7777
~QgsSVGFillSymbolLayer();
7878

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

9292
QgsSymbolLayerV2* clone() const;
9393

94-
//gettersn and setters
94+
//getters and setters
9595
void setSvgFilePath( const QString& svgPath );
9696
QString svgFilePath() const { return mSvgFilePath; }
9797
void setPatternWidth( double width ) { mPatternWidth = width;}

‎src/core/symbology-ng/qgssinglesymbolrendererv2.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ QgsSymbolV2* QgsSingleSymbolRendererV2::symbolForFeature( QgsFeature& feature )
5353
if ( mSizeScaleFieldIdx != -1 )
5454
lineSymbol->setWidth( sizeScale * mOrigSize );
5555
}
56+
else if ( mTempSymbol->type() == QgsSymbolV2::Fill )
57+
{
58+
QgsFillSymbolV2* fillSymbol = static_cast<QgsFillSymbolV2*>( mTempSymbol );
59+
if ( mRotationFieldIdx != -1 )
60+
fillSymbol->setAngle( rotation );
61+
}
5662

5763
return mTempSymbol;
5864
}

‎src/core/symbology-ng/qgssymbollayerv2.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,15 @@ class CORE_EXPORT QgsFillSymbolLayerV2 : public QgsSymbolLayerV2
120120

121121
void drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size );
122122

123+
void setAngle( double angle ) { mAngle = angle; }
124+
double angle() const { return mAngle; }
125+
123126
protected:
124127
QgsFillSymbolLayerV2( bool locked = false );
125128
/**Default method to render polygon*/
126129
void _renderPolygon( QPainter* p, const QPolygonF& points, const QList<QPolygonF>* rings );
130+
131+
double mAngle;
127132
};
128133

129134
class QgsSymbolLayerV2Widget;

‎src/core/symbology-ng/qgssymbolv2.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,3 +512,12 @@ QgsSymbolV2* QgsFillSymbolV2::clone() const
512512
cloneSymbol->setAlpha( mAlpha );
513513
return cloneSymbol;
514514
}
515+
516+
void QgsFillSymbolV2::setAngle( double angle )
517+
{
518+
for ( QgsSymbolLayerV2List::iterator it = mLayers.begin(); it != mLayers.end(); ++it )
519+
{
520+
QgsFillSymbolLayerV2* layer = ( QgsFillSymbolLayerV2* ) * it;
521+
layer->setAngle( angle );
522+
}
523+
}

‎src/core/symbology-ng/qgssymbolv2.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ class CORE_EXPORT QgsFillSymbolV2 : public QgsSymbolV2
202202
{
203203
public:
204204
QgsFillSymbolV2( QgsSymbolLayerV2List layers = QgsSymbolLayerV2List() );
205-
205+
void setAngle( double angle );
206206
void renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsRenderContext& context, int layer = -1, bool selected = false );
207207

208208
virtual QgsSymbolV2* clone() const;

‎src/gui/symbology-ng/qgssymbollayerv2widget.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,7 @@ void QgsSVGFillSymbolLayerWidget::setSymbolLayer( QgsSymbolLayerV2* layer )
678678
double width = mLayer->patternWidth();
679679
mTextureWidthSpinBox->setValue( width );
680680
mSVGLineEdit->setText( mLayer->svgFilePath() );
681+
mRotationSpinBox->setValue( mLayer->angle() );
681682
}
682683
updateOutlineIcon();
683684
}
@@ -745,6 +746,15 @@ void QgsSVGFillSymbolLayerWidget::on_mChangeOutlinePushButton_clicked()
745746
emit changed();
746747
}
747748

749+
void QgsSVGFillSymbolLayerWidget::on_mRotationSpinBox_valueChanged( double d )
750+
{
751+
if ( mLayer )
752+
{
753+
mLayer->setAngle( d );
754+
}
755+
emit changed();
756+
}
757+
748758
void QgsSVGFillSymbolLayerWidget::updateOutlineIcon()
749759
{
750760
if ( mLayer )

‎src/gui/symbology-ng/qgssymbollayerv2widget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ class GUI_EXPORT QgsSVGFillSymbolLayerWidget : public QgsSymbolLayerV2Widget, pr
247247
void on_mSVGLineEdit_textChanged( const QString & text );
248248
void setFile( const QModelIndex& item );
249249
void on_mChangeOutlinePushButton_clicked();
250+
void on_mRotationSpinBox_valueChanged( double d );
250251
};
251252

252253
//////////

‎src/ui/symbollayer/widget_svgfill.ui

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>211</width>
10-
<height>199</height>
9+
<width>185</width>
10+
<height>221</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -33,6 +33,24 @@
3333
</layout>
3434
</item>
3535
<item row="1" column="0">
36+
<layout class="QHBoxLayout" name="horizontalLayout_3">
37+
<item>
38+
<widget class="QLabel" name="mRotationLabel">
39+
<property name="text">
40+
<string>Rotation</string>
41+
</property>
42+
</widget>
43+
</item>
44+
<item>
45+
<widget class="QDoubleSpinBox" name="mRotationSpinBox">
46+
<property name="maximum">
47+
<double>360.000000000000000</double>
48+
</property>
49+
</widget>
50+
</item>
51+
</layout>
52+
</item>
53+
<item row="2" column="0">
3654
<layout class="QHBoxLayout" name="horizontalLayout_4">
3755
<item>
3856
<widget class="QLabel" name="mOutlineLabel">
@@ -50,7 +68,7 @@
5068
</item>
5169
</layout>
5270
</item>
53-
<item row="2" column="0">
71+
<item row="3" column="0">
5472
<widget class="QListView" name="mSvgListView">
5573
<property name="flow">
5674
<enum>QListView::LeftToRight</enum>
@@ -66,7 +84,7 @@
6684
</property>
6785
</widget>
6886
</item>
69-
<item row="3" column="0">
87+
<item row="4" column="0">
7088
<layout class="QHBoxLayout" name="horizontalLayout">
7189
<item>
7290
<widget class="QLineEdit" name="mSVGLineEdit"/>

0 commit comments

Comments
 (0)
Please sign in to comment.