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