QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
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 ***************************************************************************/
16#include "qgsmapcanvas.h"
17#include "qgsmessagebar.h"
18#include "qgsproject.h"
21
23 : mMapCanvas( other.mMapCanvas )
24 , mMessageBar( other.mMessageBar )
25 , mAdditionalScopes( other.mAdditionalScopes )
26 , mSymbolType( other.mSymbolType )
27{
28 if ( other.mExpressionContext )
29 {
30 mExpressionContext.reset( new QgsExpressionContext( *other.mExpressionContext ) );
31 }
32}
33
35{
36 mMapCanvas = other.mMapCanvas;
37 mMessageBar = other.mMessageBar;
38 mAdditionalScopes = other.mAdditionalScopes;
39 mSymbolType = other.mSymbolType;
40 if ( other.mExpressionContext )
41 {
42 mExpressionContext.reset( new QgsExpressionContext( *other.mExpressionContext ) );
43 }
44 else
45 {
46 mExpressionContext.reset();
47 }
48 return *this;
49}
50
52{
53 mMapCanvas = canvas;
54}
55
57{
58 return mMapCanvas;
59}
60
62{
63 mMessageBar = bar;
64}
65
67{
68 return mMessageBar;
69}
70
72{
73 if ( context )
74 mExpressionContext.reset( new QgsExpressionContext( *context ) );
75 else
76 mExpressionContext.reset();
77}
78
80{
81 return mExpressionContext.get();
82}
83
84void QgsSymbolWidgetContext::setAdditionalExpressionContextScopes( const QList<QgsExpressionContextScope> &scopes )
85{
86 mAdditionalScopes = scopes;
87}
88
89QList<QgsExpressionContextScope> QgsSymbolWidgetContext::additionalExpressionContextScopes() const
90{
91 return mAdditionalScopes;
92}
93
94QList<QgsExpressionContextScope *> QgsSymbolWidgetContext::globalProjectAtlasMapLayerScopes( const QgsMapLayer *layer ) const
95{
96 QList<QgsExpressionContextScope *> scopes;
100 if ( mMapCanvas )
101 {
103 << mMapCanvas->defaultExpressionContextScope()
105
106 if ( const QgsExpressionContextScopeGenerator *generator = dynamic_cast< const QgsExpressionContextScopeGenerator * >( mMapCanvas->temporalController() ) )
107 {
108 scopes << generator->createExpressionContextScope();
109 }
110 }
111 else
112 {
114 }
115 if ( layer )
116 scopes << QgsExpressionContextUtils::layerScope( layer );
117 return scopes;
118}
119
121{
122 return mSymbolType;
123}
124
126{
127 mSymbolType = type;
128}
SymbolType
Symbol types.
Definition: qgis.h:401
Abstract interface for generating an expression context scope.
Single scope for storing variables and functions for use within a QgsExpressionContext.
static QgsExpressionContextScope * projectScope(const QgsProject *project)
Creates a new scope which contains variables and functions relating to a QGIS project.
static QgsExpressionContextScope * atlasScope(const 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.
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:93
QgsExpressionContextScope * defaultExpressionContextScope() const
Creates a new scope which contains default variables and functions relating to the map canvas.
QgsExpressionContextScope & expressionContextScope()
Returns a reference to the expression context scope for the map canvas.
Definition: qgsmapcanvas.h:734
const QgsTemporalController * temporalController() const
Gets access to the temporal controller that will be used to update the canvas temporal range.
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
Base class for all map layer types.
Definition: qgsmaplayer.h:75
The QgsMapSettings class contains configuration for rendering of the map.
A bar for displaying non-blocking messages to the user.
Definition: qgsmessagebar.h:61
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:481
Contains settings which reflect the context in which a symbol (or renderer) widget is shown,...
QList< QgsExpressionContextScope > additionalExpressionContextScopes() const
Returns the list of additional expression context scopes to show as available within the layer.
void setSymbolType(Qgis::SymbolType type)
Sets the associated symbol type, if the widget is being shown as a subcomponent of a parent symbol co...
void setMapCanvas(QgsMapCanvas *canvas)
Sets the map canvas associated with the widget.
QList< QgsExpressionContextScope * > globalProjectAtlasMapLayerScopes(const QgsMapLayer *layer) const
Returns list of scopes: global, project, atlas, map, layer.
void setAdditionalExpressionContextScopes(const QList< QgsExpressionContextScope > &scopes)
Sets a list of additional expression context scopes to show as available within the layer.
QgsSymbolWidgetContext & operator=(const QgsSymbolWidgetContext &other)
void setMessageBar(QgsMessageBar *bar)
Sets the message bar associated with the widget.
QgsSymbolWidgetContext()=default
Constructor for QgsSymbolWidgetContext.
void setExpressionContext(QgsExpressionContext *context)
Sets the optional expression context used for the widget.
QgsExpressionContext * expressionContext() const
Returns the expression context used for the widget, if set.
QgsMapCanvas * mapCanvas() const
Returns the map canvas associated with the widget.
Qgis::SymbolType symbolType() const
Returns the associated symbol type, if the widget is being shown as a subcomponent of a parent symbol...
QgsMessageBar * messageBar() const
Returns the message bar associated with the widget.