QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
qgsmergedfeaturerendererwidget.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsmergedfeaturerendererwidget.cpp
3 ---------------------
4 begin : December 2020
5 copyright : (C) 2020 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 "moc_qgsmergedfeaturerendererwidget.cpp"
18#include "qgsrendererregistry.h"
19#include "qgsvectorlayer.h"
20#include "qgsapplication.h"
21
26
28 : QgsRendererWidget( layer, style )
29{
30 if ( !layer )
31 {
32 return;
33 }
34
36
37 // the renderer only applies to line or polygon vector layers
39 {
40 //setup blank dialog
41 mRenderer.reset( nullptr );
42 QGridLayout *layout = new QGridLayout( this );
43 QLabel *label = new QLabel( tr( "The merged feature renderer only applies to line and polygon layers. \n"
44 "'%1' is not a line or polygon layer and then cannot be displayed" )
45 .arg( layer->name() ),
46 this );
47 this->setLayout( layout );
48 layout->addWidget( label );
49 return;
50 }
51 setupUi( this );
52 connect( mRendererComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsMergedFeatureRendererWidget::mRendererComboBox_currentIndexChanged );
53
54 // try to recognize the previous renderer
55 // (null renderer means "no previous renderer")
56 if ( renderer )
57 {
59 }
60 if ( !mRenderer )
61 {
62 // use default embedded renderer
63 mRenderer.reset( new QgsMergedFeatureRenderer( QgsFeatureRenderer::defaultRenderer( type ) ) );
64 if ( renderer )
65 renderer->copyRendererData( mRenderer.get() );
66 }
67
68 int currentEmbeddedIdx = 0;
69 //insert possible renderer types
71 QStringList::const_iterator it = rendererList.constBegin();
72 int idx = 0;
73 mRendererComboBox->blockSignals( true );
74 for ( ; it != rendererList.constEnd(); ++it, ++idx )
75 {
76 if ( *it != QLatin1String( "mergedFeatureRenderer" )
77 && *it != QLatin1String( "invertedPolygonRenderer" ) ) //< an merged renderer cannot contain another merged or inverted renderer
78 {
80 mRendererComboBox->addItem( m->icon(), m->visibleName(), /* data */ *it );
81 const QgsFeatureRenderer *embeddedRenderer = mRenderer->embeddedRenderer();
82 if ( embeddedRenderer && embeddedRenderer->type() == m->name() )
83 {
84 // store the combo box index of the current renderer
85 currentEmbeddedIdx = idx;
86 }
87 }
88 }
89 mRendererComboBox->blockSignals( false );
90
91 const int oldIdx = mRendererComboBox->currentIndex();
92 mRendererComboBox->setCurrentIndex( currentEmbeddedIdx );
93 if ( oldIdx == currentEmbeddedIdx )
94 {
95 // force update
96 mRendererComboBox_currentIndexChanged( currentEmbeddedIdx );
97 }
98}
99
101
103{
104 if ( mRenderer && mEmbeddedRendererWidget )
105 {
106 QgsFeatureRenderer *embeddedRenderer = mEmbeddedRendererWidget->renderer();
107 if ( embeddedRenderer )
108 {
109 mRenderer->setEmbeddedRenderer( embeddedRenderer->clone() );
110 }
111 }
112 return mRenderer.get();
113}
114
116{
118 if ( mEmbeddedRendererWidget )
119 mEmbeddedRendererWidget->setContext( context );
120}
121
123{
125 if ( mEmbeddedRendererWidget )
126 mEmbeddedRendererWidget->setDockMode( dockMode );
127}
128
129void QgsMergedFeatureRendererWidget::mRendererComboBox_currentIndexChanged( int index )
130{
131 const QString rendererId = mRendererComboBox->itemData( index ).toString();
133 if ( m )
134 {
135 const std::unique_ptr<QgsFeatureRenderer> oldRenderer( mRenderer->embeddedRenderer()->clone() );
136 mEmbeddedRendererWidget.reset( m->createRendererWidget( mLayer, mStyle, oldRenderer.get() ) );
137 connect( mEmbeddedRendererWidget.get(), &QgsRendererWidget::widgetChanged, this, &QgsMergedFeatureRendererWidget::widgetChanged );
138 mEmbeddedRendererWidget->setContext( mContext );
139 mEmbeddedRendererWidget->disableSymbolLevels();
140 mEmbeddedRendererWidget->setDockMode( this->dockMode() );
141 connect( mEmbeddedRendererWidget.get(), &QgsPanelWidget::showPanel, this, &QgsPanelWidget::openPanel );
142
143 if ( layout()->count() > 2 )
144 {
145 // remove the current renderer widget
146 layout()->takeAt( 2 );
147 }
148 layout()->addWidget( mEmbeddedRendererWidget.get() );
149 }
150}
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:337
@ Polygon
Polygons.
static QgsRendererRegistry * rendererRegistry()
Returns the application's renderer registry, used for managing vector layer renderers.
Abstract base class for all 2D vector feature renderers.
static QgsFeatureRenderer * defaultRenderer(Qgis::GeometryType geomType)
Returns a new renderer - used by default in vector layers.
QString type() const
void copyRendererData(QgsFeatureRenderer *destRenderer) const
Clones generic renderer data to another renderer.
virtual QgsFeatureRenderer * clone() const =0
Create a deep copy of this renderer.
QString name
Definition qgsmaplayer.h:80
A widget used represent options of a QgsMergedFeatureRenderer.
~QgsMergedFeatureRendererWidget() override
QgsMergedFeatureRendererWidget(QgsVectorLayer *layer, QgsStyle *style, QgsFeatureRenderer *renderer)
Constructor.
QgsFeatureRenderer * renderer() override
Returns pointer to the renderer (no transfer of ownership)
void setDockMode(bool dockMode) override
Set the widget in dock mode which tells the widget to emit panel widgets and not open dialogs.
void setContext(const QgsSymbolWidgetContext &context) override
Sets the context in which the renderer widget is shown, e.g., the associated map canvas and expressio...
static QgsRendererWidget * create(QgsVectorLayer *layer, QgsStyle *style, QgsFeatureRenderer *renderer)
Static creation method.
QgsMergedFeatureRenderer is a polygon or line-only feature renderer used to renderer a set of feature...
static QgsMergedFeatureRenderer * convertFromRenderer(const QgsFeatureRenderer *renderer)
Creates a QgsMergedFeatureRenderer by a conversion from an existing renderer.
void showPanel(QgsPanelWidget *panel)
Emit when you require a panel to be show in the interface.
void openPanel(QgsPanelWidget *panel)
Open a panel or dialog depending on dock mode setting If dock mode is true this method will emit the ...
void widgetChanged()
Emitted when the widget state changes.
bool dockMode()
Returns the dock mode state.
Stores metadata about one renderer class.
@ LineLayer
Compatible with line layers.
@ PolygonLayer
Compatible with polygon layers.
QIcon icon() const
Returns an icon representing the renderer.
QString visibleName() const
Returns a friendly display name of the renderer.
virtual QgsRendererWidget * createRendererWidget(QgsVectorLayer *layer, QgsStyle *style, QgsFeatureRenderer *oldRenderer)
Returns new instance of settings widget for the renderer.
QString name() const
Returns the unique name of the renderer.
QStringList renderersList(QgsRendererAbstractMetadata::LayerTypes layerTypes=QgsRendererAbstractMetadata::All) const
Returns a list of available renderers.
QgsRendererAbstractMetadata * rendererMetadata(const QString &rendererName)
Returns the metadata for a specified renderer.
Base class for renderer settings widgets.
void setDockMode(bool dockMode) override
Set the widget in dock mode which tells the widget to emit panel widgets and not open dialogs.
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
Contains settings which reflect the context in which a symbol (or renderer) widget is shown,...
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.
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...