Skip to content

Commit

Permalink
Loading of function list from QgsExpression now working
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanW2 committed Sep 26, 2011
1 parent d90dcef commit f64ae1c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/core/qgsexpression.cpp
Expand Up @@ -386,7 +386,7 @@ bool QgsExpression::isFunctionName( QString name )

int QgsExpression::functionIndex( QString name )
{
int count = sizeof( BuiltinFunctions ) / sizeof( FunctionDef);
int count = functionCount();
for ( int i = 0; i < count; i++ )
{
if ( QString::compare( name, BuiltinFunctions[i].mName, Qt::CaseInsensitive ) == 0 )
Expand All @@ -395,6 +395,11 @@ int QgsExpression::functionIndex( QString name )
return -1;
}

int QgsExpression::functionCount()
{
return ( sizeof( BuiltinFunctions ) / sizeof( FunctionDef) );
}


QgsExpression::QgsExpression( const QString& expr )
: mExpression( expr ), mRowNumber( 0 ), mCalc( NULL )
Expand Down
5 changes: 5 additions & 0 deletions src/core/qgsexpression.h
Expand Up @@ -194,6 +194,11 @@ class CORE_EXPORT QgsExpression
// return index of the function in BuiltinFunctions array
static int functionIndex( QString name );

/** Returns the number of functions defined in the parser
* @return The number of function defined in the parser.
*/
static int functionCount();

//! return quoted column reference (in double quotes)
static QString quotedColumnRef( QString name ) { return QString( "\"%1\"" ).arg( name.replace( "\"", "\"\"" ) ); }

Expand Down
5 changes: 3 additions & 2 deletions src/gui/qgsexpressionbuilder.cpp
Expand Up @@ -41,13 +41,14 @@ QgsExpressionBuilderWidget::QgsExpressionBuilderWidget(QgsVectorLayer *layer)
"<br> Joins two values together into a string " \
"<br> <i>Usage:</i><br>'Dia' || Diameter");

int count = sizeof( QgsExpression::BuiltinFunctions ) / sizeof( QgsExpression::FunctionDef);
// Load the fuctions from the QgsExpression class
int count = QgsExpression::functionCount();
for ( int i = 0; i < count; i++ )
{
QgsExpression::FunctionDef func = QgsExpression::BuiltinFunctions[i];
QString name = func.mName;
if ( func.mParams >= 1 )
name + "(";
name += "(";
this->registerItem(func.mGroup,func.mName, " " + name + " ", func.mHelpText);
};
}
Expand Down

0 comments on commit f64ae1c

Please sign in to comment.