QGIS API Documentation  3.0.2-Girona (307d082)
qgssymbolwidgetcontext.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgssymbolwidgetcontext.cpp
3  --------------------------
4  begin : September 2016
5  copyright : (C) 2016 by Nyall Dawson
6  email : nyall dot dawson 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 #include "qgssymbolwidgetcontext.h"
16 #include "qgsmapcanvas.h"
17 #include "qgsproject.h"
18 
20  : mMapCanvas( other.mMapCanvas )
21  , mAdditionalScopes( other.mAdditionalScopes )
22 {
23  if ( other.mExpressionContext )
24  {
25  mExpressionContext.reset( new QgsExpressionContext( *other.mExpressionContext ) );
26  }
27 }
28 
30 {
31  mMapCanvas = other.mMapCanvas;
32  mAdditionalScopes = other.mAdditionalScopes;
33  if ( other.mExpressionContext )
34  {
35  mExpressionContext.reset( new QgsExpressionContext( *other.mExpressionContext ) );
36  }
37  else
38  {
39  mExpressionContext.reset();
40  }
41  return *this;
42 }
43 
45 {
46  mMapCanvas = canvas;
47 }
48 
50 {
51  return mMapCanvas;
52 }
53 
55 {
56  if ( context )
57  mExpressionContext.reset( new QgsExpressionContext( *context ) );
58  else
59  mExpressionContext.reset();
60 }
61 
63 {
64  return mExpressionContext.get();
65 }
66 
67 void QgsSymbolWidgetContext::setAdditionalExpressionContextScopes( const QList<QgsExpressionContextScope> &scopes )
68 {
69  mAdditionalScopes = scopes;
70 }
71 
72 QList<QgsExpressionContextScope> QgsSymbolWidgetContext::additionalExpressionContextScopes() const
73 {
74  return mAdditionalScopes;
75 }
76 
77 QList<QgsExpressionContextScope *> QgsSymbolWidgetContext::globalProjectAtlasMapLayerScopes( const QgsMapLayer *layer ) const
78 {
79  QList<QgsExpressionContextScope *> scopes;
83  if ( mMapCanvas )
84  {
86  << new QgsExpressionContextScope( mMapCanvas->expressionContextScope() );
87  }
88  else
89  {
91  }
92  if ( layer )
93  scopes << QgsExpressionContextUtils::layerScope( layer );
94  return scopes;
95 }
QList< QgsExpressionContextScope * > globalProjectAtlasMapLayerScopes(const QgsMapLayer *layer) const
Returns list of scopes: global, project, atlas, map, layer.
Base class for all map layer types.
Definition: qgsmaplayer.h:56
QgsSymbolWidgetContext & operator=(const QgsSymbolWidgetContext &other)
static QgsExpressionContextScope * projectScope(const QgsProject *project)
Creates a new scope which contains variables and functions relating to a QGIS project.
void setMapCanvas(QgsMapCanvas *canvas)
Sets the map canvas associated with the widget.
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:74
The QgsMapSettings class contains configuration for rendering of the map.
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context...
Contains settings which reflect the context in which a symbol (or renderer) widget is shown...
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Single scope for storing variables and functions for use within a QgsExpressionContext.
void setAdditionalExpressionContextScopes(const QList< QgsExpressionContextScope > &scopes)
Sets a list of additional expression context scopes to show as available within the layer...
void setExpressionContext(QgsExpressionContext *context)
Sets the optional expression context used for the widget.
QgsSymbolWidgetContext()=default
Constructor for QgsSymbolWidgetContext.
const QgsMapSettings & mapSettings() const
Get access to properties used for map rendering.
QgsMapCanvas * mapCanvas() const
Returns the map canvas associated with the widget.
QgsExpressionContext * expressionContext() const
Returns the expression context used for the widget, if set.
static QgsExpressionContextScope * atlasScope(QgsLayoutAtlas *atlas)
Creates a new scope which contains variables and functions relating to a QgsLayoutAtlas.
static QgsExpressionContextScope * mapSettingsScope(const QgsMapSettings &mapSettings)
Creates a new scope which contains variables and functions relating to a QgsMapSettings object...
QgsExpressionContextScope & expressionContextScope()
Returns a reference to the expression context scope for the map canvas.
Definition: qgsmapcanvas.h:563
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:383
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
QList< QgsExpressionContextScope > additionalExpressionContextScopes() const
Returns the list of additional expression context scopes to show as available within the layer...