QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 "qgssymbolv2.h"
18 
19 #include <QDomDocument>
20 #include <QDomElement>
21 
23  : QgsFeatureRendererV2( "nullSymbol" )
24 {
25 }
26 
28 {
29 }
30 
32 {
33  return nullptr;
34 }
35 
37 {
38  return nullptr;
39 }
40 
41 bool QgsNullSymbolRenderer::renderFeature( QgsFeature &feature, QgsRenderContext &context, int layer, bool selected, bool drawVertexMarker )
42 {
43  //render selected features or features being edited only
44  if ( !selected && !drawVertexMarker )
45  {
46  return true;
47  }
48 
49  if ( !feature.constGeometry() ||
50  feature.constGeometry()->type() == QGis::NoGeometry ||
51  feature.constGeometry()->type() == QGis::UnknownGeometry )
52  return true;
53 
54  if ( mSymbol.isNull() )
55  {
56  //create default symbol
57  mSymbol.reset( QgsSymbolV2::defaultSymbol( feature.constGeometry()->type() ) );
58  mSymbol->startRender( context );
59  }
60 
61  mSymbol->renderFeature( feature, context, layer, selected, drawVertexMarker, mCurrentVertexMarkerType, mCurrentVertexMarkerSize );
62 
63  return true;
64 }
65 
67 {
68  Q_UNUSED( context );
69  Q_UNUSED( fields );
70 }
71 
73 {
74  if ( mSymbol.data() )
75  {
76  mSymbol->stopRender( context );
77  }
78 }
79 
81 {
82  //return true for every feature - so they are still selectable
83  return true;
84 }
85 
87 {
88  return QList<QString>();
89 }
90 
92 {
93  return QString( "NULL" );
94 }
95 
97 {
99  return r;
100 }
101 
103 {
104  return QgsSymbolV2List();
105 }
106 
108 {
109  Q_UNUSED( element );
111  return r;
112 }
113 
115 {
116  QDomElement rendererElem = doc.createElement( RENDERER_TAG_NAME );
117  rendererElem.setAttribute( "type", "nullSymbol" );
118  return rendererElem;
119 }
120 
122 {
123  Q_UNUSED( renderer );
124  return new QgsNullSymbolRenderer();
125 }
#define RENDERER_TAG_NAME
Definition: qgsrendererv2.h:49
static QgsNullSymbolRenderer * convertFromRenderer(const QgsFeatureRendererV2 *renderer)
Creates a QgsNullSymbolRenderer from an existing renderer.
QList< QgsSymbolV2 * > QgsSymbolV2List
Definition: qgsrendererv2.h:40
virtual QString dump() const override
for debugging
Container of fields for a vector layer.
Definition: qgsfield.h:252
const QgsGeometry * constGeometry() const
Gets a const pointer to the geometry object associated with this feature.
Definition: qgsfeature.cpp:82
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:187
void reset(T *other)
virtual QgsFeatureRendererV2 * clone() const override
virtual QgsSymbolV2 * symbolForFeature(QgsFeature &feature, QgsRenderContext &context) override
To be overridden.
Null symbol renderer.
int mCurrentVertexMarkerSize
The current size of editing marker.
void setAttribute(const QString &name, const QString &value)
static QgsFeatureRendererV2 * create(QDomElement &element)
Creates a null renderer from XML element.
virtual bool willRenderFeature(QgsFeature &feat, QgsRenderContext &context) override
Returns whether the renderer will render a feature or not.
int mCurrentVertexMarkerType
The current type of editing marker.
virtual Q_DECL_DEPRECATED QgsSymbolV2List symbols()
For symbol levels.
QGis::GeometryType type() const
Returns type of the geometry as a QGis::GeometryType.
virtual bool renderFeature(QgsFeature &feature, QgsRenderContext &context, int layer=-1, bool selected=false, bool drawVertexMarker=false) override
Render a feature using this renderer in the given context.
T * data() const
bool isNull() const
Contains information about the context of a rendering operation.
virtual QgsSymbolV2 * originalSymbolForFeature(QgsFeature &feature, QgsRenderContext &context) override
Return symbol for feature.
static QgsSymbolV2 * defaultSymbol(QGis::GeometryType geomType)
return new default symbol for specified geometry type
virtual void stopRender(QgsRenderContext &context) override
Needs to be called when a render cycle has finished to clean up.
virtual QList< QString > usedAttributes() override
Returns a set of attributes required for this renderer.
QDomElement createElement(const QString &tagName)
virtual void startRender(QgsRenderContext &context, const QgsFields &fields) override
Needs to be called when a new render cycle is started.
virtual QDomElement save(QDomDocument &doc) override
store renderer info to XML element