4
4
#include < QPainter>
5
5
#include < QSet>
6
6
7
- QgsEllipseSymbolLayerV2::QgsEllipseSymbolLayerV2 (): mSymbolName(" circle" ), mSymbolWidth(4 ), mSymbolHeight(3 ),
8
- mFillColor( Qt::black ), mOutlineColor( Qt::white ), mOutlineWidth( 0 )
7
+ QgsEllipseSymbolLayerV2::QgsEllipseSymbolLayerV2 (): mSymbolName( " circle" ), mSymbolWidth( 4 ), mSymbolHeight( 3 ),
8
+ mFillColor( Qt::black ), mOutlineColor( Qt::white ), mOutlineWidth( 0 )
9
9
{
10
10
mPen .setColor ( mOutlineColor );
11
11
mPen .setWidth ( 1.0 );
@@ -30,61 +30,61 @@ QgsEllipseSymbolLayerV2::~QgsEllipseSymbolLayerV2()
30
30
QgsSymbolLayerV2* QgsEllipseSymbolLayerV2::create ( const QgsStringMap& properties )
31
31
{
32
32
QgsEllipseSymbolLayerV2* layer = new QgsEllipseSymbolLayerV2 ();
33
- if ( properties.contains ( " symbol_name" ) )
33
+ if ( properties.contains ( " symbol_name" ) )
34
34
{
35
35
layer->setSymbolName ( properties[ " symbol_name" ] );
36
36
}
37
- if ( properties.contains ( " symbol_width" ) )
37
+ if ( properties.contains ( " symbol_width" ) )
38
38
{
39
39
layer->setSymbolWidth ( properties[" symbol_width" ].toDouble () );
40
40
}
41
- if ( properties.contains (" symbol_height" ) )
41
+ if ( properties.contains ( " symbol_height" ) )
42
42
{
43
43
layer->setSymbolHeight ( properties[" symbol_height" ].toDouble () );
44
44
}
45
- if ( properties.contains (" angle" ) )
45
+ if ( properties.contains ( " angle" ) )
46
46
{
47
47
layer->setAngle ( properties[" angle" ].toDouble () );
48
48
}
49
- if ( properties.contains ( " outline_width" ) )
49
+ if ( properties.contains ( " outline_width" ) )
50
50
{
51
51
layer->setOutlineWidth ( properties[" outline_width" ].toDouble () );
52
52
}
53
- if ( properties.contains ( " fill_color" ) )
53
+ if ( properties.contains ( " fill_color" ) )
54
54
{
55
55
layer->setFillColor ( QgsSymbolLayerV2Utils::decodeColor ( properties[" fill_color" ] ) );
56
56
}
57
- if ( properties.contains ( " outline_color" ) )
57
+ if ( properties.contains ( " outline_color" ) )
58
58
{
59
59
layer->setOutlineColor ( QgsSymbolLayerV2Utils::decodeColor ( properties[" outline_color" ] ) );
60
60
}
61
61
62
62
// data defined properties
63
- if ( properties.contains ( " height_index" ) && properties.contains ( " height_field" ) )
63
+ if ( properties.contains ( " height_index" ) && properties.contains ( " height_field" ) )
64
64
{
65
65
layer->setHeightField ( properties[" height_index" ].toInt (), properties[" height_field" ] );
66
66
}
67
- if ( properties.contains ( " width_index" ) && properties.contains (" width_field" ) )
67
+ if ( properties.contains ( " width_index" ) && properties.contains ( " width_field" ) )
68
68
{
69
- layer->setWidthField ( properties[" width_index" ].toInt (), properties[" width_field" ]);
69
+ layer->setWidthField ( properties[" width_index" ].toInt (), properties[" width_field" ] );
70
70
}
71
- if ( properties.contains ( " rotation_index" ) && properties.contains (" rotation_field" ) )
71
+ if ( properties.contains ( " rotation_index" ) && properties.contains ( " rotation_field" ) )
72
72
{
73
73
layer->setRotationField ( properties[" rotation_index" ].toInt (), properties[" rotation_field" ] );
74
74
}
75
- if ( properties.contains (" outline_width_index" ) && properties.contains (" outline_width_field" ) )
75
+ if ( properties.contains ( " outline_width_index" ) && properties.contains ( " outline_width_field" ) )
76
76
{
77
77
layer->setOutlineWidthField ( properties[" outline_width_index" ].toInt (), properties[" outline_width_field" ] );
78
78
}
79
- if ( properties.contains (" fill_color_index" ) && properties.contains (" fill_color_field" ) )
79
+ if ( properties.contains ( " fill_color_index" ) && properties.contains ( " fill_color_field" ) )
80
80
{
81
81
layer->setFillColorField ( properties[" fill_color_index" ].toInt (), properties[" fill_color_field" ] );
82
82
}
83
- if ( properties.contains (" outline_color_index" ) && properties.contains (" outline_color_field" ) )
83
+ if ( properties.contains ( " outline_color_index" ) && properties.contains ( " outline_color_field" ) )
84
84
{
85
85
layer->setOutlineColorField ( properties[" outline_color_index" ].toInt (), properties[" outline_color_field" ] );
86
86
}
87
- if ( properties.contains (" symbol_name_index" ) && properties.contains (" symbol_name_field" ) )
87
+ if ( properties.contains ( " symbol_name_index" ) && properties.contains ( " symbol_name_field" ) )
88
88
{
89
89
layer->setSymbolNameField ( properties[" symbol_name_index" ].toInt (), properties[" symbol_name_field" ] );
90
90
}
@@ -96,49 +96,49 @@ void QgsEllipseSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2Rend
96
96
{
97
97
const QgsFeature* f = context.feature ();
98
98
99
- if ( f )
99
+ if ( f )
100
100
{
101
- if ( mOutlineWidthField .first != -1 )
101
+ if ( mOutlineWidthField .first != -1 )
102
102
{
103
103
double width = context.outputLineWidth ( f->attributeMap ()[mOutlineWidthField .first ].toDouble () );
104
104
mPen .setWidth ( width );
105
105
}
106
- if ( mFillColorField .first != -1 )
106
+ if ( mFillColorField .first != -1 )
107
107
{
108
108
mBrush .setColor ( QColor ( f->attributeMap ()[mFillColorField .first ].toString () ) );
109
109
}
110
- if ( mOutlineColorField .first != -1 )
110
+ if ( mOutlineColorField .first != -1 )
111
111
{
112
112
mPen .setColor ( QColor ( f->attributeMap ()[mOutlineColorField .first ].toString () ) );
113
113
}
114
114
115
- if ( mWidthField .first != -1 || mHeightField .first != -1 || mSymbolNameField .first != -1 )
115
+ if ( mWidthField .first != -1 || mHeightField .first != -1 || mSymbolNameField .first != -1 )
116
116
{
117
117
QString symbolName = ( mSymbolNameField .first == -1 ) ? mSymbolName : f->attributeMap ()[mSymbolNameField .first ].toString ();
118
118
preparePath ( symbolName, context, f );
119
119
}
120
120
}
121
121
122
122
QPainter* p = context.renderContext ().painter ();
123
- if ( !p )
123
+ if ( !p )
124
124
{
125
125
return ;
126
126
}
127
127
128
128
// priority for rotation: 1. data defined, 2. symbol layer rotation (mAngle)
129
129
double rotation = 0.0 ;
130
- if ( f && mRotationField .first != -1 )
130
+ if ( f && mRotationField .first != -1 )
131
131
{
132
132
rotation = f->attributeMap ()[mRotationField .first ].toDouble ();
133
133
}
134
- else if ( !doubleNear ( mAngle , 0.0 ) )
134
+ else if ( !doubleNear ( mAngle , 0.0 ) )
135
135
{
136
136
rotation = mAngle ;
137
137
}
138
138
139
139
QMatrix transform;
140
140
transform.translate ( point.x (), point.y () );
141
- if ( !doubleNear ( rotation, 0.0 ) )
141
+ if ( !doubleNear ( rotation, 0.0 ) )
142
142
{
143
143
transform.rotate ( rotation );
144
144
}
@@ -155,7 +155,7 @@ QString QgsEllipseSymbolLayerV2::layerType() const
155
155
156
156
void QgsEllipseSymbolLayerV2::startRender ( QgsSymbolV2RenderContext& context )
157
157
{
158
- if ( !hasDataDefinedProperty () )
158
+ if ( !context. feature () || !hasDataDefinedProperty () )
159
159
{
160
160
preparePath ( mSymbolName , context );
161
161
}
@@ -176,7 +176,7 @@ QgsSymbolLayerV2* QgsEllipseSymbolLayerV2::clone() const
176
176
QgsStringMap QgsEllipseSymbolLayerV2::properties () const
177
177
{
178
178
QgsStringMap map;
179
- map[" symbol_name" ] = mSymbolName ;
179
+ map[" symbol_name" ] = mSymbolName ;
180
180
map[" symbol_width" ] = QString::number ( mSymbolWidth );
181
181
map[" width_index" ] = QString::number ( mWidthField .first );
182
182
map[" width_field" ] = mWidthField .second ;
@@ -195,23 +195,23 @@ QgsStringMap QgsEllipseSymbolLayerV2::properties() const
195
195
map[" outline_color" ] = QgsSymbolLayerV2Utils::encodeColor ( mOutlineColor );
196
196
map[" outline_color_index" ] = QString::number ( mOutlineColorField .first );
197
197
map[" outline_color_field" ] = mOutlineColorField .second ;
198
- map[" symbol_name_index" ] = QString::number (mSymbolNameField .first );
198
+ map[" symbol_name_index" ] = QString::number ( mSymbolNameField .first );
199
199
map[" symbol_name_field" ] = mSymbolNameField .second ;
200
200
return map;
201
201
}
202
202
203
203
bool QgsEllipseSymbolLayerV2::hasDataDefinedProperty () const
204
204
{
205
- return ( mWidthField .first != -1 || mHeightField .first != -1 || mOutlineWidthField .first != -1
206
- || mFillColorField .first != -1 || mOutlineColorField .first != -1 );
205
+ return ( mWidthField .first != -1 || mHeightField .first != -1 || mOutlineWidthField .first != -1
206
+ || mFillColorField .first != -1 || mOutlineColorField .first != -1 );
207
207
}
208
208
209
209
void QgsEllipseSymbolLayerV2::preparePath ( const QString& symbolName, QgsSymbolV2RenderContext& context, const QgsFeature* f )
210
210
{
211
211
mPainterPath = QPainterPath ();
212
212
213
213
double width = 0 ;
214
- if ( f && mWidthField .first != -1 )
214
+ if ( f && mWidthField .first != -1 )
215
215
{
216
216
width = context.outputLineWidth ( f->attributeMap ()[mWidthField .first ].toDouble () );
217
217
}
@@ -221,7 +221,7 @@ void QgsEllipseSymbolLayerV2::preparePath( const QString& symbolName, QgsSymbolV
221
221
}
222
222
223
223
double height = 0 ;
224
- if ( f && mHeightField .first != -1 )
224
+ if ( f && mHeightField .first != -1 )
225
225
{
226
226
height = context.outputLineWidth ( f->attributeMap ()[mHeightField .first ].toDouble () );
227
227
}
@@ -230,22 +230,22 @@ void QgsEllipseSymbolLayerV2::preparePath( const QString& symbolName, QgsSymbolV
230
230
height = context.outputLineWidth ( mSymbolHeight );
231
231
}
232
232
233
- if ( symbolName == " circle" )
233
+ if ( symbolName == " circle" )
234
234
{
235
235
mPainterPath .addEllipse ( QRectF ( -width / 2.0 , -height / 2.0 , width, height ) );
236
236
}
237
- else if ( symbolName == " rectangle" )
237
+ else if ( symbolName == " rectangle" )
238
238
{
239
239
mPainterPath .addRect ( QRectF ( -width / 2.0 , -height / 2.0 , width, height ) );
240
240
}
241
- else if ( symbolName == " cross" )
241
+ else if ( symbolName == " cross" )
242
242
{
243
243
mPainterPath .moveTo ( 0 , -height / 2.0 );
244
244
mPainterPath .lineTo ( 0 , height / 2.0 );
245
245
mPainterPath .moveTo ( -width / 2.0 , 0 );
246
246
mPainterPath .lineTo ( width / 2.0 , 0 );
247
247
}
248
- else if ( symbolName == " triangle" )
248
+ else if ( symbolName == " triangle" )
249
249
{
250
250
mPainterPath .moveTo ( 0 , -height / 2.0 );
251
251
mPainterPath .lineTo ( -width / 2.0 , height / 2.0 );
@@ -257,31 +257,31 @@ void QgsEllipseSymbolLayerV2::preparePath( const QString& symbolName, QgsSymbolV
257
257
QSet<QString> QgsEllipseSymbolLayerV2::usedAttributes () const
258
258
{
259
259
QSet<QString> dataDefinedAttributes;
260
- if ( mWidthField .first != -1 )
260
+ if ( mWidthField .first != -1 )
261
261
{
262
262
dataDefinedAttributes.insert ( mWidthField .second );
263
263
}
264
- if ( mHeightField .first != -1 )
264
+ if ( mHeightField .first != -1 )
265
265
{
266
266
dataDefinedAttributes.insert ( mHeightField .second );
267
267
}
268
- if ( mRotationField .first != -1 )
268
+ if ( mRotationField .first != -1 )
269
269
{
270
270
dataDefinedAttributes.insert ( mRotationField .second );
271
271
}
272
- if ( mOutlineWidthField .first != -1 )
272
+ if ( mOutlineWidthField .first != -1 )
273
273
{
274
274
dataDefinedAttributes.insert ( mOutlineWidthField .second );
275
275
}
276
- if ( mFillColorField .first != -1 )
276
+ if ( mFillColorField .first != -1 )
277
277
{
278
278
dataDefinedAttributes.insert ( mFillColorField .second );
279
279
}
280
- if ( mOutlineColorField .first != -1 )
280
+ if ( mOutlineColorField .first != -1 )
281
281
{
282
282
dataDefinedAttributes.insert ( mOutlineColorField .second );
283
283
}
284
- if ( mSymbolNameField .first != -1 )
284
+ if ( mSymbolNameField .first != -1 )
285
285
{
286
286
dataDefinedAttributes.insert ( mSymbolNameField .second );
287
287
}
@@ -306,11 +306,11 @@ void QgsEllipseSymbolLayerV2::setHeightField( int index, const QString& field )
306
306
mHeightField .second = field;
307
307
}
308
308
309
- void QgsEllipseSymbolLayerV2::setRotationField ( int index, const QString& field )
310
- {
311
- mRotationField .first = index;
312
- mRotationField .second = field;
313
- }
309
+ void QgsEllipseSymbolLayerV2::setRotationField ( int index, const QString& field )
310
+ {
311
+ mRotationField .first = index;
312
+ mRotationField .second = field;
313
+ }
314
314
315
315
void QgsEllipseSymbolLayerV2::setOutlineWidthField ( int index, const QString& field )
316
316
{
0 commit comments