QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 {
30  return nullptr;
31 }
32 
34 {
35  return nullptr;
36 }
37 
38 bool QgsNullSymbolRenderer::renderFeature( const QgsFeature &feature, QgsRenderContext &context, int layer, bool selected, bool drawVertexMarker )
39 {
40  //render selected features or features being edited only
41  if ( !selected && !drawVertexMarker )
42  {
43  return true;
44  }
45 
46  if ( !feature.hasGeometry() ||
47  feature.geometry().type() == QgsWkbTypes::NullGeometry ||
49  return true;
50 
51  if ( !mSymbol )
52  {
53  //create default symbol
54  mSymbol.reset( QgsSymbol::defaultSymbol( feature.geometry().type() ) );
55  mSymbol->startRender( context );
56  }
57 
58  mSymbol->renderFeature( feature, context, layer, selected, drawVertexMarker, mCurrentVertexMarkerType, mCurrentVertexMarkerSize );
59 
60  return true;
61 }
62 
64 {
66 
67  if ( mSymbol )
68  {
69  mSymbol->stopRender( context );
70  }
71 }
72 
74 {
75  //return true for every feature - so they are still selectable
76  return true;
77 }
78 
80 {
81  return QSet<QString>();
82 }
83 
85 {
86  return QStringLiteral( "NULL" );
87 }
88 
90 {
92  return r;
93 }
94 
96 {
97  return QgsSymbolList();
98 }
99 
101 {
102  Q_UNUSED( element )
103  Q_UNUSED( context )
105  return r;
106 }
107 
108 QDomElement QgsNullSymbolRenderer::save( QDomDocument &doc, const QgsReadWriteContext &context )
109 {
110  Q_UNUSED( context )
111  QDomElement rendererElem = doc.createElement( RENDERER_TAG_NAME );
112  rendererElem.setAttribute( QStringLiteral( "type" ), QStringLiteral( "nullSymbol" ) );
113  return rendererElem;
114 }
115 
117 {
118  Q_UNUSED( renderer )
119  return new QgsNullSymbolRenderer();
120 }
QgsNullSymbolRenderer::usedAttributes
QSet< QString > usedAttributes(const QgsRenderContext &context) const override
Returns a list of attributes required by this renderer.
Definition: qgsnullsymbolrenderer.cpp:79
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:38
QgsFeatureRenderer::mCurrentVertexMarkerSize
double mCurrentVertexMarkerSize
The current size of editing marker.
Definition: qgsrenderer.h:527
qgsnullsymbolrenderer.h
QgsReadWriteContext
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:301
QgsNullSymbolRenderer::clone
QgsFeatureRenderer * clone() const override
Create a deep copy of this renderer.
Definition: qgsnullsymbolrenderer.cpp:89
QgsWkbTypes::NullGeometry
@ NullGeometry
Definition: qgswkbtypes.h:145
QgsNullSymbolRenderer::dump
QString dump() const override
Returns debug information about this renderer.
Definition: qgsnullsymbolrenderer.cpp:84
QgsFeature::geometry
QgsGeometry geometry
Definition: qgsfeature.h:71
QgsRenderContext
Definition: qgsrendercontext.h:57
QgsSymbol
Definition: qgssymbol.h:63
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:107
QgsNullSymbolRenderer::QgsNullSymbolRenderer
QgsNullSymbolRenderer()
Definition: qgsnullsymbolrenderer.cpp:23
QgsFeatureRenderer::mCurrentVertexMarkerType
int mCurrentVertexMarkerType
The current type of editing marker.
Definition: qgsrenderer.h:525
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:63
QgsSymbolList
QList< QgsSymbol * > QgsSymbolList
Definition: qgsrenderer.h:45
QgsNullSymbolRenderer::convertFromRenderer
static QgsNullSymbolRenderer * convertFromRenderer(const QgsFeatureRenderer *renderer)
Creates a QgsNullSymbolRenderer from an existing renderer.
Definition: qgsnullsymbolrenderer.cpp:116
RENDERER_TAG_NAME
#define RENDERER_TAG_NAME
Definition: qgsrenderer.h:51
QgsNullSymbolRenderer::willRenderFeature
bool willRenderFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Returns whether the renderer will render a feature or not.
Definition: qgsnullsymbolrenderer.cpp:73
QgsNullSymbolRenderer::originalSymbolForFeature
QgsSymbol * originalSymbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Returns symbol for feature.
Definition: qgsnullsymbolrenderer.cpp:33
QgsNullSymbolRenderer::create
static QgsFeatureRenderer * create(QDomElement &element, const QgsReadWriteContext &context)
Creates a null renderer from XML element.
Definition: qgsnullsymbolrenderer.cpp:100
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
store renderer info to XML element
Definition: qgsnullsymbolrenderer.cpp:108
qgsgeometry.h
QgsFeatureRenderer
Definition: qgsrenderer.h:102
QgsFeature::hasGeometry
bool hasGeometry() const
Returns true if the feature has an associated geometry.
Definition: qgsfeature.cpp:197
QgsNullSymbolRenderer::symbols
QgsSymbolList symbols(QgsRenderContext &context) const override
Returns list of symbols used by the renderer.
Definition: qgsnullsymbolrenderer.cpp:95
QgsWkbTypes::UnknownGeometry
@ UnknownGeometry
Definition: qgswkbtypes.h:144
QgsFeature
Definition: qgsfeature.h:55
QgsNullSymbolRenderer::symbolForFeature
QgsSymbol * symbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
To be overridden.
Definition: qgsnullsymbolrenderer.cpp:28
QgsGeometry::type
QgsWkbTypes::GeometryType type
Definition: qgsgeometry.h:126
qgssymbol.h