Skip to content

Commit 437fc82

Browse files
committed
Followup 43f150d, fix labels always enabling with diagrams
1 parent 18e4a0c commit 437fc82

File tree

7 files changed

+56
-16
lines changed

7 files changed

+56
-16
lines changed

python/core/qgsvectorlayer.sip

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,12 @@ class QgsVectorLayer : QgsMapLayer
427427
/** Returns the bounding box of the selected features. If there is no selection, QgsRectangle(0,0,0,0) is returned */
428428
QgsRectangle boundingBoxOfSelected();
429429

430+
/** Returns whether the layer contains labels which are enabled and should be drawn.
431+
* @return true if layer contains enabled labels
432+
* @note added in QGIS 2.9
433+
*/
434+
bool labelsEnabled() const;
435+
430436
/** Returns whether the layer contains diagrams which are enabled and should be drawn.
431437
* @return true if layer contains enabled diagrams
432438
* @note added in QGIS 2.9
@@ -706,11 +712,15 @@ class QgsVectorLayer : QgsMapLayer
706712
*/
707713
int insertSegmentVerticesForSnap( const QList<QgsSnappingResult>& snapResults );
708714

709-
/** Set labels on */
710-
void enableLabels( bool on );
715+
/** Set labels on
716+
* @deprecated this method is for the old labeling engine
717+
*/
718+
void enableLabels( bool on ) /Deprecated/;
711719

712-
/** Label is on */
713-
bool hasLabelsEnabled() const;
720+
/** Label is on
721+
* @deprecated this method is for the old labeling engine, use labelsEnabled instead
722+
*/
723+
bool hasLabelsEnabled() const /Deprecated/;
714724

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

757-
/** Draws the layer labels using coordinate transformation */
758-
void drawLabels( QgsRenderContext& rendererContext );
767+
/** Draws the layer labels using the old labeling engine
768+
* @note deprecated
769+
*/
770+
void drawLabels( QgsRenderContext& rendererContext ) /Deprecated/;
759771

760772
/** Return the extent of the layer as a QRect */
761773
QgsRectangle extent();

src/app/qgisapp.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5320,11 +5320,13 @@ void QgisApp::checkForDeprecatedLabelsInProject()
53205320
continue;
53215321
}
53225322

5323+
Q_NOWARN_DEPRECATED_PUSH
53235324
depLabelsUsed = vl->hasLabelsEnabled();
53245325
if ( depLabelsUsed )
53255326
{
53265327
break;
53275328
}
5329+
Q_NOWARN_DEPRECATED_POP
53285330
}
53295331
if ( depLabelsUsed )
53305332
{

src/app/qgsvectorlayerproperties.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ void QgsVectorLayerProperties::syncToLayer( void )
455455
labelingDialog->init();
456456
}
457457

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

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

545547
actionDialog->apply();
546548

549+
Q_NOWARN_DEPRECATED_PUSH
547550
if ( mOptsPage_LabelsOld )
548551
{
549552
if ( labelDialog )
@@ -552,6 +555,7 @@ void QgsVectorLayerProperties::apply()
552555
}
553556
layer->enableLabels( labelCheckBox->isChecked() );
554557
}
558+
Q_NOWARN_DEPRECATED_POP
555559

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

src/core/qgsofflineediting.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,9 @@ QgsVectorLayer* QgsOfflineEditing::copyVectorLayer( QgsVectorLayer* layer, sqlit
562562
QList<QgsMapLayer *>() << newLayer );
563563

564564
// copy style
565+
Q_NOWARN_DEPRECATED_PUSH
565566
bool hasLabels = layer->hasLabelsEnabled();
567+
Q_NOWARN_DEPRECATED_POP
566568
if ( !hasLabels )
567569
{
568570
// NOTE: copy symbology before adding the layer so it is displayed correctly

src/core/qgspallabeling.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ void QgsPalLayerSettings::readFromLayer( QgsVectorLayer* layer )
714714

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

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

719719
// text style
720720
fieldName = layer->customProperty( "labeling/fieldName" ).toString();
@@ -3152,8 +3152,7 @@ bool QgsPalLabeling::staticWillUseLayer( QgsVectorLayer* layer )
31523152
// don't do QgsPalLayerSettings::readFromLayer( layer ) if not needed
31533153
bool enabled = false;
31543154
if ( layer->customProperty( "labeling" ).toString() == QString( "pal" ) )
3155-
enabled = layer->customProperty( "labeling/enabled", QVariant( false ) ).toBool()
3156-
|| layer->diagramsEnabled();
3155+
enabled = layer->labelsEnabled() || layer->diagramsEnabled();
31573156

31583157
return enabled;
31593158
}
@@ -3187,7 +3186,7 @@ int QgsPalLabeling::prepareLayer( QgsVectorLayer* layer, QStringList& attrNames,
31873186
{
31883187
Q_ASSERT( mMapSettings != NULL );
31893188

3190-
if ( !willUseLayer( layer ) )
3189+
if ( !willUseLayer( layer ) || !layer->labelsEnabled() )
31913190
{
31923191
return 0;
31933192
}

src/core/qgsvectorlayer.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,11 @@ QgsRectangle QgsVectorLayer::boundingBoxOfSelected()
711711
return retval;
712712
}
713713

714+
bool QgsVectorLayer::labelsEnabled() const
715+
{
716+
return customProperty( "labeling/enabled", QVariant( false ) ).toBool();
717+
}
718+
714719
bool QgsVectorLayer::diagramsEnabled() const
715720
{
716721
if ( !mDiagramRenderer || !mDiagramLayerSettings )
@@ -1602,6 +1607,7 @@ bool QgsVectorLayer::readSymbology( const QDomNode& node, QString& errorMessage
16021607
QDomNode labelnode = node.namedItem( "label" );
16031608
QDomElement element = labelnode.toElement();
16041609
int hasLabelsEnabled = element.text().toInt();
1610+
Q_NOWARN_DEPRECATED_PUSH
16051611
if ( hasLabelsEnabled < 1 )
16061612
{
16071613
enableLabels( false );
@@ -1610,6 +1616,7 @@ bool QgsVectorLayer::readSymbology( const QDomNode& node, QString& errorMessage
16101616
{
16111617
enableLabels( true );
16121618
}
1619+
Q_NOWARN_DEPRECATED_POP
16131620

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

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

1871+
Q_NOWARN_DEPRECATED_PUSH
18641872
if ( hasLabelsEnabled() )
18651873
{
18661874
labelText.setData( "1" );
@@ -1869,6 +1877,7 @@ bool QgsVectorLayer::writeSymbology( QDomNode& node, QDomDocument& doc, QString&
18691877
{
18701878
labelText.setData( "0" );
18711879
}
1880+
Q_NOWARN_DEPRECATED_POP
18721881
labelElem.appendChild( labelText );
18731882

18741883
node.appendChild( labelElem );

src/core/qgsvectorlayer.h

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,12 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
789789
/** Returns the bounding box of the selected features. If there is no selection, QgsRectangle(0,0,0,0) is returned */
790790
QgsRectangle boundingBoxOfSelected();
791791

792+
/** Returns whether the layer contains labels which are enabled and should be drawn.
793+
* @return true if layer contains enabled labels
794+
* @note added in QGIS 2.9
795+
*/
796+
bool labelsEnabled() const;
797+
792798
/** Returns whether the layer contains diagrams which are enabled and should be drawn.
793799
* @return true if layer contains enabled diagrams
794800
* @note added in QGIS 2.9
@@ -1068,11 +1074,15 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
10681074
*/
10691075
int insertSegmentVerticesForSnap( const QList<QgsSnappingResult>& snapResults );
10701076

1071-
/** Set labels on */
1072-
void enableLabels( bool on );
1077+
/** Set labels on
1078+
* @deprecated this method is for the old labeling engine
1079+
*/
1080+
Q_DECL_DEPRECATED void enableLabels( bool on );
10731081

1074-
/** Label is on */
1075-
bool hasLabelsEnabled() const;
1082+
/** Label is on
1083+
* @deprecated this method is for the old labeling engine, use labelsEnabled instead
1084+
*/
1085+
Q_DECL_DEPRECATED bool hasLabelsEnabled() const;
10761086

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

1119-
/** Draws the layer labels using coordinate transformation */
1120-
void drawLabels( QgsRenderContext& rendererContext ) override;
1129+
/** Draws the layer labels using the old labeling engine
1130+
* @note deprecated
1131+
*/
1132+
Q_DECL_DEPRECATED void drawLabels( QgsRenderContext& rendererContext ) override;
11211133

11221134
/** Return the extent of the layer as a QRect */
11231135
QgsRectangle extent() override;

0 commit comments

Comments
 (0)