QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 "qgsrendererv2registry.h"
18 
19 #include "qgssymbolv2.h"
20 
21 #include "qgslogger.h"
22 #include "qgsvectorlayer.h"
23 
25 {
26  return new QgsInvertedPolygonRendererWidget( layer, style, renderer );
27 }
28 
30  : QgsRendererV2Widget( layer, style )
31 {
32  if ( !layer )
33  {
34  return;
35  }
36 
37  // the renderer only applies to polygon vector layers
38  if ( layer->wkbType() != QGis::WKBPolygon &&
39  layer->wkbType() != QGis::WKBPolygon25D &&
40  layer->wkbType() != QGis::WKBMultiPolygon &&
41  layer->wkbType() != QGis::WKBMultiPolygon25D )
42  {
43  //setup blank dialog
44  mRenderer.reset( 0 );
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  layout->addWidget( label );
50  return;
51  }
52  setupUi( this );
53 
54  // try to recognize the previous renderer
55  // (null renderer means "no previous renderer")
56 
57  if ( renderer )
58  {
60  }
61  if ( ! mRenderer )
62  {
64  }
65  mMergePolygonsCheckBox->blockSignals( true );
66  mMergePolygonsCheckBox->setCheckState( mRenderer->preprocessingEnabled() ? Qt::Checked : Qt::Unchecked );
67  mMergePolygonsCheckBox->blockSignals( false );
68 
69  int currentEmbeddedIdx = 0;
70  //insert possible renderer types
71  QStringList rendererList = QgsRendererV2Registry::instance()->renderersList();
72  QStringList::const_iterator it = rendererList.constBegin();
73  int idx = 0;
74  mRendererComboBox->blockSignals( true );
75  for ( ; it != rendererList.constEnd(); ++it, ++idx )
76  {
77  if (( *it != "invertedPolygonRenderer" ) && //< an inverted renderer cannot contain another inverted renderer
78  ( *it != "pointDisplacement" ) ) //< an inverted renderer can only contain a polygon renderer
79  {
81  mRendererComboBox->addItem( m->icon(), m->visibleName(), /* data */ *it );
82  const QgsFeatureRendererV2* 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  int oldIdx = mRendererComboBox->currentIndex();
93  mRendererComboBox->setCurrentIndex( currentEmbeddedIdx );
94  if ( oldIdx == currentEmbeddedIdx )
95  {
96  // force update
97  on_mRendererComboBox_currentIndexChanged( currentEmbeddedIdx );
98  }
99 }
100 
102 {
104  {
105  QgsFeatureRendererV2* embeddedRenderer = mEmbeddedRendererWidget->renderer();
106  if ( embeddedRenderer )
107  {
108  mRenderer->setEmbeddedRenderer( embeddedRenderer->clone() );
109  }
110  }
111  return mRenderer.data();
112 }
113 
114 void QgsInvertedPolygonRendererWidget::on_mRendererComboBox_currentIndexChanged( int index )
115 {
116  QString rendererId = mRendererComboBox->itemData( index ).toString();
118  if ( m )
119  {
120  mEmbeddedRendererWidget.reset( m->createRendererWidget( mLayer, mStyle, const_cast<QgsFeatureRendererV2*>( mRenderer->embeddedRenderer() )->clone() ) );
121 
122  if ( mLayout->count() > 2 )
123  {
124  // remove the current renderer widget
125  mLayout->takeAt( 2 );
126  }
127  mLayout->addWidget( mEmbeddedRendererWidget.data() );
128  }
129 }
130 
131 void QgsInvertedPolygonRendererWidget::on_mMergePolygonsCheckBox_stateChanged( int state )
132 {
133  mRenderer->setPreprocessingEnabled( state == Qt::Checked );
134 }