|
21 | 21 | #include "qgsexpression.h" |
22 | 22 | #include "qgsnetworkaccessmanager.h" |
23 | 23 | #include "qgscomposermodel.h" |
| 24 | +#include "qgsvectorlayer.h" |
| 25 | +#include "qgsproject.h" |
24 | 26 |
|
25 | 27 | #include <QCoreApplication> |
26 | 28 | #include <QDate> |
|
32 | 34 | #include <QWebPage> |
33 | 35 | #include <QEventLoop> |
34 | 36 |
|
35 | | -QgsComposerLabel::QgsComposerLabel( QgsComposition *composition ): |
36 | | - QgsComposerItem( composition ), mHtmlState( 0 ), mHtmlUnitsToMM( 1.0 ), |
37 | | - mHtmlLoaded( false ), mMargin( 1.0 ), mFontColor( QColor( 0, 0, 0 ) ), |
38 | | - mHAlignment( Qt::AlignLeft ), mVAlignment( Qt::AlignTop ), |
39 | | - mExpressionFeature( 0 ), mExpressionLayer( 0 ) |
| 37 | +QgsComposerLabel::QgsComposerLabel( QgsComposition *composition ) |
| 38 | + : QgsComposerItem( composition ) |
| 39 | + , mHtmlState( 0 ) |
| 40 | + , mHtmlUnitsToMM( 1.0 ) |
| 41 | + , mHtmlLoaded( false ) |
| 42 | + , mMargin( 1.0 ) |
| 43 | + , mFontColor( QColor( 0, 0, 0 ) ) |
| 44 | + , mHAlignment( Qt::AlignLeft ) |
| 45 | + , mVAlignment( Qt::AlignTop ) |
| 46 | + , mExpressionFeature( 0 ) |
| 47 | + , mExpressionLayer( 0 ) |
| 48 | + , mDistanceArea( 0 ) |
40 | 49 | { |
| 50 | + mDistanceArea = new QgsDistanceArea(); |
41 | 51 | mHtmlUnitsToMM = htmlUnitsToMM(); |
42 | 52 |
|
43 | 53 | //get default composer font from settings |
@@ -71,6 +81,7 @@ QgsComposerLabel::QgsComposerLabel( QgsComposition *composition ): |
71 | 81 |
|
72 | 82 | QgsComposerLabel::~QgsComposerLabel() |
73 | 83 | { |
| 84 | + delete mDistanceArea; |
74 | 85 | } |
75 | 86 |
|
76 | 87 | void QgsComposerLabel::paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget ) |
@@ -221,6 +232,23 @@ void QgsComposerLabel::setExpressionContext( QgsFeature* feature, QgsVectorLayer |
221 | 232 | mExpressionFeature = feature; |
222 | 233 | mExpressionLayer = layer; |
223 | 234 | mSubstitutions = substitutions; |
| 235 | + |
| 236 | + //setup distance area conversion |
| 237 | + if ( layer ) |
| 238 | + { |
| 239 | + mDistanceArea->setSourceCrs( layer->crs().srsid() ); |
| 240 | + } |
| 241 | + else if ( mComposition ) |
| 242 | + { |
| 243 | + //set to composition's mapsettings' crs |
| 244 | + mDistanceArea->setSourceCrs( mComposition->mapSettings().destinationCrs().srsid() ); |
| 245 | + } |
| 246 | + if ( mComposition ) |
| 247 | + { |
| 248 | + mDistanceArea->setEllipsoidalMode( mComposition->mapSettings().hasCrsTransformEnabled() ); |
| 249 | + } |
| 250 | + mDistanceArea->setEllipsoid( QgsProject::instance()->readEntry( "Measure", "/Ellipsoid", GEO_NONE ) ); |
| 251 | + |
224 | 252 | // Force label to redraw -- fixes label printing for labels with blend modes when used with atlas |
225 | 253 | update(); |
226 | 254 | } |
@@ -248,7 +276,7 @@ QString QgsComposerLabel::displayText() const |
248 | 276 | replaceDateText( displayText ); |
249 | 277 | QMap<QString, QVariant> subs = mSubstitutions; |
250 | 278 | subs[ "$page" ] = QVariant(( int )mComposition->itemPageNumber( this ) + 1 ); |
251 | | - return QgsExpression::replaceExpressionText( displayText, mExpressionFeature, mExpressionLayer, &subs ); |
| 279 | + return QgsExpression::replaceExpressionText( displayText, mExpressionFeature, mExpressionLayer, &subs, mDistanceArea ); |
252 | 280 | } |
253 | 281 |
|
254 | 282 | void QgsComposerLabel::replaceDateText( QString& text ) const |
|
0 commit comments