@@ -555,13 +555,7 @@ class CORE_EXPORT QgsExpression
555555 */
556556 virtual QVariant func ( const QVariantList& values, const QgsExpressionContext* context, QgsExpression* parent ) = 0;
557557
558- bool operator ==( const Function& other ) const
559- {
560- if ( QString::compare ( mName , other.mName , Qt::CaseInsensitive ) == 0 )
561- return true ;
562-
563- return false ;
564- }
558+ bool operator ==( const Function& other ) const ;
565559
566560 virtual bool handlesNull () const { return mHandlesNull ; }
567561
@@ -830,7 +824,7 @@ class CORE_EXPORT QgsExpression
830824 /* * Adds a named node. Takes ownership of the provided node.
831825 * @note added in QGIS 2.16
832826 */
833- void append ( NamedNode* node ) { mList . append ( node-> node ); mNameList . append ( node-> name . toLower () ); mHasNamedNodes = true ; }
827+ void append ( NamedNode* node );
834828
835829 /* * Returns the number of nodes in the list.
836830 */
@@ -909,8 +903,8 @@ class CORE_EXPORT QgsExpression
909903 virtual QVariant eval ( QgsExpression* parent, const QgsExpressionContext* context ) override ;
910904 virtual QString dump () const override ;
911905
912- virtual QStringList referencedColumns () const override { return mOpLeft -> referencedColumns () + mOpRight -> referencedColumns (); }
913- virtual bool needsGeometry () const override { return mOpLeft -> needsGeometry () || mOpRight -> needsGeometry (); }
906+ virtual QStringList referencedColumns () const override ;
907+ virtual bool needsGeometry () const override ;
914908 virtual Node* clone () const override ;
915909
916910 int precedence () const ;
@@ -953,8 +947,8 @@ class CORE_EXPORT QgsExpression
953947 virtual QVariant eval ( QgsExpression* parent, const QgsExpressionContext* context ) override ;
954948 virtual QString dump () const override ;
955949
956- virtual QStringList referencedColumns () const override { QStringList lst ( mNode -> referencedColumns () ); Q_FOREACH ( const Node* n, mList -> list () ) lst. append ( n-> referencedColumns () ); return lst; }
957- virtual bool needsGeometry () const override { bool needs = false ; Q_FOREACH ( Node* n, mList -> list () ) needs |= n-> needsGeometry (); return needs; }
950+ virtual QStringList referencedColumns () const override ;
951+ virtual bool needsGeometry () const override ;
958952 virtual Node* clone () const override ;
959953
960954 protected:
@@ -968,44 +962,7 @@ class CORE_EXPORT QgsExpression
968962 class CORE_EXPORT NodeFunction : public Node
969963 {
970964 public:
971- NodeFunction ( int fnIndex, NodeList* args ) : mFnIndex ( fnIndex )
972- {
973- const ParameterList& functionParams = Functions ()[mFnIndex ]->parameters ();
974- if ( !args || functionParams.isEmpty () )
975- {
976- // no parameters, or function does not support them
977- mArgs = args;
978- }
979- else
980- {
981- mArgs = new NodeList ();
982-
983- int idx = 0 ;
984- // first loop through unnamed arguments
985- while ( idx < args->names ().size () && args->names ().at ( idx ).isEmpty () )
986- {
987- mArgs ->append ( args->list ().at ( idx )->clone () );
988- idx++;
989- }
990-
991- // next copy named parameters in order expected by function
992- for ( ; idx < functionParams.count (); ++idx )
993- {
994- int nodeIdx = args->names ().indexOf ( functionParams.at ( idx ).name ().toLower () );
995- if ( nodeIdx < 0 )
996- {
997- // parameter not found - insert default value for parameter
998- mArgs ->append ( new NodeLiteral ( functionParams.at ( idx ).defaultValue () ) );
999- }
1000- else
1001- {
1002- mArgs ->append ( args->list ().at ( nodeIdx )->clone () );
1003- }
1004- }
1005-
1006- delete args;
1007- }
1008- }
965+ NodeFunction ( int fnIndex, NodeList* args );
1009966
1010967 virtual ~NodeFunction () { delete mArgs ; }
1011968
@@ -1018,82 +975,11 @@ class CORE_EXPORT QgsExpression
1018975 virtual QString dump () const override ;
1019976
1020977 virtual QStringList referencedColumns () const override ;
1021- virtual bool needsGeometry () const override { bool needs = Functions ()[ mFnIndex ]-> usesGeometry (); if ( mArgs ) { Q_FOREACH ( Node* n, mArgs -> list () ) needs |= n-> needsGeometry (); } return needs; }
978+ virtual bool needsGeometry () const override ;
1022979 virtual Node* clone () const override ;
1023980
1024981 // ! Tests whether the provided argument list is valid for the matching function
1025- static bool validateParams ( int fnIndex, NodeList* args, QString& error )
1026- {
1027- if ( !args || !args->hasNamedNodes () )
1028- return true ;
1029-
1030- const ParameterList& functionParams = Functions ()[fnIndex]->parameters ();
1031- if ( functionParams.isEmpty () )
1032- {
1033- error = QString ( " %1 does not supported named parameters" ).arg ( Functions ()[fnIndex]->name () );
1034- return false ;
1035- }
1036- else
1037- {
1038- QSet< int > providedArgs;
1039- QSet< int > handledArgs;
1040- int idx = 0 ;
1041- // first loop through unnamed arguments
1042- while ( args->names ().at ( idx ).isEmpty () )
1043- {
1044- providedArgs << idx;
1045- handledArgs << idx;
1046- idx++;
1047- }
1048-
1049- // next check named parameters
1050- for ( ; idx < functionParams.count (); ++idx )
1051- {
1052- int nodeIdx = args->names ().indexOf ( functionParams.at ( idx ).name ().toLower () );
1053- if ( nodeIdx < 0 )
1054- {
1055- if ( !functionParams.at ( idx ).optional () )
1056- {
1057- error = QString ( " No value specified for parameter '%1' for %2" ).arg ( functionParams.at ( idx ).name (), Functions ()[fnIndex]->name () );
1058- return false ;
1059- }
1060- }
1061- else
1062- {
1063- if ( providedArgs.contains ( idx ) )
1064- {
1065- error = QString ( " Duplicate parameter specified for '%1' for %2" ).arg ( functionParams.at ( idx ).name (), Functions ()[fnIndex]->name () );
1066- return false ;
1067- }
1068- }
1069- providedArgs << idx;
1070- handledArgs << nodeIdx;
1071- }
1072-
1073- // last check for bad names
1074- idx = 0 ;
1075- Q_FOREACH ( const QString& name, args->names () )
1076- {
1077- if ( !name.isEmpty () && !functionParams.contains ( name ) )
1078- {
1079- error = QString ( " Invalid parameter name '%1' for %2" ).arg ( name, Functions ()[fnIndex]->name () );
1080- return false ;
1081- }
1082- if ( !name.isEmpty () && !handledArgs.contains ( idx ) )
1083- {
1084- int functionIdx = functionParams.indexOf ( name );
1085- if ( providedArgs.contains ( functionIdx ) )
1086- {
1087- error = QString ( " Duplicate parameter specified for '%1' for %2" ).arg ( functionParams.at ( functionIdx ).name (), Functions ()[fnIndex]->name () );
1088- return false ;
1089- }
1090- }
1091- idx++;
1092- }
1093-
1094- }
1095- return true ;
1096- }
982+ static bool validateParams ( int fnIndex, NodeList* args, QString& error );
1097983
1098984 protected:
1099985 int mFnIndex ;
@@ -1333,6 +1219,8 @@ class CORE_EXPORT QgsExpression
13331219 friend class QgsOgcUtils ;
13341220};
13351221
1222+
1223+
13361224Q_DECLARE_METATYPE ( QgsExpression::Node* )
13371225
13381226#endif // QGSEXPRESSION_H
0 commit comments