Skip to content

Commit f64ae1c

Browse files
committed
Loading of function list from QgsExpression now working
1 parent d90dcef commit f64ae1c

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

src/core/qgsexpression.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ bool QgsExpression::isFunctionName( QString name )
386386

387387
int QgsExpression::functionIndex( QString name )
388388
{
389-
int count = sizeof( BuiltinFunctions ) / sizeof( FunctionDef);
389+
int count = functionCount();
390390
for ( int i = 0; i < count; i++ )
391391
{
392392
if ( QString::compare( name, BuiltinFunctions[i].mName, Qt::CaseInsensitive ) == 0 )
@@ -395,6 +395,11 @@ int QgsExpression::functionIndex( QString name )
395395
return -1;
396396
}
397397

398+
int QgsExpression::functionCount()
399+
{
400+
return ( sizeof( BuiltinFunctions ) / sizeof( FunctionDef) );
401+
}
402+
398403

399404
QgsExpression::QgsExpression( const QString& expr )
400405
: mExpression( expr ), mRowNumber( 0 ), mCalc( NULL )

src/core/qgsexpression.h

+5
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,11 @@ class CORE_EXPORT QgsExpression
194194
// return index of the function in BuiltinFunctions array
195195
static int functionIndex( QString name );
196196

197+
/** Returns the number of functions defined in the parser
198+
* @return The number of function defined in the parser.
199+
*/
200+
static int functionCount();
201+
197202
//! return quoted column reference (in double quotes)
198203
static QString quotedColumnRef( QString name ) { return QString( "\"%1\"" ).arg( name.replace( "\"", "\"\"" ) ); }
199204

src/gui/qgsexpressionbuilder.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,14 @@ QgsExpressionBuilderWidget::QgsExpressionBuilderWidget(QgsVectorLayer *layer)
4141
"<br> Joins two values together into a string " \
4242
"<br> <i>Usage:</i><br>'Dia' || Diameter");
4343

44-
int count = sizeof( QgsExpression::BuiltinFunctions ) / sizeof( QgsExpression::FunctionDef);
44+
// Load the fuctions from the QgsExpression class
45+
int count = QgsExpression::functionCount();
4546
for ( int i = 0; i < count; i++ )
4647
{
4748
QgsExpression::FunctionDef func = QgsExpression::BuiltinFunctions[i];
4849
QString name = func.mName;
4950
if ( func.mParams >= 1 )
50-
name + "(";
51+
name += "(";
5152
this->registerItem(func.mGroup,func.mName, " " + name + " ", func.mHelpText);
5253
};
5354
}

0 commit comments

Comments
 (0)