QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 
19 #include "qgssymbol.h"
20 
21 #include "qgslogger.h"
22 #include "qgsvectorlayer.h"
23 #include "qgsapplication.h"
24 
26 {
27  return new QgsInvertedPolygonRendererWidget( layer, style, renderer );
28 }
29 
31  : QgsRendererWidget( layer, style )
32 {
33  if ( !layer )
34  {
35  return;
36  }
37 
39 
40  // the renderer only applies to polygon vector layers
41  if ( type != QgsWkbTypes::Polygon && type != QgsWkbTypes::CurvePolygon )
42  {
43  //setup blank dialog
44  mRenderer.reset( nullptr );
45  QGridLayout *layout = new QGridLayout( this );
46  QLabel *label = new QLabel( tr( "The inverted polygon renderer only applies to polygon and multipolygon layers. \n"
47  "'%1' is not a polygon layer and then cannot be displayed" )
48  .arg( layer->name() ), this );
49  this->setLayout( layout );
50  layout->addWidget( label );
51  return;
52  }
53  setupUi( this );
54  connect( mRendererComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsInvertedPolygonRendererWidget::mRendererComboBox_currentIndexChanged );
55  connect( mMergePolygonsCheckBox, &QCheckBox::stateChanged, this, &QgsInvertedPolygonRendererWidget::mMergePolygonsCheckBox_stateChanged );
56 
57  // try to recognize the previous renderer
58  // (null renderer means "no previous renderer")
59 
60  if ( renderer )
61  {
63  }
64  if ( ! mRenderer )
65  {
67  if ( renderer )
69  }
70  mMergePolygonsCheckBox->blockSignals( true );
71  mMergePolygonsCheckBox->setCheckState( mRenderer->preprocessingEnabled() ? Qt::Checked : Qt::Unchecked );
72  mMergePolygonsCheckBox->blockSignals( false );
73 
74  int currentEmbeddedIdx = 0;
75  //insert possible renderer types
77  QStringList::const_iterator it = rendererList.constBegin();
78  int idx = 0;
79  mRendererComboBox->blockSignals( true );
80  for ( ; it != rendererList.constEnd(); ++it, ++idx )
81  {
82  if ( *it != QLatin1String( "invertedPolygonRenderer" ) ) //< an inverted renderer cannot contain another inverted renderer
83  {
85  mRendererComboBox->addItem( m->icon(), m->visibleName(), /* data */ *it );
86  const QgsFeatureRenderer *embeddedRenderer = mRenderer->embeddedRenderer();
87  if ( embeddedRenderer && embeddedRenderer->type() == m->name() )
88  {
89  // store the combo box index of the current renderer
90  currentEmbeddedIdx = idx;
91  }
92  }
93  }
94  mRendererComboBox->blockSignals( false );
95 
96  const int oldIdx = mRendererComboBox->currentIndex();
97  mRendererComboBox->setCurrentIndex( currentEmbeddedIdx );
98  if ( oldIdx == currentEmbeddedIdx )
99  {
100  // force update
101  mRendererComboBox_currentIndexChanged( currentEmbeddedIdx );
102  }
103 }
104 
106 
108 {
110  {
111  QgsFeatureRenderer *embeddedRenderer = mEmbeddedRendererWidget->renderer();
112  if ( embeddedRenderer )
113  {
114  mRenderer->setEmbeddedRenderer( embeddedRenderer->clone() );
115  }
116  }
117  return mRenderer.get();
118 }
119 
121 {
124  mEmbeddedRendererWidget->setContext( context );
125 }
126 
128 {
131  mEmbeddedRendererWidget->setDockMode( dockMode );
132 }
133 
134 void QgsInvertedPolygonRendererWidget::mRendererComboBox_currentIndexChanged( int index )
135 {
136  const QString rendererId = mRendererComboBox->itemData( index ).toString();
138  if ( m )
139  {
140  const std::unique_ptr< QgsFeatureRenderer > oldRenderer( mRenderer->embeddedRenderer()->clone() );
141  mEmbeddedRendererWidget.reset( m->createRendererWidget( mLayer, mStyle, oldRenderer.get() ) );
143  mEmbeddedRendererWidget->setContext( mContext );
144  mEmbeddedRendererWidget->disableSymbolLevels();
145  mEmbeddedRendererWidget->setDockMode( this->dockMode() );
147 
148  if ( layout()->count() > 2 )
149  {
150  // remove the current renderer widget
151  layout()->takeAt( 2 );
152  }
153  layout()->addWidget( mEmbeddedRendererWidget.get() );
154  }
155 }
156 
157 void QgsInvertedPolygonRendererWidget::mMergePolygonsCheckBox_stateChanged( int state )
158 {
159  mRenderer->setPreprocessingEnabled( state == Qt::Checked );
160  emit widgetChanged();
161 }
QgsFeatureRenderer::copyRendererData
void copyRendererData(QgsFeatureRenderer *destRenderer) const
Clones generic renderer data to another renderer.
Definition: qgsrenderer.cpp:52
QgsRendererWidget::mStyle
QgsStyle * mStyle
Definition: qgsrendererwidget.h:113
QgsApplication::rendererRegistry
static QgsRendererRegistry * rendererRegistry()
Returns the application's renderer registry, used for managing vector layer renderers.
Definition: qgsapplication.cpp:2320
QgsVectorLayer::wkbType
Q_INVOKABLE QgsWkbTypes::Type wkbType() const FINAL
Returns the WKBType or WKBUnknown in case of error.
Definition: qgsvectorlayer.cpp:725
QgsRendererWidget::mLayer
QgsVectorLayer * mLayer
Definition: qgsrendererwidget.h:112
QgsInvertedPolygonRenderer::convertFromRenderer
static QgsInvertedPolygonRenderer * convertFromRenderer(const QgsFeatureRenderer *renderer)
Creates a QgsInvertedPolygonRenderer by a conversion from an existing renderer.
Definition: qgsinvertedpolygonrenderer.cpp:101
QgsWkbTypes::flatType
static Type flatType(Type type) SIP_HOLDGIL
Returns the flat type for a WKB type.
Definition: qgswkbtypes.h:732
QgsRendererAbstractMetadata::visibleName
QString visibleName() const
Returns a friendly display name of the renderer.
Definition: qgsrendererregistry.h:82
QgsRendererAbstractMetadata::name
QString name() const
Returns the unique name of the renderer.
Definition: qgsrendererregistry.h:76
QgsRendererWidget::context
QgsSymbolWidgetContext context() const
Returns the context in which the renderer widget is shown, e.g., the associated map canvas and expres...
Definition: qgsrendererwidget.cpp:346
QgsSymbolWidgetContext
Contains settings which reflect the context in which a symbol (or renderer) widget is shown,...
Definition: qgssymbolwidgetcontext.h:35
QgsPanelWidget::openPanel
void openPanel(QgsPanelWidget *panel)
Open a panel or dialog depending on dock mode setting If dock mode is true this method will emit the ...
Definition: qgspanelwidget.cpp:84
QgsInvertedPolygonRendererWidget::mEmbeddedRendererWidget
std::unique_ptr< QgsRendererWidget > mEmbeddedRendererWidget
The widget used to represent the mask's embedded renderer.
Definition: qgsinvertedpolygonrendererwidget.h:65
QgsFeatureRenderer::type
QString type() const
Definition: qgsrenderer.h:142
QgsInvertedPolygonRendererWidget::renderer
QgsFeatureRenderer * renderer() override
Returns pointer to the renderer (no transfer of ownership)
Definition: qgsinvertedpolygonrendererwidget.cpp:107
QgsWkbTypes::Type
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:69
QgsPanelWidget::dockMode
bool dockMode()
Returns the dock mode state.
Definition: qgspanelwidget.h:93
QgsPanelWidget::showPanel
void showPanel(QgsPanelWidget *panel)
Emit when you require a panel to be show in the interface.
qgsapplication.h
QgsInvertedPolygonRendererWidget::~QgsInvertedPolygonRendererWidget
~QgsInvertedPolygonRendererWidget() override
QgsFeatureRenderer::clone
virtual QgsFeatureRenderer * clone() const =0
Create a deep copy of this renderer.
QgsInvertedPolygonRendererWidget::QgsInvertedPolygonRendererWidget
QgsInvertedPolygonRendererWidget(QgsVectorLayer *layer, QgsStyle *style, QgsFeatureRenderer *renderer)
Constructor.
Definition: qgsinvertedpolygonrendererwidget.cpp:30
qgsrendererregistry.h
QgsWkbTypes::CurvePolygon
@ CurvePolygon
Definition: qgswkbtypes.h:82
QgsRendererWidget::setDockMode
void setDockMode(bool dockMode) override
Set the widget in dock mode which tells the widget to emit panel widgets and not open dialogs.
Definition: qgsrendererwidget.cpp:356
QgsPanelWidget::widgetChanged
void widgetChanged()
Emitted when the widget state changes.
QgsInvertedPolygonRendererWidget::create
static QgsRendererWidget * create(QgsVectorLayer *layer, QgsStyle *style, QgsFeatureRenderer *renderer)
Static creation method.
Definition: qgsinvertedpolygonrendererwidget.cpp:25
QgsRendererRegistry::renderersList
QStringList renderersList(QgsRendererAbstractMetadata::LayerTypes layerTypes=QgsRendererAbstractMetadata::All) const
Returns a list of available renderers.
Definition: qgsrendererregistry.cpp:137
QgsInvertedPolygonRendererWidget::setDockMode
void setDockMode(bool dockMode) override
Set the widget in dock mode which tells the widget to emit panel widgets and not open dialogs.
Definition: qgsinvertedpolygonrendererwidget.cpp:127
QgsInvertedPolygonRendererWidget::mRenderer
std::unique_ptr< QgsInvertedPolygonRenderer > mRenderer
The mask renderer.
Definition: qgsinvertedpolygonrendererwidget.h:63
QgsRendererWidget
Base class for renderer settings widgets.
Definition: qgsrendererwidget.h:45
qgsvectorlayer.h
QgsFeatureRenderer
Definition: qgsrenderer.h:101
QgsStyle
Definition: qgsstyle.h:159
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
QgsWkbTypes::Polygon
@ Polygon
Definition: qgswkbtypes.h:74
QgsRendererWidget::mContext
QgsSymbolWidgetContext mContext
Context in which widget is shown.
Definition: qgsrendererwidget.h:131
qgsinvertedpolygonrendererwidget.h
QgsInvertedPolygonRendererWidget::setContext
void setContext(const QgsSymbolWidgetContext &context) override
Sets the context in which the renderer widget is shown, e.g., the associated map canvas and expressio...
Definition: qgsinvertedpolygonrendererwidget.cpp:120
QgsMapLayer::name
QString name
Definition: qgsmaplayer.h:76
QgsRendererAbstractMetadata::icon
QIcon icon() const
Returns an icon representing the renderer.
Definition: qgsrendererregistry.h:88
qgsinvertedpolygonrenderer.h
qgslogger.h
QgsRendererAbstractMetadata::createRendererWidget
virtual QgsRendererWidget * createRendererWidget(QgsVectorLayer *layer, QgsStyle *style, QgsFeatureRenderer *oldRenderer)
Returns new instance of settings widget for the renderer.
Definition: qgsrendererregistry.h:115
QgsWkbTypes::singleType
static Type singleType(Type type) SIP_HOLDGIL
Returns the single type for a WKB type.
Definition: qgswkbtypes.h:157
QgsRendererRegistry::rendererMetadata
QgsRendererAbstractMetadata * rendererMetadata(const QString &rendererName)
Returns the metadata for a specified renderer.
Definition: qgsrendererregistry.cpp:132
QgsRendererAbstractMetadata
Stores metadata about one renderer class.
Definition: qgsrendererregistry.h:41
QgsRendererWidget::setContext
virtual void setContext(const QgsSymbolWidgetContext &context)
Sets the context in which the renderer widget is shown, e.g., the associated map canvas and expressio...
Definition: qgsrendererwidget.cpp:341
qgssymbol.h
QgsRendererAbstractMetadata::PolygonLayer
@ PolygonLayer
Compatible with polygon layers.
Definition: qgsrendererregistry.h:53
QgsInvertedPolygonRenderer
QgsInvertedPolygonRenderer is a polygon-only feature renderer used to display features inverted,...
Definition: qgsinvertedpolygonrenderer.h:42