Skip to content

Commit

Permalink
[FEATURE][diagrams] Add optional legend entries for diagram sizes
Browse files Browse the repository at this point in the history
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 efb84ea
Show file tree
Hide file tree
Showing 25 changed files with 966 additions and 127 deletions.
1 change: 1 addition & 0 deletions images/images.qrc
Expand Up @@ -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>
Expand Down
258 changes: 258 additions & 0 deletions images/themes/default/legend.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions python/core/diagram/qgsdiagram.sip
Expand Up @@ -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 );
Expand Down Expand Up @@ -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;
};
1 change: 1 addition & 0 deletions python/core/diagram/qgshistogramdiagram.sip
Expand Up @@ -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;
};
1 change: 1 addition & 0 deletions python/core/diagram/qgspiediagram.sip
Expand Up @@ -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;
};
1 change: 1 addition & 0 deletions python/core/diagram/qgstextdiagram.sip
Expand Up @@ -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;
};
49 changes: 49 additions & 0 deletions python/core/qgsdiagramrendererv2.sip
Expand Up @@ -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
Expand Down

0 comments on commit efb84ea

Please sign in to comment.