Skip to content
Permalink
Browse files

Use smart pointers to handle mSettings and mFilter

  • Loading branch information
Hugo Mercier
Hugo Mercier committed Jun 21, 2018
1 parent cd39798 commit 831d1b1e9e56b9399455fa77974f516ca721913f
Showing with 11 additions and 17 deletions.
  1. +7 −12 src/core/qgsrulebasedlabeling.cpp
  2. +4 −5 src/core/qgsrulebasedlabeling.h
@@ -65,25 +65,21 @@ QgsRuleBasedLabeling::Rule::Rule( QgsPalLayerSettings *settings, int scaleMinDen
, mIsActive( true )

{
mRuleKey = QUuid::createUuid().toString();
initFilter();
}

QgsRuleBasedLabeling::Rule::~Rule()
{
delete mSettings;
delete mFilter;
qDeleteAll( mChildren );
// do NOT delete parent
}

void QgsRuleBasedLabeling::Rule::setSettings( QgsPalLayerSettings *settings )
{
if ( mSettings == settings )
if ( mSettings.get() == settings )
return;

delete mSettings;
mSettings = settings;
mSettings.reset( settings );
}

QgsRuleBasedLabeling::RuleList QgsRuleBasedLabeling::Rule::descendants() const
@@ -102,16 +98,15 @@ void QgsRuleBasedLabeling::Rule::initFilter()
if ( mElseRule || mFilterExp.compare( QLatin1String( "ELSE" ), Qt::CaseInsensitive ) == 0 )
{
mElseRule = true;
mFilter = nullptr;
mFilter.reset( nullptr );
}
else if ( !mFilterExp.isEmpty() )
{
delete mFilter;
mFilter = new QgsExpression( mFilterExp );
mFilter.reset( new QgsExpression( mFilterExp ) );
}
else
{
mFilter = nullptr;
mFilter.reset( nullptr );
}
}

@@ -204,7 +199,7 @@ QgsRuleBasedLabeling::Rule *QgsRuleBasedLabeling::Rule::findRuleByKey( const QSt

QgsRuleBasedLabeling::Rule *QgsRuleBasedLabeling::Rule::clone() const
{
QgsPalLayerSettings *s = mSettings ? new QgsPalLayerSettings( *mSettings ) : nullptr;
QgsPalLayerSettings *s = mSettings.get() ? new QgsPalLayerSettings( *mSettings ) : nullptr;
Rule *newrule = new Rule( s, mMaximumScale, mMinimumScale, mFilterExp, mDescription );
newrule->setActive( mIsActive );
// clone children
@@ -286,7 +281,7 @@ void QgsRuleBasedLabeling::Rule::createSubProviders( QgsVectorLayer *layer, QgsR
if ( mSettings )
{
// add provider!
QgsVectorLayerLabelProvider *p = provider->createProvider( layer, mRuleKey, false, mSettings );
QgsVectorLayerLabelProvider *p = provider->createProvider( layer, mRuleKey, false, mSettings.get() );
delete subProviders.value( this, nullptr );
subProviders[this] = p;
}
@@ -52,7 +52,7 @@ class CORE_EXPORT QgsRuleBasedLabeling : public QgsAbstractVectorLayerLabeling
class CORE_EXPORT Rule
{
public:
//! takes ownership of settings
//! takes ownership of settings, settings may be nullptr
Rule( QgsPalLayerSettings *settings SIP_TRANSFER, int maximumScale = 0, int minimumScale = 0, const QString &filterExp = QString(), const QString &description = QString(), bool elseRule = false );
~Rule();

@@ -72,7 +72,7 @@ class CORE_EXPORT QgsRuleBasedLabeling : public QgsAbstractVectorLayerLabeling
/**
* Gets the labeling settings. May return a null pointer.
*/
QgsPalLayerSettings *settings() const { return mSettings; }
QgsPalLayerSettings *settings() const { return mSettings.get(); }

/**
* Determines if scale based labeling is active
@@ -325,7 +325,7 @@ class CORE_EXPORT QgsRuleBasedLabeling : public QgsAbstractVectorLayerLabeling

private:
Rule *mParent; // parent rule (NULL only for root rule)
QgsPalLayerSettings *mSettings = nullptr;
std::unique_ptr<QgsPalLayerSettings> mSettings;
double mMaximumScale = 0;
double mMinimumScale = 0;
QString mFilterExp, mDescription;
@@ -336,8 +336,7 @@ class CORE_EXPORT QgsRuleBasedLabeling : public QgsAbstractVectorLayerLabeling

QString mRuleKey; // string used for unique identification of rule within labeling

// temporary
QgsExpression *mFilter = nullptr;
std::unique_ptr<QgsExpression> mFilter;

};

0 comments on commit 831d1b1

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