Skip to content

Commit 0b066e5

Browse files
author
Hugo Mercier
committed
Use smart pointers to handle mSettings and mFilter
1 parent 026ddf3 commit 0b066e5

File tree

3 files changed

+12
-18
lines changed

3 files changed

+12
-18
lines changed

python/core/auto_generated/qgsrulebasedlabeling.sip.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class QgsRuleBasedLabeling : QgsAbstractVectorLayerLabeling
3737
public:
3838
Rule( QgsPalLayerSettings *settings /Transfer/, int maximumScale = 0, int minimumScale = 0, const QString &filterExp = QString(), const QString &description = QString(), bool elseRule = false );
3939
%Docstring
40-
takes ownership of settings
40+
takes ownership of settings, settings may be None
4141
%End
4242
~Rule();
4343

src/core/qgsrulebasedlabeling.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,25 +65,21 @@ QgsRuleBasedLabeling::Rule::Rule( QgsPalLayerSettings *settings, int scaleMinDen
6565
, mIsActive( true )
6666

6767
{
68-
mRuleKey = QUuid::createUuid().toString();
6968
initFilter();
7069
}
7170

7271
QgsRuleBasedLabeling::Rule::~Rule()
7372
{
74-
delete mSettings;
75-
delete mFilter;
7673
qDeleteAll( mChildren );
7774
// do NOT delete parent
7875
}
7976

8077
void QgsRuleBasedLabeling::Rule::setSettings( QgsPalLayerSettings *settings )
8178
{
82-
if ( mSettings == settings )
79+
if ( mSettings.get() == settings )
8380
return;
8481

85-
delete mSettings;
86-
mSettings = settings;
82+
mSettings.reset( settings );
8783
}
8884

8985
QgsRuleBasedLabeling::RuleList QgsRuleBasedLabeling::Rule::descendants() const
@@ -102,16 +98,15 @@ void QgsRuleBasedLabeling::Rule::initFilter()
10298
if ( mElseRule || mFilterExp.compare( QLatin1String( "ELSE" ), Qt::CaseInsensitive ) == 0 )
10399
{
104100
mElseRule = true;
105-
mFilter = nullptr;
101+
mFilter.reset( nullptr );
106102
}
107103
else if ( !mFilterExp.isEmpty() )
108104
{
109-
delete mFilter;
110-
mFilter = new QgsExpression( mFilterExp );
105+
mFilter.reset( new QgsExpression( mFilterExp ) );
111106
}
112107
else
113108
{
114-
mFilter = nullptr;
109+
mFilter.reset( nullptr );
115110
}
116111
}
117112

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

205200
QgsRuleBasedLabeling::Rule *QgsRuleBasedLabeling::Rule::clone() const
206201
{
207-
QgsPalLayerSettings *s = mSettings ? new QgsPalLayerSettings( *mSettings ) : nullptr;
202+
QgsPalLayerSettings *s = mSettings.get() ? new QgsPalLayerSettings( *mSettings ) : nullptr;
208203
Rule *newrule = new Rule( s, mMaximumScale, mMinimumScale, mFilterExp, mDescription );
209204
newrule->setActive( mIsActive );
210205
// clone children
@@ -286,7 +281,7 @@ void QgsRuleBasedLabeling::Rule::createSubProviders( QgsVectorLayer *layer, QgsR
286281
if ( mSettings )
287282
{
288283
// add provider!
289-
QgsVectorLayerLabelProvider *p = provider->createProvider( layer, mRuleKey, false, mSettings );
284+
QgsVectorLayerLabelProvider *p = provider->createProvider( layer, mRuleKey, false, mSettings.get() );
290285
delete subProviders.value( this, nullptr );
291286
subProviders[this] = p;
292287
}

src/core/qgsrulebasedlabeling.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class CORE_EXPORT QgsRuleBasedLabeling : public QgsAbstractVectorLayerLabeling
5252
class CORE_EXPORT Rule
5353
{
5454
public:
55-
//! takes ownership of settings
55+
//! takes ownership of settings, settings may be nullptr
5656
Rule( QgsPalLayerSettings *settings SIP_TRANSFER, int maximumScale = 0, int minimumScale = 0, const QString &filterExp = QString(), const QString &description = QString(), bool elseRule = false );
5757
~Rule();
5858

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

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

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

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

339-
// temporary
340-
QgsExpression *mFilter = nullptr;
339+
std::unique_ptr<QgsExpression> mFilter;
341340

342341
};
343342

0 commit comments

Comments
 (0)