Skip to content
Permalink
Browse files

Followup 43f150d, fix labels always enabling with diagrams

  • Loading branch information
nyalldawson committed Apr 13, 2015
1 parent 18e4a0c commit 437fc82435a1142cb6631fb2774a4c9c1bfa004f
@@ -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
@@ -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;
@@ -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();
@@ -5320,11 +5320,13 @@ void QgisApp::checkForDeprecatedLabelsInProject()
continue;
}

Q_NOWARN_DEPRECATED_PUSH
depLabelsUsed = vl->hasLabelsEnabled();
if ( depLabelsUsed )
{
break;
}
Q_NOWARN_DEPRECATED_POP
}
if ( depLabelsUsed )
{
@@ -455,6 +455,7 @@ void QgsVectorLayerProperties::syncToLayer( void )
labelingDialog->init();
}

Q_NOWARN_DEPRECATED_PUSH
if ( mOptsPage_LabelsOld )
{
if ( labelDialog && layer->hasGeometryType() )
@@ -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
@@ -544,6 +546,7 @@ void QgsVectorLayerProperties::apply()

actionDialog->apply();

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

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

@@ -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
@@ -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();
@@ -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;
}
@@ -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;
}
@@ -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 )
@@ -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 );
@@ -1610,6 +1616,7 @@ bool QgsVectorLayer::readSymbology( const QDomNode& node, QString& errorMessage
{
enableLabels( true );
}
Q_NOWARN_DEPRECATED_POP

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

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

0 comments on commit 437fc82

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