QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgsinvertedpolygonrenderer.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsinvertedpolygonrenderer.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  ***************************************************************************/
15 
17 
18 #include "qgssymbol.h"
19 #include "qgssymbollayerutils.h"
20 
21 #include "qgslogger.h"
22 #include "qgsfeature.h"
23 #include "qgsvectorlayer.h"
24 #include "qgssymbollayer.h"
25 #include "qgsogcutils.h"
26 #include "qgspainteffect.h"
27 #include "qgspainteffectregistry.h"
28 #include "qgsstyleentityvisitor.h"
29 
30 #include <QDomDocument>
31 #include <QDomElement>
32 
34  : QgsMergedFeatureRenderer( QStringLiteral( "invertedPolygonRenderer" ), subRenderer )
35 {
36  if ( !subRenderer )
37  {
39  }
41 }
42 
44 {
45  if ( !mSubRenderer )
46  {
47  return QStringLiteral( "INVERTED: NULL" );
48  }
49  return "INVERTED [" + mSubRenderer->dump() + ']';
50 }
51 
53 {
54  QgsInvertedPolygonRenderer *newRenderer = nullptr;
55  if ( !mSubRenderer )
56  {
57  newRenderer = new QgsInvertedPolygonRenderer( nullptr );
58  }
59  else
60  {
61  newRenderer = new QgsInvertedPolygonRenderer( mSubRenderer->clone() );
62  }
64  copyRendererData( newRenderer );
65  return newRenderer;
66 }
67 
69 {
71  //look for an embedded renderer <renderer-v2>
72  QDomElement embeddedRendererElem = element.firstChildElement( QStringLiteral( "renderer-v2" ) );
73  if ( !embeddedRendererElem.isNull() )
74  {
75  QgsFeatureRenderer *renderer = QgsFeatureRenderer::load( embeddedRendererElem, context );
76  r->setEmbeddedRenderer( renderer );
77  }
78  r->setPreprocessingEnabled( element.attribute( QStringLiteral( "preprocessing" ), QStringLiteral( "0" ) ).toInt() == 1 );
79  return r;
80 }
81 
82 QDomElement QgsInvertedPolygonRenderer::save( QDomDocument &doc, const QgsReadWriteContext &context )
83 {
84  // clazy:skip
85 
86  QDomElement rendererElem = doc.createElement( RENDERER_TAG_NAME );
87  rendererElem.setAttribute( QStringLiteral( "type" ), QStringLiteral( "invertedPolygonRenderer" ) );
88  rendererElem.setAttribute( QStringLiteral( "preprocessing" ), preprocessingEnabled() ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
89 
90  if ( mSubRenderer )
91  {
92  const QDomElement embeddedRendererElem = mSubRenderer->save( doc, context );
93  rendererElem.appendChild( embeddedRendererElem );
94  }
95 
96  saveRendererData( doc, rendererElem, context );
97 
98  return rendererElem;
99 }
100 
102 {
103  if ( renderer->type() == QLatin1String( "invertedPolygonRenderer" ) )
104  {
105  return dynamic_cast<QgsInvertedPolygonRenderer *>( renderer->clone() );
106  }
107  else if ( renderer->type() == QLatin1String( "singleSymbol" ) ||
108  renderer->type() == QLatin1String( "categorizedSymbol" ) ||
109  renderer->type() == QLatin1String( "graduatedSymbol" ) ||
110  renderer->type() == QLatin1String( "RuleRenderer" ) )
111  {
112  std::unique_ptr< QgsInvertedPolygonRenderer > res = std::make_unique< QgsInvertedPolygonRenderer >( renderer->clone() );
113  renderer->copyRendererData( res.get() );
114  return res.release();
115  }
116  else if ( renderer->type() == QLatin1String( "mergedFeatureRenderer" ) )
117  {
118  std::unique_ptr< QgsInvertedPolygonRenderer > res = std::make_unique< QgsInvertedPolygonRenderer >( renderer->embeddedRenderer() ? renderer->embeddedRenderer()->clone() : nullptr );
119  renderer->copyRendererData( res.get() );
120  return res.release();
121  }
122  return nullptr;
123 }
124 
QgsFeatureRenderer::copyRendererData
void copyRendererData(QgsFeatureRenderer *destRenderer) const
Clones generic renderer data to another renderer.
Definition: qgsrenderer.cpp:52
QgsFeatureRenderer::defaultRenderer
static QgsFeatureRenderer * defaultRenderer(QgsWkbTypes::GeometryType geomType)
Returns a new renderer - used by default in vector layers.
Definition: qgsrenderer.cpp:79
QgsInvertedPolygonRenderer::preprocessingEnabled
bool preprocessingEnabled() const
Definition: qgsinvertedpolygonrenderer.h:81
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:34
QgsMergedFeatureRenderer::mOperation
GeometryOperation mOperation
Operation to apply to collected geometries.
Definition: qgsmergedfeaturerenderer.h:140
QgsInvertedPolygonRenderer::convertFromRenderer
static QgsInvertedPolygonRenderer * convertFromRenderer(const QgsFeatureRenderer *renderer)
Creates a QgsInvertedPolygonRenderer by a conversion from an existing renderer.
Definition: qgsinvertedpolygonrenderer.cpp:101
QgsInvertedPolygonRenderer::QgsInvertedPolygonRenderer
QgsInvertedPolygonRenderer(QgsFeatureRenderer *embeddedRenderer=nullptr)
Constructor.
Definition: qgsinvertedpolygonrenderer.cpp:33
qgssymbollayerutils.h
qgsfeature.h
QgsFeatureRenderer::type
QString type() const
Definition: qgsrenderer.h:142
qgspainteffectregistry.h
qgspainteffect.h
QgsFeatureRenderer::load
static QgsFeatureRenderer * load(QDomElement &symbologyElem, const QgsReadWriteContext &context)
create a renderer from XML element
Definition: qgsrenderer.cpp:157
QgsWkbTypes::PolygonGeometry
@ PolygonGeometry
Definition: qgswkbtypes.h:144
qgsogcutils.h
QgsInvertedPolygonRenderer::dump
QString dump() const override
Returns debug information about this renderer.
Definition: qgsinvertedpolygonrenderer.cpp:43
QgsFeatureRenderer::saveRendererData
void saveRendererData(QDomDocument &doc, QDomElement &element, const QgsReadWriteContext &context)
Saves generic renderer data into the specified element.
Definition: qgsrenderer.cpp:204
QgsFeatureRenderer::clone
virtual QgsFeatureRenderer * clone() const =0
Create a deep copy of this renderer.
RENDERER_TAG_NAME
#define RENDERER_TAG_NAME
Definition: qgsrenderer.h:50
QgsMergedFeatureRenderer::setEmbeddedRenderer
void setEmbeddedRenderer(QgsFeatureRenderer *subRenderer) override
Sets an embedded renderer (subrenderer) for this feature renderer.
Definition: qgsmergedfeaturerenderer.cpp:48
qgssymbollayer.h
qgsvectorlayer.h
QgsInvertedPolygonRenderer::save
QDomElement save(QDomDocument &doc, const QgsReadWriteContext &context) override
Stores renderer properties to an XML element.
Definition: qgsinvertedpolygonrenderer.cpp:82
QgsFeatureRenderer
Definition: qgsrenderer.h:101
QgsInvertedPolygonRenderer::create
static QgsFeatureRenderer * create(QDomElement &element, const QgsReadWriteContext &context)
Creates a renderer out of an XML, for loading.
Definition: qgsinvertedpolygonrenderer.cpp:68
QgsInvertedPolygonRenderer::clone
QgsInvertedPolygonRenderer * clone() const override
Create a deep copy of this renderer.
Definition: qgsinvertedpolygonrenderer.cpp:52
QgsMergedFeatureRenderer::InvertOnly
@ InvertOnly
Invert features only (polygons only)
Definition: qgsmergedfeaturerenderer.h:135
qgsinvertedpolygonrenderer.h
QgsMergedFeatureRenderer
QgsMergedFeatureRenderer is a polygon or line-only feature renderer used to renderer a set of feature...
Definition: qgsmergedfeaturerenderer.h:40
QgsInvertedPolygonRenderer::setPreprocessingEnabled
void setPreprocessingEnabled(bool enabled)
Definition: qgsinvertedpolygonrenderer.h:89
qgslogger.h
QgsMergedFeatureRenderer::mSubRenderer
std::unique_ptr< QgsFeatureRenderer > mSubRenderer
Embedded renderer.
Definition: qgsmergedfeaturerenderer.h:143
QgsFeatureRenderer::embeddedRenderer
virtual const QgsFeatureRenderer * embeddedRenderer() const
Returns the current embedded renderer (subrenderer) for this feature renderer.
Definition: qgsrenderer.cpp:484
qgssymbol.h
qgsstyleentityvisitor.h
QgsInvertedPolygonRenderer
QgsInvertedPolygonRenderer is a polygon-only feature renderer used to display features inverted,...
Definition: qgsinvertedpolygonrenderer.h:42