Skip to content
Permalink
Browse files

[FEATURE][diagrams] Add optional legend entries for diagram sizes

A new "legend" tab has been added to diagram properties, allowing
both the existing attribute legend and a new size legend to be
enabled/disabled. The size legend has a configurable marker
symbol.

Also includes unit tests for both diagram attribute and size
legends.

Sponsored by ADUGA
  • Loading branch information
nyalldawson committed Apr 18, 2016
1 parent e9c41e8 commit efb84ea2fabb31e41c1d4f1bf7e6acf9c4d021e4
@@ -576,6 +576,7 @@
<file>icons/qgis-icon-60x60_xmas.png</file>
<file>themes/default/mActionTracing.png</file>
<file>themes/default/vector_grid.png</file>
<file>themes/default/legend.svg</file>
<file>themes/default/multieditChangedValues.svg</file>
<file>themes/default/multieditMixedValues.svg</file>
<file>themes/default/multieditSameValues.svg</file>
@@ -0,0 +1,258 @@
<?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="24"
height="24"
id="svg5692"
version="1.1"
inkscape:version="0.91 r13725"
sodipodi:docname="mLegend.svg"
inkscape:export-filename="/home/denis/Desktop/oracle.png"
inkscape:export-xdpi="67.5"
inkscape:export-ydpi="67.5">
<title
id="title2829">GIS icon theme 0.2</title>
<defs
id="defs5694">
<inkscape:perspective
sodipodi:type="inkscape:persp3d"
inkscape:vp_x="0 : 16 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_z="32 : 16 : 1"
inkscape:persp3d-origin="16 : 10.666667 : 1"
id="perspective3486" />
<inkscape:perspective
id="perspective3496"
inkscape:persp3d-origin="0.5 : 0.33333333 : 1"
inkscape:vp_z="1 : 0.5 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_x="0 : 0.5 : 1"
sodipodi:type="inkscape:persp3d" />
<inkscape:perspective
id="perspective3600"
inkscape:persp3d-origin="0.5 : 0.33333333 : 1"
inkscape:vp_z="1 : 0.5 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_x="0 : 0.5 : 1"
sodipodi:type="inkscape:persp3d" />
<inkscape:perspective
id="perspective7871"
inkscape:persp3d-origin="0.5 : 0.33333333 : 1"
inkscape:vp_z="1 : 0.5 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_x="0 : 0.5 : 1"
sodipodi:type="inkscape:persp3d" />
<inkscape:perspective
id="perspective8710"
inkscape:persp3d-origin="0.5 : 0.33333333 : 1"
inkscape:vp_z="1 : 0.5 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_x="0 : 0.5 : 1"
sodipodi:type="inkscape:persp3d" />
<inkscape:perspective
id="perspective9811"
inkscape:persp3d-origin="0.5 : 0.33333333 : 1"
inkscape:vp_z="1 : 0.5 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_x="0 : 0.5 : 1"
sodipodi:type="inkscape:persp3d" />
<inkscape:perspective
id="perspective4762"
inkscape:persp3d-origin="0.5 : 0.33333333 : 1"
inkscape:vp_z="1 : 0.5 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_x="0 : 0.5 : 1"
sodipodi:type="inkscape:persp3d" />
<filter
y="-0.25"
x="-0.25"
height="1.5"
width="1.5"
inkscape:label="Drop shadow"
id="filter4128"
color-interpolation-filters="sRGB">
<feGaussianBlur
result="blur"
stdDeviation="2.000000"
in="SourceAlpha"
id="feGaussianBlur4130" />
<feColorMatrix
values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0.351000 0 "
type="matrix"
result="bluralpha"
id="feColorMatrix4132" />
<feOffset
result="offsetBlur"
dy="7.500000"
dx="7.500000"
in="bluralpha"
id="feOffset4134" />
<feMerge
id="feMerge4136">
<feMergeNode
in="offsetBlur"
id="feMergeNode4138" />
<feMergeNode
in="SourceGraphic"
id="feMergeNode4140" />
</feMerge>
</filter>
<inkscape:perspective
id="perspective2850"
inkscape:persp3d-origin="270.04437 : 185.57625 : 1"
inkscape:vp_z="540.08875 : 278.36438 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_x="0 : 278.36438 : 1"
sodipodi:type="inkscape:persp3d" />
<inkscape:perspective
id="perspective2491"
inkscape:persp3d-origin="270.04437 : 185.57625 : 1"
inkscape:vp_z="540.08875 : 278.36438 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_x="0 : 278.36438 : 1"
sodipodi:type="inkscape:persp3d" />
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="31.875"
inkscape:cx="4.3254767"
inkscape:cy="17.604737"
inkscape:current-layer="layer2"
showgrid="true"
inkscape:grid-bbox="true"
inkscape:document-units="px"
borderlayer="false"
inkscape:window-width="1855"
inkscape:window-height="1056"
inkscape:window-x="65"
inkscape:window-y="24"
inkscape:window-maximized="1"
inkscape:snap-global="true"
showguides="true"
inkscape:guide-bbox="true"
inkscape:snap-object-midpoints="false"
inkscape:snap-grids="true"
inkscape:object-paths="false">
<inkscape:grid
type="xygrid"
id="grid5700"
empspacing="5"
visible="true"
enabled="true"
snapvisiblegridlinesonly="true"
dotted="true"
originx="0"
originy="0" />
</sodipodi:namedview>
<metadata
id="metadata5697">
<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>GIS icon theme 0.2</dc:title>
<dc:creator>
<cc:Agent>
<dc:title>Robert Szczepanek</dc:title>
</cc:Agent>
</dc:creator>
<dc:rights>
<cc:Agent>
<dc:title>Robert Szczepanek</dc:title>
</cc:Agent>
</dc:rights>
<dc:subject>
<rdf:Bag>
<rdf:li>GIS icons</rdf:li>
</rdf:Bag>
</dc:subject>
<dc:coverage>GIS icons</dc:coverage>
<dc:description>http://robert.szczepanek.pl/</dc:description>
<cc:license
rdf:resource="http://creativecommons.org/licenses/by-sa/3.0/" />
</cc:Work>
<cc:License
rdf:about="http://creativecommons.org/licenses/by-sa/3.0/">
<cc:permits
rdf:resource="http://creativecommons.org/ns#Reproduction" />
<cc:permits
rdf:resource="http://creativecommons.org/ns#Distribution" />
<cc:requires
rdf:resource="http://creativecommons.org/ns#Notice" />
<cc:requires
rdf:resource="http://creativecommons.org/ns#Attribution" />
<cc:permits
rdf:resource="http://creativecommons.org/ns#DerivativeWorks" />
<cc:requires
rdf:resource="http://creativecommons.org/ns#ShareAlike" />
</cc:License>
</rdf:RDF>
</metadata>
<g
inkscape:groupmode="layer"
id="layer2"
inkscape:label="Layer"
style="display:inline"
transform="translate(0,-8)">
<g
id="orginal-6"
style="fill-rule:nonzero;stroke:#415a75;stroke-miterlimit:4;stroke-opacity:1"
transform="matrix(0.04360941,0,0,0.04360941,-23.975751,6.5017873)" />
<path
inkscape:connector-curvature="0"
id="path2484"
style="fill-rule:nonzero;stroke:#415a75;stroke-width:0.13082823;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1"
d="" />
<rect
style="opacity:1;fill:#ffdd00;fill-opacity:1;stroke:#ffa600;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
id="rect4176"
width="4"
height="4"
x="3.5"
y="11.5" />
<rect
style="display:inline;opacity:1;fill:#ff4900;fill-opacity:1;stroke:#bd2c00;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
id="rect4176-2"
width="4"
height="4"
x="3.5"
y="17.5" />
<rect
style="display:inline;opacity:1;fill:#00ba58;fill-opacity:1;stroke:#005338;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
id="rect4176-6"
width="4"
height="4"
x="3.5"
y="23.5" />
<path
style="fill:none;fill-rule:evenodd;stroke:#9a9a9a;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 9,27 4,0"
id="path4225"
inkscape:connector-curvature="0" />
<path
style="display:inline;fill:none;fill-rule:evenodd;stroke:#9a9a9a;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="M 8.9999999,21 18,21"
id="path4225-3"
inkscape:connector-curvature="0" />
<path
style="display:inline;fill:none;fill-rule:evenodd;stroke:#9a9a9a;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 9,15 6,0"
id="path4225-3-9"
inkscape:connector-curvature="0" />
</g>
</svg>
@@ -33,6 +33,14 @@ class QgsDiagram
/** Returns the size in map units the diagram will use to render. Interpolate size*/
virtual QSizeF diagramSize( const QgsFeature& feature, const QgsRenderContext& c, const QgsDiagramSettings& s, const QgsDiagramInterpolationSettings& is ) = 0;

/** Returns the size of the legend item for the diagram corresponding to a specified value.
* @param value value to return legend item size for
* @param s diagram settings
* @param is interpolation settings
* @note added in QGIS 2.16
*/
virtual double legendSize( double value, const QgsDiagramSettings& s, const QgsDiagramInterpolationSettings& is ) const = 0;

protected:
QgsDiagram();
QgsDiagram( const QgsDiagram& other );
@@ -69,4 +77,12 @@ class QgsDiagram
* @return The properly scaled font for rendering
*/
QFont scaledFont( const QgsDiagramSettings& s, const QgsRenderContext& c );

/** Returns the scaled size of a diagram for a value, respecting the specified diagram interpolation settings.
* @param value value to calculate corresponding circular size for
* @param s diagram settings
* @param is interpolation settings
* @note added in QGIS 2.16
*/
QSizeF sizeForValue( double value, const QgsDiagramSettings& s, const QgsDiagramInterpolationSettings& is ) const;
};
@@ -13,5 +13,6 @@ class QgsHistogramDiagram: QgsDiagram

QSizeF diagramSize( const QgsAttributes& attributes, const QgsRenderContext& c, const QgsDiagramSettings& s );
QSizeF diagramSize( const QgsFeature& feature, const QgsRenderContext& c, const QgsDiagramSettings& s, const QgsDiagramInterpolationSettings& is );
double legendSize( double value, const QgsDiagramSettings& s, const QgsDiagramInterpolationSettings& is ) const;
QString diagramName() const;
};
@@ -13,5 +13,6 @@ class QgsPieDiagram: QgsDiagram

QSizeF diagramSize( const QgsAttributes& attributes, const QgsRenderContext& c, const QgsDiagramSettings& s );
QSizeF diagramSize( const QgsFeature& feature, const QgsRenderContext& c, const QgsDiagramSettings& s, const QgsDiagramInterpolationSettings& is );
double legendSize( double value, const QgsDiagramSettings& s, const QgsDiagramInterpolationSettings& is ) const;
QString diagramName() const;
};
@@ -26,6 +26,7 @@ class QgsTextDiagram: QgsDiagram

QSizeF diagramSize( const QgsAttributes& attributes, const QgsRenderContext& c, const QgsDiagramSettings& s );
QSizeF diagramSize( const QgsFeature& feature, const QgsRenderContext& c, const QgsDiagramSettings& s, const QgsDiagramInterpolationSettings& is );
double legendSize( double value, const QgsDiagramSettings& s, const QgsDiagramInterpolationSettings& is ) const;

QString diagramName() const;
};
@@ -410,7 +410,56 @@ class QgsDiagramRendererV2
*/
virtual QList< QgsLayerTreeModelLegendNode* > legendItems( QgsLayerTreeLayer* nodeLayer ) const /Factory/;

/** Returns true if renderer will show legend items for diagram attributes.
* @note added in QGIS 2.16
* @see setAttributeLegend()
* @see sizeLegend()
*/
bool attributeLegend() const;

/** Sets whether the renderer will show legend items for diagram attributes.
* @param enabled set to true to show diagram attribute legend
* @note added in QGIS 2.16
* @see attributeLegend()
* @see setSizeLegend()
*/
void setAttributeLegend( bool enabled );

/** Returns true if renderer will show legend items for diagram sizes.
* @note added in QGIS 2.16
* @see setSizeLegend()
* @see attributeLegend()
* @see sizeLegendSymbol()
*/
bool sizeLegend() const;

/** Sets whether the renderer will show legend items for diagram sizes.
* @param enabled set to true to show diagram size legend
* @note added in QGIS 2.16
* @see sizeLegend()
* @see setAttributeLegend()
* @see setSizeLegendSymbol()
*/
void setSizeLegend( bool enabled );

/** Returns the marker symbol used for rendering the diagram size legend.
* @note added in QGIS 2.16
* @see setSizeLegendSymbol()
* @see sizeLegend()
*/
QgsMarkerSymbolV2* sizeLegendSymbol() const;

/** Sets the marker symbol used for rendering the diagram size legend.
* @param symbol marker symbol, ownership is transferred to the renderer.
* @note added in QGIS 2.16
* @see sizeLegendSymbol()
* @see setSizeLegend()
*/
void setSizeLegendSymbol( QgsMarkerSymbolV2* symbol /Transfer/ );

protected:
QgsDiagramRendererV2( const QgsDiagramRendererV2& other );
//QgsDiagramRendererV2& operator=( const QgsDiagramRendererV2& other );

/** Returns diagram settings for a feature (or false if the diagram for the feature is not to be rendered). Used internally within renderDiagram()
* @param feature the feature

0 comments on commit efb84ea

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