Skip to content
Permalink
Browse files

Fix inverted polygon & displacement renderer don't show

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 a1e1614c6c20b4473f9a71b96c1455cba0a558bc
@@ -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.*/
@@ -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.*/
@@ -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();

@@ -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 );

@@ -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
@@ -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() );
}
@@ -29,7 +29,7 @@
#include <QDomDocument>
#include <QDomElement>

QgsInvertedPolygonRenderer::QgsInvertedPolygonRenderer( const QgsFeatureRendererV2* subRenderer )
QgsInvertedPolygonRenderer::QgsInvertedPolygonRenderer( QgsFeatureRendererV2* subRenderer )
: QgsFeatureRendererV2( "invertedPolygonRenderer" )
, mPreprocessingEnabled( false )
{
@@ -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
{
@@ -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 );
@@ -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;
@@ -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.*/
@@ -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; }
@@ -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;
@@ -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
@@ -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 );

0 comments on commit a1e1614

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