QGIS API Documentation 4.1.0-Master (5bf3c20f3c9)
Loading...
Searching...
No Matches
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
17#include <memory>
18
20#include "qgsmapcanvas.h"
21#include "qgsmessagebar.h"
22#include "qgsproject.h"
24
26 : mMapCanvas( other.mMapCanvas )
27 , mMessageBar( other.mMessageBar )
28 , mAdditionalScopes( other.mAdditionalScopes )
29 , mSymbolType( other.mSymbolType )
30{
31 if ( other.mExpressionContext )
32 {
33 mExpressionContext = std::make_unique<QgsExpressionContext>( *other.mExpressionContext );
34 }
35}
36
38{
39 if ( &other == this )
40 return *this;
41
42 mMapCanvas = other.mMapCanvas;
43 mMessageBar = other.mMessageBar;
44 mAdditionalScopes = other.mAdditionalScopes;
45 mSymbolType = other.mSymbolType;
46 if ( other.mExpressionContext )
47 {
48 mExpressionContext = std::make_unique<QgsExpressionContext>( *other.mExpressionContext );
49 }
50 else
51 {
52 mExpressionContext.reset();
53 }
54 return *this;
55}
56
58{
59 mMapCanvas = canvas;
60}
61
63{
64 return mMapCanvas;
65}
66
68{
69 mMessageBar = bar;
70}
71
73{
74 return mMessageBar;
75}
76
78{
79 if ( context )
80 mExpressionContext = std::make_unique<QgsExpressionContext>( *context );
81 else
82 mExpressionContext.reset();
83}
84
86{
87 return mExpressionContext.get();
88}
89
90void QgsSymbolWidgetContext::setAdditionalExpressionContextScopes( const QList<QgsExpressionContextScope> &scopes )
91{
92 mAdditionalScopes = scopes;
93}
94
95QList<QgsExpressionContextScope> QgsSymbolWidgetContext::additionalExpressionContextScopes() const
96{
97 return mAdditionalScopes;
98}
99
100QList<QgsExpressionContextScope *> QgsSymbolWidgetContext::globalProjectAtlasMapLayerScopes( const QgsMapLayer *layer ) const
101{
102 QList<QgsExpressionContextScope *> scopes;
104 if ( mMapCanvas )
105 {
106 scopes << QgsExpressionContextUtils::mapSettingsScope( mMapCanvas->mapSettings() ) << mMapCanvas->defaultExpressionContextScope() << new QgsExpressionContextScope( mMapCanvas->expressionContextScope() );
107
108 if ( const QgsExpressionContextScopeGenerator *generator = dynamic_cast<const QgsExpressionContextScopeGenerator *>( mMapCanvas->temporalController() ) )
109 {
110 scopes << generator->createExpressionContextScope();
111 }
112 }
113 else
114 {
116 }
117 if ( layer )
118 scopes << QgsExpressionContextUtils::layerScope( layer );
119 return scopes;
120}
121
123{
124 return mSymbolType;
125}
126
128{
129 mSymbolType = type;
130}
SymbolType
Symbol types.
Definition qgis.h:636
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.
Base class for all map layer types.
Definition qgsmaplayer.h:83
Contains configuration for rendering maps.
A bar for displaying non-blocking messages to the user.
static QgsProject * instance()
Returns the QgsProject singleton instance.
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
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.