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