Skip to content
Permalink
Browse files

[FEATURE] Legend for markers with data-defined size

(Merge pull request #4752 from wonder-sk/legend-data-defined-size)
  • Loading branch information
wonder-sk committed Jun 22, 2017
2 parents df07772 + 863b7d2 commit 7cd517c6bace1530f9ade28e2571361f385ef96c
Showing with 2,176 additions and 272 deletions.
  1. +2 −1 doc/api_break.dox
  2. +1 −0 python/core/core.sip
  3. +30 −0 python/core/layertree/qgslayertreemodellegendnode.sip
  4. +177 −0 python/core/qgsdatadefinedsizelegend.sip
  5. +27 −40 python/core/qgsdiagramrenderer.sip
  6. +22 −0 python/core/symbology-ng/qgscategorizedsymbolrenderer.sip
  7. +22 −0 python/core/symbology-ng/qgsgraduatedsymbolrenderer.sip
  8. +16 −0 python/core/symbology-ng/qgslegendsymbolitem.sip
  9. +22 −0 python/core/symbology-ng/qgssinglesymbolrenderer.sip
  10. +1 −0 python/gui/gui.sip
  11. +49 −0 python/gui/symbology-ng/qgsdatadefinedsizelegendwidget.sip
  12. +6 −0 python/gui/symbology-ng/qgsrendererwidget.sip
  13. +0 −7 python/gui/symbology-ng/qgssinglesymbolrendererwidget.sip
  14. +29 −38 src/app/qgsdiagramproperties.cpp
  15. +2 −2 src/app/qgsdiagramproperties.h
  16. +2 −0 src/core/CMakeLists.txt
  17. +79 −4 src/core/layertree/qgslayertreemodellegendnode.cpp
  18. +26 −3 src/core/layertree/qgslayertreemodellegendnode.h
  19. +378 −0 src/core/qgsdatadefinedsizelegend.cpp
  20. +143 −0 src/core/qgsdatadefinedsizelegend.h
  21. +81 −25 src/core/qgsdiagramrenderer.cpp
  22. +31 −38 src/core/qgsdiagramrenderer.h
  23. +4 −2 src/core/qgsmaplayerlegend.cpp
  24. +37 −22 src/core/symbology-ng/qgscategorizedsymbolrenderer.cpp
  25. +23 −0 src/core/symbology-ng/qgscategorizedsymbolrenderer.h
  26. +35 −23 src/core/symbology-ng/qgsgraduatedsymbolrenderer.cpp
  27. +23 −0 src/core/symbology-ng/qgsgraduatedsymbolrenderer.h
  28. +12 −0 src/core/symbology-ng/qgslegendsymbolitem.cpp
  29. +21 −0 src/core/symbology-ng/qgslegendsymbolitem.h
  30. +34 −17 src/core/symbology-ng/qgssinglesymbolrenderer.cpp
  31. +23 −0 src/core/symbology-ng/qgssinglesymbolrenderer.h
  32. +2 −0 src/gui/CMakeLists.txt
  33. +23 −0 src/gui/symbology-ng/qgscategorizedsymbolrendererwidget.cpp
  34. +1 −0 src/gui/symbology-ng/qgscategorizedsymbolrendererwidget.h
  35. +217 −0 src/gui/symbology-ng/qgsdatadefinedsizelegendwidget.cpp
  36. +78 −0 src/gui/symbology-ng/qgsdatadefinedsizelegendwidget.h
  37. +23 −0 src/gui/symbology-ng/qgsgraduatedsymbolrendererwidget.cpp
  38. +1 −0 src/gui/symbology-ng/qgsgraduatedsymbolrendererwidget.h
  39. +17 −0 src/gui/symbology-ng/qgsrendererwidget.cpp
  40. +7 −0 src/gui/symbology-ng/qgsrendererwidget.h
  41. +26 −1 src/gui/symbology-ng/qgssinglesymbolrendererwidget.cpp
  42. +4 −2 src/gui/symbology-ng/qgssinglesymbolrendererwidget.h
  43. +158 −0 src/ui/qgsdatadefinedsizelegendwidget.ui
  44. +34 −44 src/ui/qgsdiagrampropertiesbase.ui
  45. +1 −0 tests/src/core/CMakeLists.txt
  46. +159 −0 tests/src/core/testqgsdatadefinedsizelegend.cpp
  47. +67 −2 tests/src/core/testqgslegendrenderer.cpp
  48. +0 −1 tests/src/python/test_qgsvectorlayer.py
  49. BIN .../testdata/control_images/data_defined_size_legend/expected_basic_bottom/expected_basic_bottom.png
  50. BIN .../testdata/control_images/data_defined_size_legend/expected_basic_center/expected_basic_center.png
  51. BIN tests/testdata/control_images/data_defined_size_legend/expected_crowded/expected_crowded.png
  52. BIN ...egend/expected_legend_data_defined_size_collapsed/expected_legend_data_defined_size_collapsed.png
@@ -987,7 +987,7 @@ QgsDiagramRenderer {#qgis_api_break_3_0_QgsDiagramRenderer}
- renderDiagram() now takes an optional data defined overrides collection argument.
- readXml(), _readXml(), writeXml(), _writeXml() do not take QgsVectorLayer as an argument anymore.
- readXml(), _readXml(), writeXml(), _writeXml() require a new argument: a reference to QgsReadWriteContext

- sizeLegend(), setSizeLegend(), sizeLegendSymbol() and setSizeLegendSymbol() have been replaced by dataDefinedSizeLegend() and setDataDefinedSizeLegend() methods in QgsLinearlyInterpolatedDiagramRenderer.


QgsDiagramLayerSettings {#qgis_api_break_3_0_QgsDiagramLayerSettings}
@@ -2110,6 +2110,7 @@ QgsSingleSymbolRendererWidget {#qgis_api_break_3_0_QgsSingleSymbolRendere

- sizeScaleFieldChanged() and scaleMethodChanged() were removed. These settings are no longer exposed in the widget's GUI.
- The Mode enum was removed.
- changeSingleSymbol() and showSymbolLevels() slots were made private.

QgsSlider {#qgis_api_break_3_0_QgsSlider}
---------
@@ -36,6 +36,7 @@
%Include qgscoordinatetransform.sip
%Include qgscredentials.sip
%Include qgscrscache.sip
%Include qgsdatadefinedsizelegend.sip
%Include qgsdataitem.sip
%Include qgsdataitemprovider.sip
%Include qgsdataitemproviderregistry.sip
@@ -151,6 +151,12 @@ Emitted on internal data change so the layer tree model can forward the signal t
Construct the node with pointer to its parent layer node
%End

QgsRenderContext *createTemporaryRenderContext() const /Factory/;
%Docstring
Returns a temporary context or null if legendMapViewData are not valid
:rtype: QgsRenderContext
%End

protected:
};

@@ -371,6 +377,30 @@ class QgsWmsLegendNode : QgsLayerTreeModelLegendNode

};


class QgsDataDefinedSizeLegendNode : QgsLayerTreeModelLegendNode
{
%Docstring
Produces legend node with a marker symbol
.. versionadded:: 3.0
%End

%TypeHeaderCode
#include "qgslayertreemodellegendnode.h"
%End
public:
QgsDataDefinedSizeLegendNode( QgsLayerTreeLayer *nodeLayer, const QgsDataDefinedSizeLegend &settings, QObject *parent /TransferThis/ = 0 );
%Docstring
Construct the node using QgsDataDefinedSizeLegend as definition of the node's appearance
%End

virtual QVariant data( int role ) const;

virtual ItemMetrics draw( const QgsLegendSettings &settings, ItemContext *ctx );


};

/************************************************************************
* This file has been generated automatically from *
* *
@@ -0,0 +1,177 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgsdatadefinedsizelegend.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/






class QgsDataDefinedSizeLegend
{
%Docstring
Object that keeps configuration of appearance of marker symbol's data-defined size in legend.
For example: the list of classes (size values), whether the classes should appear in separate
legend nodes or whether to collapse them into one legend node.

.. versionadded:: 3.0
%End

%TypeHeaderCode
#include "qgsdatadefinedsizelegend.h"
%End
public:
QgsDataDefinedSizeLegend();

QgsDataDefinedSizeLegend( const QgsDataDefinedSizeLegend &other );
%Docstring
Copy constructor
%End

enum LegendType
{
LegendSeparated,
LegendCollapsed,
};

enum VerticalAlignment
{
AlignCenter,
AlignBottom,
};

struct SizeClass
{
SizeClass( double size, const QString &label );

double size; //!< Marker size in units used by the symbol (usually millimeters)
QString label; //!< Label to be shown with the particular symbol size
};

void setLegendType( LegendType type );
%Docstring
Sets how the legend should be rendered
%End
LegendType legendType() const;
%Docstring
Returns how the legend should be rendered
:rtype: LegendType
%End

void setSymbol( QgsMarkerSymbol *symbol /Transfer/ );
%Docstring
Sets marker symbol that will be used to draw markers in legend
%End
QgsMarkerSymbol *symbol() const;
%Docstring
Returns marker symbol that will be used to draw markers in legend
:rtype: QgsMarkerSymbol
%End

void setClasses( const QList<QgsDataDefinedSizeLegend::SizeClass> &classes );
%Docstring
Sets list of classes: each class is a pair of symbol size (in units used by the symbol) and label
%End
QList<QgsDataDefinedSizeLegend::SizeClass> classes() const;
%Docstring
Returns list of classes: each class is a pair of symbol size (in units used by the symbol) and label
:rtype: list of QgsDataDefinedSizeLegend.SizeClass
%End

void setTitle( const QString &title );
%Docstring
Sets title label for data-defined size legend
%End
QString title() const;
%Docstring
Returns title label for data-defined size legend
:rtype: str
%End

void setVerticalAlignment( VerticalAlignment vAlign );
%Docstring
Sets vertical alignment of symbols - only valid for collapsed legend
%End
VerticalAlignment verticalAlignment() const;
%Docstring
Returns vertical alignment of symbols - only valid for collapsed legend
:rtype: VerticalAlignment
%End

void setFont( const QFont &font );
%Docstring
Sets font used for rendering of labels - only valid for collapsed legend
%End
QFont font() const;
%Docstring
Returns font used for rendering of labels - only valid for collapsed legend
:rtype: QFont
%End

void setTextColor( const QColor &color );
%Docstring
Sets text color for rendering of labels - only valid for collapsed legend
%End
QColor textColor() const;
%Docstring
Returns text color for rendering of labels - only valid for collapsed legend
:rtype: QColor
%End

void setTextAlignment( Qt::AlignmentFlag flag );
%Docstring
Sets horizontal text alignment for rendering of labels - only valid for collapsed legend
%End
Qt::AlignmentFlag textAlignment() const;
%Docstring
Returns horizontal text alignment for rendering of labels - only valid for collapsed legend
:rtype: Qt.AlignmentFlag
%End


void updateFromSymbolAndProperty( const QgsMarkerSymbol *symbol, const QgsProperty &ddSize );
%Docstring
Updates the list of classes, source symbol and title label from given symbol and property
%End

QgsLegendSymbolList legendSymbolList() const;
%Docstring
Generates legend symbol items according to the configuration
:rtype: QgsLegendSymbolList
%End

void drawCollapsedLegend( QgsRenderContext &context, QSize *outputSize /Out/ = 0, int *labelXOffset /Out/ = 0 ) const;
%Docstring
Does nothing if legend is not configured as collapsed.
%End

QImage collapsedLegendImage( QgsRenderContext &context, const QColor &backgroundColor = Qt::transparent, double paddingMM = 1 ) const;
%Docstring
Returns output image that would be shown in the legend. Returns invalid image if legend is not configured as collapsed.
:rtype: QImage
%End

static QgsDataDefinedSizeLegend *readXml( const QDomElement &elem, const QgsReadWriteContext &context ) /Factory/;
%Docstring
Creates instance from given element and returns it (caller takes ownership). Returns null on error.
:rtype: QgsDataDefinedSizeLegend
%End

void writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const;
%Docstring
Writes configuration to the given XML element.
%End

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgsdatadefinedsizelegend.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -450,6 +450,15 @@ class QgsDiagramRenderer

%TypeHeaderCode
#include "qgsdiagramrenderer.h"
%End

%ConvertToSubClassCode
if ( sipCpp->rendererName() == QStringLiteral( "SingleCategory" ) )
sipType = sipType_QgsSingleCategoryDiagramRenderer;
else if ( sipCpp->rendererName() == QStringLiteral( "LinearlyInterpolated" ) )
sipType = sipType_QgsLinearlyInterpolatedDiagramRenderer;
else
sipType = NULL;
%End
public:

@@ -545,44 +554,6 @@ Returns list with all diagram settings in the renderer
.. versionadded:: 2.16
.. seealso:: attributeLegend()
.. seealso:: setSizeLegend()
%End

bool sizeLegend() const;
%Docstring
Returns true if renderer will show legend items for diagram sizes.
.. versionadded:: 2.16
.. seealso:: setSizeLegend()
.. seealso:: attributeLegend()
.. seealso:: sizeLegendSymbol()
:rtype: bool
%End

void setSizeLegend( bool enabled );
%Docstring
Sets whether the renderer will show legend items for diagram sizes.
\param enabled set to true to show diagram size legend
.. versionadded:: 2.16
.. seealso:: sizeLegend()
.. seealso:: setAttributeLegend()
.. seealso:: setSizeLegendSymbol()
%End

QgsMarkerSymbol *sizeLegendSymbol() const;
%Docstring
Returns the marker symbol used for rendering the diagram size legend.
.. versionadded:: 2.16
.. seealso:: setSizeLegendSymbol()
.. seealso:: sizeLegend()
:rtype: QgsMarkerSymbol
%End

void setSizeLegendSymbol( QgsMarkerSymbol *symbol /Transfer/ );
%Docstring
Sets the marker symbol used for rendering the diagram size legend.
\param symbol marker symbol, ownership is transferred to the renderer.
.. versionadded:: 2.16
.. seealso:: sizeLegendSymbol()
.. seealso:: setSizeLegend()
%End

protected:
@@ -628,8 +599,6 @@ Returns the paint device dpi (or -1 in case of error
%End




};

class QgsSingleCategoryDiagramRenderer : QgsDiagramRenderer
@@ -760,13 +729,31 @@ Returns list with all diagram settings in the renderer
virtual QList< QgsLayerTreeModelLegendNode * > legendItems( QgsLayerTreeLayer *nodeLayer ) const /Factory/;


void setDataDefinedSizeLegend( QgsDataDefinedSizeLegend *settings /Transfer/ );
%Docstring
Configures appearance of legend. Takes ownership of the passed settings objects.
.. versionadded:: 3.0
%End

QgsDataDefinedSizeLegend *dataDefinedSizeLegend() const;
%Docstring
Returns configuration of appearance of legend. Will return null if no configuration has been set.
.. versionadded:: 3.0
:rtype: QgsDataDefinedSizeLegend
%End

protected:
virtual bool diagramSettings( const QgsFeature &feature, const QgsRenderContext &c, QgsDiagramSettings &s ) const;


virtual QSizeF diagramSize( const QgsFeature &, const QgsRenderContext &c ) const;


QgsLinearlyInterpolatedDiagramRenderer( const QgsLinearlyInterpolatedDiagramRenderer &other );
%Docstring
Copy constructor
%End

};

/************************************************************************
@@ -78,6 +78,7 @@ class QgsCategorizedSymbolRenderer : QgsFeatureRenderer
public:

QgsCategorizedSymbolRenderer( const QString &attrName = QString(), const QgsCategoryList &categories = QgsCategoryList() );
~QgsCategorizedSymbolRenderer();

virtual QgsSymbol *symbolForFeature( QgsFeature &feature, QgsRenderContext &context );
virtual QgsSymbol *originalSymbolForFeature( QgsFeature &feature, QgsRenderContext &context );
@@ -220,10 +221,31 @@ create renderer from XML element
:rtype: QgsCategorizedSymbolRenderer
%End

void setDataDefinedSizeLegend( QgsDataDefinedSizeLegend *settings /Transfer/ );
%Docstring
Configures appearance of legend when renderer is configured to use data-defined size for marker symbols.
This allows to configure for what values (symbol sizes) should be shown in the legend, whether to display
different symbol sizes collapsed in one legend node or separated across multiple legend nodes etc.

When renderer does not use data-defined size or does not use marker symbols, these settings will be ignored.
Takes ownership of the passed settings objects. Null pointer is a valid input that disables data-defined
size legend.
.. versionadded:: 3.0
%End

QgsDataDefinedSizeLegend *dataDefinedSizeLegend() const;
%Docstring
Returns configuration of appearance of legend when using data-defined size for marker symbols.
Will return null if the functionality is disabled.
.. versionadded:: 3.0
:rtype: QgsDataDefinedSizeLegend
%End

protected:




void rebuildHash();
%Docstring
hashtable for faster access to symbols

0 comments on commit 7cd517c

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