Skip to content

Commit

Permalink
Add function to QgsExpression
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanW2 committed Aug 30, 2012
1 parent ab36a36 commit 4a97a92
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/core/qgsexpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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" ) )
;
}

Expand Down
5 changes: 5 additions & 0 deletions src/core/qgsexpression.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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

int mRowNumber;
double mScale;

void initGeomCalculator();
QgsDistanceArea* mCalc;
Expand Down
2 changes: 2 additions & 0 deletions src/core/qgspallabeling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,7 @@ void QgsPalLayerSettings::registerFeature( QgsVectorLayer* layer, QgsFeature& f
}

QString labelText;

// Check to see if we are a expression string.
if ( isExpression )
{
Expand All @@ -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() )
{
Expand Down

0 comments on commit 4a97a92

Please sign in to comment.