Skip to content

Commit 5d50b17

Browse files
committedMay 7, 2017
Swap some members to unique_ptrs to make ownership clearer
1 parent fefa572 commit 5d50b17

File tree

2 files changed

+10
-22
lines changed

2 files changed

+10
-22
lines changed
 

‎src/core/symbology-ng/qgssymbol.cpp

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ QgsSymbol::QgsSymbol( SymbolType type, const QgsSymbolLayerList &layers )
8383
, mRenderHints( 0 )
8484
, mClipFeaturesToExtent( true )
8585
, mLayer( nullptr )
86-
, mSymbolRenderContext( nullptr )
8786
{
8887

8988
// check they're all correct symbol layers
@@ -188,7 +187,6 @@ void QgsSymbol::_getPolygon( QPolygonF &pts, QList<QPolygonF> &holes, QgsRenderC
188187

189188
QgsSymbol::~QgsSymbol()
190189
{
191-
delete mSymbolRenderContext;
192190
// delete all symbol layers (we own them, so it's okay)
193191
qDeleteAll( mLayers );
194192
}
@@ -377,14 +375,12 @@ bool QgsSymbol::changeSymbolLayer( int index, QgsSymbolLayer *layer )
377375

378376
void QgsSymbol::startRender( QgsRenderContext &context, const QgsFields &fields )
379377
{
380-
delete mSymbolRenderContext;
381-
mSymbolRenderContext = new QgsSymbolRenderContext( context, outputUnit(), mAlpha, false, mRenderHints, nullptr, fields, mapUnitScale() );
378+
mSymbolRenderContext.reset( new QgsSymbolRenderContext( context, outputUnit(), mAlpha, false, mRenderHints, nullptr, fields, mapUnitScale() ) );
382379

383380
QgsSymbolRenderContext symbolContext( context, outputUnit(), mAlpha, false, mRenderHints, nullptr, fields, mapUnitScale() );
384381

385-
QgsExpressionContextScope *scope = QgsExpressionContextUtils::updateSymbolScope( this, new QgsExpressionContextScope() );
386-
387-
mSymbolRenderContext->setExpressionContextScope( scope );
382+
std::unique_ptr< QgsExpressionContextScope > scope( QgsExpressionContextUtils::updateSymbolScope( this, new QgsExpressionContextScope() ) );
383+
mSymbolRenderContext->setExpressionContextScope( scope.release() );
388384

389385
Q_FOREACH ( QgsSymbolLayer *layer, mLayers )
390386
{
@@ -410,8 +406,7 @@ void QgsSymbol::stopRender( QgsRenderContext &context )
410406
}
411407
}
412408

413-
delete mSymbolRenderContext;
414-
mSymbolRenderContext = nullptr;
409+
mSymbolRenderContext.reset( nullptr );
415410

416411
mLayer = nullptr;
417412
}
@@ -985,7 +980,7 @@ void QgsSymbol::renderFeature( const QgsFeature &feature, QgsRenderContext &cont
985980

986981
QgsSymbolRenderContext *QgsSymbol::symbolRenderContext()
987982
{
988-
return mSymbolRenderContext;
983+
return mSymbolRenderContext.get();
989984
}
990985

991986
void QgsSymbol::renderVertexMarker( QPointF pt, QgsRenderContext &context, int currentVertexMarkerType, int currentVertexMarkerSize )
@@ -998,7 +993,6 @@ void QgsSymbol::renderVertexMarker( QPointF pt, QgsRenderContext &context, int c
998993

999994
QgsSymbolRenderContext::QgsSymbolRenderContext( QgsRenderContext &c, QgsUnitTypes::RenderUnit u, qreal alpha, bool selected, QgsSymbol::RenderHints renderHints, const QgsFeature *f, const QgsFields &fields, const QgsMapUnitScale &mapUnitScale )
1000995
: mRenderContext( c )
1001-
, mExpressionContextScope( nullptr )
1002996
, mOutputUnit( u )
1003997
, mMapUnitScale( mapUnitScale )
1004998
, mAlpha( alpha )
@@ -1011,11 +1005,6 @@ QgsSymbolRenderContext::QgsSymbolRenderContext( QgsRenderContext &c, QgsUnitType
10111005
{
10121006
}
10131007

1014-
QgsSymbolRenderContext::~QgsSymbolRenderContext()
1015-
{
1016-
delete mExpressionContextScope;
1017-
}
1018-
10191008
void QgsSymbolRenderContext::setOriginalValueVariable( const QVariant &value )
10201009
{
10211010
mRenderContext.expressionContext().setOriginalValueVariable( value );
@@ -1043,12 +1032,12 @@ QgsSymbolRenderContext &QgsSymbolRenderContext::operator=( const QgsSymbolRender
10431032

10441033
QgsExpressionContextScope *QgsSymbolRenderContext::expressionContextScope()
10451034
{
1046-
return mExpressionContextScope;
1035+
return mExpressionContextScope.get();
10471036
}
10481037

10491038
void QgsSymbolRenderContext::setExpressionContextScope( QgsExpressionContextScope *contextScope )
10501039
{
1051-
mExpressionContextScope = contextScope;
1040+
mExpressionContextScope.reset( contextScope );
10521041
}
10531042

10541043
///////////////////

‎src/core/symbology-ng/qgssymbol.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ class CORE_EXPORT QgsSymbol
363363

364364
private:
365365
//! Initialized in startRender, destroyed in stopRender
366-
QgsSymbolRenderContext *mSymbolRenderContext = nullptr;
366+
std::unique_ptr< QgsSymbolRenderContext > mSymbolRenderContext;
367367

368368
Q_DISABLE_COPY( QgsSymbol )
369369

@@ -391,7 +391,6 @@ class CORE_EXPORT QgsSymbolRenderContext
391391
* \param mapUnitScale
392392
*/
393393
QgsSymbolRenderContext( QgsRenderContext &c, QgsUnitTypes::RenderUnit u, qreal alpha = 1.0, bool selected = false, QgsSymbol::RenderHints renderHints = 0, const QgsFeature *f = nullptr, const QgsFields &fields = QgsFields(), const QgsMapUnitScale &mapUnitScale = QgsMapUnitScale() );
394-
~QgsSymbolRenderContext();
395394

396395
QgsRenderContext &renderContext() { return mRenderContext; }
397396
const QgsRenderContext &renderContext() const { return mRenderContext; }
@@ -497,11 +496,11 @@ class CORE_EXPORT QgsSymbolRenderContext
497496
*
498497
* \param contextScope An expression scope for details about this symbol
499498
*/
500-
void setExpressionContextScope( QgsExpressionContextScope *contextScope );
499+
void setExpressionContextScope( QgsExpressionContextScope *contextScope SIP_TRANSFER );
501500

502501
private:
503502
QgsRenderContext &mRenderContext;
504-
QgsExpressionContextScope *mExpressionContextScope = nullptr;
503+
std::unique_ptr< QgsExpressionContextScope > mExpressionContextScope;
505504
QgsUnitTypes::RenderUnit mOutputUnit;
506505
QgsMapUnitScale mMapUnitScale;
507506
qreal mAlpha;

0 commit comments

Comments
 (0)
Please sign in to comment.