Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix seg fault with using empty expression labels, added checks for em…
…pty expression
  • Loading branch information
NathanW2 committed Jun 18, 2011
1 parent 027efca commit 6610187
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/app/qgslabelinggui.cpp
Expand Up @@ -74,7 +74,7 @@ QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsM
populateFieldNames();

//Add the current expression to the bottom of the list.
if (lyr.isExpression)
if (lyr.isExpression and !lyr.fieldName.isEmpty())
cboFieldName->addItem(lyr.fieldName);
populateDataDefinedCombos( lyr );

Expand Down Expand Up @@ -190,7 +190,6 @@ QgsLabelingGui::~QgsLabelingGui()
void QgsLabelingGui::apply()
{
QgsPalLayerSettings settings = layerSettings();
// If we get here we are good to go.
settings.writeToLayer( mLayer );
// trigger refresh
if ( mMapCanvas )
Expand All @@ -205,7 +204,7 @@ QgsPalLayerSettings QgsLabelingGui::layerSettings()
lyr.fieldName = cboFieldName->currentText();
// Check if we are an expression. Also treats expressions with just a column name as non expressions,
// this saves time later so we don't have to parse the expression tree.
lyr.isExpression = mLayer->fieldNameIndex( lyr.fieldName ) == -1;
lyr.isExpression = mLayer->fieldNameIndex( lyr.fieldName ) == -1 && !lyr.fieldName.isEmpty();

lyr.dist = 0;
lyr.placementFlags = 0;
Expand Down Expand Up @@ -484,8 +483,12 @@ void QgsLabelingGui::showExpressionDialog()
return;
}

cboFieldName->addItem(expression);
cboFieldName->setCurrentIndex(cboFieldName->count() - 1);
// Only add the expression if the user has entered some text.
if (!expression.isEmpty())
{
cboFieldName->addItem(expression);
cboFieldName->setCurrentIndex(cboFieldName->count() - 1);
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/core/qgspallabeling.cpp
Expand Up @@ -727,6 +727,8 @@ int QgsPalLabeling::prepareLayer( QgsVectorLayer* layer, QSet<int>& attrIndices,
int fldIndex ;
if(lyrTmp.isExpression)
{
if (lyrTmp.fieldName.isEmpty())
return 0;
QgsSearchString searchString;
searchString.setString( lyrTmp.fieldName );
searchString.tree()->referencedColumns();
Expand Down

0 comments on commit 6610187

Please sign in to comment.