Skip to content
Permalink
Browse files

Fix inverted polygons and displacement renderer don't allow right

click on legend items (fix #14966)

(cherry-picked from b2c43cb)
  • Loading branch information
nyalldawson committed Jun 30, 2016
1 parent a1e1614 commit 0750c1d5d1b8ba3296eabe9b18f8b6bf9c84f7b8
@@ -85,6 +85,8 @@ class QgsInvertedPolygonRenderer : QgsFeatureRendererV2
void setEmbeddedRenderer( QgsFeatureRendererV2* subRenderer /Transfer/ );
const QgsFeatureRendererV2* embeddedRenderer() const;

virtual void setLegendSymbolItem( const QString& key, QgsSymbolV2* symbol );

/** @returns true if the geometries are to be preprocessed (merged with an union) before rendering.*/
bool preprocessingEnabled() const;
/**
@@ -71,6 +71,8 @@ class QgsPointDisplacementRenderer : QgsFeatureRendererV2
void setEmbeddedRenderer( QgsFeatureRendererV2* r /Transfer/ );
QgsFeatureRendererV2* embeddedRenderer();

virtual void setLegendSymbolItem( const QString& key, QgsSymbolV2* symbol );

//! not available in python bindings
//! @deprecated since 2.4
// void setDisplacementGroups( const QList<QMap<QgsFeatureId, QgsFeature> >& list );
@@ -264,44 +264,44 @@ QMenu* QgsAppLayerTreeViewMenuProvider::createContextMenu()
menu->addAction( QgsApplication::getThemeIcon( "/mActionHideAllLayers.png" ), tr( "&Hide All Items" ),
symbolNode, SLOT( uncheckAllItems() ) );
menu->addSeparator();
}

if ( symbolNode->symbol() )
if ( symbolNode->symbol() )
{
QgsColorWheel* colorWheel = new QgsColorWheel( menu );
colorWheel->setColor( symbolNode->symbol()->color() );
QgsColorWidgetAction* colorAction = new QgsColorWidgetAction( colorWheel, menu, menu );
colorAction->setDismissOnColorSelection( false );
connect( colorAction, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setSymbolLegendNodeColor( const QColor& ) ) );
//store the layer id and rule key in action, so we can later retrieve the corresponding
//legend node, if it still exists
colorAction->setProperty( "layerId", symbolNode->layerNode()->layerId() );
colorAction->setProperty( "ruleKey", symbolNode->data( QgsLayerTreeModelLegendNode::RuleKeyRole ).toString() );
menu->addAction( colorAction );

//add recent colors action
QList<QgsRecentColorScheme *> recentSchemes;
QgsColorSchemeRegistry::instance()->schemes( recentSchemes );
if ( !recentSchemes.isEmpty() )
{
QgsColorWheel* colorWheel = new QgsColorWheel( menu );
colorWheel->setColor( symbolNode->symbol()->color() );
QgsColorWidgetAction* colorAction = new QgsColorWidgetAction( colorWheel, menu, menu );
colorAction->setDismissOnColorSelection( false );
connect( colorAction, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setSymbolLegendNodeColor( const QColor& ) ) );
//store the layer id and rule key in action, so we can later retrieve the corresponding
//legend node, if it still exists
colorAction->setProperty( "layerId", symbolNode->layerNode()->layerId() );
colorAction->setProperty( "ruleKey", symbolNode->data( QgsLayerTreeModelLegendNode::RuleKeyRole ).toString() );
menu->addAction( colorAction );

//add recent colors action
QList<QgsRecentColorScheme *> recentSchemes;
QgsColorSchemeRegistry::instance()->schemes( recentSchemes );
if ( !recentSchemes.isEmpty() )
{
QgsColorSwatchGridAction* recentColorAction = new QgsColorSwatchGridAction( recentSchemes.at( 0 ), menu, "symbology", menu );
recentColorAction->setProperty( "layerId", symbolNode->layerNode()->layerId() );
recentColorAction->setProperty( "ruleKey", symbolNode->data( QgsLayerTreeModelLegendNode::RuleKeyRole ).toString() );
recentColorAction->setDismissOnColorSelection( false );
menu->addAction( recentColorAction );
connect( recentColorAction, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setSymbolLegendNodeColor( const QColor& ) ) );
}

menu->addSeparator();
QgsColorSwatchGridAction* recentColorAction = new QgsColorSwatchGridAction( recentSchemes.at( 0 ), menu, "symbology", menu );
recentColorAction->setProperty( "layerId", symbolNode->layerNode()->layerId() );
recentColorAction->setProperty( "ruleKey", symbolNode->data( QgsLayerTreeModelLegendNode::RuleKeyRole ).toString() );
recentColorAction->setDismissOnColorSelection( false );
menu->addAction( recentColorAction );
connect( recentColorAction, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setSymbolLegendNodeColor( const QColor& ) ) );
}

QAction* editSymbolAction = new QAction( tr( "Edit Symbol..." ), menu );
//store the layer id and rule key in action, so we can later retrieve the corresponding
//legend node, if it still exists
editSymbolAction->setProperty( "layerId", symbolNode->layerNode()->layerId() );
editSymbolAction->setProperty( "ruleKey", symbolNode->data( QgsLayerTreeModelLegendNode::RuleKeyRole ).toString() );
connect( editSymbolAction, SIGNAL( triggered() ), this, SLOT( editSymbolLegendNodeSymbol() ) );
menu->addAction( editSymbolAction );
menu->addSeparator();
}

QAction* editSymbolAction = new QAction( tr( "Edit Symbol..." ), menu );
//store the layer id and rule key in action, so we can later retrieve the corresponding
//legend node, if it still exists
editSymbolAction->setProperty( "layerId", symbolNode->layerNode()->layerId() );
editSymbolAction->setProperty( "ruleKey", symbolNode->data( QgsLayerTreeModelLegendNode::RuleKeyRole ).toString() );
connect( editSymbolAction, SIGNAL( triggered() ), this, SLOT( editSymbolLegendNodeSymbol() ) );
menu->addAction( editSymbolAction );
}
}

@@ -64,6 +64,14 @@ const QgsFeatureRendererV2* QgsInvertedPolygonRenderer::embeddedRenderer() const
return mSubRenderer.data();
}

void QgsInvertedPolygonRenderer::setLegendSymbolItem( const QString& key, QgsSymbolV2* symbol )
{
if ( !mSubRenderer )
return;

mSubRenderer->setLegendSymbolItem( key, symbol );
}

void QgsInvertedPolygonRenderer::startRender( QgsRenderContext& context, const QgsFields& fields )
{
if ( !mSubRenderer )
@@ -121,6 +121,8 @@ class CORE_EXPORT QgsInvertedPolygonRenderer : public QgsFeatureRendererV2
void setEmbeddedRenderer( QgsFeatureRendererV2* subRenderer ) override;
const QgsFeatureRendererV2* embeddedRenderer() const override;

virtual void setLegendSymbolItem( const QString& key, QgsSymbolV2* symbol ) override;

/** @returns true if the geometries are to be preprocessed (merged with an union) before rendering.*/
bool preprocessingEnabled() const { return mPreprocessingEnabled; }
/**
@@ -226,6 +226,14 @@ const QgsFeatureRendererV2* QgsPointDisplacementRenderer::embeddedRenderer() con
return mRenderer;
}

void QgsPointDisplacementRenderer::setLegendSymbolItem( const QString& key, QgsSymbolV2* symbol )
{
if ( !mRenderer )
return;

mRenderer->setLegendSymbolItem( key, symbol );
}

QList<QString> QgsPointDisplacementRenderer::usedAttributes()
{
QList<QString> attributeList;
@@ -98,6 +98,8 @@ class CORE_EXPORT QgsPointDisplacementRenderer: public QgsFeatureRendererV2
void setEmbeddedRenderer( QgsFeatureRendererV2* r ) override;
const QgsFeatureRendererV2* embeddedRenderer() const override;

virtual void setLegendSymbolItem( const QString& key, QgsSymbolV2* symbol ) override;

//! not available in python bindings
//! @deprecated since 2.4
Q_DECL_DEPRECATED void setDisplacementGroups( const QList<QMap<QgsFeatureId, QgsFeature> >& list ) { Q_UNUSED( list ); }

0 comments on commit 0750c1d

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