Skip to content

Commit 5e1d1a4

Browse files
committed
Deprecate vector layer setter/getter within QgsSymbol
It's not used, and potentially very dangerous
1 parent e63fedf commit 5e1d1a4

File tree

4 files changed

+46
-6
lines changed

4 files changed

+46
-6
lines changed

python/core/auto_generated/symbology/qgssymbol.sip.in

+9-2
Original file line numberDiff line numberDiff line change
@@ -387,14 +387,21 @@ Returns whether the symbol utilizes any data defined properties.
387387
.. versionadded:: 2.12
388388
%End
389389

390-
void setLayer( const QgsVectorLayer *layer );
390+
void setLayer( const QgsVectorLayer *layer ) /Deprecated/;
391391
%Docstring
392392

393393
.. note::
394394

395395
the layer will be NULL after stopRender
396+
397+
.. deprecated:: Will be removed in QGIS 4.0
398+
%End
399+
400+
const QgsVectorLayer *layer() const /Deprecated/;
401+
%Docstring
402+
403+
.. deprecated:: Will be removed in QGIS 4.0
396404
%End
397-
const QgsVectorLayer *layer() const;
398405

399406
void renderFeature( const QgsFeature &feature, QgsRenderContext &context, int layer = -1, bool selected = false, bool drawVertexMarker = false, int currentVertexMarkerType = 0, int currentVertexMarkerSize = 0 );
400407
%Docstring

src/core/symbology/qgssymbol.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ QgsProperty scaleWholeSymbol( double scaleFactorX, double scaleFactorY, const Qg
7878

7979
////////////////////
8080

81+
Q_NOWARN_DEPRECATED_PUSH // because of deprecated mLayer
8182
QgsSymbol::QgsSymbol( SymbolType type, const QgsSymbolLayerList &layers )
8283
: mType( type )
8384
, mLayers( layers )
@@ -97,6 +98,7 @@ QgsSymbol::QgsSymbol( SymbolType type, const QgsSymbolLayerList &layers )
9798
}
9899
}
99100
}
101+
Q_NOWARN_DEPRECATED_POP
100102

101103
QPolygonF QgsSymbol::_getLineString( QgsRenderContext &context, const QgsCurve &curve, bool clipToExtent )
102104
{
@@ -434,7 +436,9 @@ void QgsSymbol::stopRender( QgsRenderContext &context )
434436

435437
mSymbolRenderContext.reset( nullptr );
436438

439+
Q_NOWARN_DEPRECATED_PUSH
437440
mLayer = nullptr;
441+
Q_NOWARN_DEPRECATED_POP
438442
}
439443

440444
void QgsSymbol::setColor( const QColor &color )
@@ -669,6 +673,20 @@ bool QgsSymbol::hasDataDefinedProperties() const
669673
return false;
670674
}
671675

676+
void QgsSymbol::setLayer( const QgsVectorLayer *layer )
677+
{
678+
Q_NOWARN_DEPRECATED_PUSH
679+
mLayer = layer;
680+
Q_NOWARN_DEPRECATED_POP
681+
}
682+
683+
const QgsVectorLayer *QgsSymbol::layer() const
684+
{
685+
Q_NOWARN_DEPRECATED_PUSH
686+
return mLayer;
687+
Q_NOWARN_DEPRECATED_POP
688+
}
689+
672690
///@cond PRIVATE
673691

674692
/**
@@ -1554,7 +1572,9 @@ QgsMarkerSymbol *QgsMarkerSymbol::clone() const
15541572
{
15551573
QgsMarkerSymbol *cloneSymbol = new QgsMarkerSymbol( cloneLayers() );
15561574
cloneSymbol->setOpacity( mOpacity );
1575+
Q_NOWARN_DEPRECATED_PUSH
15571576
cloneSymbol->setLayer( mLayer );
1577+
Q_NOWARN_DEPRECATED_POP
15581578
cloneSymbol->setClipFeaturesToExtent( mClipFeaturesToExtent );
15591579
return cloneSymbol;
15601580
}
@@ -1771,7 +1791,9 @@ QgsLineSymbol *QgsLineSymbol::clone() const
17711791
{
17721792
QgsLineSymbol *cloneSymbol = new QgsLineSymbol( cloneLayers() );
17731793
cloneSymbol->setOpacity( mOpacity );
1794+
Q_NOWARN_DEPRECATED_PUSH
17741795
cloneSymbol->setLayer( mLayer );
1796+
Q_NOWARN_DEPRECATED_POP
17751797
cloneSymbol->setClipFeaturesToExtent( mClipFeaturesToExtent );
17761798
return cloneSymbol;
17771799
}
@@ -1889,7 +1911,9 @@ QgsFillSymbol *QgsFillSymbol::clone() const
18891911
{
18901912
QgsFillSymbol *cloneSymbol = new QgsFillSymbol( cloneLayers() );
18911913
cloneSymbol->setOpacity( mOpacity );
1914+
Q_NOWARN_DEPRECATED_PUSH
18921915
cloneSymbol->setLayer( mLayer );
1916+
Q_NOWARN_DEPRECATED_POP
18931917
cloneSymbol->setClipFeaturesToExtent( mClipFeaturesToExtent );
18941918
return cloneSymbol;
18951919
}

src/core/symbology/qgssymbol.h

+11-4
Original file line numberDiff line numberDiff line change
@@ -394,9 +394,16 @@ class CORE_EXPORT QgsSymbol
394394
*/
395395
bool hasDataDefinedProperties() const;
396396

397-
//! \note the layer will be NULL after stopRender
398-
void setLayer( const QgsVectorLayer *layer ) { mLayer = layer; }
399-
const QgsVectorLayer *layer() const { return mLayer; }
397+
/**
398+
* \note the layer will be NULL after stopRender
399+
* \deprecated Will be removed in QGIS 4.0
400+
*/
401+
Q_DECL_DEPRECATED void setLayer( const QgsVectorLayer *layer ) SIP_DEPRECATED;
402+
403+
/**
404+
* \deprecated Will be removed in QGIS 4.0
405+
*/
406+
Q_DECL_DEPRECATED const QgsVectorLayer *layer() const SIP_DEPRECATED;
400407

401408
/**
402409
* Render a feature. Before calling this the startRender() method should be called to initialize
@@ -483,7 +490,7 @@ class CORE_EXPORT QgsSymbol
483490
RenderHints mRenderHints = nullptr;
484491
bool mClipFeaturesToExtent = true;
485492

486-
const QgsVectorLayer *mLayer = nullptr; //current vectorlayer
493+
Q_DECL_DEPRECATED const QgsVectorLayer *mLayer = nullptr; //current vectorlayer
487494

488495
private:
489496
#ifdef SIP_RUN

src/gui/symbology/qgssymbolselectordialog.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,9 @@ void QgsSymbolSelectorWidget::layerChanged()
472472
{
473473
mDataDefineRestorer.reset();
474474
// then it must be a symbol
475+
Q_NOWARN_DEPRECATED_PUSH
475476
currentItem->symbol()->setLayer( mVectorLayer );
477+
Q_NOWARN_DEPRECATED_POP
476478
// Now populate symbols of that type using the symbols list widget:
477479
QgsSymbolsListWidget *symbolsList = new QgsSymbolsListWidget( currentItem->symbol(), mStyle, mAdvancedMenu, this, mVectorLayer );
478480
symbolsList->setContext( mContext );

0 commit comments

Comments
 (0)