Skip to content
Permalink
Browse files

Check for empty field name. Fixes #4914

  • Loading branch information
NathanW2 committed Feb 1, 2012
1 parent 42c24da commit cc5c8a3b954a5c8c749f74c81b8c654b30216d19
Showing with 19 additions and 7 deletions.
  1. +15 −4 src/app/qgsfieldcalculator.cpp
  2. +4 −3 src/app/qgsfieldcalculator.h
@@ -36,8 +36,7 @@ QgsFieldCalculator::QgsFieldCalculator( QgsVectorLayer* vl )
populateFields();
populateOutputFieldTypes();

QPushButton* okbutton = mButtonBox->button( QDialogButtonBox::Ok );
connect( builder, SIGNAL( expressionParsed( bool ) ), okbutton, SLOT( setEnabled( bool ) ) );
connect( builder, SIGNAL( expressionParsed( bool ) ), this, SLOT( setOkButtonState() ) );

//default values for field width and precision
mOuputFieldWidthSpinBox->setValue( 10 );
@@ -269,7 +268,19 @@ void QgsFieldCalculator::populateFields()

void QgsFieldCalculator::setOkButtonState()
{
bool okEnabled = ( !mOutputFieldNameLineEdit->text().isEmpty() || mUpdateExistingGroupBox->isChecked() ) && builder->isExpressionValid();
QPushButton* okButton = mButtonBox->button( QDialogButtonBox::Ok );
okButton->setToolTip("");

mButtonBox->button( QDialogButtonBox::Ok )->setEnabled( okEnabled );
bool emptyFieldName = mOutputFieldNameLineEdit->text().isEmpty();
bool expressionVaild = builder->isExpressionValid();

if ( emptyFieldName )
okButton->setToolTip( tr("Please enter a field name") );

if ( !expressionVaild )
okButton->setToolTip( okButton->toolTip() + tr("\n The expression is invaild see (more info) for details") );

bool okEnabled = ( !emptyFieldName || mUpdateExistingGroupBox->isChecked() ) && expressionVaild;

okButton->setEnabled( okEnabled );
}
@@ -41,6 +41,10 @@ class QgsFieldCalculator: public QDialog, private Ui::QgsFieldCalculatorBase

void on_mButtonBox_helpRequested() { QgsContextHelp::run( metaObject()->className() ); }

private slots:
/**Sets the ok button enabled / disabled*/
void setOkButtonState();

private:
//default constructor forbidden
QgsFieldCalculator();
@@ -49,9 +53,6 @@ class QgsFieldCalculator: public QDialog, private Ui::QgsFieldCalculatorBase
/**Inserts the types supported by the provider into the combo box*/
void populateOutputFieldTypes();

/**Sets the ok button enabled / disabled*/
void setOkButtonState();

QgsVectorLayer* mVectorLayer;
/**Key: field name, Value: field index*/
QMap<QString, int> mFieldMap;

0 comments on commit cc5c8a3

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