Skip to content

Commit

Permalink
Add Show Label to advanced labeling data defined columns
Browse files Browse the repository at this point in the history
- 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 2fbc98e
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 14 deletions.
3 changes: 3 additions & 0 deletions src/app/qgslabelinggui.cpp
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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()
Expand Down
13 changes: 13 additions & 0 deletions src/app/qgslabelpropertydialog.cpp
Expand Up @@ -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() );
Expand Down Expand Up @@ -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() );
Expand All @@ -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 );
Expand All @@ -189,6 +196,7 @@ void QgsLabelPropertyDialog::disableGuiElements()

void QgsLabelPropertyDialog::blockElementSignals( bool block )
{
mShowLabelChkbx->blockSignals( block );
mFontSizeSpinBox->blockSignals( block );
mBufferSizeSpinBox->blockSignals( block );
mFontPushButton->blockSignals( block );
Expand Down Expand Up @@ -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 );
Expand Down
1 change: 1 addition & 0 deletions src/app/qgslabelpropertydialog.h
Expand Up @@ -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 );
Expand Down
28 changes: 22 additions & 6 deletions src/core/qgspallabeling.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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 )
Expand Down
4 changes: 3 additions & 1 deletion src/core/qgspallabeling.h
Expand Up @@ -80,6 +80,7 @@ class CORE_EXPORT QgsPalLayerSettings
MapOrientation = 8
};

// increment iterator in _writeDataDefinedPropertyMap() when adding more
enum DataDefinedProperties
{
Size = 0,
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/ui/qgslabelingguibase.ui
Expand Up @@ -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>
Expand Down
28 changes: 22 additions & 6 deletions src/ui/qgslabelpropertydialogbase.ui
Expand Up @@ -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">
Expand All @@ -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>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand All @@ -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>
Expand Down

0 comments on commit 2fbc98e

Please sign in to comment.