@@ -54,6 +54,7 @@ QgsFieldCalculator::QgsFieldCalculator( QgsVectorLayer* vl )
54
54
populateOutputFieldTypes ();
55
55
56
56
connect ( builder, SIGNAL ( expressionParsed ( bool ) ), this , SLOT ( setOkButtonState () ) );
57
+ connect ( mOutputFieldWidthSpinBox , SIGNAL ( editingFinished () ), this , SLOT ( setPrecisionMinMax () ) );
57
58
58
59
QgsDistanceArea myDa;
59
60
myDa.setSourceCrs ( vl->crs ().srsid () );
@@ -64,6 +65,7 @@ QgsFieldCalculator::QgsFieldCalculator( QgsVectorLayer* vl )
64
65
// default values for field width and precision
65
66
mOutputFieldWidthSpinBox ->setValue ( 10 );
66
67
mOutputFieldPrecisionSpinBox ->setValue ( 3 );
68
+ setPrecisionMinMax ();
67
69
68
70
if ( vl->providerType () == " ogr" && vl->storageType () == " ESRI Shapefile" )
69
71
{
@@ -420,13 +422,7 @@ void QgsFieldCalculator::on_mOutputFieldTypeComboBox_activated( int index )
420
422
if ( mOutputFieldWidthSpinBox ->value () > mOutputFieldWidthSpinBox ->maximum () )
421
423
mOutputFieldWidthSpinBox ->setValue ( mOutputFieldWidthSpinBox ->maximum () );
422
424
423
- mOutputFieldPrecisionSpinBox ->setMinimum ( mOutputFieldTypeComboBox ->itemData ( index , Qt::UserRole + 4 ).toInt () );
424
- mOutputFieldPrecisionSpinBox ->setMaximum ( mOutputFieldTypeComboBox ->itemData ( index , Qt::UserRole + 5 ).toInt () );
425
- mOutputFieldPrecisionSpinBox ->setEnabled ( mOutputFieldPrecisionSpinBox ->minimum () < mOutputFieldPrecisionSpinBox ->maximum () );
426
- if ( mOutputFieldPrecisionSpinBox ->value () < mOutputFieldPrecisionSpinBox ->minimum () )
427
- mOutputFieldPrecisionSpinBox ->setValue ( mOutputFieldPrecisionSpinBox ->minimum () );
428
- if ( mOutputFieldPrecisionSpinBox ->value () > mOutputFieldPrecisionSpinBox ->maximum () )
429
- mOutputFieldPrecisionSpinBox ->setValue ( mOutputFieldPrecisionSpinBox ->maximum () );
425
+ setPrecisionMinMax ();
430
426
}
431
427
432
428
void QgsFieldCalculator::populateFields ()
@@ -477,3 +473,13 @@ void QgsFieldCalculator::setOkButtonState()
477
473
okButton->setToolTip ( " " );
478
474
okButton->setEnabled ( true );
479
475
}
476
+
477
+ void QgsFieldCalculator::setPrecisionMinMax ()
478
+ {
479
+ int idx = mOutputFieldTypeComboBox ->currentIndex ();
480
+ int minPrecType = mOutputFieldTypeComboBox ->itemData ( idx, Qt::UserRole + 4 ).toInt ();
481
+ int maxPrecType = mOutputFieldTypeComboBox ->itemData ( idx, Qt::UserRole + 5 ).toInt ();
482
+ mOutputFieldPrecisionSpinBox ->setEnabled ( minPrecType < maxPrecType );
483
+ mOutputFieldPrecisionSpinBox ->setMinimum ( minPrecType );
484
+ mOutputFieldPrecisionSpinBox ->setMaximum ( qMax ( minPrecType, qMin ( maxPrecType, mOutputFieldWidthSpinBox ->value () ) ) );
485
+ }
0 commit comments