Skip to content
Permalink
Browse files

Add function to QgsExpression

  • Loading branch information
NathanW2 committed Aug 30, 2012
1 parent ab36a36 commit 4a97a9200ccc9766223f4c66a0469a7820a8277d
Showing with 13 additions and 0 deletions.
  1. +6 −0 src/core/qgsexpression.cpp
  2. +5 −0 src/core/qgsexpression.h
  3. +2 −0 src/core/qgspallabeling.cpp
@@ -787,6 +787,11 @@ static QVariant fcnRound( const QVariantList& values , QgsFeature *f, QgsExpress
return QVariant();
}

static QVariant fcnScale( const QVariantList&, QgsFeature*, QgsExpression* parent )
{
return QVariant( parent->scale() );
}

QList<QgsExpression::FunctionDef> QgsExpression::gmBuiltinFunctions;

const QList<QgsExpression::FunctionDef> &QgsExpression::BuiltinFunctions()
@@ -854,6 +859,7 @@ const QList<QgsExpression::FunctionDef> &QgsExpression::BuiltinFunctions()
// special columns
<< FunctionDef( "$rownum", 0, fcnRowNumber, QObject::tr( "Record" ) )
<< FunctionDef( "$id", 0, fcnFeatureId, QObject::tr( "Record" ) )
<< FunctionDef( "$scale", 0, fcnScale, QObject::tr( "Record" ) )
;
}

@@ -121,6 +121,10 @@ class CORE_EXPORT QgsExpression
//! Return the number used for $rownum special column
int currentRowNumber() { return mRowNumber; }

void setScale( double scale ) { mScale = scale; }

int scale() {return mScale; }

//! Return the parsed expression as a string - useful for debugging
QString dump() const;

@@ -510,6 +514,7 @@ class CORE_EXPORT QgsExpression
QString mEvalErrorString;

int mRowNumber;
double mScale;

void initGeomCalculator();
QgsDistanceArea* mCalc;
@@ -567,6 +567,7 @@ void QgsPalLayerSettings::registerFeature( QgsVectorLayer* layer, QgsFeature& f
}

QString labelText;

// Check to see if we are a expression string.
if ( isExpression )
{
@@ -576,6 +577,7 @@ void QgsPalLayerSettings::registerFeature( QgsVectorLayer* layer, QgsFeature& f
QgsDebugMsg( "Expression parser error:" + exp->parserErrorString() );
return;
}
exp->setScale( context.rendererScale() );
QVariant result = exp->evaluate( &f, layer->pendingFields() );
if ( exp->hasEvalError() )
{

0 comments on commit 4a97a92

Please sign in to comment.
You can’t perform that action at this time.