Skip to content

Commit 2f3fb28

Browse files
committedJun 15, 2011
Fix preview with data defined settings, indentation
1 parent 3213d3d commit 2f3fb28

File tree

2 files changed

+68
-50
lines changed

2 files changed

+68
-50
lines changed
 

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

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

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 )
99
{
1010
mPen.setColor( mOutlineColor );
1111
mPen.setWidth( 1.0 );
@@ -30,61 +30,61 @@ QgsEllipseSymbolLayerV2::~QgsEllipseSymbolLayerV2()
3030
QgsSymbolLayerV2* QgsEllipseSymbolLayerV2::create( const QgsStringMap& properties )
3131
{
3232
QgsEllipseSymbolLayerV2* layer = new QgsEllipseSymbolLayerV2();
33-
if( properties.contains( "symbol_name" ) )
33+
if ( properties.contains( "symbol_name" ) )
3434
{
3535
layer->setSymbolName( properties[ "symbol_name" ] );
3636
}
37-
if( properties.contains( "symbol_width" ) )
37+
if ( properties.contains( "symbol_width" ) )
3838
{
3939
layer->setSymbolWidth( properties["symbol_width"].toDouble() );
4040
}
41-
if( properties.contains("symbol_height") )
41+
if ( properties.contains( "symbol_height" ) )
4242
{
4343
layer->setSymbolHeight( properties["symbol_height"].toDouble() );
4444
}
45-
if( properties.contains("angle") )
45+
if ( properties.contains( "angle" ) )
4646
{
4747
layer->setAngle( properties["angle"].toDouble() );
4848
}
49-
if( properties.contains( "outline_width" ) )
49+
if ( properties.contains( "outline_width" ) )
5050
{
5151
layer->setOutlineWidth( properties["outline_width"].toDouble() );
5252
}
53-
if( properties.contains( "fill_color" ) )
53+
if ( properties.contains( "fill_color" ) )
5454
{
5555
layer->setFillColor( QgsSymbolLayerV2Utils::decodeColor( properties["fill_color"] ) );
5656
}
57-
if( properties.contains( "outline_color" ) )
57+
if ( properties.contains( "outline_color" ) )
5858
{
5959
layer->setOutlineColor( QgsSymbolLayerV2Utils::decodeColor( properties["outline_color"] ) );
6060
}
6161

6262
//data defined properties
63-
if( properties.contains( "height_index" ) && properties.contains( "height_field") )
63+
if ( properties.contains( "height_index" ) && properties.contains( "height_field" ) )
6464
{
6565
layer->setHeightField( properties["height_index"].toInt(), properties["height_field"] );
6666
}
67-
if( properties.contains( "width_index") && properties.contains("width_field") )
67+
if ( properties.contains( "width_index" ) && properties.contains( "width_field" ) )
6868
{
69-
layer->setWidthField( properties["width_index"].toInt(), properties["width_field"]);
69+
layer->setWidthField( properties["width_index"].toInt(), properties["width_field"] );
7070
}
71-
if( properties.contains( "rotation_index" ) && properties.contains("rotation_field") )
71+
if ( properties.contains( "rotation_index" ) && properties.contains( "rotation_field" ) )
7272
{
7373
layer->setRotationField( properties["rotation_index"].toInt(), properties["rotation_field"] );
7474
}
75-
if( properties.contains("outline_width_index") && properties.contains("outline_width_field") )
75+
if ( properties.contains( "outline_width_index" ) && properties.contains( "outline_width_field" ) )
7676
{
7777
layer->setOutlineWidthField( properties["outline_width_index"].toInt(), properties["outline_width_field"] );
7878
}
79-
if( properties.contains("fill_color_index") && properties.contains("fill_color_field") )
79+
if ( properties.contains( "fill_color_index" ) && properties.contains( "fill_color_field" ) )
8080
{
8181
layer->setFillColorField( properties["fill_color_index"].toInt(), properties["fill_color_field"] );
8282
}
83-
if( properties.contains("outline_color_index") && properties.contains("outline_color_field") )
83+
if ( properties.contains( "outline_color_index" ) && properties.contains( "outline_color_field" ) )
8484
{
8585
layer->setOutlineColorField( properties["outline_color_index"].toInt(), properties["outline_color_field"] );
8686
}
87-
if( properties.contains("symbol_name_index") && properties.contains("symbol_name_field") )
87+
if ( properties.contains( "symbol_name_index" ) && properties.contains( "symbol_name_field" ) )
8888
{
8989
layer->setSymbolNameField( properties["symbol_name_index"].toInt(), properties["symbol_name_field"] );
9090
}
@@ -96,49 +96,49 @@ void QgsEllipseSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2Rend
9696
{
9797
const QgsFeature* f = context.feature();
9898

99-
if( f )
99+
if ( f )
100100
{
101-
if( mOutlineWidthField.first != -1 )
101+
if ( mOutlineWidthField.first != -1 )
102102
{
103103
double width = context.outputLineWidth( f->attributeMap()[mOutlineWidthField.first].toDouble() );
104104
mPen.setWidth( width );
105105
}
106-
if( mFillColorField.first != -1 )
106+
if ( mFillColorField.first != -1 )
107107
{
108108
mBrush.setColor( QColor( f->attributeMap()[mFillColorField.first].toString() ) );
109109
}
110-
if( mOutlineColorField.first != -1 )
110+
if ( mOutlineColorField.first != -1 )
111111
{
112112
mPen.setColor( QColor( f->attributeMap()[mOutlineColorField.first].toString() ) );
113113
}
114114

115-
if( mWidthField.first != -1 || mHeightField.first != -1 || mSymbolNameField.first != -1 )
115+
if ( mWidthField.first != -1 || mHeightField.first != -1 || mSymbolNameField.first != -1 )
116116
{
117117
QString symbolName = ( mSymbolNameField.first == -1 ) ? mSymbolName : f->attributeMap()[mSymbolNameField.first].toString();
118118
preparePath( symbolName, context, f );
119119
}
120120
}
121121

122122
QPainter* p = context.renderContext().painter();
123-
if( !p )
123+
if ( !p )
124124
{
125125
return;
126126
}
127127

128128
//priority for rotation: 1. data defined, 2. symbol layer rotation (mAngle)
129129
double rotation = 0.0;
130-
if( f && mRotationField.first != -1 )
130+
if ( f && mRotationField.first != -1 )
131131
{
132132
rotation = f->attributeMap()[mRotationField.first].toDouble();
133133
}
134-
else if( !doubleNear( mAngle, 0.0 ) )
134+
else if ( !doubleNear( mAngle, 0.0 ) )
135135
{
136136
rotation = mAngle;
137137
}
138138

139139
QMatrix transform;
140140
transform.translate( point.x(), point.y() );
141-
if( !doubleNear( rotation, 0.0 ) )
141+
if ( !doubleNear( rotation, 0.0 ) )
142142
{
143143
transform.rotate( rotation );
144144
}
@@ -155,7 +155,7 @@ QString QgsEllipseSymbolLayerV2::layerType() const
155155

156156
void QgsEllipseSymbolLayerV2::startRender( QgsSymbolV2RenderContext& context )
157157
{
158-
if( !hasDataDefinedProperty() )
158+
if ( !context.feature() || !hasDataDefinedProperty() )
159159
{
160160
preparePath( mSymbolName, context );
161161
}
@@ -176,7 +176,7 @@ QgsSymbolLayerV2* QgsEllipseSymbolLayerV2::clone() const
176176
QgsStringMap QgsEllipseSymbolLayerV2::properties() const
177177
{
178178
QgsStringMap map;
179-
map["symbol_name"] = mSymbolName;
179+
map["symbol_name"] = mSymbolName;
180180
map["symbol_width"] = QString::number( mSymbolWidth );
181181
map["width_index"] = QString::number( mWidthField.first );
182182
map["width_field"] = mWidthField.second;
@@ -195,23 +195,23 @@ QgsStringMap QgsEllipseSymbolLayerV2::properties() const
195195
map["outline_color"] = QgsSymbolLayerV2Utils::encodeColor( mOutlineColor );
196196
map["outline_color_index"] = QString::number( mOutlineColorField.first );
197197
map["outline_color_field"] = mOutlineColorField.second;
198-
map["symbol_name_index"] = QString::number(mSymbolNameField.first);
198+
map["symbol_name_index"] = QString::number( mSymbolNameField.first );
199199
map["symbol_name_field"] = mSymbolNameField.second;
200200
return map;
201201
}
202202

203203
bool QgsEllipseSymbolLayerV2::hasDataDefinedProperty() const
204204
{
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 );
207207
}
208208

209209
void QgsEllipseSymbolLayerV2::preparePath( const QString& symbolName, QgsSymbolV2RenderContext& context, const QgsFeature* f )
210210
{
211211
mPainterPath = QPainterPath();
212212

213213
double width = 0;
214-
if( f && mWidthField.first != -1 )
214+
if ( f && mWidthField.first != -1 )
215215
{
216216
width = context.outputLineWidth( f->attributeMap()[mWidthField.first].toDouble() );
217217
}
@@ -221,7 +221,7 @@ void QgsEllipseSymbolLayerV2::preparePath( const QString& symbolName, QgsSymbolV
221221
}
222222

223223
double height = 0;
224-
if( f && mHeightField.first != -1 )
224+
if ( f && mHeightField.first != -1 )
225225
{
226226
height = context.outputLineWidth( f->attributeMap()[mHeightField.first].toDouble() );
227227
}
@@ -230,22 +230,22 @@ void QgsEllipseSymbolLayerV2::preparePath( const QString& symbolName, QgsSymbolV
230230
height = context.outputLineWidth( mSymbolHeight );
231231
}
232232

233-
if( symbolName == "circle" )
233+
if ( symbolName == "circle" )
234234
{
235235
mPainterPath.addEllipse( QRectF( -width / 2.0, -height / 2.0, width, height ) );
236236
}
237-
else if( symbolName == "rectangle" )
237+
else if ( symbolName == "rectangle" )
238238
{
239239
mPainterPath.addRect( QRectF( -width / 2.0, -height / 2.0, width, height ) );
240240
}
241-
else if( symbolName == "cross" )
241+
else if ( symbolName == "cross" )
242242
{
243243
mPainterPath.moveTo( 0, -height / 2.0 );
244244
mPainterPath.lineTo( 0, height / 2.0 );
245245
mPainterPath.moveTo( -width / 2.0, 0 );
246246
mPainterPath.lineTo( width / 2.0, 0 );
247247
}
248-
else if( symbolName == "triangle" )
248+
else if ( symbolName == "triangle" )
249249
{
250250
mPainterPath.moveTo( 0, -height / 2.0 );
251251
mPainterPath.lineTo( -width / 2.0, height / 2.0 );
@@ -257,31 +257,31 @@ void QgsEllipseSymbolLayerV2::preparePath( const QString& symbolName, QgsSymbolV
257257
QSet<QString> QgsEllipseSymbolLayerV2::usedAttributes() const
258258
{
259259
QSet<QString> dataDefinedAttributes;
260-
if( mWidthField.first != -1 )
260+
if ( mWidthField.first != -1 )
261261
{
262262
dataDefinedAttributes.insert( mWidthField.second );
263263
}
264-
if( mHeightField.first != -1 )
264+
if ( mHeightField.first != -1 )
265265
{
266266
dataDefinedAttributes.insert( mHeightField.second );
267267
}
268-
if( mRotationField.first != -1 )
268+
if ( mRotationField.first != -1 )
269269
{
270270
dataDefinedAttributes.insert( mRotationField.second );
271271
}
272-
if( mOutlineWidthField.first != -1 )
272+
if ( mOutlineWidthField.first != -1 )
273273
{
274274
dataDefinedAttributes.insert( mOutlineWidthField.second );
275275
}
276-
if( mFillColorField.first != -1 )
276+
if ( mFillColorField.first != -1 )
277277
{
278278
dataDefinedAttributes.insert( mFillColorField.second );
279279
}
280-
if( mOutlineColorField.first != -1 )
280+
if ( mOutlineColorField.first != -1 )
281281
{
282282
dataDefinedAttributes.insert( mOutlineColorField.second );
283283
}
284-
if( mSymbolNameField.first != -1 )
284+
if ( mSymbolNameField.first != -1 )
285285
{
286286
dataDefinedAttributes.insert( mSymbolNameField.second );
287287
}
@@ -306,11 +306,11 @@ void QgsEllipseSymbolLayerV2::setHeightField( int index, const QString& field )
306306
mHeightField.second = field;
307307
}
308308

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+
}
314314

315315
void QgsEllipseSymbolLayerV2::setOutlineWidthField( int index, const QString& field )
316316
{

‎src/ui/symbollayer/widget_ellipse.ui

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,23 +106,41 @@
106106
<item row="6" column="0" colspan="2">
107107
<widget class="QListWidget" name="mShapeListWidget">
108108
<property name="dragDropMode">
109-
<enum>QAbstractItemView::DragDrop</enum>
109+
<enum>QAbstractItemView::DropOnly</enum>
110110
</property>
111111
<property name="iconSize">
112112
<size>
113113
<width>20</width>
114114
<height>20</height>
115115
</size>
116116
</property>
117+
<property name="movement">
118+
<enum>QListView::Static</enum>
119+
</property>
117120
<property name="flow">
118121
<enum>QListView::LeftToRight</enum>
119122
</property>
123+
<property name="resizeMode">
124+
<enum>QListView::Adjust</enum>
125+
</property>
120126
<property name="spacing">
121127
<number>4</number>
122128
</property>
129+
<property name="gridSize">
130+
<size>
131+
<width>30</width>
132+
<height>24</height>
133+
</size>
134+
</property>
123135
<property name="viewMode">
124136
<enum>QListView::IconMode</enum>
125137
</property>
138+
<property name="wordWrap">
139+
<bool>true</bool>
140+
</property>
141+
<property name="selectionRectVisible">
142+
<bool>true</bool>
143+
</property>
126144
</widget>
127145
</item>
128146
<item row="4" column="1">

0 commit comments

Comments
 (0)