Skip to content

Commit ea2c674

Browse files
committed
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.
1 parent 727ef9b commit ea2c674

File tree

2 files changed

+86
-17
lines changed

2 files changed

+86
-17
lines changed

src/app/qgslabelpropertydialog.cpp

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ QgsLabelPropertyDialog::QgsLabelPropertyDialog( const QString& layerId, int feat
3434
setupUi( this );
3535
fillHaliComboBox();
3636
fillValiComboBox();
37+
3738
init( layerId, featureId, labelText );
3839

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

113114
//set all the gui elements to the default layer-level values
115+
mLabelDistanceSpinBox->clear();
116+
mLabelDistanceSpinBox->setSpecialValueText( tr( "Layer default (%1)" ).arg( QString::number( layerSettings.dist, 'f', mLabelDistanceSpinBox->decimals() ) ) );
117+
mBufferSizeSpinBox->clear();
118+
mBufferSizeSpinBox->setSpecialValueText( tr( "Layer default (%1)" ).arg( QString::number( layerSettings.bufferSize, 'f', mBufferSizeSpinBox->decimals() ) ) );
119+
mRotationSpinBox->clear();
120+
mXCoordSpinBox->clear();
121+
mYCoordSpinBox->clear();
122+
114123
mShowLabelChkbx->setChecked( true );
115124
mFontColorButton->setColor( layerSettings.textColor );
116125
mBufferColorButton->setColor( layerSettings.bufferColor );
117-
mLabelDistanceSpinBox->setValue( layerSettings.dist );
118-
mBufferSizeSpinBox->setValue( layerSettings.bufferSize );
119126
mMinScaleSpinBox->setValue( layerSettings.scaleMin );
120127
mMaxScaleSpinBox->setValue( layerSettings.scaleMax );
121128
mHaliComboBox->setCurrentIndex( mHaliComboBox->findText( "Left" ) );
@@ -486,17 +493,35 @@ void QgsLabelPropertyDialog::on_mMaxScaleSpinBox_valueChanged( int i )
486493

487494
void QgsLabelPropertyDialog::on_mLabelDistanceSpinBox_valueChanged( double d )
488495
{
489-
insertChangedValue( QgsPalLayerSettings::LabelDistance, d );
496+
QVariant distance( d );
497+
if ( d < 0 )
498+
{
499+
//null value so that distance is reset to default
500+
distance.clear();
501+
}
502+
insertChangedValue( QgsPalLayerSettings::LabelDistance, distance );
490503
}
491504

492505
void QgsLabelPropertyDialog::on_mXCoordSpinBox_valueChanged( double d )
493506
{
494-
insertChangedValue( QgsPalLayerSettings::PositionX, d );
507+
QVariant x( d );
508+
if ( d < mXCoordSpinBox->minimum() + mXCoordSpinBox->singleStep() )
509+
{
510+
//null value
511+
x.clear();
512+
}
513+
insertChangedValue( QgsPalLayerSettings::PositionX, x );
495514
}
496515

497516
void QgsLabelPropertyDialog::on_mYCoordSpinBox_valueChanged( double d )
498517
{
499-
insertChangedValue( QgsPalLayerSettings::PositionY, d );
518+
QVariant y( d );
519+
if ( d < mYCoordSpinBox->minimum() + mYCoordSpinBox->singleStep() )
520+
{
521+
//null value
522+
y.clear();
523+
}
524+
insertChangedValue( QgsPalLayerSettings::PositionY, y );
500525
}
501526

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

555580
void QgsLabelPropertyDialog::on_mBufferSizeSpinBox_valueChanged( double d )
556581
{
557-
insertChangedValue( QgsPalLayerSettings::PositionX, d );
582+
QVariant size( d );
583+
if ( d < 0 )
584+
{
585+
//null value so that size is reset to default
586+
size.clear();
587+
}
588+
insertChangedValue( QgsPalLayerSettings::BufferSize, size );
558589
}
559590

560591
void QgsLabelPropertyDialog::on_mRotationSpinBox_valueChanged( double d )
561592
{
562-
insertChangedValue( QgsPalLayerSettings::Rotation, d );
593+
QVariant rotation( d );
594+
if ( d < 0 )
595+
{
596+
//null value so that size is reset to default
597+
rotation.clear();
598+
}
599+
insertChangedValue( QgsPalLayerSettings::Rotation, rotation );
563600
}
564601

565602
void QgsLabelPropertyDialog::on_mFontColorButton_colorChanged( const QColor &color )

src/ui/qgslabelpropertydialogbase.ui

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@
237237
<property name="value">
238238
<double>0.000000000000000</double>
239239
</property>
240-
<property name="showClearButton">
240+
<property name="showClearButton" stdset="0">
241241
<bool>true</bool>
242242
</property>
243243
</widget>
@@ -311,7 +311,7 @@
311311
<property name="maximum">
312312
<number>999999999</number>
313313
</property>
314-
<property name="showClearButton">
314+
<property name="showClearButton" stdset="0">
315315
<bool>false</bool>
316316
</property>
317317
</widget>
@@ -330,7 +330,7 @@
330330
<property name="value">
331331
<number>10000000</number>
332332
</property>
333-
<property name="showClearButton">
333+
<property name="showClearButton" stdset="0">
334334
<bool>false</bool>
335335
</property>
336336
</widget>
@@ -380,11 +380,14 @@
380380
</item>
381381
<item>
382382
<widget class="QgsDoubleSpinBox" name="mBufferSizeSpinBox">
383+
<property name="minimum">
384+
<double>-1.000000000000000</double>
385+
</property>
383386
<property name="maximum">
384387
<double>999999.000000000000000</double>
385388
</property>
386-
<property name="showClearButton">
387-
<bool>false</bool>
389+
<property name="showClearButton" stdset="0">
390+
<bool>true</bool>
388391
</property>
389392
</widget>
390393
</item>
@@ -438,7 +441,20 @@
438441
</widget>
439442
</item>
440443
<item row="0" column="1">
441-
<widget class="QgsDoubleSpinBox" name="mLabelDistanceSpinBox"/>
444+
<widget class="QgsDoubleSpinBox" name="mLabelDistanceSpinBox">
445+
<property name="specialValueText">
446+
<string>Default</string>
447+
</property>
448+
<property name="minimum">
449+
<double>-1.000000000000000</double>
450+
</property>
451+
<property name="maximum">
452+
<double>999999.000000000000000</double>
453+
</property>
454+
<property name="showClearButton" stdset="0">
455+
<bool>true</bool>
456+
</property>
457+
</widget>
442458
</item>
443459
<item row="1" column="0">
444460
<widget class="QLabel" name="mXCoordLabel">
@@ -455,14 +471,17 @@
455471
</item>
456472
<item row="1" column="1">
457473
<widget class="QgsDoubleSpinBox" name="mXCoordSpinBox">
474+
<property name="specialValueText">
475+
<string>Default</string>
476+
</property>
458477
<property name="minimum">
459478
<double>-999999999.000000000000000</double>
460479
</property>
461480
<property name="maximum">
462481
<double>999999999.000000000000000</double>
463482
</property>
464-
<property name="showClearButton">
465-
<bool>false</bool>
483+
<property name="showClearButton" stdset="0">
484+
<bool>true</bool>
466485
</property>
467486
</widget>
468487
</item>
@@ -481,14 +500,17 @@
481500
</item>
482501
<item row="2" column="1">
483502
<widget class="QgsDoubleSpinBox" name="mYCoordSpinBox">
503+
<property name="specialValueText">
504+
<string>Default</string>
505+
</property>
484506
<property name="minimum">
485507
<double>-999999999.000000000000000</double>
486508
</property>
487509
<property name="maximum">
488510
<double>999999999.000000000000000</double>
489511
</property>
490-
<property name="showClearButton">
491-
<bool>false</bool>
512+
<property name="showClearButton" stdset="0">
513+
<bool>true</bool>
492514
</property>
493515
</widget>
494516
</item>
@@ -539,9 +561,18 @@
539561
</item>
540562
<item row="5" column="1">
541563
<widget class="QgsDoubleSpinBox" name="mRotationSpinBox">
564+
<property name="specialValueText">
565+
<string>Default</string>
566+
</property>
567+
<property name="minimum">
568+
<double>-1.000000000000000</double>
569+
</property>
542570
<property name="maximum">
543571
<double>360.000000000000000</double>
544572
</property>
573+
<property name="showClearButton" stdset="0">
574+
<bool>true</bool>
575+
</property>
545576
</widget>
546577
</item>
547578
</layout>
@@ -564,6 +595,7 @@
564595
<class>QgsColorButtonV2</class>
565596
<extends>QToolButton</extends>
566597
<header>qgscolorbuttonv2.h</header>
598+
<container>1</container>
567599
</customwidget>
568600
<customwidget>
569601
<class>QgsDoubleSpinBox</class>

0 commit comments

Comments
 (0)