Skip to content

Commit

Permalink
API cleanup for legend support in renderers
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Jun 12, 2017
1 parent b3bd45b commit a899963
Show file tree
Hide file tree
Showing 38 changed files with 92 additions and 347 deletions.
15 changes: 14 additions & 1 deletion doc/api_break.dox
Expand Up @@ -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.
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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}
--------------------

Expand Down Expand Up @@ -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}
Expand All @@ -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.


Expand Down Expand Up @@ -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.


Expand Down
23 changes: 0 additions & 23 deletions python/core/qgsmaplayerlegend.sip
Expand Up @@ -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
Expand Down Expand Up @@ -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 *
* *
Expand Down
6 changes: 0 additions & 6 deletions python/core/qgspluginlayer.sip
Expand Up @@ -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:
};

Expand Down
3 changes: 1 addition & 2 deletions python/core/symbology-ng/qgscategorizedsymbolrenderer.sip
Expand Up @@ -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 );

Expand Down
3 changes: 1 addition & 2 deletions python/core/symbology-ng/qgsgraduatedsymbolrenderer.sip
Expand Up @@ -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 );

Expand Down
8 changes: 4 additions & 4 deletions python/core/symbology-ng/qgsinvertedpolygonrenderer.sip
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion python/core/symbology-ng/qgslegendsymbolitem.sip
Expand Up @@ -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 *
Expand Down
3 changes: 1 addition & 2 deletions python/core/symbology-ng/qgspointdistancerenderer.sip
Expand Up @@ -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;
Expand Down
14 changes: 2 additions & 12 deletions python/core/symbology-ng/qgsrenderer.sip
Expand Up @@ -13,9 +13,6 @@

typedef QList<QgsSymbol *> QgsSymbolList;

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




Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down
8 changes: 3 additions & 5 deletions python/core/symbology-ng/qgsrulebasedrenderer.sip
Expand Up @@ -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;
Expand Down Expand Up @@ -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 );
Expand Down
3 changes: 1 addition & 2 deletions python/core/symbology-ng/qgssinglesymbolrenderer.sip
Expand Up @@ -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/ );

Expand Down
2 changes: 1 addition & 1 deletion src/core/layertree/qgslayertreemodellegendnode.cpp
Expand Up @@ -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 );
Expand Down
36 changes: 1 addition & 35 deletions src/core/qgsmaplayerlegend.cpp
Expand Up @@ -40,11 +40,6 @@ QgsMapLayerLegend *QgsMapLayerLegend::defaultRasterLegend( QgsRasterLayer *rl )
return new QgsDefaultRasterLayerLegend( rl );
}

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

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


Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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;
}

20 changes: 0 additions & 20 deletions src/core/qgsmaplayerlegend.h
Expand Up @@ -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();
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/core/qgsmapthemecollection.cpp
Expand Up @@ -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;
Expand Down
7 changes: 0 additions & 7 deletions src/core/qgspluginlayer.cpp
Expand Up @@ -21,7 +21,6 @@ QgsPluginLayer::QgsPluginLayer( const QString &layerType, const QString &layerNa
: QgsMapLayer( PluginLayer, layerName )
, mPluginLayerType( layerType )
{
setLegend( QgsMapLayerLegend::defaultPluginLegend( this ) );
}

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

QgsLegendSymbologyList QgsPluginLayer::legendSymbologyItems( QSize iconSize )
{
Q_UNUSED( iconSize );
return QgsLegendSymbologyList();
}
6 changes: 0 additions & 6 deletions src/core/qgspluginlayer.h
Expand Up @@ -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
Expand Down Expand Up @@ -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;
};
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsvectorlayerfeaturecounter.cpp
Expand Up @@ -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
Expand Down

0 comments on commit a899963

Please sign in to comment.