Skip to content
Permalink
Browse files
[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
  • Loading branch information
mhugent committed Aug 2, 2010
1 parent 9351aaa commit fab9760ba17ab90db87f98b3ddecce7cf3c14a70
Showing with 1,172 additions and 721 deletions.
  1. +2 −1 python/core/qgsmaprenderer.sip
  2. +87 −0 src/app/qgslabelinggui.cpp
  3. +4 −0 src/app/qgslabelinggui.h
  4. +2 −1 src/core/qgsmaprenderer.h
  5. +216 −19 src/core/qgspallabeling.cpp
  6. +32 −4 src/core/qgspallabeling.h
  7. +18 −6 src/core/qgsvectorlayer.cpp
  8. +811 −690 src/ui/qgslabelingguibase.ui
@@ -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
@@ -70,6 +70,8 @@ QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QWid
QgsPalLayerSettings lyr;
lyr.readFromLayer( layer );

populateDataDefinedCombos( lyr );

// placement
switch ( lyr.placement )
{
@@ -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;
}

@@ -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 );
@@ -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:
@@ -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
Loading

0 comments on commit fab9760

Please sign in to comment.