Skip to content

Commit

Permalink
Followup 43f150d, fix labels always enabling with diagrams
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Apr 13, 2015
1 parent 18e4a0c commit 437fc82
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 16 deletions.
24 changes: 18 additions & 6 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 labels which are enabled and should be drawn.
* @return true if layer contains enabled labels
* @note added in QGIS 2.9
*/
bool labelsEnabled() const;

/** 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
Expand Down Expand Up @@ -706,11 +712,15 @@ class QgsVectorLayer : QgsMapLayer
*/
int insertSegmentVerticesForSnap( const QList<QgsSnappingResult>& snapResults );

/** Set labels on */
void enableLabels( bool on );
/** Set labels on
* @deprecated this method is for the old labeling engine
*/
void enableLabels( bool on ) /Deprecated/;

/** Label is on */
bool hasLabelsEnabled() const;
/** Label is on
* @deprecated this method is for the old labeling engine, use labelsEnabled instead
*/
bool hasLabelsEnabled() const /Deprecated/;

/** Returns true if the provider is in editing mode */
virtual bool isEditable() const;
Expand Down Expand Up @@ -754,8 +764,10 @@ class QgsVectorLayer : QgsMapLayer
*/
bool draw( QgsRenderContext& rendererContext );

/** Draws the layer labels using coordinate transformation */
void drawLabels( QgsRenderContext& rendererContext );
/** Draws the layer labels using the old labeling engine
* @note deprecated
*/
void drawLabels( QgsRenderContext& rendererContext ) /Deprecated/;

/** Return the extent of the layer as a QRect */
QgsRectangle extent();
Expand Down
2 changes: 2 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -5320,11 +5320,13 @@ void QgisApp::checkForDeprecatedLabelsInProject()
continue;
}

Q_NOWARN_DEPRECATED_PUSH
depLabelsUsed = vl->hasLabelsEnabled();
if ( depLabelsUsed )
{
break;
}
Q_NOWARN_DEPRECATED_POP
}
if ( depLabelsUsed )
{
Expand Down
4 changes: 4 additions & 0 deletions src/app/qgsvectorlayerproperties.cpp
Expand Up @@ -455,6 +455,7 @@ void QgsVectorLayerProperties::syncToLayer( void )
labelingDialog->init();
}

Q_NOWARN_DEPRECATED_PUSH
if ( mOptsPage_LabelsOld )
{
if ( labelDialog && layer->hasGeometryType() )
Expand All @@ -475,6 +476,7 @@ void QgsVectorLayerProperties::syncToLayer( void )
QgsProject::instance()->writeEntry( "DeprecatedLabels", "/Enabled", true );
// (this also overrides any '/Enabled, false' project property the user may have manually set)
}
Q_NOWARN_DEPRECATED_POP

// delete deprecated labels tab if not already used by project
// NOTE: this is not ideal, but a quick fix for QGIS 2.0 release
Expand Down Expand Up @@ -544,6 +546,7 @@ void QgsVectorLayerProperties::apply()

actionDialog->apply();

Q_NOWARN_DEPRECATED_PUSH
if ( mOptsPage_LabelsOld )
{
if ( labelDialog )
Expand All @@ -552,6 +555,7 @@ void QgsVectorLayerProperties::apply()
}
layer->enableLabels( labelCheckBox->isChecked() );
}
Q_NOWARN_DEPRECATED_POP

layer->setLayerName( mLayerOrigNameLineEdit->text() );

Expand Down
2 changes: 2 additions & 0 deletions src/core/qgsofflineediting.cpp
Expand Up @@ -562,7 +562,9 @@ QgsVectorLayer* QgsOfflineEditing::copyVectorLayer( QgsVectorLayer* layer, sqlit
QList<QgsMapLayer *>() << newLayer );

// copy style
Q_NOWARN_DEPRECATED_PUSH
bool hasLabels = layer->hasLabelsEnabled();
Q_NOWARN_DEPRECATED_POP
if ( !hasLabels )
{
// NOTE: copy symbology before adding the layer so it is displayed correctly
Expand Down
7 changes: 3 additions & 4 deletions src/core/qgspallabeling.cpp
Expand Up @@ -714,7 +714,7 @@ void QgsPalLayerSettings::readFromLayer( QgsVectorLayer* layer )

// NOTE: set defaults for newly added properties, for backwards compatibility

enabled = layer->customProperty( "labeling/enabled" ).toBool();
enabled = layer->labelsEnabled();

// text style
fieldName = layer->customProperty( "labeling/fieldName" ).toString();
Expand Down Expand Up @@ -3152,8 +3152,7 @@ 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()
|| layer->diagramsEnabled();
enabled = layer->labelsEnabled() || layer->diagramsEnabled();

return enabled;
}
Expand Down Expand Up @@ -3187,7 +3186,7 @@ int QgsPalLabeling::prepareLayer( QgsVectorLayer* layer, QStringList& attrNames,
{
Q_ASSERT( mMapSettings != NULL );

if ( !willUseLayer( layer ) )
if ( !willUseLayer( layer ) || !layer->labelsEnabled() )
{
return 0;
}
Expand Down
9 changes: 9 additions & 0 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -711,6 +711,11 @@ QgsRectangle QgsVectorLayer::boundingBoxOfSelected()
return retval;
}

bool QgsVectorLayer::labelsEnabled() const
{
return customProperty( "labeling/enabled", QVariant( false ) ).toBool();
}

bool QgsVectorLayer::diagramsEnabled() const
{
if ( !mDiagramRenderer || !mDiagramLayerSettings )
Expand Down Expand Up @@ -1602,6 +1607,7 @@ bool QgsVectorLayer::readSymbology( const QDomNode& node, QString& errorMessage
QDomNode labelnode = node.namedItem( "label" );
QDomElement element = labelnode.toElement();
int hasLabelsEnabled = element.text().toInt();
Q_NOWARN_DEPRECATED_PUSH
if ( hasLabelsEnabled < 1 )
{
enableLabels( false );
Expand All @@ -1610,6 +1616,7 @@ bool QgsVectorLayer::readSymbology( const QDomNode& node, QString& errorMessage
{
enableLabels( true );
}
Q_NOWARN_DEPRECATED_POP

QDomNode labelattributesnode = node.namedItem( "labelattributes" );

Expand Down Expand Up @@ -1861,6 +1868,7 @@ bool QgsVectorLayer::writeSymbology( QDomNode& node, QDomDocument& doc, QString&
QDomElement labelElem = doc.createElement( "label" );
QDomText labelText = doc.createTextNode( "" );

Q_NOWARN_DEPRECATED_PUSH
if ( hasLabelsEnabled() )
{
labelText.setData( "1" );
Expand All @@ -1869,6 +1877,7 @@ bool QgsVectorLayer::writeSymbology( QDomNode& node, QDomDocument& doc, QString&
{
labelText.setData( "0" );
}
Q_NOWARN_DEPRECATED_POP
labelElem.appendChild( labelText );

node.appendChild( labelElem );
Expand Down
24 changes: 18 additions & 6 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 labels which are enabled and should be drawn.
* @return true if layer contains enabled labels
* @note added in QGIS 2.9
*/
bool labelsEnabled() const;

/** 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
Expand Down Expand Up @@ -1068,11 +1074,15 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
*/
int insertSegmentVerticesForSnap( const QList<QgsSnappingResult>& snapResults );

/** Set labels on */
void enableLabels( bool on );
/** Set labels on
* @deprecated this method is for the old labeling engine
*/
Q_DECL_DEPRECATED void enableLabels( bool on );

/** Label is on */
bool hasLabelsEnabled() const;
/** Label is on
* @deprecated this method is for the old labeling engine, use labelsEnabled instead
*/
Q_DECL_DEPRECATED bool hasLabelsEnabled() const;

/** Returns true if the provider is in editing mode */
virtual bool isEditable() const override;
Expand Down Expand Up @@ -1116,8 +1126,10 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
*/
bool draw( QgsRenderContext& rendererContext ) override;

/** Draws the layer labels using coordinate transformation */
void drawLabels( QgsRenderContext& rendererContext ) override;
/** Draws the layer labels using the old labeling engine
* @note deprecated
*/
Q_DECL_DEPRECATED void drawLabels( QgsRenderContext& rendererContext ) override;

/** Return the extent of the layer as a QRect */
QgsRectangle extent() override;
Expand Down

0 comments on commit 437fc82

Please sign in to comment.