Skip to content

Commit

Permalink
Deprecate vector layer setter/getter within QgsSymbol
Browse files Browse the repository at this point in the history
It's not used, and potentially very dangerous
  • Loading branch information
nyalldawson committed Aug 31, 2018
1 parent e63fedf commit 5e1d1a4
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 6 deletions.
11 changes: 9 additions & 2 deletions python/core/auto_generated/symbology/qgssymbol.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -387,14 +387,21 @@ Returns whether the symbol utilizes any data defined properties.
.. versionadded:: 2.12
%End

void setLayer( const QgsVectorLayer *layer );
void setLayer( const QgsVectorLayer *layer ) /Deprecated/;
%Docstring

.. note::

the layer will be NULL after stopRender

.. deprecated:: Will be removed in QGIS 4.0
%End

const QgsVectorLayer *layer() const /Deprecated/;
%Docstring

.. deprecated:: Will be removed in QGIS 4.0
%End
const QgsVectorLayer *layer() const;

void renderFeature( const QgsFeature &feature, QgsRenderContext &context, int layer = -1, bool selected = false, bool drawVertexMarker = false, int currentVertexMarkerType = 0, int currentVertexMarkerSize = 0 );
%Docstring
Expand Down
24 changes: 24 additions & 0 deletions src/core/symbology/qgssymbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ QgsProperty scaleWholeSymbol( double scaleFactorX, double scaleFactorY, const Qg

////////////////////

Q_NOWARN_DEPRECATED_PUSH // because of deprecated mLayer
QgsSymbol::QgsSymbol( SymbolType type, const QgsSymbolLayerList &layers )
: mType( type )
, mLayers( layers )
Expand All @@ -97,6 +98,7 @@ QgsSymbol::QgsSymbol( SymbolType type, const QgsSymbolLayerList &layers )
}
}
}
Q_NOWARN_DEPRECATED_POP

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

mSymbolRenderContext.reset( nullptr );

Q_NOWARN_DEPRECATED_PUSH
mLayer = nullptr;
Q_NOWARN_DEPRECATED_POP
}

void QgsSymbol::setColor( const QColor &color )
Expand Down Expand Up @@ -669,6 +673,20 @@ bool QgsSymbol::hasDataDefinedProperties() const
return false;
}

void QgsSymbol::setLayer( const QgsVectorLayer *layer )
{
Q_NOWARN_DEPRECATED_PUSH
mLayer = layer;
Q_NOWARN_DEPRECATED_POP
}

const QgsVectorLayer *QgsSymbol::layer() const
{
Q_NOWARN_DEPRECATED_PUSH
return mLayer;
Q_NOWARN_DEPRECATED_POP
}

///@cond PRIVATE

/**
Expand Down Expand Up @@ -1554,7 +1572,9 @@ QgsMarkerSymbol *QgsMarkerSymbol::clone() const
{
QgsMarkerSymbol *cloneSymbol = new QgsMarkerSymbol( cloneLayers() );
cloneSymbol->setOpacity( mOpacity );
Q_NOWARN_DEPRECATED_PUSH
cloneSymbol->setLayer( mLayer );
Q_NOWARN_DEPRECATED_POP
cloneSymbol->setClipFeaturesToExtent( mClipFeaturesToExtent );
return cloneSymbol;
}
Expand Down Expand Up @@ -1771,7 +1791,9 @@ QgsLineSymbol *QgsLineSymbol::clone() const
{
QgsLineSymbol *cloneSymbol = new QgsLineSymbol( cloneLayers() );
cloneSymbol->setOpacity( mOpacity );
Q_NOWARN_DEPRECATED_PUSH
cloneSymbol->setLayer( mLayer );
Q_NOWARN_DEPRECATED_POP
cloneSymbol->setClipFeaturesToExtent( mClipFeaturesToExtent );
return cloneSymbol;
}
Expand Down Expand Up @@ -1889,7 +1911,9 @@ QgsFillSymbol *QgsFillSymbol::clone() const
{
QgsFillSymbol *cloneSymbol = new QgsFillSymbol( cloneLayers() );
cloneSymbol->setOpacity( mOpacity );
Q_NOWARN_DEPRECATED_PUSH
cloneSymbol->setLayer( mLayer );
Q_NOWARN_DEPRECATED_POP
cloneSymbol->setClipFeaturesToExtent( mClipFeaturesToExtent );
return cloneSymbol;
}
Expand Down
15 changes: 11 additions & 4 deletions src/core/symbology/qgssymbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,16 @@ class CORE_EXPORT QgsSymbol
*/
bool hasDataDefinedProperties() const;

//! \note the layer will be NULL after stopRender
void setLayer( const QgsVectorLayer *layer ) { mLayer = layer; }
const QgsVectorLayer *layer() const { return mLayer; }
/**
* \note the layer will be NULL after stopRender
* \deprecated Will be removed in QGIS 4.0
*/
Q_DECL_DEPRECATED void setLayer( const QgsVectorLayer *layer ) SIP_DEPRECATED;

/**
* \deprecated Will be removed in QGIS 4.0
*/
Q_DECL_DEPRECATED const QgsVectorLayer *layer() const SIP_DEPRECATED;

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

const QgsVectorLayer *mLayer = nullptr; //current vectorlayer
Q_DECL_DEPRECATED const QgsVectorLayer *mLayer = nullptr; //current vectorlayer

private:
#ifdef SIP_RUN
Expand Down
2 changes: 2 additions & 0 deletions src/gui/symbology/qgssymbolselectordialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,9 @@ void QgsSymbolSelectorWidget::layerChanged()
{
mDataDefineRestorer.reset();
// then it must be a symbol
Q_NOWARN_DEPRECATED_PUSH
currentItem->symbol()->setLayer( mVectorLayer );
Q_NOWARN_DEPRECATED_POP
// Now populate symbols of that type using the symbols list widget:
QgsSymbolsListWidget *symbolsList = new QgsSymbolsListWidget( currentItem->symbol(), mStyle, mAdvancedMenu, this, mVectorLayer );
symbolsList->setContext( mContext );
Expand Down

0 comments on commit 5e1d1a4

Please sign in to comment.