Skip to content

Commit 82e36f0

Browse files
committed
Code cleanup in QgsExpression
1 parent 0cc7311 commit 82e36f0

File tree

2 files changed

+40
-23
lines changed

2 files changed

+40
-23
lines changed

src/core/qgsexpression.cpp

+20-2
Original file line numberDiff line numberDiff line change
@@ -5838,7 +5838,8 @@ bool QgsExpression::NodeCondition::prepareNode( QgsExpression *parent, const Qgs
58385838
{
58395839
res = cond->mWhenExp->prepare( parent, context )
58405840
& cond->mThenExp->prepare( parent, context );
5841-
if ( !res ) return false;
5841+
if ( !res )
5842+
return false;
58425843
}
58435844

58445845
if ( mElseExp )
@@ -5907,7 +5908,7 @@ QgsExpression::Node *QgsExpression::NodeCondition::clone() const
59075908
{
59085909
WhenThenList conditions;
59095910
Q_FOREACH ( WhenThen *wt, mConditions )
5910-
conditions.append( new WhenThen( wt->mWhenExp->clone(), wt->mThenExp->clone() ) );
5911+
conditions.append( wt->clone() );
59115912
return new NodeCondition( conditions, mElseExp ? mElseExp->clone() : nullptr );
59125913
}
59135914

@@ -6352,3 +6353,20 @@ bool QgsExpression::Node::prepare( QgsExpression *parent, const QgsExpressionCon
63526353
return prepareNode( parent, context );
63536354
}
63546355
}
6356+
6357+
QgsExpression::WhenThen::WhenThen( QgsExpression::Node *whenExp, QgsExpression::Node *thenExp )
6358+
: mWhenExp( whenExp )
6359+
, mThenExp( thenExp )
6360+
{
6361+
}
6362+
6363+
QgsExpression::WhenThen::~WhenThen()
6364+
{
6365+
delete mWhenExp;
6366+
delete mThenExp;
6367+
}
6368+
6369+
QgsExpression::WhenThen *QgsExpression::WhenThen::clone() const
6370+
{
6371+
return new WhenThen( mWhenExp->clone(), mThenExp->clone() );
6372+
}

src/core/qgsexpression.h

+20-21
Original file line numberDiff line numberDiff line change
@@ -1011,11 +1011,9 @@ class CORE_EXPORT QgsExpression
10111011

10121012
virtual QString dump() const;
10131013

1014-
protected:
1015-
QList<QgsExpression::Node *> mList;
1016-
QStringList mNameList;
1017-
10181014
private:
1015+
QList<Node *> mList;
1016+
QStringList mNameList;
10191017

10201018
bool mHasNamedNodes;
10211019
};
@@ -1046,9 +1044,9 @@ class CORE_EXPORT QgsExpression
10461044

10471045
virtual bool isStatic( QgsExpression *parent, const QgsExpressionContext *context ) const override;
10481046

1049-
protected:
1050-
QgsExpression::UnaryOperator mOp;
1051-
QgsExpression::Node *mOperand = nullptr;
1047+
private:
1048+
UnaryOperator mOp;
1049+
Node *mOperand = nullptr;
10521050
};
10531051

10541052
/** \ingroup core
@@ -1124,7 +1122,7 @@ class CORE_EXPORT QgsExpression
11241122
virtual QgsExpression::Node *clone() const override;
11251123
virtual bool isStatic( QgsExpression *parent, const QgsExpressionContext *context ) const override;
11261124

1127-
protected:
1125+
private:
11281126
Node *mNode = nullptr;
11291127
NodeList *mList = nullptr;
11301128
bool mNotIn;
@@ -1185,7 +1183,7 @@ class CORE_EXPORT QgsExpression
11851183
virtual QgsExpression::Node *clone() const override;
11861184
virtual bool isStatic( QgsExpression *parent, const QgsExpressionContext *context ) const override;
11871185

1188-
protected:
1186+
private:
11891187
QVariant mValue;
11901188
};
11911189

@@ -1214,35 +1212,36 @@ class CORE_EXPORT QgsExpression
12141212
virtual QgsExpression::Node *clone() const override;
12151213
virtual bool isStatic( QgsExpression *parent, const QgsExpressionContext *context ) const override;
12161214

1217-
protected:
1215+
private:
12181216
QString mName;
12191217
int mIndex;
12201218
};
12211219

1220+
class NodeCondition;
1221+
12221222
/** \ingroup core
12231223
*/
12241224
class CORE_EXPORT WhenThen
12251225
{
12261226
public:
1227-
WhenThen( QgsExpression::Node *whenExp SIP_TRANSFER, QgsExpression::Node *thenExp SIP_TRANSFER )
1228-
: mWhenExp( whenExp )
1229-
, mThenExp( thenExp )
1230-
{}
1231-
~WhenThen() { delete mWhenExp; delete mThenExp; }
1227+
WhenThen( QgsExpression::Node *whenExp, QgsExpression::Node *thenExp );
1228+
~WhenThen();
12321229

12331230
//! WhenThen nodes cannot be copied.
12341231
WhenThen( const WhenThen &rh ) = delete;
12351232
//! WhenThen nodes cannot be copied.
12361233
WhenThen &operator=( const WhenThen &rh ) = delete;
12371234

1238-
// protected:
1239-
QgsExpression::Node *mWhenExp = nullptr;
1240-
QgsExpression::Node *mThenExp = nullptr;
1235+
WhenThen *clone() const;
12411236

12421237
private:
12431238
#ifdef SIP_RUN
12441239
WhenThen( const QgsExpression::WhenThen &rh );
12451240
#endif
1241+
Node *mWhenExp = nullptr;
1242+
Node *mThenExp = nullptr;
1243+
1244+
friend class NodeCondition;
12461245

12471246
};
12481247
typedef QList<QgsExpression::WhenThen *> WhenThenList;
@@ -1275,9 +1274,9 @@ class CORE_EXPORT QgsExpression
12751274
virtual QgsExpression::Node *clone() const override;
12761275
virtual bool isStatic( QgsExpression *parent, const QgsExpressionContext *context ) const override;
12771276

1278-
protected:
1279-
QgsExpression::WhenThenList mConditions;
1280-
QgsExpression::Node *mElseExp = nullptr;
1277+
private:
1278+
WhenThenList mConditions;
1279+
Node *mElseExp = nullptr;
12811280
};
12821281

12831282
/** Returns the help text for a specified function.

0 commit comments

Comments
 (0)