Skip to content

Commit fab9760

Browse files
author
mhugent
committed
[FEATURE]: data defined font and buffer settings for labeling-ng
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@13998 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 9351aaa commit fab9760

File tree

8 files changed

+1172
-721
lines changed

8 files changed

+1172
-721
lines changed

python/core/qgsmaprenderer.sip

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ public:
1717
//! called to find out whether the layer is used for labeling
1818
virtual bool willUseLayer( QgsVectorLayer* layer ) = 0;
1919
//! called when starting rendering of a layer
20-
virtual int prepareLayer(QgsVectorLayer* layer, int& attrIndex, QgsRenderContext& ctx ) = 0;
20+
//! @note: this method was added in version 1.6
21+
virtual int prepareLayer( QgsVectorLayer* layer, QSet<int>& attrIndices, QgsRenderContext& ctx ) = 0;
2122
//! called for every feature
2223
virtual void registerFeature( QgsVectorLayer* layer, QgsFeature& feat, const QgsRenderContext& context = QgsRenderContext() ) = 0;
2324
//! called when the map is drawn and labels should be placed

src/app/qgslabelinggui.cpp

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QWid
7070
QgsPalLayerSettings lyr;
7171
lyr.readFromLayer( layer );
7272

73+
populateDataDefinedCombos( lyr );
74+
7375
// placement
7476
switch ( lyr.placement )
7577
{
@@ -237,6 +239,18 @@ QgsPalLayerSettings QgsLabelingGui::layerSettings()
237239
lyr.bufferSize = 0;
238240
}
239241
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+
240254
return lyr;
241255
}
242256

@@ -250,6 +264,79 @@ void QgsLabelingGui::populateFieldNames()
250264
}
251265
}
252266

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+
253340
void QgsLabelingGui::changeTextColor()
254341
{
255342
QColor color = QColorDialog::getColor( btnTextColor->color(), this );

src/app/qgslabelinggui.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ class QgsLabelingGui : public QDialog, private Ui::QgsLabelingGuiBase
4848
protected:
4949
void populatePlacementMethods();
5050
void populateFieldNames();
51+
void populateDataDefinedCombos( QgsPalLayerSettings& s );
52+
/**Sets data defined property attribute to map (if selected in combo box)*/
53+
void setDataDefinedProperty( const QComboBox* c, QgsPalLayerSettings::DataDefinedProperties p, QgsPalLayerSettings& lyr );
54+
void setCurrentComboValue( QComboBox* c, const QgsPalLayerSettings& s, QgsPalLayerSettings::DataDefinedProperties p );
5155
void updateFont( QFont font );
5256

5357
private:

src/core/qgsmaprenderer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ class QgsLabelingEngineInterface
5151
//! called to find out whether the layer is used for labeling
5252
virtual bool willUseLayer( QgsVectorLayer* layer ) = 0;
5353
//! called when starting rendering of a layer
54-
virtual int prepareLayer( QgsVectorLayer* layer, int& attrIndex, QgsRenderContext& ctx ) = 0;
54+
//! @note: this method was added in version 1.6
55+
virtual int prepareLayer( QgsVectorLayer* layer, QSet<int>& attrIndices, QgsRenderContext& ctx ) = 0;
5556
//! called for every feature
5657
virtual void registerFeature( QgsVectorLayer* layer, QgsFeature& feat, const QgsRenderContext& context = QgsRenderContext() ) = 0;
5758
//! called when the map is drawn and labels should be placed

0 commit comments

Comments
 (0)