Skip to content

Commit 51ca548

Browse files
committedJun 10, 2011
started rotation / data defined rotation
1 parent 45fcb78 commit 51ca548

File tree

7 files changed

+120
-27
lines changed

7 files changed

+120
-27
lines changed
 

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,9 @@ class QgsSymbolV2RenderContext
626626
//! @note added in 1.5
627627
void setRenderHints( int hints );
628628

629+
void setFeature( const QgsFeature* f );
630+
const QgsFeature* feature() const;
631+
629632
// Color used for selections
630633
static QColor selectionColor();
631634

@@ -759,7 +762,7 @@ public:
759762
void setSize(double size);
760763
double size();
761764

762-
void renderPoint(const QPointF& point, QgsRenderContext& context, int layer = -1, bool selected = false );
765+
void renderPoint(const QPointF& point, const QgsFeature* f, QgsRenderContext& context, int layer = -1, bool selected = false );
763766

764767
virtual QgsSymbolV2* clone() const /Factory/;
765768
};
@@ -784,7 +787,7 @@ public:
784787
void setWidth(double width);
785788
double width();
786789

787-
void renderPolyline(const QPolygonF& points, QgsRenderContext& context, int layer = -1, bool selected = false );
790+
void renderPolyline(const QPolygonF& points, const QgsFeature* f, QgsRenderContext& context, int layer = -1, bool selected = false );
788791

789792
virtual QgsSymbolV2* clone() const /Factory/;
790793
};
@@ -807,7 +810,7 @@ public:
807810
QgsFillSymbolV2(QgsSymbolLayerV2List layers /Transfer/ = QgsSymbolLayerV2List());
808811

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

812815
virtual QgsSymbolV2* clone() const /Factory/;
813816
};
@@ -839,7 +842,7 @@ class QgsSymbolLayerV2AbstractMetadata
839842
/** create a symbol layer of this type given the map of properties. */
840843
virtual QgsSymbolLayerV2* createSymbolLayer( const QgsStringMap& map ) = 0 /Factory/;
841844
/** create widget for symbol layer of this type. Can return NULL if there's no GUI */
842-
virtual QgsSymbolLayerV2Widget* createSymbolLayerWidget() /Factory/;
845+
virtual QgsSymbolLayerV2Widget* createSymbolLayerWidget( const QgsVectorLayer* vl ) /Factory/;
843846
};
844847

845848
//////////

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class QgsSymbolV2PropertiesDialog : QDialog //, private Ui::DlgSymbolV2Propertie
77
%End
88

99
public:
10-
QgsSymbolV2PropertiesDialog(QgsSymbolV2* symbol, QWidget* parent = NULL);
10+
QgsSymbolV2PropertiesDialog(QgsSymbolV2* symbol, const QgsVectorLayer*, QWidget* parent = NULL);
1111

1212

1313
public slots:
@@ -75,7 +75,7 @@ class QgsSymbolV2SelectorDialog : QDialog //, private Ui::QgsSymbolV2SelectorDia
7575
%End
7676

7777
public:
78-
QgsSymbolV2SelectorDialog(QgsSymbolV2* symbol, QgsStyleV2* style, QWidget* parent = NULL, bool embedded = false);
78+
QgsSymbolV2SelectorDialog(QgsSymbolV2* symbol, QgsStyleV2* style, const QgsVectorLayer*, QWidget* parent = NULL, bool embedded = false);
7979

8080
protected:
8181
void populateSymbolView();
@@ -106,7 +106,7 @@ class QgsSymbolLayerV2Widget : QWidget
106106
%End
107107

108108
public:
109-
QgsSymbolLayerV2Widget( QWidget* parent );
109+
QgsSymbolLayerV2Widget( const QgsVectorLayer* vl, Widget* parent );
110110
virtual ~QgsSymbolLayerV2Widget();
111111

112112
virtual void setSymbolLayer( QgsSymbolLayerV2* layer ) = 0;

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

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include <QPainter>
55
#include <QSet>
66

7-
QgsEllipseSymbolLayerV2::QgsEllipseSymbolLayerV2(): mSymbolName("circle"), mSymbolWidth(4), mSymbolHeight(3), mFillColor( Qt::black ), mOutlineColor( Qt::white )
7+
QgsEllipseSymbolLayerV2::QgsEllipseSymbolLayerV2(): mSymbolName("circle"), mSymbolWidth(4), mSymbolHeight(3), mRotation(0), mFillColor( Qt::black ), mOutlineColor( Qt::white )
88
{
99
mPen.setColor( mOutlineColor );
1010
mPen.setWidth( 1.0 );
@@ -14,6 +14,7 @@ QgsEllipseSymbolLayerV2::QgsEllipseSymbolLayerV2(): mSymbolName("circle"), mSymb
1414

1515
mWidthField.first = -1;
1616
mHeightField.first = -1;
17+
mRotationField.first = -1;
1718
mOutlineWidthField.first = -1;
1819
mFillColorField.first = -1;
1920
mOutlineColorField.first = -1;
@@ -38,6 +39,10 @@ QgsSymbolLayerV2* QgsEllipseSymbolLayerV2::create( const QgsStringMap& propertie
3839
{
3940
layer->setSymbolHeight( properties["symbol_height"].toDouble() );
4041
}
42+
if( properties.contains("rotation") )
43+
{
44+
layer->setRotation( properties["rotation"].toDouble() );
45+
}
4146
if( properties.contains( "outline_width" ) )
4247
{
4348
layer->setOutlineWidth( properties["outline_width"].toDouble() );
@@ -60,6 +65,10 @@ QgsSymbolLayerV2* QgsEllipseSymbolLayerV2::create( const QgsStringMap& propertie
6065
{
6166
layer->setWidthField( properties["width_index"].toInt(), properties["width_field"]);
6267
}
68+
if( properties.contains( "rotation_index" ) && properties.contains("rotation_field") )
69+
{
70+
layer->setRotationField( properties["rotation_index"].toInt(), properties["rotation_field"] );
71+
}
6372
if( properties.contains("outline_width_index") && properties.contains("outline_width_field") )
6473
{
6574
layer->setOutlineWidthField( properties["outline_width_index"].toInt(), properties["outline_width_field"] );
@@ -113,9 +122,15 @@ void QgsEllipseSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2Rend
113122
QMatrix transform;
114123
transform.translate( point.x() + off.x(), point.y() + off.y() );
115124

125+
p->save();
126+
if( !doubleNear( mRotation, 0.0 ) )
127+
{
128+
p->rotate( mRotation );
129+
}
116130
p->setPen( mPen );
117131
p->setBrush( mBrush );
118132
p->drawPath( transform.map( mPainterPath ) );
133+
p->restore();
119134
}
120135

121136
QString QgsEllipseSymbolLayerV2::layerType() const
@@ -146,13 +161,16 @@ QgsSymbolLayerV2* QgsEllipseSymbolLayerV2::clone() const
146161
QgsStringMap QgsEllipseSymbolLayerV2::properties() const
147162
{
148163
QgsStringMap map;
149-
map["symbol_name"] = mSymbolName;
164+
map["symbol_name"] = mSymbolName;
150165
map["symbol_width"] = QString::number( mSymbolWidth );
151-
map["height_index"] = QString::number( mHeightField.first );
152-
map["height_field"] = mHeightField.second;
153-
map["symbol_height"] = QString::number( mSymbolHeight );
154166
map["width_index"] = QString::number( mWidthField.first );
155167
map["width_field"] = mWidthField.second;
168+
map["symbol_height"] = QString::number( mSymbolHeight );
169+
map["height_index"] = QString::number( mHeightField.first );
170+
map["height_field"] = mHeightField.second;
171+
map["rotation"] = QString::number( mRotation );
172+
map["rotation_index"] = QString::number( mRotationField.first );
173+
map["rotation_field"] = mRotationField.second;
156174
map["outline_width"] = QString::number( mOutlineWidth );
157175
map["outline_width_index"] = QString::number( mOutlineWidthField.first );
158176
map["outline_width_field"] = mOutlineWidthField.second;
@@ -257,6 +275,12 @@ void QgsEllipseSymbolLayerV2::setHeightField( int index, const QString& field )
257275
mHeightField.second = field;
258276
}
259277

278+
void QgsEllipseSymbolLayerV2::setRotationField( int index, const QString& field )
279+
{
280+
mRotationField.first = index;
281+
mRotationField.second = field;
282+
}
283+
260284
void QgsEllipseSymbolLayerV2::setOutlineWidthField( int index, const QString& field )
261285
{
262286
mOutlineWidthField.first = index;

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ class QgsEllipseSymbolLayerV2: public QgsMarkerSymbolLayerV2
3535
void setHeightField( int index, const QString& field );
3636
const QPair<int, QString>& heightField() const { return mHeightField; }
3737

38+
void setRotation( double r ){ mRotation = r; }
39+
double rotation() const { return mRotation; }
40+
41+
void setRotationField( int index, const QString& field );
42+
const QPair<int, QString>& rotationField() const { return mRotationField; }
43+
3844
void setOutlineWidth( double w ){ mOutlineWidth = w; }
3945
double outlineWidth() const { return mOutlineWidth; }
4046

@@ -58,18 +64,24 @@ class QgsEllipseSymbolLayerV2: public QgsMarkerSymbolLayerV2
5864
private:
5965
QString mSymbolName;
6066
double mSymbolWidth;
67+
double mSymbolHeight;
68+
double mRotation;
69+
QColor mFillColor;
70+
QColor mOutlineColor;
71+
double mOutlineWidth;
72+
6173
/**Take width from attribute (-1 if fixed width)*/
6274
QPair<int, QString> mWidthField;
63-
double mSymbolHeight;
6475
/**Take height from attribute (-1 if fixed height)*/
6576
QPair<int, QString> mHeightField;
66-
double mOutlineWidth;
77+
/**Take symbol rotation from attribute (-1 if fixed rotation)*/
78+
QPair<int, QString> mRotationField;
6779
/**Take outline width from attribute (-1 if fixed outline width)*/
6880
QPair<int, QString> mOutlineWidthField;
69-
QColor mFillColor;
81+
7082
/**Take fill color from attribute (-1 if fixed fill color)*/
7183
QPair<int, QString> mFillColorField;
72-
QColor mOutlineColor;
84+
7385
/**Take outline color from attribute (-1 if fixed outline color)*/
7486
QPair<int, QString> mOutlineColorField;
7587
QPainterPath mPainterPath;

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ void QgsEllipseSymbolLayerV2Widget::setSymbolLayer( QgsSymbolLayerV2* layer )
4141
mLayer = static_cast<QgsEllipseSymbolLayerV2*>( layer );
4242
mWidthSpinBox->setValue( mLayer->symbolWidth() );
4343
mHeightSpinBox->setValue( mLayer->symbolHeight() );
44+
mRotationSpinBox->setValue( mLayer->rotation() );
4445
mOutlineWidthSpinBox->setValue( mLayer->outlineWidth() );
4546

4647
QList<QListWidgetItem *> symbolItemList = mShapeListWidget->findItems( mLayer->symbolName(), Qt::MatchExactly );
@@ -61,6 +62,10 @@ void QgsEllipseSymbolLayerV2Widget::setSymbolLayer( QgsSymbolLayerV2* layer )
6162
{
6263
mDDSymbolHeightComboBox->setCurrentIndex( mDDSymbolHeightComboBox->findText( mLayer->heightField().second ) );
6364
}
65+
if( mLayer->rotationField().first != -1 )
66+
{
67+
mDDRotationComboBox->setCurrentIndex( mDDRotationComboBox->findText( mLayer->rotationField().second ) );
68+
}
6469
if( mLayer->outlineWidthField().first != -1 )
6570
{
6671
mDDOutlineWidthComboBox->setCurrentIndex( mDDOutlineWidthComboBox->findText( mLayer->outlineWidthField().second ) );
@@ -113,6 +118,15 @@ void QgsEllipseSymbolLayerV2Widget::on_mHeightSpinBox_valueChanged( double d )
113118
}
114119
}
115120

121+
void QgsEllipseSymbolLayerV2Widget::on_mRotationSpinBox_valueChanged( double d )
122+
{
123+
if( mLayer )
124+
{
125+
mLayer->setRotation( d );
126+
emit changed();
127+
}
128+
}
129+
116130
void QgsEllipseSymbolLayerV2Widget::on_mOutlineWidthSpinBox_valueChanged( double d )
117131
{
118132
if( mLayer )
@@ -154,6 +168,8 @@ void QgsEllipseSymbolLayerV2Widget::fillDataDefinedComboBoxes()
154168
mDDSymbolWidthComboBox->addItem( "", -1 );
155169
mDDSymbolHeightComboBox->clear();
156170
mDDSymbolHeightComboBox->addItem( "", -1 );
171+
mDDRotationComboBox->clear();
172+
mDDRotationComboBox->addItem( "", -1 );
157173
mDDOutlineWidthComboBox->clear();
158174
mDDOutlineWidthComboBox->addItem( "", -1 );
159175
mDDFillColorComboBox->clear();
@@ -174,6 +190,7 @@ void QgsEllipseSymbolLayerV2Widget::fillDataDefinedComboBoxes()
174190

175191
mDDSymbolWidthComboBox->addItem( fieldName, index );
176192
mDDSymbolHeightComboBox->addItem( fieldName, index );
193+
mDDRotationComboBox->addItem( fieldName, index );
177194
mDDOutlineWidthComboBox->addItem( fieldName, index );
178195
mDDFillColorComboBox->addItem( fieldName, index );
179196
mDDOutlineColorComboBox->addItem( fieldName, index );
@@ -187,6 +204,7 @@ void QgsEllipseSymbolLayerV2Widget::on_mDDSymbolWidthComboBox_currentIndexChange
187204
if( mLayer )
188205
{
189206
mLayer->setWidthField( mDDSymbolWidthComboBox->itemData( idx ).toInt(), mDDSymbolWidthComboBox->itemText( idx ) );
207+
emit changed();
190208
}
191209
}
192210

@@ -195,6 +213,16 @@ void QgsEllipseSymbolLayerV2Widget::on_mDDSymbolHeightComboBox_currentIndexChang
195213
if( mLayer )
196214
{
197215
mLayer->setHeightField( mDDSymbolHeightComboBox->itemData( idx ).toInt(), mDDSymbolHeightComboBox->itemText( idx ));
216+
emit changed();
217+
}
218+
}
219+
220+
void QgsEllipseSymbolLayerV2Widget::on_mDDRotationComboBox_currentIndexChanged( int idx )
221+
{
222+
if( mLayer )
223+
{
224+
mLayer->setRotationField( mDDRotationComboBox->itemData( idx ).toInt(), mDDRotationComboBox->itemText( idx ) );
225+
emit changed();
198226
}
199227
}
200228

@@ -203,6 +231,7 @@ void QgsEllipseSymbolLayerV2Widget::on_mDDOutlineWidthComboBox_currentIndexChang
203231
if( mLayer )
204232
{
205233
mLayer->setOutlineWidthField( mDDOutlineWidthComboBox->itemData( idx ).toInt(), mDDOutlineWidthComboBox->itemText( idx ) );
234+
emit changed();
206235
}
207236
}
208237

@@ -211,6 +240,7 @@ void QgsEllipseSymbolLayerV2Widget::on_mDDFillColorComboBox_currentIndexChanged(
211240
if( mLayer )
212241
{
213242
mLayer->setFillColorField( mDDFillColorComboBox->itemData( idx ).toInt(), mDDFillColorComboBox->itemText( idx ) );
243+
emit changed();
214244
}
215245
}
216246

@@ -219,6 +249,7 @@ void QgsEllipseSymbolLayerV2Widget::on_mDDOutlineColorComboBox_currentIndexChang
219249
if( mLayer )
220250
{
221251
mLayer->setOutlineColorField( mDDOutlineColorComboBox->itemData( idx ).toInt(), mDDOutlineColorComboBox->itemText( idx ) );
252+
emit changed();
222253
}
223254
}
224255

@@ -231,6 +262,7 @@ void QgsEllipseSymbolLayerV2Widget::blockComboSignals( bool block )
231262
{
232263
mDDSymbolWidthComboBox->blockSignals( block );
233264
mDDSymbolHeightComboBox->blockSignals( block );
265+
mDDRotationComboBox->blockSignals( block );
234266
mDDOutlineWidthComboBox->blockSignals( block );
235267
mDDFillColorComboBox->blockSignals( block );
236268
mDDOutlineColorComboBox->blockSignals( block);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ class GUI_EXPORT QgsEllipseSymbolLayerV2Widget: public QgsSymbolLayerV2Widget, p
3131
void on_mShapeListWidget_itemSelectionChanged();
3232
void on_mWidthSpinBox_valueChanged( double d );
3333
void on_mHeightSpinBox_valueChanged( double d );
34+
void on_mRotationSpinBox_valueChanged( double d );
3435
void on_mOutlineWidthSpinBox_valueChanged( double d );
3536
void on_btnChangeColorBorder_clicked();
3637
void on_btnChangeColorFill_clicked();
3738

3839
void on_mDDSymbolWidthComboBox_currentIndexChanged( int idx );
3940
void on_mDDSymbolHeightComboBox_currentIndexChanged( int idx );
41+
void on_mDDRotationComboBox_currentIndexChanged( int idx );
4042
void on_mDDOutlineWidthComboBox_currentIndexChanged( int idx );
4143
void on_mDDFillColorComboBox_currentIndexChanged( int idx );
4244
void on_mDDOutlineColorComboBox_currentIndexChanged( int idx );

‎src/ui/symbollayer/widget_ellipse.ui

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,14 @@
8686
</property>
8787
</widget>
8888
</item>
89-
<item row="4" column="0">
89+
<item row="5" column="0">
9090
<widget class="QLabel" name="mSymbolHeightLabel">
9191
<property name="text">
9292
<string>Symbol height</string>
9393
</property>
9494
</widget>
9595
</item>
96-
<item row="4" column="1">
96+
<item row="5" column="1">
9797
<widget class="QDoubleSpinBox" name="mHeightSpinBox">
9898
<property name="decimals">
9999
<number>6</number>
@@ -103,7 +103,7 @@
103103
</property>
104104
</widget>
105105
</item>
106-
<item row="5" column="0" colspan="2">
106+
<item row="6" column="0" colspan="2">
107107
<widget class="QListWidget" name="mShapeListWidget">
108108
<property name="dragDropMode">
109109
<enum>QAbstractItemView::DragDrop</enum>
@@ -125,6 +125,16 @@
125125
</property>
126126
</widget>
127127
</item>
128+
<item row="4" column="1">
129+
<widget class="QDoubleSpinBox" name="mRotationSpinBox"/>
130+
</item>
131+
<item row="4" column="0">
132+
<widget class="QLabel" name="mRotationLabel">
133+
<property name="text">
134+
<string>Rotation</string>
135+
</property>
136+
</widget>
137+
</item>
128138
</layout>
129139
</widget>
130140
<widget class="QWidget" name="tab_2">
@@ -152,46 +162,56 @@
152162
<item row="1" column="1">
153163
<widget class="QComboBox" name="mDDSymbolHeightComboBox"/>
154164
</item>
155-
<item row="2" column="0">
165+
<item row="3" column="0">
156166
<widget class="QLabel" name="mDDOutlineWidthLabel">
157167
<property name="text">
158168
<string>Outline width</string>
159169
</property>
160170
</widget>
161171
</item>
162-
<item row="2" column="1">
172+
<item row="3" column="1">
163173
<widget class="QComboBox" name="mDDOutlineWidthComboBox"/>
164174
</item>
165-
<item row="3" column="0">
175+
<item row="4" column="0">
166176
<widget class="QLabel" name="mDDFillColorLabel">
167177
<property name="text">
168178
<string>Fill color</string>
169179
</property>
170180
</widget>
171181
</item>
172-
<item row="3" column="1">
182+
<item row="4" column="1">
173183
<widget class="QComboBox" name="mDDFillColorComboBox"/>
174184
</item>
175-
<item row="4" column="0">
185+
<item row="5" column="0">
176186
<widget class="QLabel" name="mDDOutlineLabel">
177187
<property name="text">
178188
<string>Outline color</string>
179189
</property>
180190
</widget>
181191
</item>
182-
<item row="4" column="1">
192+
<item row="5" column="1">
183193
<widget class="QComboBox" name="mDDOutlineColorComboBox"/>
184194
</item>
185-
<item row="5" column="0">
195+
<item row="6" column="0">
186196
<widget class="QLabel" name="mDDShapeLabel">
187197
<property name="text">
188198
<string>Shape</string>
189199
</property>
190200
</widget>
191201
</item>
192-
<item row="5" column="1">
202+
<item row="6" column="1">
193203
<widget class="QComboBox" name="mDDShapeComboBox"/>
194204
</item>
205+
<item row="2" column="1">
206+
<widget class="QComboBox" name="mDDRotationComboBox"/>
207+
</item>
208+
<item row="2" column="0">
209+
<widget class="QLabel" name="mDDRotationLabel">
210+
<property name="text">
211+
<string>Rotation</string>
212+
</property>
213+
</widget>
214+
</item>
195215
</layout>
196216
</widget>
197217
</widget>

0 commit comments

Comments
 (0)
Please sign in to comment.