1 /***************************************************************************
2  qgssymbolrendercontext.cpp
3  ---------------------
4  begin                : November 2009
5  copyright            : (C) 2009 by Martin Dobias
6  email                : wonder dot sk at gmail dot com
7  ***************************************************************************
8  *                                                                         *
9  *   This program is free software; you can redistribute it and/or modify  *
10  *   it under the terms of the GNU General Public License as published by  *
11  *   the Free Software Foundation; either version 2 of the License, or     *
12  *   (at your option) any later version.                                   *
13  *                                                                         *
14  ***************************************************************************/
15 
16 #include "qgssymbolrendercontext.h"
17 #include "qgsrendercontext.h"
18 #include "qgslegendpatchshape.h"
19 
QgsSymbolRenderContext(QgsRenderContext & c,QgsUnitTypes::RenderUnit u,qreal opacity,bool selected,Qgis::SymbolRenderHints renderHints,const QgsFeature * f,const QgsFields & fields,const QgsMapUnitScale & mapUnitScale)20 QgsSymbolRenderContext::QgsSymbolRenderContext( QgsRenderContext &c, QgsUnitTypes::RenderUnit u, qreal opacity, bool selected, Qgis::SymbolRenderHints renderHints, const QgsFeature *f, const QgsFields &fields, const QgsMapUnitScale &mapUnitScale )
21   : mRenderContext( c )
22   , mOutputUnit( u )
23   , mMapUnitScale( mapUnitScale )
24   , mOpacity( opacity )
25   , mSelected( selected )
26   , mRenderHints( renderHints )
27   , mFeature( f )
28   , mFields( fields )
29   , mGeometryPartCount( 0 )
30   , mGeometryPartNum( 0 )
31 {
32 }
33 
34 QgsSymbolRenderContext::~QgsSymbolRenderContext() = default;
35 
setOriginalValueVariable(const QVariant & value)36 void QgsSymbolRenderContext::setOriginalValueVariable( const QVariant &value )
37 {
38   mRenderContext.expressionContext().setOriginalValueVariable( value );
39 }
40 
outputLineWidth(double width) const41 double QgsSymbolRenderContext::outputLineWidth( double width ) const
42 {
43   return mRenderContext.convertToPainterUnits( width, mOutputUnit, mMapUnitScale );
44 }
45 
outputPixelSize(double size) const46 double QgsSymbolRenderContext::outputPixelSize( double size ) const
47 {
48   return mRenderContext.convertToPainterUnits( size, mOutputUnit, mMapUnitScale );
49 }
50 
51 // cppcheck-suppress operatorEqVarError
operator =(const QgsSymbolRenderContext &)52 QgsSymbolRenderContext &QgsSymbolRenderContext::operator=( const QgsSymbolRenderContext & )
53 {
54   // This is just a dummy implementation of assignment.
55   // sip 4.7 generates a piece of code that needs this function to exist.
56   // It's not generated automatically by the compiler because of
57   // mRenderContext member which is a reference (and thus can't be changed).
58   Q_ASSERT( false );
59   return *this;
60 }
61 
expressionContextScope()62 QgsExpressionContextScope *QgsSymbolRenderContext::expressionContextScope()
63 {
64   return mExpressionContextScope.get();
65 }
66 
setExpressionContextScope(QgsExpressionContextScope * contextScope)67 void QgsSymbolRenderContext::setExpressionContextScope( QgsExpressionContextScope *contextScope )
68 {
69   mExpressionContextScope.reset( contextScope );
70 }
71 
patchShape() const72 const QgsLegendPatchShape *QgsSymbolRenderContext::patchShape() const
73 {
74   return mPatchShape.get();
75 }
76 
setPatchShape(const QgsLegendPatchShape & patchShape)77 void QgsSymbolRenderContext::setPatchShape( const QgsLegendPatchShape &patchShape )
78 {
79   mPatchShape.reset( new QgsLegendPatchShape( patchShape ) );
80 }
81