Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Code cleanup in QgsExpression
  • Loading branch information
m-kuhn committed Apr 30, 2017
1 parent 0cc7311 commit 82e36f0
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 23 deletions.
22 changes: 20 additions & 2 deletions src/core/qgsexpression.cpp
Expand Up @@ -5838,7 +5838,8 @@ bool QgsExpression::NodeCondition::prepareNode( QgsExpression *parent, const Qgs
{
res = cond->mWhenExp->prepare( parent, context )
& cond->mThenExp->prepare( parent, context );
if ( !res ) return false;
if ( !res )
return false;
}

if ( mElseExp )
Expand Down Expand Up @@ -5907,7 +5908,7 @@ QgsExpression::Node *QgsExpression::NodeCondition::clone() const
{
WhenThenList conditions;
Q_FOREACH ( WhenThen *wt, mConditions )
conditions.append( new WhenThen( wt->mWhenExp->clone(), wt->mThenExp->clone() ) );
conditions.append( wt->clone() );
return new NodeCondition( conditions, mElseExp ? mElseExp->clone() : nullptr );
}

Expand Down Expand Up @@ -6352,3 +6353,20 @@ bool QgsExpression::Node::prepare( QgsExpression *parent, const QgsExpressionCon
return prepareNode( parent, context );
}
}

QgsExpression::WhenThen::WhenThen( QgsExpression::Node *whenExp, QgsExpression::Node *thenExp )
: mWhenExp( whenExp )
, mThenExp( thenExp )
{
}

QgsExpression::WhenThen::~WhenThen()
{
delete mWhenExp;
delete mThenExp;
}

QgsExpression::WhenThen *QgsExpression::WhenThen::clone() const
{
return new WhenThen( mWhenExp->clone(), mThenExp->clone() );
}
41 changes: 20 additions & 21 deletions src/core/qgsexpression.h
Expand Up @@ -1011,11 +1011,9 @@ class CORE_EXPORT QgsExpression

virtual QString dump() const;

protected:
QList<QgsExpression::Node *> mList;
QStringList mNameList;

private:
QList<Node *> mList;
QStringList mNameList;

bool mHasNamedNodes;
};
Expand Down Expand Up @@ -1046,9 +1044,9 @@ class CORE_EXPORT QgsExpression

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

protected:
QgsExpression::UnaryOperator mOp;
QgsExpression::Node *mOperand = nullptr;
private:
UnaryOperator mOp;
Node *mOperand = nullptr;
};

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

protected:
private:
Node *mNode = nullptr;
NodeList *mList = nullptr;
bool mNotIn;
Expand Down Expand Up @@ -1185,7 +1183,7 @@ class CORE_EXPORT QgsExpression
virtual QgsExpression::Node *clone() const override;
virtual bool isStatic( QgsExpression *parent, const QgsExpressionContext *context ) const override;

protected:
private:
QVariant mValue;
};

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

protected:
private:
QString mName;
int mIndex;
};

class NodeCondition;

/** \ingroup core
*/
class CORE_EXPORT WhenThen
{
public:
WhenThen( QgsExpression::Node *whenExp SIP_TRANSFER, QgsExpression::Node *thenExp SIP_TRANSFER )
: mWhenExp( whenExp )
, mThenExp( thenExp )
{}
~WhenThen() { delete mWhenExp; delete mThenExp; }
WhenThen( QgsExpression::Node *whenExp, QgsExpression::Node *thenExp );
~WhenThen();

//! WhenThen nodes cannot be copied.
WhenThen( const WhenThen &rh ) = delete;
//! WhenThen nodes cannot be copied.
WhenThen &operator=( const WhenThen &rh ) = delete;

// protected:
QgsExpression::Node *mWhenExp = nullptr;
QgsExpression::Node *mThenExp = nullptr;
WhenThen *clone() const;

private:
#ifdef SIP_RUN
WhenThen( const QgsExpression::WhenThen &rh );
#endif
Node *mWhenExp = nullptr;
Node *mThenExp = nullptr;

friend class NodeCondition;

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

protected:
QgsExpression::WhenThenList mConditions;
QgsExpression::Node *mElseExp = nullptr;
private:
WhenThenList mConditions;
Node *mElseExp = nullptr;
};

/** Returns the help text for a specified function.
Expand Down

0 comments on commit 82e36f0

Please sign in to comment.