Skip to content

Commit

Permalink
[FEATURE]: data defined font and buffer settings for labeling-ng
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@13998 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Aug 2, 2010
1 parent c8edb3d commit 33194f8
Show file tree
Hide file tree
Showing 8 changed files with 1,172 additions and 721 deletions.
3 changes: 2 additions & 1 deletion python/core/qgsmaprenderer.sip
Expand Up @@ -17,7 +17,8 @@ public:
//! called to find out whether the layer is used for labeling
virtual bool willUseLayer( QgsVectorLayer* layer ) = 0;
//! called when starting rendering of a layer
virtual int prepareLayer(QgsVectorLayer* layer, int& attrIndex, QgsRenderContext& ctx ) = 0;
//! @note: this method was added in version 1.6
virtual int prepareLayer( QgsVectorLayer* layer, QSet<int>& attrIndices, QgsRenderContext& ctx ) = 0;
//! called for every feature
virtual void registerFeature( QgsVectorLayer* layer, QgsFeature& feat, const QgsRenderContext& context = QgsRenderContext() ) = 0;
//! called when the map is drawn and labels should be placed
Expand Down
87 changes: 87 additions & 0 deletions src/app/qgslabelinggui.cpp
Expand Up @@ -70,6 +70,8 @@ QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QWid
QgsPalLayerSettings lyr;
lyr.readFromLayer( layer );

populateDataDefinedCombos( lyr );

// placement
switch ( lyr.placement )
{
Expand Down Expand Up @@ -237,6 +239,18 @@ QgsPalLayerSettings QgsLabelingGui::layerSettings()
lyr.bufferSize = 0;
}
lyr.minFeatureSize = mMinSizeSpinBox->value();

//data defined labeling
setDataDefinedProperty( mSizeAttributeComboBox, QgsPalLayerSettings::Size, lyr );
setDataDefinedProperty( mColorAttributeComboBox, QgsPalLayerSettings::Color, lyr );
setDataDefinedProperty( mBoldAttributeComboBox, QgsPalLayerSettings::Bold, lyr );
setDataDefinedProperty( mItalicAttributeComboBox, QgsPalLayerSettings::Italic, lyr );
setDataDefinedProperty( mUnderlineAttributeComboBox, QgsPalLayerSettings::Underline, lyr );
setDataDefinedProperty( mStrikeoutAttributeComboBox, QgsPalLayerSettings::Strikeout, lyr );
setDataDefinedProperty( mFontFamilyAttributeComboBox, QgsPalLayerSettings::Family, lyr );
setDataDefinedProperty( mBufferSizeAttributeComboBox, QgsPalLayerSettings:: BufferSize, lyr );
setDataDefinedProperty( mBufferColorAttributeComboBox, QgsPalLayerSettings::BufferColor, lyr );

return lyr;
}

Expand All @@ -250,6 +264,79 @@ void QgsLabelingGui::populateFieldNames()
}
}

void QgsLabelingGui::setDataDefinedProperty( const QComboBox* c, QgsPalLayerSettings::DataDefinedProperties p, QgsPalLayerSettings& lyr )
{
if ( !c )
{
return;
}

QVariant propertyField = c->itemData( c->currentIndex() );
if ( propertyField.isValid() )
{
lyr.setDataDefinedProperty( p, propertyField.toInt() );
}
}

void QgsLabelingGui::setCurrentComboValue( QComboBox* c, const QgsPalLayerSettings& s, QgsPalLayerSettings::DataDefinedProperties p )
{
if ( !c )
{
return;
}

QMap< QgsPalLayerSettings::DataDefinedProperties, int >::const_iterator it = s.dataDefinedProperties.find( p );
if ( it == s.dataDefinedProperties.constEnd() )
{
c->setCurrentIndex( 0 );
}
else
{
c->setCurrentIndex( c->findData( it.value() ) );
}
}

void QgsLabelingGui::populateDataDefinedCombos( QgsPalLayerSettings& s )
{
QList<QComboBox*> comboList;
comboList << mSizeAttributeComboBox;
comboList << mColorAttributeComboBox;
comboList << mBoldAttributeComboBox;
comboList << mItalicAttributeComboBox;
comboList << mUnderlineAttributeComboBox;
comboList << mStrikeoutAttributeComboBox;
comboList << mFontFamilyAttributeComboBox;
comboList << mBufferSizeAttributeComboBox;
comboList << mBufferColorAttributeComboBox;

QList<QComboBox*>::iterator comboIt = comboList.begin();
for ( ; comboIt != comboList.end(); ++comboIt )
{
( *comboIt )->addItem( "", QVariant() );
}

const QgsFieldMap& fields = mLayer->dataProvider()->fields();
for ( QgsFieldMap::const_iterator it = fields.constBegin(); it != fields.constEnd(); it++ )
{
for ( comboIt = comboList.begin(); comboIt != comboList.end(); ++comboIt )
{
( *comboIt )->addItem( it.value().name(), it.key() );
}

}

//set current combo boxes to already existing indices
setCurrentComboValue( mSizeAttributeComboBox, s, QgsPalLayerSettings::Size );
setCurrentComboValue( mColorAttributeComboBox, s, QgsPalLayerSettings::Color );
setCurrentComboValue( mBoldAttributeComboBox, s, QgsPalLayerSettings::Bold );
setCurrentComboValue( mItalicAttributeComboBox, s, QgsPalLayerSettings::Italic );
setCurrentComboValue( mUnderlineAttributeComboBox, s, QgsPalLayerSettings::Underline );
setCurrentComboValue( mStrikeoutAttributeComboBox, s, QgsPalLayerSettings::Strikeout );
setCurrentComboValue( mFontFamilyAttributeComboBox, s, QgsPalLayerSettings::Family );
setCurrentComboValue( mBufferSizeAttributeComboBox, s , QgsPalLayerSettings::BufferSize );
setCurrentComboValue( mBufferColorAttributeComboBox, s, QgsPalLayerSettings::BufferColor );
}

void QgsLabelingGui::changeTextColor()
{
QColor color = QColorDialog::getColor( btnTextColor->color(), this );
Expand Down
4 changes: 4 additions & 0 deletions src/app/qgslabelinggui.h
Expand Up @@ -48,6 +48,10 @@ class QgsLabelingGui : public QDialog, private Ui::QgsLabelingGuiBase
protected:
void populatePlacementMethods();
void populateFieldNames();
void populateDataDefinedCombos( QgsPalLayerSettings& s );
/**Sets data defined property attribute to map (if selected in combo box)*/
void setDataDefinedProperty( const QComboBox* c, QgsPalLayerSettings::DataDefinedProperties p, QgsPalLayerSettings& lyr );
void setCurrentComboValue( QComboBox* c, const QgsPalLayerSettings& s, QgsPalLayerSettings::DataDefinedProperties p );
void updateFont( QFont font );

private:
Expand Down
3 changes: 2 additions & 1 deletion src/core/qgsmaprenderer.h
Expand Up @@ -51,7 +51,8 @@ class QgsLabelingEngineInterface
//! called to find out whether the layer is used for labeling
virtual bool willUseLayer( QgsVectorLayer* layer ) = 0;
//! called when starting rendering of a layer
virtual int prepareLayer( QgsVectorLayer* layer, int& attrIndex, QgsRenderContext& ctx ) = 0;
//! @note: this method was added in version 1.6
virtual int prepareLayer( QgsVectorLayer* layer, QSet<int>& attrIndices, QgsRenderContext& ctx ) = 0;
//! called for every feature
virtual void registerFeature( QgsVectorLayer* layer, QgsFeature& feat, const QgsRenderContext& context = QgsRenderContext() ) = 0;
//! called when the map is drawn and labels should be placed
Expand Down

0 comments on commit 33194f8

Please sign in to comment.