Skip to content

Commit

Permalink
Remove visitor pattern from QgsExpression (#3569)
Browse files Browse the repository at this point in the history
It is not in use anywhere and can easily be reintroduced if there is a use case
where it is an appropriate fit.

Fix qgis/qgis4.0_api#64
  • Loading branch information
m-kuhn authored Oct 4, 2016
1 parent 62c8510 commit 7332dda
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 98 deletions.
1 change: 1 addition & 0 deletions doc/api_break.dox
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,7 @@ version instead.</li>
<li>replaceExpressionText() no longer accepts a substitution map parameter. Use expression context variables instead.</li>
<li>helptext() has been renamed to helpText()</li>
<li>isValid() has been renamed to checkExpression()</li>
<li>acceptVisitor() has been removed</li>
</ul>

\subsection qgis_api_break_3_0_QgsFeature QgsFeature
Expand Down
45 changes: 0 additions & 45 deletions python/core/qgsexpression.sip
Original file line number Diff line number Diff line change
Expand Up @@ -528,23 +528,6 @@ class QgsExpression
* @return true if a geometry is required to evaluate this expression
*/
virtual bool needsGeometry() const = 0;

/**
* Support the visitor pattern.
*
* For any implementation this should look like
*
* C++:
*
* v.visit( *this );
*
* Python:
*
* v.visit( self)
*
* @param v A visitor that visits this node.
*/
virtual void accept( QgsExpression::Visitor& v ) const = 0;
};

//! Named node
Expand Down Expand Up @@ -615,7 +598,6 @@ class QgsExpression

virtual QStringList referencedColumns() const;
virtual bool needsGeometry() const;
virtual void accept( QgsExpression::Visitor& v ) const;
virtual QgsExpression::Node* clone() const;
};

Expand All @@ -636,7 +618,6 @@ class QgsExpression

virtual QStringList referencedColumns() const;
virtual bool needsGeometry() const;
virtual void accept( QgsExpression::Visitor& v ) const;
virtual QgsExpression::Node* clone() const;

int precedence() const;
Expand Down Expand Up @@ -671,7 +652,6 @@ class QgsExpression

virtual QStringList referencedColumns() const;
virtual bool needsGeometry() const;
virtual void accept( QgsExpression::Visitor& v ) const;
virtual QgsExpression::Node* clone() const;
};

Expand All @@ -692,7 +672,6 @@ class QgsExpression

virtual QStringList referencedColumns() const;
virtual bool needsGeometry() const;
virtual void accept( QgsExpression::Visitor& v ) const;
virtual QgsExpression::Node* clone() const;

//! Tests whether the provided argument list is valid for the matching function
Expand All @@ -715,7 +694,6 @@ class QgsExpression

virtual QStringList referencedColumns() const;
virtual bool needsGeometry() const;
virtual void accept( QgsExpression::Visitor& v ) const;
};

class NodeColumnRef : QgsExpression::Node
Expand All @@ -734,7 +712,6 @@ class QgsExpression
virtual QStringList referencedColumns() const;
virtual bool needsGeometry() const;

virtual void accept( QgsExpression::Visitor& v ) const;
virtual QgsExpression::Node* clone() const;
};

Expand Down Expand Up @@ -766,30 +743,8 @@ class QgsExpression

virtual QStringList referencedColumns() const;
virtual bool needsGeometry() const;
virtual void accept( QgsExpression::Visitor& v ) const;
virtual QgsExpression::Node* clone() const;
};

//////

/** Support for visitor pattern - algorithms dealing with the expressions
may be implemented without modifying the Node classes */
class Visitor
{
public:
virtual ~Visitor();
virtual void visit( const QgsExpression::NodeUnaryOperator& n ) = 0;
virtual void visit( const QgsExpression::NodeBinaryOperator& n ) = 0;
virtual void visit( const QgsExpression::NodeInOperator& n ) = 0;
virtual void visit( const QgsExpression::NodeFunction& n ) = 0;
virtual void visit( const QgsExpression::NodeLiteral& n ) = 0;
virtual void visit( const QgsExpression::NodeColumnRef& n ) = 0;
virtual void visit( const QgsExpression::NodeCondition& n ) = 0;
};

/** Entry function for the visitor pattern */
void acceptVisitor( QgsExpression::Visitor& v ) const;

/** Returns the help text for a specified function.
* @param name function name
* @see variableHelpText()
Expand Down
6 changes: 0 additions & 6 deletions src/core/qgsexpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3976,12 +3976,6 @@ void QgsExpression::setAreaUnits( QgsUnitTypes::AreaUnit unit )
d->mAreaUnit = unit;
}

void QgsExpression::acceptVisitor( QgsExpression::Visitor& v ) const
{
if ( d->mRootNode )
d->mRootNode->accept( v );
}

QString QgsExpression::replaceExpressionText( const QString &action, const QgsExpressionContext *context, const QgsDistanceArea *distanceArea )
{
QString expr_action;
Expand Down
47 changes: 0 additions & 47 deletions src/core/qgsexpression.h
Original file line number Diff line number Diff line change
Expand Up @@ -715,8 +715,6 @@ class CORE_EXPORT QgsExpression

//////

class Visitor; // visitor interface is defined below

enum NodeType
{
ntUnaryOperator,
Expand Down Expand Up @@ -794,23 +792,6 @@ class CORE_EXPORT QgsExpression
* @return true if a geometry is required to evaluate this expression
*/
virtual bool needsGeometry() const = 0;

/**
* Support the visitor pattern.
*
* For any implementation this should look like
*
* C++:
*
* v.visit( *this );
*
* Python:
*
* v.visit( self)
*
* @param v A visitor that visits this node.
*/
virtual void accept( Visitor& v ) const = 0;
};

//! Named node
Expand Down Expand Up @@ -900,7 +881,6 @@ class CORE_EXPORT QgsExpression

virtual QStringList referencedColumns() const override { return mOperand->referencedColumns(); }
virtual bool needsGeometry() const override { return mOperand->needsGeometry(); }
virtual void accept( Visitor& v ) const override { v.visit( *this ); }
virtual Node* clone() const override;

protected:
Expand Down Expand Up @@ -931,7 +911,6 @@ class CORE_EXPORT QgsExpression

virtual QStringList referencedColumns() const override { return mOpLeft->referencedColumns() + mOpRight->referencedColumns(); }
virtual bool needsGeometry() const override { return mOpLeft->needsGeometry() || mOpRight->needsGeometry(); }
virtual void accept( Visitor& v ) const override { v.visit( *this ); }
virtual Node* clone() const override;

int precedence() const;
Expand Down Expand Up @@ -976,7 +955,6 @@ class CORE_EXPORT QgsExpression

virtual QStringList referencedColumns() const override { QStringList lst( mNode->referencedColumns() ); Q_FOREACH ( const Node* n, mList->list() ) lst.append( n->referencedColumns() ); return lst; }
virtual bool needsGeometry() const override { bool needs = false; Q_FOREACH ( Node* n, mList->list() ) needs |= n->needsGeometry(); return needs; }
virtual void accept( Visitor& v ) const override { v.visit( *this ); }
virtual Node* clone() const override;

protected:
Expand Down Expand Up @@ -1041,7 +1019,6 @@ class CORE_EXPORT QgsExpression

virtual QStringList referencedColumns() const override;
virtual bool needsGeometry() const override { bool needs = Functions()[mFnIndex]->usesGeometry(); if ( mArgs ) { Q_FOREACH ( Node* n, mArgs->list() ) needs |= n->needsGeometry(); } return needs; }
virtual void accept( Visitor& v ) const override { v.visit( *this ); }
virtual Node* clone() const override;

//! Tests whether the provided argument list is valid for the matching function
Expand Down Expand Up @@ -1143,7 +1120,6 @@ class CORE_EXPORT QgsExpression

virtual QStringList referencedColumns() const override { return QStringList(); }
virtual bool needsGeometry() const override { return false; }
virtual void accept( Visitor& v ) const override { v.visit( *this ); }
virtual Node* clone() const override;

protected:
Expand Down Expand Up @@ -1171,7 +1147,6 @@ class CORE_EXPORT QgsExpression
virtual QStringList referencedColumns() const override { return QStringList( mName ); }
virtual bool needsGeometry() const override { return false; }

virtual void accept( Visitor& v ) const override { v.visit( *this ); }
virtual Node* clone() const override;

protected:
Expand Down Expand Up @@ -1222,35 +1197,13 @@ class CORE_EXPORT QgsExpression

virtual QStringList referencedColumns() const override;
virtual bool needsGeometry() const override;
virtual void accept( Visitor& v ) const override { v.visit( *this ); }
virtual Node* clone() const override;

protected:
WhenThenList mConditions;
Node* mElseExp;
};

//////

/** \ingroup core
* Support for visitor pattern - algorithms dealing with the expressions
may be implemented without modifying the Node classes */
class CORE_EXPORT Visitor
{
public:
virtual ~Visitor() {}
virtual void visit( const NodeUnaryOperator& n ) = 0;
virtual void visit( const NodeBinaryOperator& n ) = 0;
virtual void visit( const NodeInOperator& n ) = 0;
virtual void visit( const NodeFunction& n ) = 0;
virtual void visit( const NodeLiteral& n ) = 0;
virtual void visit( const NodeColumnRef& n ) = 0;
virtual void visit( const NodeCondition& n ) = 0;
};

/** Entry function for the visitor pattern */
void acceptVisitor( Visitor& v ) const;

/** Returns the help text for a specified function.
* @param name function name
* @see variableHelpText()
Expand Down

0 comments on commit 7332dda

Please sign in to comment.