Skip to content

Commit 6610187

Browse files
committed
Fix seg fault with using empty expression labels, added checks for empty expression
1 parent 027efca commit 6610187

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

src/app/qgslabelinggui.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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()
190190
void 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

src/core/qgspallabeling.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,8 @@ int QgsPalLabeling::prepareLayer( QgsVectorLayer* layer, QSet<int>& attrIndices,
727727
int fldIndex ;
728728
if(lyrTmp.isExpression)
729729
{
730+
if (lyrTmp.fieldName.isEmpty())
731+
return 0;
730732
QgsSearchString searchString;
731733
searchString.setString( lyrTmp.fieldName );
732734
searchString.tree()->referencedColumns();

0 commit comments

Comments
 (0)