Skip to content
Permalink
Browse files

API cleanup for legend support in renderers

  • Loading branch information
wonder-sk committed Jun 12, 2017
1 parent b3bd45b commit a8999639c7b3ea681b0d024287f3328d0164ddc8
Showing with 92 additions and 347 deletions.
  1. +14 −1 doc/api_break.dox
  2. +0 −23 python/core/qgsmaplayerlegend.sip
  3. +0 −6 python/core/qgspluginlayer.sip
  4. +1 −2 python/core/symbology-ng/qgscategorizedsymbolrenderer.sip
  5. +1 −2 python/core/symbology-ng/qgsgraduatedsymbolrenderer.sip
  6. +4 −4 python/core/symbology-ng/qgsinvertedpolygonrenderer.sip
  7. +1 −1 python/core/symbology-ng/qgslegendsymbolitem.sip
  8. +1 −2 python/core/symbology-ng/qgspointdistancerenderer.sip
  9. +2 −12 python/core/symbology-ng/qgsrenderer.sip
  10. +3 −5 python/core/symbology-ng/qgsrulebasedrenderer.sip
  11. +1 −2 python/core/symbology-ng/qgssinglesymbolrenderer.sip
  12. +1 −1 src/core/layertree/qgslayertreemodellegendnode.cpp
  13. +1 −35 src/core/qgsmaplayerlegend.cpp
  14. +0 −20 src/core/qgsmaplayerlegend.h
  15. +1 −1 src/core/qgsmapthemecollection.cpp
  16. +0 −7 src/core/qgspluginlayer.cpp
  17. +0 −6 src/core/qgspluginlayer.h
  18. +1 −1 src/core/qgsvectorlayerfeaturecounter.cpp
  19. +9 −26 src/core/symbology-ng/qgscategorizedsymbolrenderer.cpp
  20. +3 −3 src/core/symbology-ng/qgscategorizedsymbolrenderer.h
  21. +11 −29 src/core/symbology-ng/qgsgraduatedsymbolrenderer.cpp
  22. +4 −3 src/core/symbology-ng/qgsgraduatedsymbolrenderer.h
  23. +2 −11 src/core/symbology-ng/qgsinvertedpolygonrenderer.cpp
  24. +1 −4 src/core/symbology-ng/qgsinvertedpolygonrenderer.h
  25. +1 −1 src/core/symbology-ng/qgslegendsymbolitem.h
  26. +2 −12 src/core/symbology-ng/qgspointdistancerenderer.cpp
  27. +1 −2 src/core/symbology-ng/qgspointdistancerenderer.h
  28. +1 −22 src/core/symbology-ng/qgsrenderer.cpp
  29. +2 −16 src/core/symbology-ng/qgsrenderer.h
  30. +4 −38 src/core/symbology-ng/qgsrulebasedrenderer.cpp
  31. +2 −7 src/core/symbology-ng/qgsrulebasedrenderer.h
  32. +1 −21 src/core/symbology-ng/qgssinglesymbolrenderer.cpp
  33. +1 −3 src/core/symbology-ng/qgssinglesymbolrenderer.h
  34. +1 −3 src/gui/symbology-ng/qgsrendererwidget.cpp
  35. +1 −3 src/gui/symbology-ng/qgsrulebasedrendererwidget.cpp
  36. +9 −8 src/gui/symbology-ng/qgssymbollevelsdialog.cpp
  37. +1 −1 src/server/services/wms/qgswmsrenderer.cpp
  38. +3 −3 tests/src/core/testqgslayertree.cpp
@@ -265,6 +265,7 @@ should now call QgsCoordinateReferenceSystem::invalidateCache() and QgsCoordinat
- QgsDataDefined was removed. Use the QgsProperty framework instead.
- QgsDataDefinedButton was removed. Use QgsPropertyOverrideButton instead.
- QgsDataDefinedSymbolDialog was removed. Code using this dialog should be reworked to use QgsPropertyOverrideButton
- QgsDefaultPluginLayerLegend was removed. Use QgsMapLayer::setLegend() to provide legend nodes for plugin layers.
- QgsFileNameWidgetWrapper was removed. Use QgsExternalResourceWidgetWrapper instead.
- QgsFormAnnotationItem. Use QgsFormAnnotation instead.
- QgsHtmlAnnotationItem. Use QgsHtmlAnnotation instead.
@@ -1181,6 +1182,9 @@ QgsFeatureRendererV2 {#qgis_api_break_3_0_QgsFeatureRendererV2}
- usedAttributes() now requires a QgsRenderContext argument.
- save() expects QgsReadWriteContext reference as the last argument
- static create() method in subclasses expects QgsReadWriteContext reference as the last argument
- legendSymbologyItems() was removed.
- legendSymbolItems() was removed.
- legendSymbolItemsV2() has been renamed to legendSymbolItems()


QgsFeatureRequest {#qgis_api_break_3_0_QgsFeatureRequest}
@@ -1530,6 +1534,12 @@ QgsMapLayerActionRegistry {#qgis_api_break_3_0_QgsMapLayerActionRegistry}
- This class is no longer a singleton and instance() has been removed. Instead use QgsGui::mapLayerActionRegistry().


QgsMapLayerLegend {#qgis_api_break_3_0_QgsMapLayerLegend}
-----------------

- defaultPluginLegend() was removed. Plugin layers have to provide their legend implementation.


QgsMapOverviewCanvas {#qgis_api_break_3_0_QgsMapOverviewCanvas}
--------------------

@@ -1768,6 +1778,7 @@ QgsPluginLayer {#qgis_api_break_3_0_QgsPluginLayer}

- createMapRenderer(): default implementation (which called plugin's draw() method) has been removed. Plugin layers must implement createMapRenderer().
- clone(): new pure virtual method. Plugin layer must implement clone().
- legendSymbologyItems() has been removed. Use QgsMapLayer::setLegend() to provide legend nodes.


QgsPluginLayerRegistry {#qgis_api_break_3_0_QgsPluginLayerRegistry}
@@ -1786,7 +1797,7 @@ QgsPointDisplacementRenderer {#qgis_api_break_3_0_QgsPointDisplacementRen
----------------------------

- The deprecated method setDisplacementGroups() has been removed. This method has had no effect since QGIS 2.4
- setMaxLabelScaleDenominator() and maxLabelScaleDenominator() were renamed to setMinimumLabelScale() and
- setMaxLabelScaleDenominator() and maxLabelScaleDenominator() were renamed to setMinimumLabelScale() and
minimumLabelScale() for consistency with other areas in the QGIS API.


@@ -2008,6 +2019,8 @@ QgsRuleBasedRenderer {#qgis_api_break_3_0_QgsRuleBasedRenderer}
- QgsRuleBasedRenderer.Rule checkState() and setCheckState() were removed. Use active() and setActive() instead.
- QgsRuleBasedRenderer.Rule updateElseRules() was removed.
- QgsRuleBasedRenderer.Rule scaleMinDenom(), scaleMaxDenom(), setScaleMaxDenom() and setScaleMinDenom() were removed. Use minimumScale(), maximumScale(), setMinimumScale() and setMaximumScale() instead.
- QgsRuleBasedRenderer.Rule legendSymbolItems() was removed.
- QgsRuleBasedRenderer.Rule legendSymbolItemsV2() was renamed to legendSymbolItems()
- startRender( QgsRenderContext& context, const QgsFields& fields ) was removed. Use startRender( QgsRenderContext& context, const QgsFields& fields, QString& filter ) instead.


@@ -43,12 +43,6 @@ Create new legend implementation for vector layer

static QgsMapLayerLegend *defaultRasterLegend( QgsRasterLayer *rl ) /Factory/;
%Docstring
Create new legend implementation for raster layer
:rtype: QgsMapLayerLegend
%End

static QgsMapLayerLegend *defaultPluginLegend( QgsPluginLayer *pl ) /Factory/;
%Docstring
Create new legend implementation for raster layer
:rtype: QgsMapLayerLegend
%End
@@ -137,23 +131,6 @@ class QgsDefaultRasterLayerLegend : QgsMapLayerLegend
};


class QgsDefaultPluginLayerLegend : QgsMapLayerLegend
{
%Docstring
Default legend implementation for plugin layers
.. versionadded:: 2.6
%End

%TypeHeaderCode
#include "qgsmaplayerlegend.h"
%End
public:
explicit QgsDefaultPluginLayerLegend( QgsPluginLayer *pl );

virtual QList<QgsLayerTreeModelLegendNode *> createLayerTreeModelLegendNodes( QgsLayerTreeLayer *nodeLayer ) /Factory/;

};

/************************************************************************
* This file has been generated automatically from *
* *
@@ -52,12 +52,6 @@ Set extent of the layer
.. versionadded:: 2.16
%End

virtual QgsLegendSymbologyList legendSymbologyItems( QSize iconSize );
%Docstring
.. versionadded:: 2.1
:rtype: QgsLegendSymbologyList
%End

protected:
};

@@ -163,8 +163,7 @@ create renderer from XML element
%End

virtual QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context );
virtual QgsLegendSymbologyList legendSymbologyItems( QSize iconSize );
virtual QgsLegendSymbolListV2 legendSymbolItemsV2() const;
virtual QgsLegendSymbolList legendSymbolItems() const;

virtual QSet< QString > legendKeysForFeature( QgsFeature &feature, QgsRenderContext &context );

@@ -308,8 +308,7 @@ create renderer from XML element
%End

virtual QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context );
virtual QgsLegendSymbologyList legendSymbologyItems( QSize iconSize );
virtual QgsLegendSymbolListV2 legendSymbolItemsV2() const;
virtual QgsLegendSymbolList legendSymbolItems() const;

virtual QSet< QString > legendKeysForFeature( QgsFeature &feature, QgsRenderContext &context );

@@ -105,13 +105,13 @@ Proxy that will call this method on the embedded renderer.
Proxy that will call this method on the embedded renderer.
:rtype: QgsSymbolList
%End
virtual QgsLegendSymbologyList legendSymbologyItems( QSize iconSize );

virtual QgsLegendSymbolList legendSymbolItems() const;
%Docstring
Proxy that will call this method on the embedded renderer.
:rtype: QgsLegendSymbologyList
Proxy that will call this method on the embedded renderer.
:rtype: QgsLegendSymbolList
%End


virtual bool willRenderFeature( QgsFeature &feat, QgsRenderContext &context );
%Docstring
Proxy that will call this method on the embedded renderer.
@@ -97,7 +97,7 @@ Set symbol of the item. Takes ownership of symbol.
};


typedef QList< QgsLegendSymbolItem > QgsLegendSymbolListV2;
typedef QList< QgsLegendSymbolItem > QgsLegendSymbolList;

/************************************************************************
* This file has been generated automatically from *
@@ -83,8 +83,7 @@ Optional label text
virtual void startRender( QgsRenderContext &context, const QgsFields &fields );
virtual void stopRender( QgsRenderContext &context );

virtual QgsLegendSymbologyList legendSymbologyItems( QSize iconSize );

virtual QgsLegendSymbolList legendSymbolItems() const;
virtual void setEmbeddedRenderer( QgsFeatureRenderer *r /Transfer/ );

virtual const QgsFeatureRenderer *embeddedRenderer() const;
@@ -13,9 +13,6 @@

typedef QList<QgsSymbol *> QgsSymbolList;

typedef QList< QPair<QString, QPixmap> > QgsLegendSymbologyList;
typedef QList< QPair<QString, QgsSymbol *> > QgsLegendSymbolList;




@@ -267,12 +264,6 @@ store renderer info to XML element
used from subclasses to create SLD Rule elements following SLD v1.1 specs
%End

virtual QgsLegendSymbologyList legendSymbologyItems( QSize iconSize );
%Docstring
return a list of symbology items for the legend
:rtype: QgsLegendSymbologyList
%End

virtual bool legendSymbolItemsCheckable() const;
%Docstring
.. versionadded:: 2.5
@@ -298,11 +289,10 @@ return a list of symbology items for the legend
.. versionadded:: 2.14
%End


virtual QgsLegendSymbolListV2 legendSymbolItemsV2() const;
virtual QgsLegendSymbolList legendSymbolItems() const;
%Docstring
.. versionadded:: 2.6
:rtype: QgsLegendSymbolListV2
:rtype: QgsLegendSymbolList
%End

virtual QString legendClassificationAttribute() const;
@@ -118,11 +118,10 @@ Constructor takes ownership of the symbol
:rtype: QgsSymbolList
%End


QgsLegendSymbolListV2 legendSymbolItemsV2( int currentLevel = -1 ) const;
QgsLegendSymbolList legendSymbolItems( int currentLevel = -1 ) const;
%Docstring
.. versionadded:: 2.6
:rtype: QgsLegendSymbolListV2
:rtype: QgsLegendSymbolList
%End

bool isFilterOK( QgsFeature &f, QgsRenderContext *context = 0 ) const;
@@ -486,13 +485,12 @@ return symbol for current feature. Should not be used individually: there could
virtual QgsSymbolList symbols( QgsRenderContext &context );

virtual QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context );
virtual QgsLegendSymbologyList legendSymbologyItems( QSize iconSize );
virtual bool legendSymbolItemsCheckable() const;
virtual bool legendSymbolItemChecked( const QString &key );
virtual void checkLegendSymbolItem( const QString &key, bool state = true );

virtual void setLegendSymbolItem( const QString &key, QgsSymbol *symbol /Transfer/ );
virtual QgsLegendSymbolListV2 legendSymbolItemsV2() const;
virtual QgsLegendSymbolList legendSymbolItems() const;
virtual QString dump() const;
virtual bool willRenderFeature( QgsFeature &feat, QgsRenderContext &context );
virtual QgsSymbolList symbolsForFeature( QgsFeature &feat, QgsRenderContext &context );
@@ -48,8 +48,7 @@ create renderer from XML element
:rtype: QgsFeatureRenderer
%End
virtual QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context );
virtual QgsLegendSymbologyList legendSymbologyItems( QSize iconSize );
virtual QgsLegendSymbolListV2 legendSymbolItemsV2() const;
virtual QgsLegendSymbolList legendSymbolItems() const;
virtual QSet< QString > legendKeysForFeature( QgsFeature &feature, QgsRenderContext &context );
virtual void setLegendSymbolItem( const QString &key, QgsSymbol *symbol /Transfer/ );

@@ -239,7 +239,7 @@ void QgsSymbolLegendNode::checkAll( bool state )
if ( !vlayer || !vlayer->renderer() )
return;

QgsLegendSymbolListV2 symbolList = vlayer->renderer()->legendSymbolItemsV2();
QgsLegendSymbolList symbolList = vlayer->renderer()->legendSymbolItems();
Q_FOREACH ( const QgsLegendSymbolItem &item, symbolList )
{
vlayer->renderer()->checkLegendSymbolItem( item.ruleKey(), state );
@@ -40,11 +40,6 @@ QgsMapLayerLegend *QgsMapLayerLegend::defaultRasterLegend( QgsRasterLayer *rl )
return new QgsDefaultRasterLayerLegend( rl );
}

QgsMapLayerLegend *QgsMapLayerLegend::defaultPluginLegend( QgsPluginLayer *pl )
{
return new QgsDefaultPluginLayerLegend( pl );
}

// -------------------------------------------------------------------------


@@ -199,7 +194,7 @@ QList<QgsLayerTreeModelLegendNode *> QgsDefaultVectorLayerLegend::createLayerTre
nodes.append( new QgsSimpleLegendNode( nodeLayer, r->legendClassificationAttribute() ) );
}

Q_FOREACH ( const QgsLegendSymbolItem &i, r->legendSymbolItemsV2() )
Q_FOREACH ( const QgsLegendSymbolItem &i, r->legendSymbolItems() )
{
QgsSymbolLegendNode *n = new QgsSymbolLegendNode( nodeLayer, i );
nodes.append( n );
@@ -266,32 +261,3 @@ QList<QgsLayerTreeModelLegendNode *> QgsDefaultRasterLayerLegend::createLayerTre

return nodes;
}


// -------------------------------------------------------------------------


QgsDefaultPluginLayerLegend::QgsDefaultPluginLayerLegend( QgsPluginLayer *pl )
: mLayer( pl )
{
}

QList<QgsLayerTreeModelLegendNode *> QgsDefaultPluginLayerLegend::createLayerTreeModelLegendNodes( QgsLayerTreeLayer *nodeLayer )
{
QList<QgsLayerTreeModelLegendNode *> nodes;

QSize iconSize( 16, 16 );
QgsLegendSymbologyList symbologyList = mLayer->legendSymbologyItems( iconSize );

if ( symbologyList.isEmpty() )
return nodes;

typedef QPair<QString, QPixmap> XY;
Q_FOREACH ( const XY &item, symbologyList )
{
nodes << new QgsSimpleLegendNode( nodeLayer, item.first, QIcon( item.second ) );
}

return nodes;
}

@@ -56,9 +56,6 @@ class CORE_EXPORT QgsMapLayerLegend : public QObject
//! Create new legend implementation for raster layer
static QgsMapLayerLegend *defaultRasterLegend( QgsRasterLayer *rl ) SIP_FACTORY;

//! Create new legend implementation for raster layer
static QgsMapLayerLegend *defaultPluginLegend( QgsPluginLayer *pl ) SIP_FACTORY;

signals:
//! Emitted when existing items/nodes got invalid and should be replaced by new ones
void itemsChanged();
@@ -124,21 +121,4 @@ class CORE_EXPORT QgsDefaultRasterLayerLegend : public QgsMapLayerLegend
};


/** \ingroup core
* Default legend implementation for plugin layers
* \since QGIS 2.6
*/
class CORE_EXPORT QgsDefaultPluginLayerLegend : public QgsMapLayerLegend
{
Q_OBJECT

public:
explicit QgsDefaultPluginLayerLegend( QgsPluginLayer *pl );

virtual QList<QgsLayerTreeModelLegendNode *> createLayerTreeModelLegendNodes( QgsLayerTreeLayer *nodeLayer ) SIP_FACTORY override;

private:
QgsPluginLayer *mLayer = nullptr;
};

#endif // QGSMAPLAYERLEGEND_H
@@ -308,7 +308,7 @@ void QgsMapThemeCollection::applyMapThemeCheckedLegendNodesToLayer( const MapThe

bool someNodesUnchecked = layerRec.usingLegendItems;

Q_FOREACH ( const QgsLegendSymbolItem &item, vlayer->renderer()->legendSymbolItemsV2() )
Q_FOREACH ( const QgsLegendSymbolItem &item, vlayer->renderer()->legendSymbolItems() )
{
bool checked = renderer->legendSymbolItemChecked( item.ruleKey() );
bool shouldBeChecked = someNodesUnchecked ? layerRec.checkedLegendItems.contains( item.ruleKey() ) : true;
@@ -21,7 +21,6 @@ QgsPluginLayer::QgsPluginLayer( const QString &layerType, const QString &layerNa
: QgsMapLayer( PluginLayer, layerName )
, mPluginLayerType( layerType )
{
setLegend( QgsMapLayerLegend::defaultPluginLegend( this ) );
}

QgsPluginLayer::~QgsPluginLayer()
@@ -45,9 +44,3 @@ void QgsPluginLayer::setSource( const QString &source )
{
mDataSource = source;
}

QgsLegendSymbologyList QgsPluginLayer::legendSymbologyItems( QSize iconSize )
{
Q_UNUSED( iconSize );
return QgsLegendSymbologyList();
}
@@ -18,7 +18,6 @@
#include "qgis_core.h"
#include "qgsmaplayer.h"

typedef QList< QPair<QString, QPixmap> > QgsLegendSymbologyList SIP_SKIP;

/** \ingroup core
Base class for plugin layers. These can be implemented by plugins
@@ -53,11 +52,6 @@ class CORE_EXPORT QgsPluginLayer : public QgsMapLayer
*/
void setSource( const QString &source );

//! return a list of symbology items for the legend
//! (default implementation returns nothing)
//! \since QGIS v2.1
virtual QgsLegendSymbologyList legendSymbologyItems( QSize iconSize );

protected:
QString mPluginLayerType;
};
@@ -20,7 +20,7 @@ bool QgsVectorLayerFeatureCounter::run()

for ( ; symbolIt != symbolList.constEnd(); ++symbolIt )
{
mSymbolFeatureCountMap.insert( symbolIt->first, 0 );
mSymbolFeatureCountMap.insert( symbolIt->label(), 0 );
}

// If there are no features to be counted, we can spare us the trouble

0 comments on commit a899963

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