Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix diagrams not initially showing when toggling on/off layers
  • Loading branch information
nyalldawson committed Apr 9, 2015
1 parent e8b06c7 commit 1340677
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 3 deletions.
6 changes: 6 additions & 0 deletions python/core/qgsvectorlayer.sip
Expand Up @@ -427,6 +427,12 @@ class QgsVectorLayer : QgsMapLayer
/** Returns the bounding box of the selected features. If there is no selection, QgsRectangle(0,0,0,0) is returned */
QgsRectangle boundingBoxOfSelected();

/** Returns whether the layer contains diagrams which are enabled and should be drawn.
* @return true if layer contains enabled diagrams
* @note added in QGIS 2.9
*/
bool diagramsEnabled() const;

/** Sets diagram rendering object (takes ownership) */
void setDiagramRenderer( QgsDiagramRendererV2* r /Transfer/ );
const QgsDiagramRendererV2* diagramRenderer() const;
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgisapp.cpp
Expand Up @@ -9157,7 +9157,7 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
{
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( it.value() );
if ( !vlayer || !vlayer->isEditable() ||
( !vlayer->diagramRenderer() && vlayer->customProperty( "labeling" ).toString() != QString( "pal" ) ) )
( !vlayer->diagramsEnabled() && vlayer->customProperty( "labeling" ).toString() != QString( "pal" ) ) )
continue;

int colX, colY, colShow, colAng;
Expand Down
3 changes: 2 additions & 1 deletion src/core/qgspallabeling.cpp
Expand Up @@ -3152,7 +3152,8 @@ bool QgsPalLabeling::staticWillUseLayer( QgsVectorLayer* layer )
// don't do QgsPalLayerSettings::readFromLayer( layer ) if not needed
bool enabled = false;
if ( layer->customProperty( "labeling" ).toString() == QString( "pal" ) )
enabled = layer->customProperty( "labeling/enabled", QVariant( false ) ).toBool();
enabled = layer->customProperty( "labeling/enabled", QVariant( false ) ).toBool()
|| layer->diagramsEnabled();

return enabled;
}
Expand Down
5 changes: 5 additions & 0 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -711,6 +711,11 @@ QgsRectangle QgsVectorLayer::boundingBoxOfSelected()
return retval;
}

bool QgsVectorLayer::diagramsEnabled() const
{
return mDiagramRenderer && mDiagramLayerSettings;
}

long QgsVectorLayer::featureCount() const
{
if ( !mDataProvider )
Expand Down
6 changes: 6 additions & 0 deletions src/core/qgsvectorlayer.h
Expand Up @@ -789,6 +789,12 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
/** Returns the bounding box of the selected features. If there is no selection, QgsRectangle(0,0,0,0) is returned */
QgsRectangle boundingBoxOfSelected();

/** Returns whether the layer contains diagrams which are enabled and should be drawn.
* @return true if layer contains enabled diagrams
* @note added in QGIS 2.9
*/
bool diagramsEnabled() const;

/** Sets diagram rendering object (takes ownership) */
void setDiagramRenderer( QgsDiagramRendererV2* r );
const QgsDiagramRendererV2* diagramRenderer() const { return mDiagramRenderer; }
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsvectorlayerrenderer.cpp
Expand Up @@ -489,7 +489,7 @@ void QgsVectorLayerRenderer::prepareDiagrams( QgsVectorLayer* layer, QStringList
if ( !mContext.labelingEngine() )
return;

if ( !layer->diagramRenderer() || !layer->diagramLayerSettings() )
if ( !layer->diagramsEnabled() )
return;

mDiagrams = true;
Expand Down

0 comments on commit 1340677

Please sign in to comment.