QGIS API Documentation  3.8.0-Zanzibar (11aff65)
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 "qgsmessagebar.h"
18 #include "qgsproject.h"
20 
22  : mMapCanvas( other.mMapCanvas )
23  , mMessageBar( other.mMessageBar )
24  , mAdditionalScopes( other.mAdditionalScopes )
25 {
26  if ( other.mExpressionContext )
27  {
28  mExpressionContext.reset( new QgsExpressionContext( *other.mExpressionContext ) );
29  }
30 }
31 
33 {
34  mMapCanvas = other.mMapCanvas;
35  mMessageBar = other.mMessageBar;
36  mAdditionalScopes = other.mAdditionalScopes;
37  if ( other.mExpressionContext )
38  {
39  mExpressionContext.reset( new QgsExpressionContext( *other.mExpressionContext ) );
40  }
41  else
42  {
43  mExpressionContext.reset();
44  }
45  return *this;
46 }
47 
49 {
50  mMapCanvas = canvas;
51 }
52 
54 {
55  return mMapCanvas;
56 }
57 
59 {
60  mMessageBar = bar;
61 }
62 
64 {
65  return mMessageBar;
66 }
67 
69 {
70  if ( context )
71  mExpressionContext.reset( new QgsExpressionContext( *context ) );
72  else
73  mExpressionContext.reset();
74 }
75 
77 {
78  return mExpressionContext.get();
79 }
80 
81 void QgsSymbolWidgetContext::setAdditionalExpressionContextScopes( const QList<QgsExpressionContextScope> &scopes )
82 {
83  mAdditionalScopes = scopes;
84 }
85 
86 QList<QgsExpressionContextScope> QgsSymbolWidgetContext::additionalExpressionContextScopes() const
87 {
88  return mAdditionalScopes;
89 }
90 
91 QList<QgsExpressionContextScope *> QgsSymbolWidgetContext::globalProjectAtlasMapLayerScopes( const QgsMapLayer *layer ) const
92 {
93  QList<QgsExpressionContextScope *> scopes;
97  if ( mMapCanvas )
98  {
100  << mMapCanvas->defaultExpressionContextScope()
101  << new QgsExpressionContextScope( mMapCanvas->expressionContextScope() );
102  }
103  else
104  {
106  }
107  if ( layer )
108  scopes << QgsExpressionContextUtils::layerScope( layer );
109  return scopes;
110 }
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:78
QgsSymbolWidgetContext & operator=(const QgsSymbolWidgetContext &other)
A bar for displaying non-blocking messages to the user.
Definition: qgsmessagebar.h:45
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:73
QgsExpressionContextScope * defaultExpressionContextScope()
Creates a new scope which contains default variables and functions relating to the map canvas...
The QgsMapSettings class contains configuration for rendering of the map.
void setMessageBar(QgsMessageBar *bar)
Sets the message bar associated with the widget.
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
Gets 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:561
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:438
QgsMessageBar * messageBar() const
Returns the message bar associated with the widget.
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...