Skip to content
Permalink
Browse files

Add min/max scale-based visibility to advanced labeling data defined …

…columns

- Layer-level options, if set, will override data defined values (correct behavior IMHO)
- Spinboxes for min and max added to Change Label tool's dialog
- Seems to still be a bug in renderer scale-to-value comparison, where equal scales are not always equal if user directly enters values in the map canvas scale combobox
  • Loading branch information
dakcarto committed Aug 13, 2012
1 parent ad6c964 commit 22634351bbfbf276efe607d268bccb21cad90a10
@@ -354,6 +354,8 @@ QgsPalLayerSettings QgsLabelingGui::layerSettings()
setDataDefinedProperty( mLabelDistanceComboBox, QgsPalLayerSettings::LabelDistance, lyr );
setDataDefinedProperty( mRotationComboBox, QgsPalLayerSettings::Rotation, lyr );
setDataDefinedProperty( mShowLabelAttributeComboBox, QgsPalLayerSettings::Show, lyr );
setDataDefinedProperty( mMinScaleAttributeComboBox, QgsPalLayerSettings::MinScale, lyr );
setDataDefinedProperty( mMaxScaleAttributeComboBox, QgsPalLayerSettings::MaxScale, lyr );

return lyr;
}
@@ -419,6 +421,8 @@ void QgsLabelingGui::populateDataDefinedCombos( QgsPalLayerSettings& s )
comboList << mLabelDistanceComboBox;
comboList << mRotationComboBox;
comboList << mShowLabelAttributeComboBox;
comboList << mMinScaleAttributeComboBox;
comboList << mMaxScaleAttributeComboBox;

QList<QComboBox*>::iterator comboIt = comboList.begin();
for ( ; comboIt != comboList.end(); ++comboIt )
@@ -453,6 +457,8 @@ void QgsLabelingGui::populateDataDefinedCombos( QgsPalLayerSettings& s )
setCurrentComboValue( mLabelDistanceComboBox, s, QgsPalLayerSettings::LabelDistance );
setCurrentComboValue( mRotationComboBox, s, QgsPalLayerSettings::Rotation );
setCurrentComboValue( mShowLabelAttributeComboBox, s, QgsPalLayerSettings::Show );
setCurrentComboValue( mMinScaleAttributeComboBox, s, QgsPalLayerSettings::MinScale );
setCurrentComboValue( mMaxScaleAttributeComboBox, s, QgsPalLayerSettings::MaxScale );
}

void QgsLabelingGui::changePreviewBackground()
@@ -96,6 +96,8 @@ void QgsLabelPropertyDialog::init( const QString& layerId, int featureId )
mBufferColorButton->setColor( layerSettings.textColor );
mLabelDistanceSpinBox->setValue( layerSettings.dist );
mBufferSizeSpinBox->setValue( layerSettings.bufferSize );
mMinScaleSpinBox->setValue( layerSettings.scaleMin );
mMaxScaleSpinBox->setValue( layerSettings.scaleMax );
mHaliComboBox->setCurrentIndex( mHaliComboBox->findText( "Left" ) );
mValiComboBox->setCurrentIndex( mValiComboBox->findText( "Bottom" ) );

@@ -112,6 +114,14 @@ void QgsLabelPropertyDialog::init( const QString& layerId, int featureId )
mShowLabelChkbx->setEnabled( true );
mShowLabelChkbx->setChecked( attributeValues[propIt.value()].toInt() != 0 );
break;
case QgsPalLayerSettings::MinScale:
mMinScaleSpinBox->setEnabled( true );
mMinScaleSpinBox->setValue( attributeValues[propIt.value()].toInt() );
break;
case QgsPalLayerSettings::MaxScale:
mMaxScaleSpinBox->setEnabled( true );
mMaxScaleSpinBox->setValue( attributeValues[propIt.value()].toInt() );
break;
case QgsPalLayerSettings::Size:
mFontSizeSpinBox->setEnabled( true );
mLabelFont.setPointSizeF( attributeValues[propIt.value()].toDouble() );
@@ -181,6 +191,8 @@ void QgsLabelPropertyDialog::init( const QString& layerId, int featureId )
void QgsLabelPropertyDialog::disableGuiElements()
{
mShowLabelChkbx->setEnabled( false );
mMinScaleSpinBox->setEnabled( false );
mMaxScaleSpinBox->setEnabled( false );
mFontSizeSpinBox->setEnabled( false );
mBufferSizeSpinBox->setEnabled( false );
mFontPushButton->setEnabled( false );
@@ -197,6 +209,8 @@ void QgsLabelPropertyDialog::disableGuiElements()
void QgsLabelPropertyDialog::blockElementSignals( bool block )
{
mShowLabelChkbx->blockSignals( block );
mMinScaleSpinBox->blockSignals( block );
mMaxScaleSpinBox->blockSignals( block );
mFontSizeSpinBox->blockSignals( block );
mBufferSizeSpinBox->blockSignals( block );
mFontPushButton->blockSignals( block );
@@ -229,6 +243,16 @@ void QgsLabelPropertyDialog::on_mShowLabelChkbx_toggled( bool chkd )
insertChangedValue( QgsPalLayerSettings::Show, ( chkd ? 1 : 0 ) );
}

void QgsLabelPropertyDialog::on_mMinScaleSpinBox_valueChanged( int i )
{
insertChangedValue( QgsPalLayerSettings::MinScale, i );
}

void QgsLabelPropertyDialog::on_mMaxScaleSpinBox_valueChanged(int i )
{
insertChangedValue( QgsPalLayerSettings::MaxScale, i );
}

void QgsLabelPropertyDialog::on_mLabelDistanceSpinBox_valueChanged( double d )
{
insertChangedValue( QgsPalLayerSettings::LabelDistance, d );
@@ -38,6 +38,8 @@ class QgsLabelPropertyDialog: public QDialog, private Ui::QgsLabelPropertyDialog

private slots:
void on_mShowLabelChkbx_toggled( bool chkd );
void on_mMinScaleSpinBox_valueChanged(int i );
void on_mMaxScaleSpinBox_valueChanged( int i );
void on_mLabelDistanceSpinBox_valueChanged( double d );
void on_mXCoordSpinBox_valueChanged( double d );
void on_mYCoordSpinBox_valueChanged( double d );
@@ -245,7 +245,7 @@ static void _writeDataDefinedPropertyMap( QgsVectorLayer* layer, const QMap< Qgs
{
return;
}
for ( int i = 0; i < 16; ++i )
for ( int i = 0; i < 18; ++i )
{
QMap< QgsPalLayerSettings::DataDefinedProperties, int >::const_iterator it = propertyMap.find(( QgsPalLayerSettings::DataDefinedProperties )i );
QVariant propertyValue;
@@ -301,6 +301,8 @@ static void _readDataDefinedPropertyMap( QgsVectorLayer* layer, QMap< QgsPalLaye
_readDataDefinedProperty( layer, QgsPalLayerSettings::LabelDistance, propertyMap );
_readDataDefinedProperty( layer, QgsPalLayerSettings::Rotation, propertyMap );
_readDataDefinedProperty( layer, QgsPalLayerSettings::Show, propertyMap );
_readDataDefinedProperty( layer, QgsPalLayerSettings::MinScale, propertyMap );
_readDataDefinedProperty( layer, QgsPalLayerSettings::MaxScale, propertyMap );
}

void QgsPalLayerSettings::readFromLayer( QgsVectorLayer* layer )
@@ -486,6 +488,40 @@ void QgsPalLayerSettings::registerFeature( QgsVectorLayer* layer, QgsFeature& f
}
}

// data defined min scale?
QMap< DataDefinedProperties, int >::const_iterator minScaleIt = dataDefinedProperties.find( QgsPalLayerSettings::MinScale );
if ( minScaleIt != dataDefinedProperties.constEnd() )
{
QVariant minScaleValue = f.attributeMap().value( *minScaleIt );
if ( minScaleValue.isValid() )
{
bool conversionOk;
int minScale = minScaleValue.toInt( &conversionOk );
// TODO: occasional floating point issues?
if ( conversionOk && int( context.rendererScale() ) < minScale )
{
return;
}
}
}

// data defined max scale?
QMap< DataDefinedProperties, int >::const_iterator maxScaleIt = dataDefinedProperties.find( QgsPalLayerSettings::MaxScale );
if ( maxScaleIt != dataDefinedProperties.constEnd() )
{
QVariant maxScaleValue = f.attributeMap().value( *maxScaleIt );
if ( maxScaleValue.isValid() )
{
bool conversionOk;
int maxScale = maxScaleValue.toInt( &conversionOk );
// TODO: occasional floating point issues?
if ( conversionOk && int( context.rendererScale() ) > maxScale )
{
return;
}
}
}

QString labelText;
// Check to see if we are a expression string.
if ( isExpression )
@@ -98,7 +98,9 @@ class CORE_EXPORT QgsPalLayerSettings
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)
Show
Show,
MinScale,
MaxScale
};

QString fieldName;
@@ -2047,7 +2047,7 @@
<item row="1" column="1">
<widget class="QComboBox" name="mMinScaleAttributeComboBox">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
</widget>
</item>
@@ -2085,7 +2085,7 @@
<item row="2" column="1">
<widget class="QComboBox" name="mMaxScaleAttributeComboBox">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
</widget>
</item>

0 comments on commit 2263435

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