Skip to content
Permalink
Browse files

Add Show Label to advanced labeling data defined columns

- Allows label to be shown/hidden (1 or 0) without adjusting the mapped font size field
- Current method of setting mapped font size field to 0 still works
- Show label checkbox added to Change Label tool's dialog
  • Loading branch information
dakcarto committed Aug 12, 2012
1 parent 547a05a commit 2fbc98e66f62a3c1324654a5957258ed29849f44
@@ -353,6 +353,7 @@ QgsPalLayerSettings QgsLabelingGui::layerSettings()
setDataDefinedProperty( mVerticalAlignmentComboBox, QgsPalLayerSettings::Vali, lyr );
setDataDefinedProperty( mLabelDistanceComboBox, QgsPalLayerSettings::LabelDistance, lyr );
setDataDefinedProperty( mRotationComboBox, QgsPalLayerSettings::Rotation, lyr );
setDataDefinedProperty( mShowLabelAttributeComboBox, QgsPalLayerSettings::Show, lyr );

return lyr;
}
@@ -417,6 +418,7 @@ void QgsLabelingGui::populateDataDefinedCombos( QgsPalLayerSettings& s )
comboList << mVerticalAlignmentComboBox;
comboList << mLabelDistanceComboBox;
comboList << mRotationComboBox;
comboList << mShowLabelAttributeComboBox;

QList<QComboBox*>::iterator comboIt = comboList.begin();
for ( ; comboIt != comboList.end(); ++comboIt )
@@ -450,6 +452,7 @@ void QgsLabelingGui::populateDataDefinedCombos( QgsPalLayerSettings& s )
setCurrentComboValue( mVerticalAlignmentComboBox, s, QgsPalLayerSettings::Vali );
setCurrentComboValue( mLabelDistanceComboBox, s, QgsPalLayerSettings::LabelDistance );
setCurrentComboValue( mRotationComboBox, s, QgsPalLayerSettings::Rotation );
setCurrentComboValue( mShowLabelAttributeComboBox, s, QgsPalLayerSettings::Show );
}

void QgsLabelingGui::changePreviewBackground()
@@ -108,6 +108,10 @@ void QgsLabelPropertyDialog::init( const QString& layerId, int featureId )
{
switch ( propIt.key() )
{
case QgsPalLayerSettings::Show:
mShowLabelChkbx->setEnabled( true );
mShowLabelChkbx->setChecked( attributeValues[propIt.value()].toInt() != 0 );
break;
case QgsPalLayerSettings::Size:
mFontSizeSpinBox->setEnabled( true );
mLabelFont.setPointSizeF( attributeValues[propIt.value()].toDouble() );
@@ -166,6 +170,8 @@ void QgsLabelPropertyDialog::init( const QString& layerId, int featureId )
case QgsPalLayerSettings::Family:
mLabelFont.setFamily( attributeValues[propIt.value()].toString() );
break;
default:
break;
}
}
mFontPushButton->setEnabled( labelFontEditingPossible() );
@@ -174,6 +180,7 @@ void QgsLabelPropertyDialog::init( const QString& layerId, int featureId )

void QgsLabelPropertyDialog::disableGuiElements()
{
mShowLabelChkbx->setEnabled( false );
mFontSizeSpinBox->setEnabled( false );
mBufferSizeSpinBox->setEnabled( false );
mFontPushButton->setEnabled( false );
@@ -189,6 +196,7 @@ void QgsLabelPropertyDialog::disableGuiElements()

void QgsLabelPropertyDialog::blockElementSignals( bool block )
{
mShowLabelChkbx->blockSignals( block );
mFontSizeSpinBox->blockSignals( block );
mBufferSizeSpinBox->blockSignals( block );
mFontPushButton->blockSignals( block );
@@ -216,6 +224,11 @@ void QgsLabelPropertyDialog::fillValiComboBox()
mValiComboBox->addItem( "Top" );
}

void QgsLabelPropertyDialog::on_mShowLabelChkbx_toggled( bool chkd )
{
insertChangedValue( QgsPalLayerSettings::Show, ( chkd ? 1 : 0 ) );
}

void QgsLabelPropertyDialog::on_mLabelDistanceSpinBox_valueChanged( double d )
{
insertChangedValue( QgsPalLayerSettings::LabelDistance, d );
@@ -37,6 +37,7 @@ class QgsLabelPropertyDialog: public QDialog, private Ui::QgsLabelPropertyDialog
const QgsAttributeMap& changedProperties() const { return mChangedProperties; }

private slots:
void on_mShowLabelChkbx_toggled( bool chkd );
void on_mLabelDistanceSpinBox_valueChanged( double d );
void on_mXCoordSpinBox_valueChanged( double d );
void on_mYCoordSpinBox_valueChanged( double d );
@@ -245,8 +245,7 @@ static void _writeDataDefinedPropertyMap( QgsVectorLayer* layer, const QMap< Qgs
{
return;
}

for ( int i = 0; i < 15; ++i )
for ( int i = 0; i < 16; ++i )
{
QMap< QgsPalLayerSettings::DataDefinedProperties, int >::const_iterator it = propertyMap.find(( QgsPalLayerSettings::DataDefinedProperties )i );
QVariant propertyValue;
@@ -295,12 +294,13 @@ static void _readDataDefinedPropertyMap( QgsVectorLayer* layer, QMap< QgsPalLaye
_readDataDefinedProperty( layer, QgsPalLayerSettings::Family, propertyMap );
_readDataDefinedProperty( layer, QgsPalLayerSettings::BufferSize, propertyMap );
_readDataDefinedProperty( layer, QgsPalLayerSettings::BufferColor, propertyMap );
_readDataDefinedProperty( layer, QgsPalLayerSettings::PositionX, propertyMap );
_readDataDefinedProperty( layer, QgsPalLayerSettings::PositionY, propertyMap );
_readDataDefinedProperty( layer, QgsPalLayerSettings::Hali, propertyMap );
_readDataDefinedProperty( layer, QgsPalLayerSettings::Vali, propertyMap );
_readDataDefinedProperty( layer, QgsPalLayerSettings::PositionX, propertyMap );
_readDataDefinedProperty( layer, QgsPalLayerSettings::PositionY, propertyMap );
_readDataDefinedProperty( layer, QgsPalLayerSettings::Hali, propertyMap );
_readDataDefinedProperty( layer, QgsPalLayerSettings::Vali, propertyMap );
_readDataDefinedProperty( layer, QgsPalLayerSettings::LabelDistance, propertyMap );
_readDataDefinedProperty( layer, QgsPalLayerSettings::Rotation, propertyMap );
_readDataDefinedProperty( layer, QgsPalLayerSettings::Show, propertyMap );
}

void QgsPalLayerSettings::readFromLayer( QgsVectorLayer* layer )
@@ -470,6 +470,22 @@ void QgsPalLayerSettings::calculateLabelSize( const QFontMetricsF* fm, QString t

void QgsPalLayerSettings::registerFeature( QgsVectorLayer* layer, QgsFeature& f, const QgsRenderContext& context )
{
// data defined show label? defaults to show label if not 0
QMap< DataDefinedProperties, int >::const_iterator showIt = dataDefinedProperties.find( QgsPalLayerSettings::Show );
if ( showIt != dataDefinedProperties.constEnd() )
{
QVariant showValue = f.attributeMap().value( *showIt );
if ( showValue.isValid() )
{
bool conversionOk;
int showLabel = showValue.toInt( &conversionOk );
if ( conversionOk && showLabel == 0 )
{
return;
}
}
}

QString labelText;
// Check to see if we are a expression string.
if ( isExpression )
@@ -80,6 +80,7 @@ class CORE_EXPORT QgsPalLayerSettings
MapOrientation = 8
};

// increment iterator in _writeDataDefinedPropertyMap() when adding more
enum DataDefinedProperties
{
Size = 0,
@@ -96,7 +97,8 @@ class CORE_EXPORT QgsPalLayerSettings
Hali, //horizontal alignment for data defined label position (Left, Center, Right)
Vali, //vertical alignment for data defined label position (Bottom, Base, Half, Cap, Top)
LabelDistance,
Rotation //data defined rotation (only useful in connection with data defined position)
Rotation, //data defined rotation (only useful in connection with data defined position)
Show
};

QString fieldName;
@@ -2071,7 +2071,7 @@
<item row="0" column="1">
<widget class="QComboBox" name="mShowLabelAttributeComboBox">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
</widget>
</item>
@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>284</width>
<height>411</height>
<width>326</width>
<height>535</height>
</rect>
</property>
<property name="windowTitle">
@@ -28,7 +28,7 @@
</item>
</layout>
</item>
<item row="1" column="0">
<item row="2" column="0">
<widget class="QGroupBox" name="mFontGroupBox">
<property name="title">
<string>Font</string>
@@ -75,7 +75,7 @@
</layout>
</widget>
</item>
<item row="2" column="0">
<item row="3" column="0">
<widget class="QGroupBox" name="mBufferGroupBox">
<property name="title">
<string>Buffer</string>
@@ -115,7 +115,7 @@
</layout>
</widget>
</item>
<item row="3" column="0">
<item row="4" column="0">
<widget class="QGroupBox" name="mPositionGroupBlox">
<property name="title">
<string>Position</string>
@@ -202,7 +202,7 @@
</layout>
</widget>
</item>
<item row="4" column="0">
<item row="5" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@@ -212,6 +212,22 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Display</string>
</property>
<layout class="QGridLayout" name="gridLayout_5">
<item row="0" column="0">
<widget class="QCheckBox" name="mShowLabelChkbx">
<property name="text">
<string>Show label</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<customwidgets>

0 comments on commit 2fbc98e

Please sign in to comment.
You can’t perform that action at this time.