Skip to content

Commit cc5c8a3

Browse files
committed
Check for empty field name. Fixes #4914
1 parent 42c24da commit cc5c8a3

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

src/app/qgsfieldcalculator.cpp

+15-4
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ QgsFieldCalculator::QgsFieldCalculator( QgsVectorLayer* vl )
3636
populateFields();
3737
populateOutputFieldTypes();
3838

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

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

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

274-
mButtonBox->button( QDialogButtonBox::Ok )->setEnabled( okEnabled );
274+
bool emptyFieldName = mOutputFieldNameLineEdit->text().isEmpty();
275+
bool expressionVaild = builder->isExpressionValid();
276+
277+
if ( emptyFieldName )
278+
okButton->setToolTip( tr("Please enter a field name") );
279+
280+
if ( !expressionVaild )
281+
okButton->setToolTip( okButton->toolTip() + tr("\n The expression is invaild see (more info) for details") );
282+
283+
bool okEnabled = ( !emptyFieldName || mUpdateExistingGroupBox->isChecked() ) && expressionVaild;
284+
285+
okButton->setEnabled( okEnabled );
275286
}

src/app/qgsfieldcalculator.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ class QgsFieldCalculator: public QDialog, private Ui::QgsFieldCalculatorBase
4141

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

44+
private slots:
45+
/**Sets the ok button enabled / disabled*/
46+
void setOkButtonState();
47+
4448
private:
4549
//default constructor forbidden
4650
QgsFieldCalculator();
@@ -49,9 +53,6 @@ class QgsFieldCalculator: public QDialog, private Ui::QgsFieldCalculatorBase
4953
/**Inserts the types supported by the provider into the combo box*/
5054
void populateOutputFieldTypes();
5155

52-
/**Sets the ok button enabled / disabled*/
53-
void setOkButtonState();
54-
5556
QgsVectorLayer* mVectorLayer;
5657
/**Key: field name, Value: field index*/
5758
QMap<QString, int> mFieldMap;

0 commit comments

Comments
 (0)