Skip to content

Commit

Permalink
Fix inverted polygon & displacement renderer don't show
Browse files Browse the repository at this point in the history
color wheel in legend menu

Move embedded renderer handling to QgsFeatureRendererV2 and
add support for embedded renders to legend context menu

Fix #14967

(cherry-picked from b32afce)
  • Loading branch information
nyalldawson committed Jun 30, 2016
1 parent 0a93bdd commit a1e1614
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 30 deletions.
13 changes: 5 additions & 8 deletions python/core/symbology-ng/qgsinvertedpolygonrenderer.sip
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ class QgsInvertedPolygonRenderer : QgsFeatureRendererV2
public:

/** Constructor
* @param embeddedRenderer optional embeddedRenderer. If null, a default one will be assigned
* @param embeddedRenderer optional embeddedRenderer. If null, a default one will be assigned.
* Ownership will be transferred.
*/
QgsInvertedPolygonRenderer( const QgsFeatureRendererV2* embeddedRenderer /Transfer/ = 0 );
QgsInvertedPolygonRenderer( QgsFeatureRendererV2* embeddedRenderer /Transfer/ = 0 );

virtual ~QgsInvertedPolygonRenderer();

/** Used to clone this feature renderer.*/
Expand Down Expand Up @@ -80,12 +82,7 @@ class QgsInvertedPolygonRenderer : QgsFeatureRendererV2
*/
virtual QDomElement save( QDomDocument& doc );

/** Sets the embedded renderer
* @param subRenderer the embedded renderer (will be cloned)
*/
void setEmbeddedRenderer( const QgsFeatureRendererV2* subRenderer );
/** @returns the current embedded renderer
*/
void setEmbeddedRenderer( QgsFeatureRendererV2* subRenderer /Transfer/ );
const QgsFeatureRendererV2* embeddedRenderer() const;

/** @returns true if the geometries are to be preprocessed (merged with an union) before rendering.*/
Expand Down
1 change: 0 additions & 1 deletion python/core/symbology-ng/qgspointdisplacementrenderer.sip
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ class QgsPointDisplacementRenderer : QgsFeatureRendererV2
void setLabelAttributeName( const QString& name );
QString labelAttributeName() const;

/** Sets embedded renderer (takes ownership)*/
void setEmbeddedRenderer( QgsFeatureRendererV2* r /Transfer/ );
QgsFeatureRendererV2* embeddedRenderer();

Expand Down
15 changes: 15 additions & 0 deletions python/core/symbology-ng/qgsrendererv2.sip
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,21 @@ class QgsFeatureRendererV2
*/
void setOrderByEnabled( bool enabled );

/** Sets an embedded renderer (subrenderer) for this feature renderer. The base class implementation
* does nothing with subrenderers, but individual derived classes can use these to modify their behaviour.
* @param subRenderer the embedded renderer. Ownership will be transferred.
* @see embeddedRenderer()
* @note added in QGIS 2.16
*/
virtual void setEmbeddedRenderer( QgsFeatureRendererV2* subRenderer /Transfer/ );

/** Returns the current embedded renderer (subrenderer) for this feature renderer. The base class
* implementation does not use subrenderers and will always return null.
* @see setEmbeddedRenderer()
* @note added in QGIS 2.16
*/
virtual const QgsFeatureRendererV2* embeddedRenderer() const;

protected:
QgsFeatureRendererV2( const QString& type );

Expand Down
34 changes: 30 additions & 4 deletions src/app/qgsapplayertreeviewmenuprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,11 @@ QMenu* QgsAppLayerTreeViewMenuProvider::createContextMenu()

if ( vlayer )
{
QgsSingleSymbolRendererV2* singleRenderer = dynamic_cast< QgsSingleSymbolRendererV2* >( vlayer->rendererV2() );
const QgsSingleSymbolRendererV2* singleRenderer = dynamic_cast< const QgsSingleSymbolRendererV2* >( vlayer->rendererV2() );
if ( !singleRenderer && vlayer->rendererV2()->embeddedRenderer() )
{
singleRenderer = dynamic_cast< const QgsSingleSymbolRendererV2* >( vlayer->rendererV2()->embeddedRenderer() );
}
if ( singleRenderer && singleRenderer->symbol() )
{
//single symbol renderer, so add set color/edit symbol actions
Expand Down Expand Up @@ -488,12 +492,34 @@ void QgsAppLayerTreeViewMenuProvider::setVectorSymbolColor( const QColor& color
return;

QgsSingleSymbolRendererV2* singleRenderer = dynamic_cast< QgsSingleSymbolRendererV2* >( layer->rendererV2() );
if ( !singleRenderer || !singleRenderer->symbol() )
QgsSymbolV2* newSymbol = nullptr;

if ( singleRenderer && singleRenderer->symbol() )
newSymbol = singleRenderer->symbol()->clone();

const QgsSingleSymbolRendererV2* embeddedRenderer = nullptr;
if ( !newSymbol && layer->rendererV2()->embeddedRenderer() )
{
embeddedRenderer = dynamic_cast< const QgsSingleSymbolRendererV2* >( layer->rendererV2()->embeddedRenderer() );
if ( embeddedRenderer && embeddedRenderer->symbol() )
newSymbol = embeddedRenderer->symbol()->clone();
}

if ( !newSymbol )
return;

QgsSymbolV2* newSymbol = singleRenderer->symbol()->clone();
newSymbol->setColor( color );
singleRenderer->setSymbol( newSymbol );
if ( singleRenderer )
{
singleRenderer->setSymbol( newSymbol );
}
else if ( embeddedRenderer )
{
QgsSingleSymbolRendererV2* newRenderer = embeddedRenderer->clone();
newRenderer->setSymbol( newSymbol );
layer->rendererV2()->setEmbeddedRenderer( newRenderer );
}

layer->triggerRepaint();
mView->refreshLayerSymbology( layer->id() );
}
Expand Down
9 changes: 4 additions & 5 deletions src/core/symbology-ng/qgsinvertedpolygonrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include <QDomDocument>
#include <QDomElement>

QgsInvertedPolygonRenderer::QgsInvertedPolygonRenderer( const QgsFeatureRendererV2* subRenderer )
QgsInvertedPolygonRenderer::QgsInvertedPolygonRenderer( QgsFeatureRendererV2* subRenderer )
: QgsFeatureRendererV2( "invertedPolygonRenderer" )
, mPreprocessingEnabled( false )
{
Expand All @@ -47,11 +47,11 @@ QgsInvertedPolygonRenderer::~QgsInvertedPolygonRenderer()
{
}

void QgsInvertedPolygonRenderer::setEmbeddedRenderer( const QgsFeatureRendererV2* subRenderer )
void QgsInvertedPolygonRenderer::setEmbeddedRenderer( QgsFeatureRendererV2* subRenderer )
{
if ( subRenderer )
{
mSubRenderer.reset( const_cast<QgsFeatureRendererV2*>( subRenderer )->clone() );
mSubRenderer.reset( subRenderer );
}
else
{
Expand Down Expand Up @@ -341,7 +341,7 @@ QgsInvertedPolygonRenderer* QgsInvertedPolygonRenderer::clone() const
}
else
{
newRenderer = new QgsInvertedPolygonRenderer( mSubRenderer.data() );
newRenderer = new QgsInvertedPolygonRenderer( mSubRenderer.data()->clone() );
}
newRenderer->setPreprocessingEnabled( preprocessingEnabled() );
copyRendererData( newRenderer );
Expand All @@ -357,7 +357,6 @@ QgsFeatureRendererV2* QgsInvertedPolygonRenderer::create( QDomElement& element )
{
QgsFeatureRendererV2* renderer = QgsFeatureRendererV2::load( embeddedRendererElem );
r->setEmbeddedRenderer( renderer );
delete renderer;
}
r->setPreprocessingEnabled( element.attribute( "preprocessing", "0" ).toInt() == 1 );
return r;
Expand Down
15 changes: 6 additions & 9 deletions src/core/symbology-ng/qgsinvertedpolygonrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ class CORE_EXPORT QgsInvertedPolygonRenderer : public QgsFeatureRendererV2
public:

/** Constructor
* @param embeddedRenderer optional embeddedRenderer. If null, a default one will be assigned
* @param embeddedRenderer optional embeddedRenderer. If null, a default one will be assigned.
* Ownership will be transferred.
*/
QgsInvertedPolygonRenderer( const QgsFeatureRendererV2* embeddedRenderer = nullptr );
QgsInvertedPolygonRenderer( QgsFeatureRendererV2* embeddedRenderer = nullptr );

virtual ~QgsInvertedPolygonRenderer();

/** Used to clone this feature renderer.*/
Expand Down Expand Up @@ -116,13 +118,8 @@ class CORE_EXPORT QgsInvertedPolygonRenderer : public QgsFeatureRendererV2
*/
virtual QDomElement save( QDomDocument& doc ) override;

/** Sets the embedded renderer
* @param subRenderer the embedded renderer (will be cloned)
*/
void setEmbeddedRenderer( const QgsFeatureRendererV2* subRenderer );
/** @returns the current embedded renderer
*/
const QgsFeatureRendererV2* embeddedRenderer() const;
void setEmbeddedRenderer( QgsFeatureRendererV2* subRenderer ) override;
const QgsFeatureRendererV2* embeddedRenderer() const override;

/** @returns true if the geometries are to be preprocessed (merged with an union) before rendering.*/
bool preprocessingEnabled() const { return mPreprocessingEnabled; }
Expand Down
5 changes: 5 additions & 0 deletions src/core/symbology-ng/qgspointdisplacementrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@ void QgsPointDisplacementRenderer::setEmbeddedRenderer( QgsFeatureRendererV2* r
mRenderer = r;
}

const QgsFeatureRendererV2* QgsPointDisplacementRenderer::embeddedRenderer() const
{
return mRenderer;
}

QList<QString> QgsPointDisplacementRenderer::usedAttributes()
{
QList<QString> attributeList;
Expand Down
5 changes: 2 additions & 3 deletions src/core/symbology-ng/qgspointdisplacementrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,8 @@ class CORE_EXPORT QgsPointDisplacementRenderer: public QgsFeatureRendererV2
void setLabelAttributeName( const QString& name ) { mLabelAttributeName = name; }
QString labelAttributeName() const { return mLabelAttributeName; }

/** Sets embedded renderer (takes ownership)*/
void setEmbeddedRenderer( QgsFeatureRendererV2* r );
QgsFeatureRendererV2* embeddedRenderer() const { return mRenderer;}
void setEmbeddedRenderer( QgsFeatureRendererV2* r ) override;
const QgsFeatureRendererV2* embeddedRenderer() const override;

//! not available in python bindings
//! @deprecated since 2.4
Expand Down
15 changes: 15 additions & 0 deletions src/core/symbology-ng/qgsrendererv2.h
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,21 @@ class CORE_EXPORT QgsFeatureRendererV2
*/
void setOrderByEnabled( bool enabled );

/** Sets an embedded renderer (subrenderer) for this feature renderer. The base class implementation
* does nothing with subrenderers, but individual derived classes can use these to modify their behaviour.
* @param subRenderer the embedded renderer. Ownership will be transferred.
* @see embeddedRenderer()
* @note added in QGIS 2.16
*/
virtual void setEmbeddedRenderer( QgsFeatureRendererV2* subRenderer ) { delete subRenderer; }

/** Returns the current embedded renderer (subrenderer) for this feature renderer. The base class
* implementation does not use subrenderers and will always return null.
* @see setEmbeddedRenderer()
* @note added in QGIS 2.16
*/
virtual const QgsFeatureRendererV2* embeddedRenderer() const { return nullptr; }

protected:
QgsFeatureRendererV2( const QString& type );

Expand Down

0 comments on commit a1e1614

Please sign in to comment.