Skip to content
Permalink
Browse files

Merge pull request #2682 from alexbruy/field-precision

don't allow field precision greater than field width (fix #14019, #5154)
  • Loading branch information
nyalldawson committed Jan 31, 2016
2 parents df88a9f + 9d473aa commit c1f7257b24ab79e9a3d43768bab7d69e644e3fb5
Showing with 14 additions and 7 deletions.
  1. +13 −7 src/app/qgsfieldcalculator.cpp
  2. +1 −0 src/app/qgsfieldcalculator.h
@@ -54,6 +54,7 @@ QgsFieldCalculator::QgsFieldCalculator( QgsVectorLayer* vl, QWidget* parent )
populateOutputFieldTypes();

connect( builder, SIGNAL( expressionParsed( bool ) ), this, SLOT( setOkButtonState() ) );
connect( mOutputFieldWidthSpinBox, SIGNAL( editingFinished() ), this, SLOT( setPrecisionMinMax() ) );

QgsDistanceArea myDa;
myDa.setSourceCrs( vl->crs().srsid() );
@@ -64,6 +65,7 @@ QgsFieldCalculator::QgsFieldCalculator( QgsVectorLayer* vl, QWidget* parent )
//default values for field width and precision
mOutputFieldWidthSpinBox->setValue( 10 );
mOutputFieldPrecisionSpinBox->setValue( 3 );
setPrecisionMinMax();

if ( vl->providerType() == "ogr" && vl->storageType() == "ESRI Shapefile" )
{
@@ -420,13 +422,7 @@ void QgsFieldCalculator::on_mOutputFieldTypeComboBox_activated( int index )
if ( mOutputFieldWidthSpinBox->value() > mOutputFieldWidthSpinBox->maximum() )
mOutputFieldWidthSpinBox->setValue( mOutputFieldWidthSpinBox->maximum() );

mOutputFieldPrecisionSpinBox->setMinimum( mOutputFieldTypeComboBox->itemData( index, Qt::UserRole + 4 ).toInt() );
mOutputFieldPrecisionSpinBox->setMaximum( mOutputFieldTypeComboBox->itemData( index, Qt::UserRole + 5 ).toInt() );
mOutputFieldPrecisionSpinBox->setEnabled( mOutputFieldPrecisionSpinBox->minimum() < mOutputFieldPrecisionSpinBox->maximum() );
if ( mOutputFieldPrecisionSpinBox->value() < mOutputFieldPrecisionSpinBox->minimum() )
mOutputFieldPrecisionSpinBox->setValue( mOutputFieldPrecisionSpinBox->minimum() );
if ( mOutputFieldPrecisionSpinBox->value() > mOutputFieldPrecisionSpinBox->maximum() )
mOutputFieldPrecisionSpinBox->setValue( mOutputFieldPrecisionSpinBox->maximum() );
setPrecisionMinMax();
}

void QgsFieldCalculator::populateFields()
@@ -477,3 +473,13 @@ void QgsFieldCalculator::setOkButtonState()
okButton->setToolTip( "" );
okButton->setEnabled( true );
}

void QgsFieldCalculator::setPrecisionMinMax()
{
int idx = mOutputFieldTypeComboBox->currentIndex();
int minPrecType = mOutputFieldTypeComboBox->itemData( idx, Qt::UserRole + 4 ).toInt();
int maxPrecType = mOutputFieldTypeComboBox->itemData( idx, Qt::UserRole + 5 ).toInt();
mOutputFieldPrecisionSpinBox->setEnabled( minPrecType < maxPrecType );
mOutputFieldPrecisionSpinBox->setMinimum( minPrecType );
mOutputFieldPrecisionSpinBox->setMaximum( qMax( minPrecType, qMin( maxPrecType, mOutputFieldWidthSpinBox->value() ) ) );
}
@@ -45,6 +45,7 @@ class APP_EXPORT QgsFieldCalculator: public QDialog, private Ui::QgsFieldCalcula
private slots:
/** Sets the ok button enabled / disabled*/
void setOkButtonState();
void setPrecisionMinMax();

private:
//! default constructor forbidden

0 comments on commit c1f7257

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