Skip to content

Commit efb84ea

Browse files
committedApr 18, 2016
[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
1 parent e9c41e8 commit efb84ea

25 files changed

+966
-127
lines changed
 

‎images/images.qrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,7 @@
576576
<file>icons/qgis-icon-60x60_xmas.png</file>
577577
<file>themes/default/mActionTracing.png</file>
578578
<file>themes/default/vector_grid.png</file>
579+
<file>themes/default/legend.svg</file>
579580
<file>themes/default/multieditChangedValues.svg</file>
580581
<file>themes/default/multieditMixedValues.svg</file>
581582
<file>themes/default/multieditSameValues.svg</file>

‎images/themes/default/legend.svg

Lines changed: 258 additions & 0 deletions
Loading

‎python/core/diagram/qgsdiagram.sip

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ class QgsDiagram
3333
/** Returns the size in map units the diagram will use to render. Interpolate size*/
3434
virtual QSizeF diagramSize( const QgsFeature& feature, const QgsRenderContext& c, const QgsDiagramSettings& s, const QgsDiagramInterpolationSettings& is ) = 0;
3535

36+
/** Returns the size of the legend item for the diagram corresponding to a specified value.
37+
* @param value value to return legend item size for
38+
* @param s diagram settings
39+
* @param is interpolation settings
40+
* @note added in QGIS 2.16
41+
*/
42+
virtual double legendSize( double value, const QgsDiagramSettings& s, const QgsDiagramInterpolationSettings& is ) const = 0;
43+
3644
protected:
3745
QgsDiagram();
3846
QgsDiagram( const QgsDiagram& other );
@@ -69,4 +77,12 @@ class QgsDiagram
6977
* @return The properly scaled font for rendering
7078
*/
7179
QFont scaledFont( const QgsDiagramSettings& s, const QgsRenderContext& c );
80+
81+
/** Returns the scaled size of a diagram for a value, respecting the specified diagram interpolation settings.
82+
* @param value value to calculate corresponding circular size for
83+
* @param s diagram settings
84+
* @param is interpolation settings
85+
* @note added in QGIS 2.16
86+
*/
87+
QSizeF sizeForValue( double value, const QgsDiagramSettings& s, const QgsDiagramInterpolationSettings& is ) const;
7288
};

‎python/core/diagram/qgshistogramdiagram.sip

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ class QgsHistogramDiagram: QgsDiagram
1313

1414
QSizeF diagramSize( const QgsAttributes& attributes, const QgsRenderContext& c, const QgsDiagramSettings& s );
1515
QSizeF diagramSize( const QgsFeature& feature, const QgsRenderContext& c, const QgsDiagramSettings& s, const QgsDiagramInterpolationSettings& is );
16+
double legendSize( double value, const QgsDiagramSettings& s, const QgsDiagramInterpolationSettings& is ) const;
1617
QString diagramName() const;
1718
};

‎python/core/diagram/qgspiediagram.sip

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ class QgsPieDiagram: QgsDiagram
1313

1414
QSizeF diagramSize( const QgsAttributes& attributes, const QgsRenderContext& c, const QgsDiagramSettings& s );
1515
QSizeF diagramSize( const QgsFeature& feature, const QgsRenderContext& c, const QgsDiagramSettings& s, const QgsDiagramInterpolationSettings& is );
16+
double legendSize( double value, const QgsDiagramSettings& s, const QgsDiagramInterpolationSettings& is ) const;
1617
QString diagramName() const;
1718
};

‎python/core/diagram/qgstextdiagram.sip

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class QgsTextDiagram: QgsDiagram
2626

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

3031
QString diagramName() const;
3132
};

‎python/core/qgsdiagramrendererv2.sip

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,56 @@ class QgsDiagramRendererV2
410410
*/
411411
virtual QList< QgsLayerTreeModelLegendNode* > legendItems( QgsLayerTreeLayer* nodeLayer ) const /Factory/;
412412

413+
/** Returns true if renderer will show legend items for diagram attributes.
414+
* @note added in QGIS 2.16
415+
* @see setAttributeLegend()
416+
* @see sizeLegend()
417+
*/
418+
bool attributeLegend() const;
419+
420+
/** Sets whether the renderer will show legend items for diagram attributes.
421+
* @param enabled set to true to show diagram attribute legend
422+
* @note added in QGIS 2.16
423+
* @see attributeLegend()
424+
* @see setSizeLegend()
425+
*/
426+
void setAttributeLegend( bool enabled );
427+
428+
/** Returns true if renderer will show legend items for diagram sizes.
429+
* @note added in QGIS 2.16
430+
* @see setSizeLegend()
431+
* @see attributeLegend()
432+
* @see sizeLegendSymbol()
433+
*/
434+
bool sizeLegend() const;
435+
436+
/** Sets whether the renderer will show legend items for diagram sizes.
437+
* @param enabled set to true to show diagram size legend
438+
* @note added in QGIS 2.16
439+
* @see sizeLegend()
440+
* @see setAttributeLegend()
441+
* @see setSizeLegendSymbol()
442+
*/
443+
void setSizeLegend( bool enabled );
444+
445+
/** Returns the marker symbol used for rendering the diagram size legend.
446+
* @note added in QGIS 2.16
447+
* @see setSizeLegendSymbol()
448+
* @see sizeLegend()
449+
*/
450+
QgsMarkerSymbolV2* sizeLegendSymbol() const;
451+
452+
/** Sets the marker symbol used for rendering the diagram size legend.
453+
* @param symbol marker symbol, ownership is transferred to the renderer.
454+
* @note added in QGIS 2.16
455+
* @see sizeLegendSymbol()
456+
* @see setSizeLegend()
457+
*/
458+
void setSizeLegendSymbol( QgsMarkerSymbolV2* symbol /Transfer/ );
459+
413460
protected:
461+
QgsDiagramRendererV2( const QgsDiagramRendererV2& other );
462+
//QgsDiagramRendererV2& operator=( const QgsDiagramRendererV2& other );
414463

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

0 commit comments

Comments
 (0)
Please sign in to comment.