Skip to content
Permalink
Browse files

Use unique_ptr for owned pointer

  • Loading branch information
nyalldawson committed Nov 27, 2018
1 parent 7ef6520 commit 1a199d0952b1fad92b00a6cd62aea748a6759cc4
Showing with 10 additions and 18 deletions.
  1. +6 −14 src/core/symbology/qgslegendsymbolitem.cpp
  2. +4 −4 src/core/symbology/qgslegendsymbolitem.h
@@ -32,28 +32,22 @@ QgsLegendSymbolItem::QgsLegendSymbolItem( QgsSymbol *symbol, const QString &labe
}

QgsLegendSymbolItem::QgsLegendSymbolItem( const QgsLegendSymbolItem &other )

{
*this = other;
}

QgsLegendSymbolItem::~QgsLegendSymbolItem()
{
delete mSymbol;
delete mDataDefinedSizeLegendSettings;
}
QgsLegendSymbolItem::~QgsLegendSymbolItem() = default;

QgsLegendSymbolItem &QgsLegendSymbolItem::operator=( const QgsLegendSymbolItem &other )
{
if ( this == &other )
return *this;

setSymbol( other.mSymbol );
mSymbol.reset( other.mSymbol ? other.mSymbol->clone() : nullptr );
mLabel = other.mLabel;
mKey = other.mKey;
mCheckable = other.mCheckable;
delete mDataDefinedSizeLegendSettings;
mDataDefinedSizeLegendSettings = other.mDataDefinedSizeLegendSettings ? new QgsDataDefinedSizeLegend( *other.mDataDefinedSizeLegendSettings ) : nullptr;
mDataDefinedSizeLegendSettings.reset( other.mDataDefinedSizeLegendSettings ? new QgsDataDefinedSizeLegend( *other.mDataDefinedSizeLegendSettings ) : nullptr );
mOriginalSymbolPointer = other.mOriginalSymbolPointer;
mScaleMinDenom = other.mScaleMinDenom;
mScaleMaxDenom = other.mScaleMaxDenom;
@@ -78,18 +72,16 @@ bool QgsLegendSymbolItem::isScaleOK( double scale ) const

void QgsLegendSymbolItem::setSymbol( QgsSymbol *s )
{
delete mSymbol;
mSymbol = s ? s->clone() : nullptr;
mSymbol.reset( s );
mOriginalSymbolPointer = s;
}

void QgsLegendSymbolItem::setDataDefinedSizeLegendSettings( QgsDataDefinedSizeLegend *settings )
{
delete mDataDefinedSizeLegendSettings;
mDataDefinedSizeLegendSettings = settings;
mDataDefinedSizeLegendSettings.reset( settings );
}

QgsDataDefinedSizeLegend *QgsLegendSymbolItem::dataDefinedSizeLegendSettings() const
{
return mDataDefinedSizeLegendSettings;
return mDataDefinedSizeLegendSettings.get();
}
@@ -53,7 +53,7 @@ class CORE_EXPORT QgsLegendSymbolItem
QgsLegendSymbolItem &operator=( const QgsLegendSymbolItem &other );

//! Returns associated symbol. May be null.
QgsSymbol *symbol() const { return mSymbol; }
QgsSymbol *symbol() const { return mSymbol.get(); }
//! Returns text label
QString label() const { return mLabel; }
//! Returns unique identifier of the rule for identification of the item within renderer
@@ -107,8 +107,8 @@ class CORE_EXPORT QgsLegendSymbolItem
QgsDataDefinedSizeLegend *dataDefinedSizeLegendSettings() const;

private:
//! symbol. owned by the struct. can be null.
QgsSymbol *mSymbol = nullptr;
//! Legend symbol -- may be null.
std::unique_ptr< QgsSymbol > mSymbol;
//! label of the item (may be empty or non-unique)
QString mLabel;
//! unique identifier of the symbol item (within renderer)
@@ -122,7 +122,7 @@ class CORE_EXPORT QgsLegendSymbolItem
* optional pointer to data-defined legend size settings - if set, the output legend
* node should be QgsDataDefinedSizeLegendNode rather than ordinary QgsSymbolLegendNode
*/
QgsDataDefinedSizeLegend *mDataDefinedSizeLegendSettings = nullptr;
std::unique_ptr< QgsDataDefinedSizeLegend > mDataDefinedSizeLegendSettings;

// additional data that may be used for filtering

0 comments on commit 1a199d0

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