Skip to content

Commit

Permalink
[FEATURE]: rotation for svg fills
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15139 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Feb 8, 2011
1 parent 98b631c commit ebbaa6f
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 15 deletions.
4 changes: 4 additions & 0 deletions python/core/symbology-ng-core.sip
Expand Up @@ -589,6 +589,9 @@ public:

void drawPreviewIcon(QgsSymbolV2RenderContext& context, QSize size);

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

protected:
QgsFillSymbolLayerV2(bool locked = false);
};
Expand Down Expand Up @@ -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/;
Expand Down
36 changes: 29 additions & 7 deletions src/core/symbology-ng/qgsfillsymbollayerv2.cpp
Expand Up @@ -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() );
}

Expand All @@ -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" ) )
Expand All @@ -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
{
Expand All @@ -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 );
}
}

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

r.render( &p );

if ( context.alpha() < 1.0 )
Expand Down Expand Up @@ -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 )
{
Expand Down Expand Up @@ -275,6 +296,7 @@ QgsStringMap QgsSVGFillSymbolLayer::properties() const
}

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

Expand All @@ -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 )
Expand Down
6 changes: 3 additions & 3 deletions src/core/symbology-ng/qgsfillsymbollayerv2.h
Expand Up @@ -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() );
Expand All @@ -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;}
Expand Down
6 changes: 6 additions & 0 deletions src/core/symbology-ng/qgssinglesymbolrendererv2.cpp
Expand Up @@ -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;
}
Expand Down
5 changes: 5 additions & 0 deletions src/core/symbology-ng/qgssymbollayerv2.h
Expand Up @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions src/core/symbology-ng/qgssymbolv2.cpp
Expand Up @@ -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 );
}
}
2 changes: 1 addition & 1 deletion src/core/symbology-ng/qgssymbolv2.h
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions src/gui/symbology-ng/qgssymbollayerv2widget.cpp
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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 )
Expand Down
1 change: 1 addition & 0 deletions src/gui/symbology-ng/qgssymbollayerv2widget.h
Expand Up @@ -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 );
};

//////////
Expand Down
26 changes: 22 additions & 4 deletions src/ui/symbollayer/widget_svgfill.ui
Expand Up @@ -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">
Expand All @@ -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">
Expand All @@ -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>
Expand All @@ -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"/>
Expand Down

0 comments on commit ebbaa6f

Please sign in to comment.