Skip to content
Permalink
Browse files

Add handling of null values to some widgets in label properties

This allows clearing the data defined values for these properties,
which nulls their attribute value and resets the property for
that label to the layer's default value.
  • Loading branch information
nyalldawson committed Mar 29, 2015
1 parent 727ef9b commit ea2c6742815409e0dd06f1586a42ac3bc21b9024
Showing with 86 additions and 17 deletions.
  1. +44 −7 src/app/qgslabelpropertydialog.cpp
  2. +42 −10 src/ui/qgslabelpropertydialogbase.ui
@@ -34,6 +34,7 @@ QgsLabelPropertyDialog::QgsLabelPropertyDialog( const QString& layerId, int feat
setupUi( this );
fillHaliComboBox();
fillValiComboBox();

init( layerId, featureId, labelText );

QSettings settings;
@@ -111,11 +112,17 @@ void QgsLabelPropertyDialog::init( const QString& layerId, int featureId, const
updateFont( mLabelFont, false );

//set all the gui elements to the default layer-level values
mLabelDistanceSpinBox->clear();
mLabelDistanceSpinBox->setSpecialValueText( tr( "Layer default (%1)" ).arg( QString::number( layerSettings.dist, 'f', mLabelDistanceSpinBox->decimals() ) ) );
mBufferSizeSpinBox->clear();
mBufferSizeSpinBox->setSpecialValueText( tr( "Layer default (%1)" ).arg( QString::number( layerSettings.bufferSize, 'f', mBufferSizeSpinBox->decimals() ) ) );
mRotationSpinBox->clear();
mXCoordSpinBox->clear();
mYCoordSpinBox->clear();

mShowLabelChkbx->setChecked( true );
mFontColorButton->setColor( layerSettings.textColor );
mBufferColorButton->setColor( layerSettings.bufferColor );
mLabelDistanceSpinBox->setValue( layerSettings.dist );
mBufferSizeSpinBox->setValue( layerSettings.bufferSize );
mMinScaleSpinBox->setValue( layerSettings.scaleMin );
mMaxScaleSpinBox->setValue( layerSettings.scaleMax );
mHaliComboBox->setCurrentIndex( mHaliComboBox->findText( "Left" ) );
@@ -486,17 +493,35 @@ void QgsLabelPropertyDialog::on_mMaxScaleSpinBox_valueChanged( int i )

void QgsLabelPropertyDialog::on_mLabelDistanceSpinBox_valueChanged( double d )
{
insertChangedValue( QgsPalLayerSettings::LabelDistance, d );
QVariant distance( d );
if ( d < 0 )
{
//null value so that distance is reset to default
distance.clear();
}
insertChangedValue( QgsPalLayerSettings::LabelDistance, distance );
}

void QgsLabelPropertyDialog::on_mXCoordSpinBox_valueChanged( double d )
{
insertChangedValue( QgsPalLayerSettings::PositionX, d );
QVariant x( d );
if ( d < mXCoordSpinBox->minimum() + mXCoordSpinBox->singleStep() )
{
//null value
x.clear();
}
insertChangedValue( QgsPalLayerSettings::PositionX, x );
}

void QgsLabelPropertyDialog::on_mYCoordSpinBox_valueChanged( double d )
{
insertChangedValue( QgsPalLayerSettings::PositionY, d );
QVariant y( d );
if ( d < mYCoordSpinBox->minimum() + mYCoordSpinBox->singleStep() )
{
//null value
y.clear();
}
insertChangedValue( QgsPalLayerSettings::PositionY, y );
}

void QgsLabelPropertyDialog::on_mFontFamilyCmbBx_currentFontChanged( const QFont& f )
@@ -554,12 +579,24 @@ void QgsLabelPropertyDialog::on_mFontSizeSpinBox_valueChanged( double d )

void QgsLabelPropertyDialog::on_mBufferSizeSpinBox_valueChanged( double d )
{
insertChangedValue( QgsPalLayerSettings::PositionX, d );
QVariant size( d );
if ( d < 0 )
{
//null value so that size is reset to default
size.clear();
}
insertChangedValue( QgsPalLayerSettings::BufferSize, size );
}

void QgsLabelPropertyDialog::on_mRotationSpinBox_valueChanged( double d )
{
insertChangedValue( QgsPalLayerSettings::Rotation, d );
QVariant rotation( d );
if ( d < 0 )
{
//null value so that size is reset to default
rotation.clear();
}
insertChangedValue( QgsPalLayerSettings::Rotation, rotation );
}

void QgsLabelPropertyDialog::on_mFontColorButton_colorChanged( const QColor &color )
@@ -237,7 +237,7 @@
<property name="value">
<double>0.000000000000000</double>
</property>
<property name="showClearButton">
<property name="showClearButton" stdset="0">
<bool>true</bool>
</property>
</widget>
@@ -311,7 +311,7 @@
<property name="maximum">
<number>999999999</number>
</property>
<property name="showClearButton">
<property name="showClearButton" stdset="0">
<bool>false</bool>
</property>
</widget>
@@ -330,7 +330,7 @@
<property name="value">
<number>10000000</number>
</property>
<property name="showClearButton">
<property name="showClearButton" stdset="0">
<bool>false</bool>
</property>
</widget>
@@ -380,11 +380,14 @@
</item>
<item>
<widget class="QgsDoubleSpinBox" name="mBufferSizeSpinBox">
<property name="minimum">
<double>-1.000000000000000</double>
</property>
<property name="maximum">
<double>999999.000000000000000</double>
</property>
<property name="showClearButton">
<bool>false</bool>
<property name="showClearButton" stdset="0">
<bool>true</bool>
</property>
</widget>
</item>
@@ -438,7 +441,20 @@
</widget>
</item>
<item row="0" column="1">
<widget class="QgsDoubleSpinBox" name="mLabelDistanceSpinBox"/>
<widget class="QgsDoubleSpinBox" name="mLabelDistanceSpinBox">
<property name="specialValueText">
<string>Default</string>
</property>
<property name="minimum">
<double>-1.000000000000000</double>
</property>
<property name="maximum">
<double>999999.000000000000000</double>
</property>
<property name="showClearButton" stdset="0">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="mXCoordLabel">
@@ -455,14 +471,17 @@
</item>
<item row="1" column="1">
<widget class="QgsDoubleSpinBox" name="mXCoordSpinBox">
<property name="specialValueText">
<string>Default</string>
</property>
<property name="minimum">
<double>-999999999.000000000000000</double>
</property>
<property name="maximum">
<double>999999999.000000000000000</double>
</property>
<property name="showClearButton">
<bool>false</bool>
<property name="showClearButton" stdset="0">
<bool>true</bool>
</property>
</widget>
</item>
@@ -481,14 +500,17 @@
</item>
<item row="2" column="1">
<widget class="QgsDoubleSpinBox" name="mYCoordSpinBox">
<property name="specialValueText">
<string>Default</string>
</property>
<property name="minimum">
<double>-999999999.000000000000000</double>
</property>
<property name="maximum">
<double>999999999.000000000000000</double>
</property>
<property name="showClearButton">
<bool>false</bool>
<property name="showClearButton" stdset="0">
<bool>true</bool>
</property>
</widget>
</item>
@@ -539,9 +561,18 @@
</item>
<item row="5" column="1">
<widget class="QgsDoubleSpinBox" name="mRotationSpinBox">
<property name="specialValueText">
<string>Default</string>
</property>
<property name="minimum">
<double>-1.000000000000000</double>
</property>
<property name="maximum">
<double>360.000000000000000</double>
</property>
<property name="showClearButton" stdset="0">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
@@ -564,6 +595,7 @@
<class>QgsColorButtonV2</class>
<extends>QToolButton</extends>
<header>qgscolorbuttonv2.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsDoubleSpinBox</class>

0 comments on commit ea2c674

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