@@ -70,6 +70,8 @@ QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QWid
70
70
QgsPalLayerSettings lyr;
71
71
lyr.readFromLayer ( layer );
72
72
73
+ populateDataDefinedCombos ( lyr );
74
+
73
75
// placement
74
76
switch ( lyr.placement )
75
77
{
@@ -237,6 +239,18 @@ QgsPalLayerSettings QgsLabelingGui::layerSettings()
237
239
lyr.bufferSize = 0 ;
238
240
}
239
241
lyr.minFeatureSize = mMinSizeSpinBox ->value ();
242
+
243
+ // data defined labeling
244
+ setDataDefinedProperty ( mSizeAttributeComboBox , QgsPalLayerSettings::Size, lyr );
245
+ setDataDefinedProperty ( mColorAttributeComboBox , QgsPalLayerSettings::Color, lyr );
246
+ setDataDefinedProperty ( mBoldAttributeComboBox , QgsPalLayerSettings::Bold, lyr );
247
+ setDataDefinedProperty ( mItalicAttributeComboBox , QgsPalLayerSettings::Italic, lyr );
248
+ setDataDefinedProperty ( mUnderlineAttributeComboBox , QgsPalLayerSettings::Underline, lyr );
249
+ setDataDefinedProperty ( mStrikeoutAttributeComboBox , QgsPalLayerSettings::Strikeout, lyr );
250
+ setDataDefinedProperty ( mFontFamilyAttributeComboBox , QgsPalLayerSettings::Family, lyr );
251
+ setDataDefinedProperty ( mBufferSizeAttributeComboBox , QgsPalLayerSettings:: BufferSize, lyr );
252
+ setDataDefinedProperty ( mBufferColorAttributeComboBox , QgsPalLayerSettings::BufferColor, lyr );
253
+
240
254
return lyr;
241
255
}
242
256
@@ -250,6 +264,79 @@ void QgsLabelingGui::populateFieldNames()
250
264
}
251
265
}
252
266
267
+ void QgsLabelingGui::setDataDefinedProperty ( const QComboBox* c, QgsPalLayerSettings::DataDefinedProperties p, QgsPalLayerSettings& lyr )
268
+ {
269
+ if ( !c )
270
+ {
271
+ return ;
272
+ }
273
+
274
+ QVariant propertyField = c->itemData ( c->currentIndex () );
275
+ if ( propertyField.isValid () )
276
+ {
277
+ lyr.setDataDefinedProperty ( p, propertyField.toInt () );
278
+ }
279
+ }
280
+
281
+ void QgsLabelingGui::setCurrentComboValue ( QComboBox* c, const QgsPalLayerSettings& s, QgsPalLayerSettings::DataDefinedProperties p )
282
+ {
283
+ if ( !c )
284
+ {
285
+ return ;
286
+ }
287
+
288
+ QMap< QgsPalLayerSettings::DataDefinedProperties, int >::const_iterator it = s.dataDefinedProperties .find ( p );
289
+ if ( it == s.dataDefinedProperties .constEnd () )
290
+ {
291
+ c->setCurrentIndex ( 0 );
292
+ }
293
+ else
294
+ {
295
+ c->setCurrentIndex ( c->findData ( it.value () ) );
296
+ }
297
+ }
298
+
299
+ void QgsLabelingGui::populateDataDefinedCombos ( QgsPalLayerSettings& s )
300
+ {
301
+ QList<QComboBox*> comboList;
302
+ comboList << mSizeAttributeComboBox ;
303
+ comboList << mColorAttributeComboBox ;
304
+ comboList << mBoldAttributeComboBox ;
305
+ comboList << mItalicAttributeComboBox ;
306
+ comboList << mUnderlineAttributeComboBox ;
307
+ comboList << mStrikeoutAttributeComboBox ;
308
+ comboList << mFontFamilyAttributeComboBox ;
309
+ comboList << mBufferSizeAttributeComboBox ;
310
+ comboList << mBufferColorAttributeComboBox ;
311
+
312
+ QList<QComboBox*>::iterator comboIt = comboList.begin ();
313
+ for ( ; comboIt != comboList.end (); ++comboIt )
314
+ {
315
+ ( *comboIt )->addItem ( " " , QVariant () );
316
+ }
317
+
318
+ const QgsFieldMap& fields = mLayer ->dataProvider ()->fields ();
319
+ for ( QgsFieldMap::const_iterator it = fields.constBegin (); it != fields.constEnd (); it++ )
320
+ {
321
+ for ( comboIt = comboList.begin (); comboIt != comboList.end (); ++comboIt )
322
+ {
323
+ ( *comboIt )->addItem ( it.value ().name (), it.key () );
324
+ }
325
+
326
+ }
327
+
328
+ // set current combo boxes to already existing indices
329
+ setCurrentComboValue ( mSizeAttributeComboBox , s, QgsPalLayerSettings::Size );
330
+ setCurrentComboValue ( mColorAttributeComboBox , s, QgsPalLayerSettings::Color );
331
+ setCurrentComboValue ( mBoldAttributeComboBox , s, QgsPalLayerSettings::Bold );
332
+ setCurrentComboValue ( mItalicAttributeComboBox , s, QgsPalLayerSettings::Italic );
333
+ setCurrentComboValue ( mUnderlineAttributeComboBox , s, QgsPalLayerSettings::Underline );
334
+ setCurrentComboValue ( mStrikeoutAttributeComboBox , s, QgsPalLayerSettings::Strikeout );
335
+ setCurrentComboValue ( mFontFamilyAttributeComboBox , s, QgsPalLayerSettings::Family );
336
+ setCurrentComboValue ( mBufferSizeAttributeComboBox , s , QgsPalLayerSettings::BufferSize );
337
+ setCurrentComboValue ( mBufferColorAttributeComboBox , s, QgsPalLayerSettings::BufferColor );
338
+ }
339
+
253
340
void QgsLabelingGui::changeTextColor ()
254
341
{
255
342
QColor color = QColorDialog::getColor ( btnTextColor->color (), this );
0 commit comments