QGIS API Documentation 3.38.0-Grenoble (exported)
Loading...
Searching...
No Matches
qgsembeddedsymbolrendererwidget.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsembeddedsymbolrendererwidget.cpp
3 ---------------------
4 begin : March 2021
5 copyright : (C) 2021 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 ***************************************************************************/
17#include "qgsrendererregistry.h"
18#include "qgssymbol.h"
19#include "qgsvectorlayer.h"
20
25
27 : QgsRendererWidget( layer, style )
28{
29 if ( !layer )
30 {
31 return;
32 }
33
35
36 // the renderer only applies to layers with providers supporting embedded symbols
38 {
39 //setup blank dialog
40 mRenderer.reset( nullptr );
41 QGridLayout *layout = new QGridLayout( this );
42 QLabel *label = new QLabel( tr( "The embedded symbols renderer can only be used with layers\n"
43 "containing embedded styling information.\n\n"
44 "'%1' does not contain embedded styling and cannot be displayed." )
45 .arg( layer->name() ), this );
46 this->setLayout( layout );
47 layout->addWidget( label );
48 mDefaultSymbolToolButton = nullptr;
49 return;
50 }
51 setupUi( this );
52
53 mDefaultSymbolToolButton->setSymbolType( QgsSymbol::symbolTypeForGeometryType( type ) );
54
55 // try to recognize the previous renderer
56 // (null renderer means "no previous renderer")
57 if ( renderer )
58 {
60 }
61 if ( ! mRenderer )
62 {
63 // use default embedded renderer
64 mRenderer.reset( new QgsEmbeddedSymbolRenderer( QgsSymbol::defaultSymbol( type ) ) );
65 if ( renderer )
66 renderer->copyRendererData( mRenderer.get() );
67 }
68
69 mDefaultSymbolToolButton->setSymbol( mRenderer->defaultSymbol()->clone() );
70 mDefaultSymbolToolButton->setDialogTitle( tr( "Default symbol" ) );
71 mDefaultSymbolToolButton->setLayer( mLayer );
72 mDefaultSymbolToolButton->registerExpressionContextGenerator( this );
73
74 connect( mDefaultSymbolToolButton, &QgsSymbolButton::changed, this, [ = ]
75 {
76 mRenderer->setDefaultSymbol( mDefaultSymbolToolButton->symbol()->clone() );
77 emit widgetChanged();
78 } );
79}
80
82
87
89{
91 if ( mDefaultSymbolToolButton )
92 {
93 mDefaultSymbolToolButton->setMapCanvas( context.mapCanvas() );
94 mDefaultSymbolToolButton->setMessageBar( context.messageBar() );
95 }
96}
97
99{
101 if ( QgsExpressionContext *expressionContext = mContext.expressionContext() )
102 context = *expressionContext;
103 else
105
106 const QList< QgsExpressionContextScope > scopes = mContext.additionalExpressionContextScopes();
107 for ( const QgsExpressionContextScope &s : scopes )
108 {
110 }
111 return context;
112}
113
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:274
A widget used represent options of a QgsEmbeddedSymbolRenderer.
static QgsRendererWidget * create(QgsVectorLayer *layer, QgsStyle *style, QgsFeatureRenderer *renderer)
Static creation method.
QgsEmbeddedSymbolRendererWidget(QgsVectorLayer *layer, QgsStyle *style, QgsFeatureRenderer *renderer)
Constructor.
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
void setContext(const QgsSymbolWidgetContext &context) override
Sets the context in which the renderer widget is shown, e.g., the associated map canvas and expressio...
QgsFeatureRenderer * renderer() override
Returns pointer to the renderer (no transfer of ownership)
A vector feature renderer which uses embedded feature symbology to render per-feature symbols.
static QgsEmbeddedSymbolRenderer * convertFromRenderer(const QgsFeatureRenderer *renderer)
Creates a QgsEmbeddedSymbolRenderer from an existing renderer.
Single scope for storing variables and functions for use within a QgsExpressionContext.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void copyRendererData(QgsFeatureRenderer *destRenderer) const
Clones generic renderer data to another renderer.
QString name
Definition qgsmaplayer.h:79
void widgetChanged()
Emitted when the widget state changes.
Base class for renderer settings widgets.
QgsSymbolWidgetContext mContext
Context in which widget is shown.
virtual void setContext(const QgsSymbolWidgetContext &context)
Sets the context in which the renderer widget is shown, e.g., the associated map canvas and expressio...
QgsSymbolWidgetContext context() const
Returns the context in which the renderer widget is shown, e.g., the associated map canvas and expres...
QgsVectorLayer * mLayer
void changed()
Emitted when the symbol's settings are changed.
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.
QList< QgsExpressionContextScope * > globalProjectAtlasMapLayerScopes(const QgsMapLayer *layer) const
Returns list of scopes: global, project, atlas, map, layer.
QgsExpressionContext * expressionContext() const
Returns the expression context used for the widget, if set.
QgsMapCanvas * mapCanvas() const
Returns the map canvas associated with the widget.
QgsMessageBar * messageBar() const
Returns the message bar associated with the widget.
static Qgis::SymbolType symbolTypeForGeometryType(Qgis::GeometryType type)
Returns the default symbol type required for the specified geometry type.
static QgsSymbol * defaultSymbol(Qgis::GeometryType geomType)
Returns a new default symbol for the specified geometry type.
@ FeatureSymbology
Provider is able retrieve embedded symbology associated with individual features. Since QGIS 3....
virtual Q_INVOKABLE QgsVectorDataProvider::Capabilities capabilities() const
Returns flags containing the supported capabilities.
Represents a vector layer which manages a vector based data sets.
Q_INVOKABLE Qgis::WkbType wkbType() const FINAL
Returns the WKBType or WKBUnknown in case of error.
QgsVectorDataProvider * dataProvider() FINAL
Returns the layer's data provider, it may be nullptr.
static Qgis::GeometryType geometryType(Qgis::WkbType type)
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...