Skip to content
Permalink
Browse files

Merge pull request #53 from NathanW2/expression-labels-patch

Expression label patches
  • Loading branch information
wonder-sk committed Oct 31, 2011
2 parents ed20ff3 + a739750 commit e573ce9f43e580f769bd00c2a4c46956ff8b0a72
Showing with 26 additions and 15 deletions.
  1. +7 −7 src/core/qgspallabeling.cpp
  2. +18 −7 src/gui/qgsexpressionbuilderwidget.cpp
  3. +1 −1 src/gui/qgsexpressionbuilderwidget.h
@@ -152,7 +152,7 @@ QgsPalLayerSettings::QgsPalLayerSettings()
plusSign = false;
labelPerPart = false;
mergeLines = false;
multiLineLabels = false;
multiLineLabels = true;
minFeatureSize = 0.0;
vectorScaleFactor = 1.0;
rasterCompressFactor = 1.0;
@@ -434,10 +434,11 @@ void QgsPalLayerSettings::calculateLabelSize( const QFontMetricsF* fm, QString t
{
text.append( ">" );
}
QRectF labelRect = fm->boundingRect( text );

double w, h;
if ( !multiLineLabels )
{
QRectF labelRect = fm->boundingRect( text );
w = labelRect.width() / rasterCompressFactor;
h = labelRect.height() / rasterCompressFactor;
}
@@ -452,9 +453,9 @@ void QgsPalLayerSettings::calculateLabelSize( const QFontMetricsF* fm, QString t
if ( width > w )
{
w = width;
}
w /= rasterCompressFactor;
}
}
w /= rasterCompressFactor;
}
QgsPoint ptSize = xform->toMapCoordinatesF( w, h );

@@ -471,14 +472,13 @@ void QgsPalLayerSettings::registerFeature( QgsVectorLayer* layer, QgsFeature& f
QgsExpression* exp = getLabelExpression();
if ( exp->hasParserError() )
{
QgsDebugMsg( "PASER HAS ERROR:" + exp->parserErrorString() );
QgsDebugMsg( "Expression parser error:" + exp->parserErrorString() );
return;
}
QVariant result = exp->evaluate( &f, layer->dataProvider()->fields() );
QgsDebugMsg( "VALUE = " + result.toString() );
if ( exp->hasEvalError() )
{
QgsDebugMsg( "Expression Label Error = " + exp->evalErrorString() );
QgsDebugMsg( "Expression parser eval error:" + exp->evalErrorString() );
return;
}
labelText = result.toString();
@@ -230,13 +230,24 @@ void QgsExpressionBuilderWidget::on_txtExpressionString_textChanged()
// Maybe just calling exp.evaluate()?
if ( mLayer )
{
// TODO We should really cache the feature.
QgsFeature feature;
mLayer->featureAtId( 0 , feature );
QVariant value = exp.evaluate( &feature, mLayer->pendingFields() );

if ( !exp.hasEvalError() )
lblPreview->setText( value.toString() );
if ( !mFeature.isValid() )
{
mLayer->select( mLayer->pendingAllAttributesList() );
mLayer->nextFeature( mFeature );
}

if ( mFeature.isValid() )
{
QVariant value = exp.evaluate( &mFeature, mLayer->pendingFields() );
if ( !exp.hasEvalError() )
lblPreview->setText( value.toString() );
}
else
{
// The feautre is invaild because we don't have one but that doesn't mean user can't
// build a expression string. They just get no preview.
lblPreview->setText("");
}
}

if ( exp.hasParserError() || exp.hasEvalError() )
@@ -164,7 +164,7 @@ class GUI_EXPORT QgsExpressionBuilderWidget : public QWidget, private Ui::QgsExp
QStandardItemModel *mModel;
QgsExpressionItemSearchProxy *mProxyModel;
QMap<QString, QgsExpressionItem*> mExpressionGroups;
QgsFeature* mFeature;
QgsFeature mFeature;
};

#endif // QGSEXPRESSIONBUILDER_H

0 comments on commit e573ce9

Please sign in to comment.
You can’t perform that action at this time.