Skip to content
Permalink
Browse files

[FEATURE] Null ("No symbol") renderer

Using this renderer no symbol will be drawn for features, but labeling,
diagrams and other non-symbol parts will still be shown.

Selections can still be made on the layer in the canvas and selected
features will be rendered with a default symbol. Features being edited
will also be shown.

This is intended as a handy shortcut for layers which you only want
to show labels or diagrams for, and avoids the need to render
symbols with totally transparent fill/border to achieve this.

(fix #12131)
  • Loading branch information
nyalldawson committed Apr 6, 2016
1 parent 86ec27e commit d464f862903184e94e01e4963e82e337efc4a388
@@ -36,6 +36,7 @@ PyQgsLocalServer
PyQgsMapUnitScale
PyQgsMemoryProvider
PyQgsNetworkContentFetcher
PyQgsNullSymbolRenderer
PyQgsPalLabelingBase
PyQgsPalLabelingCanvas
PyQgsPalLabelingComposer
@@ -486,6 +486,7 @@
<file>themes/default/rendererCategorizedSymbol.svg</file>
<file>themes/default/rendererGraduatedSymbol.png</file>
<file>themes/default/rendererGraduatedSymbol.svg</file>
<file>themes/default/rendererNullSymbol.svg</file>
<file>themes/default/rendererSingleSymbol.png</file>
<file>themes/default/rendererSingleSymbol.svg</file>
<file>themes/default/rendererRuleBasedSymbol.svg</file>
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->

<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="16"
height="16"
viewBox="0 0 16 16"
id="svg2"
version="1.1"
inkscape:version="0.48.5 r10040"
sodipodi:docname="rendererNullSymbol.svg">
<defs
id="defs4" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="22.4"
inkscape:cx="2.4669783"
inkscape:cy="9.4206202"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="true"
units="px"
inkscape:window-width="1659"
inkscape:window-height="908"
inkscape:window-x="65"
inkscape:window-y="24"
inkscape:window-maximized="1">
<inkscape:grid
type="xygrid"
id="grid4136"
dotted="true" />
</sodipodi:namedview>
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title />
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(0,-1036.3622)">
<rect
style="opacity:1;fill:none;fill-opacity:1;stroke:#000000;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:1, 1;stroke-dashoffset:0.50000000000000000;stroke-opacity:0.31050229"
id="rect4138"
width="10"
height="3"
x="2.5"
y="1037.8622" />
<rect
style="opacity:1;fill:none;fill-opacity:1;stroke:#000000;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:1, 1;stroke-dashoffset:0.50000000000000000;stroke-opacity:0.31050229"
id="rect4138-0"
width="10"
height="3"
x="4.5"
y="1042.8622" />
<rect
style="opacity:1;fill:none;fill-opacity:1;stroke:#000000;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:1, 1;stroke-dashoffset:0.50000000000000000;stroke-opacity:0.31050229"
id="rect4138-0-6"
width="10"
height="3"
x="2.5"
y="1047.8622" />
</g>
</svg>
@@ -289,6 +289,7 @@
%Include symbology-ng/qgsheatmaprenderer.sip
%Include symbology-ng/qgsinvertedpolygonrenderer.sip
%Include symbology-ng/qgslegendsymbolitemv2.sip
%Include symbology-ng/qgsnullsymbolrenderer.sip
%Include symbology-ng/qgspointdisplacementrenderer.sip
%Include symbology-ng/qgsrendererv2.sip
%Include symbology-ng/qgsrendererv2registry.sip
@@ -0,0 +1,46 @@
/** \ingroup core
* \class QgsNullSymbolRenderer
* \brief Null symbol renderer. Renderer which draws no symbols for features by default, but allows for labeling
* and diagrams for the layer. Selected features will also be drawn with a default symbol.
* \note Added in version 2.16
*/

class QgsNullSymbolRenderer : QgsFeatureRendererV2
{
%TypeHeaderCode
#include <qgsnullsymbolrenderer.h>
%End
public:

QgsNullSymbolRenderer();

virtual ~QgsNullSymbolRenderer();

virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature, QgsRenderContext& context );
virtual QgsSymbolV2* originalSymbolForFeature( QgsFeature& feature, QgsRenderContext& context );

virtual bool renderFeature( QgsFeature& feature, QgsRenderContext& context, int layer = -1, bool selected = false, bool drawVertexMarker = false );
virtual void startRender( QgsRenderContext& context, const QgsFields& fields );
virtual void stopRender( QgsRenderContext& context );
virtual bool willRenderFeature( QgsFeature& feat, QgsRenderContext& context );

virtual QList<QString> usedAttributes();
virtual QString dump() const;
virtual QgsFeatureRendererV2* clone() const /Factory/;
virtual QgsSymbolV2List symbols( QgsRenderContext& context ) /PyName=symbols2/;

/** Creates a null renderer from XML element.
* @param element DOM element
* @returns new null symbol renderer
*/
static QgsFeatureRendererV2* create( QDomElement& element ) /Factory/;

virtual QDomElement save( QDomDocument& doc );

/** Creates a QgsNullSymbolRenderer from an existing renderer.
* @param renderer renderer to convert from
* @returns a new renderer if the conversion was possible, otherwise nullptr.
*/
static QgsNullSymbolRenderer* convertFromRenderer( const QgsFeatureRendererV2 *renderer ) /Factory/;

};
@@ -50,6 +50,8 @@ class QgsFeatureRendererV2
sipType = sipType_QgsPointDisplacementRenderer;
else if (sipCpp->type() == "25dRenderer")
sipType = sipType_Qgs25DRenderer;
else if (sipCpp->type() == "nullSymbol")
sipType = sipType_QgsNullSymbolRenderer;
else
sipType = 0;
%End
@@ -208,6 +208,7 @@
%Include symbology-ng/qgsheatmaprendererwidget.sip
%Include symbology-ng/qgsinvertedpolygonrendererwidget.sip
%Include symbology-ng/qgslayerpropertieswidget.sip
%Include symbology-ng/qgsnullsymbolrendererwidget.sip
%Include symbology-ng/qgspenstylecombobox.sip
%Include symbology-ng/qgspointdisplacementrendererwidget.sip
%Include symbology-ng/qgsrendererv2propertiesdialog.sip
@@ -0,0 +1,24 @@
/** \ingroup gui
* \class QgsNullSymbolRendererWidget
* \brief Blank widget for customising QgsNullSymbolRenderer.
* \note Added in version 2.16
*/

class QgsNullSymbolRendererWidget : QgsRendererV2Widget
{
%TypeHeaderCode
#include <qgsnullsymbolrendererwidget.h>
%End

public:

//! Creates a new QgsNullSymbolRendererWidget object
static QgsRendererV2Widget* create( QgsVectorLayer* layer, QgsStyleV2* style, QgsFeatureRendererV2* renderer ) /Factory/;

//! Constructor for QgsNullSymbolRendererWidget
QgsNullSymbolRendererWidget( QgsVectorLayer* layer, QgsStyleV2* style, QgsFeatureRendererV2* renderer );
~QgsNullSymbolRendererWidget();

//! Returns a pointer to the configured renderer
virtual QgsFeatureRendererV2* renderer();
};
@@ -28,6 +28,7 @@ SET(QGIS_CORE_SRCS
symbology-ng/qgslegendsymbolitemv2.cpp
symbology-ng/qgslinesymbollayerv2.cpp
symbology-ng/qgsmarkersymbollayerv2.cpp
symbology-ng/qgsnullsymbolrenderer.cpp
symbology-ng/qgspointdisplacementrenderer.cpp
symbology-ng/qgsrendererv2.cpp
symbology-ng/qgsrendererv2registry.cpp
@@ -796,6 +797,7 @@ SET(QGIS_CORE_HDRS
symbology-ng/qgssinglesymbolrendererv2.h
symbology-ng/qgsheatmaprenderer.h
symbology-ng/qgsinvertedpolygonrenderer.h
symbology-ng/qgsnullsymbolrenderer.h
symbology-ng/qgssymbollayerv2.h
symbology-ng/qgssymbollayerv2registry.h
symbology-ng/qgssymbollayerv2utils.h
@@ -0,0 +1,125 @@
/***************************************************************************
qgsnullsymbolrenderer.cpp
---------------------
begin : November 2014
copyright : (C) 2014 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgsnullsymbolrenderer.h"
#include "qgssymbolv2.h"

#include <QDomDocument>
#include <QDomElement>

QgsNullSymbolRenderer::QgsNullSymbolRenderer()
: QgsFeatureRendererV2( "nullSymbol" )
{
}

QgsNullSymbolRenderer::~QgsNullSymbolRenderer()
{
}

QgsSymbolV2* QgsNullSymbolRenderer::symbolForFeature( QgsFeature& , QgsRenderContext& )
{
return nullptr;
}

QgsSymbolV2* QgsNullSymbolRenderer::originalSymbolForFeature( QgsFeature&, QgsRenderContext& )
{
return nullptr;
}

bool QgsNullSymbolRenderer::renderFeature( QgsFeature &feature, QgsRenderContext &context, int layer, bool selected, bool drawVertexMarker )
{
//render selected features or features being edited only
if ( !selected && !drawVertexMarker )
{
return true;
}

if ( !feature.constGeometry() ||
feature.constGeometry()->type() == QGis::NoGeometry ||
feature.constGeometry()->type() == QGis::UnknownGeometry )
return true;

if ( mSymbol.isNull() )
{
//create default symbol
mSymbol.reset( QgsSymbolV2::defaultSymbol( feature.constGeometry()->type() ) );
mSymbol->startRender( context );
}

mSymbol->renderFeature( feature, context, layer, selected, drawVertexMarker, mCurrentVertexMarkerType, mCurrentVertexMarkerSize );

return true;
}

void QgsNullSymbolRenderer::startRender( QgsRenderContext& context, const QgsFields& fields )
{
Q_UNUSED( context );
Q_UNUSED( fields );
}

void QgsNullSymbolRenderer::stopRender( QgsRenderContext& context )
{
if ( mSymbol.data() )
{
mSymbol->stopRender( context );
}
}

bool QgsNullSymbolRenderer::willRenderFeature( QgsFeature&, QgsRenderContext& )
{
//return true for every feature - so they are still selectable
return true;
}

QList<QString> QgsNullSymbolRenderer::usedAttributes()
{
return QList<QString>();
}

QString QgsNullSymbolRenderer::dump() const
{
return QString( "NULL" );
}

QgsFeatureRendererV2* QgsNullSymbolRenderer::clone() const
{
QgsNullSymbolRenderer* r = new QgsNullSymbolRenderer();
return r;
}

QgsSymbolV2List QgsNullSymbolRenderer::symbols( QgsRenderContext& )
{
return QgsSymbolV2List();
}

QgsFeatureRendererV2* QgsNullSymbolRenderer::create( QDomElement& element )
{
Q_UNUSED( element );
QgsNullSymbolRenderer* r = new QgsNullSymbolRenderer();
return r;
}

QDomElement QgsNullSymbolRenderer::save( QDomDocument& doc )
{
QDomElement rendererElem = doc.createElement( RENDERER_TAG_NAME );
rendererElem.setAttribute( "type", "nullSymbol" );
return rendererElem;
}

QgsNullSymbolRenderer* QgsNullSymbolRenderer::convertFromRenderer( const QgsFeatureRendererV2 *renderer )
{
Q_UNUSED( renderer );
return new QgsNullSymbolRenderer();
}

0 comments on commit d464f86

Please sign in to comment.
You can’t perform that action at this time.