Skip to content

Commit

Permalink
Fix inverted polygons and displacement renderer don't allow right
Browse files Browse the repository at this point in the history
click on legend items (fix #14966)

(cherry-picked from b2c43cb)
  • Loading branch information
nyalldawson committed Jun 30, 2016
1 parent a1e1614 commit 0750c1d
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 33 deletions.
2 changes: 2 additions & 0 deletions python/core/symbology-ng/qgsinvertedpolygonrenderer.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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;
/**
Expand Down
2 changes: 2 additions & 0 deletions python/core/symbology-ng/qgspointdisplacementrenderer.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
66 changes: 33 additions & 33 deletions src/app/qgsapplayertreeviewmenuprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/core/symbology-ng/qgsinvertedpolygonrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
2 changes: 2 additions & 0 deletions src/core/symbology-ng/qgsinvertedpolygonrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
/**
Expand Down
8 changes: 8 additions & 0 deletions src/core/symbology-ng/qgspointdisplacementrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/core/symbology-ng/qgspointdisplacementrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 ); }
Expand Down

0 comments on commit 0750c1d

Please sign in to comment.