From 7940c39555610d7b4585a2165dc7a8c90ef50fcb Mon Sep 17 00:00:00 2001 From: Nathan Woodrow Date: Thu, 27 Oct 2011 19:02:28 +1000 Subject: [PATCH 1/4] Enable multiline labels by default --- src/core/qgspallabeling.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/qgspallabeling.cpp b/src/core/qgspallabeling.cpp index d348932f04ff..aba233e77793 100644 --- a/src/core/qgspallabeling.cpp +++ b/src/core/qgspallabeling.cpp @@ -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; From 9b2bf0afd6b022c20e0b7720a74cc9d6180bd4a1 Mon Sep 17 00:00:00 2001 From: Nathan Woodrow Date: Fri, 28 Oct 2011 06:51:35 +1000 Subject: [PATCH 2/4] Fix grabbing of first QgsFeature; Cache QgsFeature being used to eval; Handle layers with no objects --- src/gui/qgsexpressionbuilderwidget.cpp | 25 ++++++++++++++++++------- src/gui/qgsexpressionbuilderwidget.h | 2 +- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/gui/qgsexpressionbuilderwidget.cpp b/src/gui/qgsexpressionbuilderwidget.cpp index 058dd5f66475..6d0b79b8a12c 100644 --- a/src/gui/qgsexpressionbuilderwidget.cpp +++ b/src/gui/qgsexpressionbuilderwidget.cpp @@ -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() ) diff --git a/src/gui/qgsexpressionbuilderwidget.h b/src/gui/qgsexpressionbuilderwidget.h index 653f5c01b464..54067c0bb126 100644 --- a/src/gui/qgsexpressionbuilderwidget.h +++ b/src/gui/qgsexpressionbuilderwidget.h @@ -164,7 +164,7 @@ class GUI_EXPORT QgsExpressionBuilderWidget : public QWidget, private Ui::QgsExp QStandardItemModel *mModel; QgsExpressionItemSearchProxy *mProxyModel; QMap mExpressionGroups; - QgsFeature* mFeature; + QgsFeature mFeature; }; #endif // QGSEXPRESSIONBUILDER_H From f5bf2b4110b5766cc127ad25fbad00c9dccd2b25 Mon Sep 17 00:00:00 2001 From: Nathan Woodrow Date: Sat, 29 Oct 2011 12:49:13 +1000 Subject: [PATCH 3/4] Remove debug noise for expression labels --- src/core/qgspallabeling.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/core/qgspallabeling.cpp b/src/core/qgspallabeling.cpp index aba233e77793..98bca6863776 100644 --- a/src/core/qgspallabeling.cpp +++ b/src/core/qgspallabeling.cpp @@ -471,14 +471,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(); From a739750e456c8d5387798b770aad65f7d0728364 Mon Sep 17 00:00:00 2001 From: Nathan Woodrow Date: Fri, 28 Oct 2011 23:20:58 +1000 Subject: [PATCH 4/4] Fix multiline overlap - Fix for #4454 --- src/core/qgspallabeling.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/core/qgspallabeling.cpp b/src/core/qgspallabeling.cpp index 98bca6863776..9d9a174234de 100644 --- a/src/core/qgspallabeling.cpp +++ b/src/core/qgspallabeling.cpp @@ -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 );