QGIS API Documentation 3.39.0-Master (132cbd6f1b5)
Loading...
Searching...
No Matches
qgsinvertedpolygonrendererwidget.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsinvertedpolygonrendererwidget.cpp
3 ---------------------
4 begin : April 2014
5 copyright : (C) 2014 Hugo Mercier / Oslandia
6 email : hugo dot mercier at oslandia 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 "qgsvectorlayer.h"
19#include "qgsapplication.h"
20
25
27 : QgsRendererWidget( layer, style )
28{
29 if ( !layer )
30 {
31 return;
32 }
33
35
36 // the renderer only applies to polygon vector layers
38 {
39 //setup blank dialog
40 mRenderer.reset( nullptr );
41 QGridLayout *layout = new QGridLayout( this );
42 QLabel *label = new QLabel( tr( "The inverted polygon renderer only applies to polygon and multipolygon layers. \n"
43 "'%1' is not a polygon layer and then cannot be displayed" )
44 .arg( layer->name() ), this );
45 this->setLayout( layout );
46 layout->addWidget( label );
47 return;
48 }
49 setupUi( this );
50 connect( mRendererComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsInvertedPolygonRendererWidget::mRendererComboBox_currentIndexChanged );
51 connect( mMergePolygonsCheckBox, &QCheckBox::stateChanged, this, &QgsInvertedPolygonRendererWidget::mMergePolygonsCheckBox_stateChanged );
52
53 // try to recognize the previous renderer
54 // (null renderer means "no previous renderer")
55
56 if ( renderer )
57 {
59 }
60 if ( ! mRenderer )
61 {
63 if ( renderer )
65 }
66 mMergePolygonsCheckBox->blockSignals( true );
67 mMergePolygonsCheckBox->setCheckState( mRenderer->preprocessingEnabled() ? Qt::Checked : Qt::Unchecked );
68 mMergePolygonsCheckBox->blockSignals( false );
69
70 int currentEmbeddedIdx = 0;
71 //insert possible renderer types
73 QStringList::const_iterator it = rendererList.constBegin();
74 int idx = 0;
75 mRendererComboBox->blockSignals( true );
76 for ( ; it != rendererList.constEnd(); ++it, ++idx )
77 {
78 if ( *it != QLatin1String( "invertedPolygonRenderer" ) ) //< an inverted renderer cannot contain another inverted renderer
79 {
81 mRendererComboBox->addItem( m->icon(), m->visibleName(), /* data */ *it );
82 const QgsFeatureRenderer *embeddedRenderer = mRenderer->embeddedRenderer();
83 if ( embeddedRenderer && embeddedRenderer->type() == m->name() )
84 {
85 // store the combo box index of the current renderer
86 currentEmbeddedIdx = idx;
87 }
88 }
89 }
90 mRendererComboBox->blockSignals( false );
91
92 const int oldIdx = mRendererComboBox->currentIndex();
93 mRendererComboBox->setCurrentIndex( currentEmbeddedIdx );
94 if ( oldIdx == currentEmbeddedIdx )
95 {
96 // force update
97 mRendererComboBox_currentIndexChanged( currentEmbeddedIdx );
98 }
99}
100
102
104{
106 {
107 QgsFeatureRenderer *embeddedRenderer = mEmbeddedRendererWidget->renderer();
108 if ( embeddedRenderer )
109 {
110 mRenderer->setEmbeddedRenderer( embeddedRenderer->clone() );
111 }
112 }
113 return mRenderer.get();
114}
115
122
129
130void QgsInvertedPolygonRendererWidget::mRendererComboBox_currentIndexChanged( int index )
131{
132 const QString rendererId = mRendererComboBox->itemData( index ).toString();
134 if ( m )
135 {
136 const std::unique_ptr< QgsFeatureRenderer > oldRenderer( mRenderer->embeddedRenderer()->clone() );
137 mEmbeddedRendererWidget.reset( m->createRendererWidget( mLayer, mStyle, oldRenderer.get() ) );
139 mEmbeddedRendererWidget->setContext( mContext );
140 mEmbeddedRendererWidget->disableSymbolLevels();
141 mEmbeddedRendererWidget->setDockMode( this->dockMode() );
143
144 if ( layout()->count() > 2 )
145 {
146 // remove the current renderer widget
147 layout()->takeAt( 2 );
148 }
149 layout()->addWidget( mEmbeddedRendererWidget.get() );
150 }
151}
152
153void QgsInvertedPolygonRendererWidget::mMergePolygonsCheckBox_stateChanged( int state )
154{
155 mRenderer->setPreprocessingEnabled( state == Qt::Checked );
156 emit widgetChanged();
157}
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:256
@ Polygon
Polygon.
@ CurvePolygon
CurvePolygon.
static QgsRendererRegistry * rendererRegistry()
Returns the application's renderer registry, used for managing vector layer renderers.
Abstract base class for all 2D vector feature renderers.
virtual void setEmbeddedRenderer(QgsFeatureRenderer *subRenderer)
Sets an embedded renderer (subrenderer) for this feature renderer.
QString type() const
void copyRendererData(QgsFeatureRenderer *destRenderer) const
Clones generic renderer data to another renderer.
virtual const QgsFeatureRenderer * embeddedRenderer() const
Returns the current embedded renderer (subrenderer) for this feature renderer.
virtual QgsFeatureRenderer * clone() const =0
Create a deep copy of this renderer.
A widget used represent options of a QgsInvertedPolygonRenderer.
std::unique_ptr< QgsRendererWidget > mEmbeddedRendererWidget
The widget used to represent the mask's embedded renderer.
void setContext(const QgsSymbolWidgetContext &context) override
Sets the context in which the renderer widget is shown, e.g., the associated map canvas and expressio...
QgsInvertedPolygonRendererWidget(QgsVectorLayer *layer, QgsStyle *style, QgsFeatureRenderer *renderer)
Constructor.
std::unique_ptr< QgsInvertedPolygonRenderer > mRenderer
The mask renderer.
static QgsRendererWidget * create(QgsVectorLayer *layer, QgsStyle *style, QgsFeatureRenderer *renderer)
Static creation method.
void setDockMode(bool dockMode) override
Set the widget in dock mode which tells the widget to emit panel widgets and not open dialogs.
QgsFeatureRenderer * renderer() override
Returns pointer to the renderer (no transfer of ownership)
QgsInvertedPolygonRenderer is a polygon-only feature renderer used to display features inverted,...
static QgsInvertedPolygonRenderer * convertFromRenderer(const QgsFeatureRenderer *renderer)
Creates a QgsInvertedPolygonRenderer by a conversion from an existing renderer.
QString name
Definition qgsmaplayer.h:80
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.
@ 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::WkbType singleType(Qgis::WkbType type)
Returns the single type for a WKB type.
Definition qgswkbtypes.h:53
static Qgis::WkbType flatType(Qgis::WkbType type)
Returns the flat type for a WKB type.