@@ -101,6 +101,12 @@ QgsColorRampShaderWidget::QgsColorRampShaderWidget( QWidget *parent )
101
101
connect ( btnColorRamp, &QgsColorRampButton::colorRampChanged, this , &QgsColorRampShaderWidget::applyColorRamp );
102
102
connect ( mNumberOfEntriesSpinBox , static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this , &QgsColorRampShaderWidget::classify );
103
103
connect ( mClipCheckBox , &QAbstractButton::toggled, this , &QgsColorRampShaderWidget::widgetChanged );
104
+ connect ( mLabelPrecisionRawData , &QCheckBox::toggled, this , [ = ]
105
+ {
106
+ autoLabel ();
107
+ mPrecisionSpinBox ->setEnabled ( ! mLabelPrecisionRawData ->isChecked () );
108
+ } );
109
+ connect ( mPrecisionSpinBox , qgis::overload<int >::of ( &QSpinBox::valueChanged ), this , [ = ]( int ) { autoLabel (); } );
104
110
}
105
111
106
112
void QgsColorRampShaderWidget::initializeForUseWithRasterLayer ()
@@ -167,6 +173,17 @@ void QgsColorRampShaderWidget::autoLabel()
167
173
QString unit = mUnitLineEdit ->text ();
168
174
QString label;
169
175
int topLevelItemCount = mColormapTreeWidget ->topLevelItemCount ();
176
+
177
+ auto applyPrecision = [ = ]( QString value )
178
+ {
179
+ // TODO: rounding to powers of 10
180
+ if ( ! mLabelPrecisionRawData ->isChecked () )
181
+ {
182
+ value = QLocale ().toString ( QLocale ().toDouble ( value ), ' f' , mPrecisionSpinBox ->value () );
183
+ }
184
+ return value;
185
+ };
186
+
170
187
QTreeWidgetItem *currentItem = nullptr ;
171
188
for ( int i = 0 ; i < topLevelItemCount; ++i )
172
189
{
@@ -181,20 +198,20 @@ void QgsColorRampShaderWidget::autoLabel()
181
198
{
182
199
if ( i == 0 )
183
200
{
184
- label = " <= " + currentItem->text ( ValueColumn ) + unit;
201
+ label = " <= " + applyPrecision ( currentItem->text ( ValueColumn ) ) + unit;
185
202
}
186
203
else if ( QLocale ().toDouble ( currentItem->text ( ValueColumn ) ) == std::numeric_limits<double >::infinity () )
187
204
{
188
- label = " > " + mColormapTreeWidget ->topLevelItem ( i - 1 )->text ( ValueColumn ) + unit;
205
+ label = " > " + applyPrecision ( mColormapTreeWidget ->topLevelItem ( i - 1 )->text ( ValueColumn ) ) + unit;
189
206
}
190
207
else
191
208
{
192
- label = mColormapTreeWidget ->topLevelItem ( i - 1 )->text ( ValueColumn ) + " - " + currentItem->text ( ValueColumn ) + unit;
209
+ label = applyPrecision ( mColormapTreeWidget ->topLevelItem ( i - 1 )->text ( ValueColumn ) ) + " - " + applyPrecision ( currentItem->text ( ValueColumn ) ) + unit;
193
210
}
194
211
}
195
212
else
196
213
{
197
- label = currentItem->text ( ValueColumn ) + unit;
214
+ label = applyPrecision ( currentItem->text ( ValueColumn ) ) + unit;
198
215
}
199
216
200
217
if ( currentItem->text ( LabelColumn ).isEmpty () || currentItem->text ( LabelColumn ) == label || currentItem->foreground ( LabelColumn ).color () == QColor ( Qt::gray ) )
0 commit comments