@@ -74,7 +74,7 @@ QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsM
7474 populateFieldNames ();
7575
7676 // Add the current expression to the bottom of the list.
77- if (lyr.isExpression )
77+ if (lyr.isExpression and !lyr. fieldName . isEmpty () )
7878 cboFieldName->addItem (lyr.fieldName );
7979 populateDataDefinedCombos ( lyr );
8080
@@ -190,7 +190,6 @@ QgsLabelingGui::~QgsLabelingGui()
190190void QgsLabelingGui::apply ()
191191{
192192 QgsPalLayerSettings settings = layerSettings ();
193- // If we get here we are good to go.
194193 settings.writeToLayer ( mLayer );
195194 // trigger refresh
196195 if ( mMapCanvas )
@@ -205,7 +204,7 @@ QgsPalLayerSettings QgsLabelingGui::layerSettings()
205204 lyr.fieldName = cboFieldName->currentText ();
206205 // Check if we are an expression. Also treats expressions with just a column name as non expressions,
207206 // this saves time later so we don't have to parse the expression tree.
208- lyr.isExpression = mLayer ->fieldNameIndex ( lyr.fieldName ) == -1 ;
207+ lyr.isExpression = mLayer ->fieldNameIndex ( lyr.fieldName ) == -1 && !lyr. fieldName . isEmpty () ;
209208
210209 lyr.dist = 0 ;
211210 lyr.placementFlags = 0 ;
@@ -484,8 +483,12 @@ void QgsLabelingGui::showExpressionDialog()
484483 return ;
485484 }
486485
487- cboFieldName->addItem (expression);
488- cboFieldName->setCurrentIndex (cboFieldName->count () - 1 );
486+ // Only add the expression if the user has entered some text.
487+ if (!expression.isEmpty ())
488+ {
489+ cboFieldName->addItem (expression);
490+ cboFieldName->setCurrentIndex (cboFieldName->count () - 1 );
491+ }
489492 }
490493 }
491494
0 commit comments