Skip to content

Commit

Permalink
Check for empty field name. Fixes #4914
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanW2 committed Feb 1, 2012
1 parent 42c24da commit cc5c8a3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
19 changes: 15 additions & 4 deletions src/app/qgsfieldcalculator.cpp
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
}
7 changes: 4 additions & 3 deletions src/app/qgsfieldcalculator.h
Expand Up @@ -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();
Expand All @@ -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;
Expand Down

0 comments on commit cc5c8a3

Please sign in to comment.