QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgsnullsymbolrenderer.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsnullsymbolrenderer.cpp
3  ---------------------
4  begin : November 2014
5  copyright : (C) 2014 by Nyall Dawson
6  email : nyall dot dawson at gmail 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 
16 #include "qgsnullsymbolrenderer.h"
17 #include "qgssymbol.h"
18 #include "qgsgeometry.h"
19 
20 #include <QDomDocument>
21 #include <QDomElement>
22 
24  : QgsFeatureRenderer( QStringLiteral( "nullSymbol" ) )
25 {
26 }
27 
29 
31 {
32  return nullptr;
33 }
34 
36 {
37  return nullptr;
38 }
39 
40 bool QgsNullSymbolRenderer::renderFeature( const QgsFeature &feature, QgsRenderContext &context, int layer, bool selected, bool drawVertexMarker )
41 {
42  //render selected features or features being edited only
43  if ( !selected && !drawVertexMarker )
44  {
45  return true;
46  }
47 
48  if ( !feature.hasGeometry() ||
49  feature.geometry().type() == QgsWkbTypes::NullGeometry ||
51  return true;
52 
53  if ( !mSymbol )
54  {
55  //create default symbol
56  mSymbol.reset( QgsSymbol::defaultSymbol( feature.geometry().type() ) );
57  mSymbol->startRender( context );
58  }
59 
60  mSymbol->renderFeature( feature, context, layer, selected, drawVertexMarker, mCurrentVertexMarkerType, mCurrentVertexMarkerSize );
61 
62  return true;
63 }
64 
66 {
68 
69  if ( mSymbol )
70  {
71  mSymbol->stopRender( context );
72  }
73 }
74 
76 {
77  //return true for every feature - so they are still selectable
78  return true;
79 }
80 
82 {
83  return QSet<QString>();
84 }
85 
87 {
88  return QStringLiteral( "NULL" );
89 }
90 
92 {
94  copyRendererData( r );
95  return r;
96 }
97 
99 {
100  return QgsSymbolList();
101 }
102 
104 {
105  Q_UNUSED( element )
106  Q_UNUSED( context )
108  return r;
109 }
110 
111 QDomElement QgsNullSymbolRenderer::save( QDomDocument &doc, const QgsReadWriteContext &context )
112 {
113  Q_UNUSED( context )
114  QDomElement rendererElem = doc.createElement( RENDERER_TAG_NAME );
115  rendererElem.setAttribute( QStringLiteral( "type" ), QStringLiteral( "nullSymbol" ) );
116 
117  saveRendererData( doc, rendererElem, context );
118 
119  return rendererElem;
120 }
121 
123 {
124  std::unique_ptr< QgsNullSymbolRenderer > res = std::make_unique< QgsNullSymbolRenderer >();
125  renderer->copyRendererData( res.get() );
126  return res.release();
127 }
QgsFeatureRenderer::copyRendererData
void copyRendererData(QgsFeatureRenderer *destRenderer) const
Clones generic renderer data to another renderer.
Definition: qgsrenderer.cpp:52
QgsNullSymbolRenderer::usedAttributes
QSet< QString > usedAttributes(const QgsRenderContext &context) const override
Returns a list of attributes required by this renderer.
Definition: qgsnullsymbolrenderer.cpp:81
QgsNullSymbolRenderer::renderFeature
bool renderFeature(const QgsFeature &feature, QgsRenderContext &context, int layer=-1, bool selected=false, bool drawVertexMarker=false) override SIP_THROW(QgsCsException)
Render a feature using this renderer in the given context.
Definition: qgsnullsymbolrenderer.cpp:40
QgsFeatureRenderer::mCurrentVertexMarkerSize
double mCurrentVertexMarkerSize
The current size of editing marker.
Definition: qgsrenderer.h:603
qgsnullsymbolrenderer.h
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:34
QgsSymbol::defaultSymbol
static QgsSymbol * defaultSymbol(QgsWkbTypes::GeometryType geomType)
Returns a new default symbol for the specified geometry type.
Definition: qgssymbol.cpp:673
QgsNullSymbolRenderer::clone
QgsFeatureRenderer * clone() const override
Create a deep copy of this renderer.
Definition: qgsnullsymbolrenderer.cpp:91
QgsWkbTypes::NullGeometry
@ NullGeometry
Definition: qgswkbtypes.h:146
QgsNullSymbolRenderer::~QgsNullSymbolRenderer
~QgsNullSymbolRenderer()
QgsNullSymbolRenderer::dump
QString dump() const override
Returns debug information about this renderer.
Definition: qgsnullsymbolrenderer.cpp:86
QgsFeatureRenderer::mCurrentVertexMarkerType
Qgis::VertexMarkerType mCurrentVertexMarkerType
The current type of editing marker.
Definition: qgsrenderer.h:600
QgsFeature::geometry
QgsGeometry geometry
Definition: qgsfeature.h:71
QgsRenderContext
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:59
QgsSymbol
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:92
QgsFeatureRenderer::stopRender
virtual void stopRender(QgsRenderContext &context)
Must be called when a render cycle has finished, to allow the renderer to clean up.
Definition: qgsrenderer.cpp:110
QgsNullSymbolRenderer::QgsNullSymbolRenderer
QgsNullSymbolRenderer()
Definition: qgsnullsymbolrenderer.cpp:23
QgsNullSymbolRenderer::stopRender
void stopRender(QgsRenderContext &context) override
Must be called when a render cycle has finished, to allow the renderer to clean up.
Definition: qgsnullsymbolrenderer.cpp:65
QgsSymbolList
QList< QgsSymbol * > QgsSymbolList
Definition: qgsrenderer.h:44
QgsNullSymbolRenderer::convertFromRenderer
static QgsNullSymbolRenderer * convertFromRenderer(const QgsFeatureRenderer *renderer)
Creates a QgsNullSymbolRenderer from an existing renderer.
Definition: qgsnullsymbolrenderer.cpp:122
QgsFeatureRenderer::saveRendererData
void saveRendererData(QDomDocument &doc, QDomElement &element, const QgsReadWriteContext &context)
Saves generic renderer data into the specified element.
Definition: qgsrenderer.cpp:204
RENDERER_TAG_NAME
#define RENDERER_TAG_NAME
Definition: qgsrenderer.h:50
QgsNullSymbolRenderer::willRenderFeature
bool willRenderFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Returns whether the renderer will render a feature or not.
Definition: qgsnullsymbolrenderer.cpp:75
QgsNullSymbolRenderer::originalSymbolForFeature
QgsSymbol * originalSymbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Returns symbol for feature.
Definition: qgsnullsymbolrenderer.cpp:35
QgsNullSymbolRenderer::create
static QgsFeatureRenderer * create(QDomElement &element, const QgsReadWriteContext &context)
Creates a null renderer from XML element.
Definition: qgsnullsymbolrenderer.cpp:103
QgsNullSymbolRenderer
Null symbol renderer. Renderer which draws no symbols for features by default, but allows for labelin...
Definition: qgsnullsymbolrenderer.h:31
QgsNullSymbolRenderer::save
QDomElement save(QDomDocument &doc, const QgsReadWriteContext &context) override
Stores renderer properties to an XML element.
Definition: qgsnullsymbolrenderer.cpp:111
qgsgeometry.h
QgsFeatureRenderer
Definition: qgsrenderer.h:101
QgsFeature::hasGeometry
bool hasGeometry() const
Returns true if the feature has an associated geometry.
Definition: qgsfeature.cpp:230
QgsNullSymbolRenderer::symbols
QgsSymbolList symbols(QgsRenderContext &context) const override
Returns list of symbols used by the renderer.
Definition: qgsnullsymbolrenderer.cpp:98
QgsWkbTypes::UnknownGeometry
@ UnknownGeometry
Definition: qgswkbtypes.h:145
QgsFeature
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:55
QgsNullSymbolRenderer::symbolForFeature
QgsSymbol * symbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
To be overridden.
Definition: qgsnullsymbolrenderer.cpp:30
QgsGeometry::type
QgsWkbTypes::GeometryType type
Definition: qgsgeometry.h:128
qgssymbol.h