Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed the rebasing-mess
  • Loading branch information
homann committed Sep 4, 2012
1 parent e83dce5 commit 1f1448d
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 3 deletions.
67 changes: 65 additions & 2 deletions src/core/qgsexpression.cpp
Expand Up @@ -787,6 +787,18 @@ static QVariant fcnRound( const QVariantList& values , QgsFeature *f, QgsExpress
return QVariant();
}

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

static QVariant fcnFormatNumber( const QVariantList& values, QgsFeature*, QgsExpression* parent )
{
double value = getDoubleValue( values.at( 0 ), parent );
int places = getIntValue( values.at( 1 ), parent );
return QString( "%L1" ).arg( value, 0, 'f', places );
}

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

const QList<QgsExpression::FunctionDef> &QgsExpression::BuiltinFunctions()
Expand Down Expand Up @@ -842,6 +854,7 @@ const QList<QgsExpression::FunctionDef> &QgsExpression::BuiltinFunctions()
<< FunctionDef( "right", 2, fcnRight, QObject::tr( "String" ) )
<< FunctionDef( "rpad", 3, fcnRPad, QObject::tr( "String" ) )
<< FunctionDef( "lpad", 3, fcnLPad, QObject::tr( "String" ) )
<< FunctionDef( "format_number", 2, fcnFormatNumber, QObject::tr( "String" ) )

// geometry accessors
<< FunctionDef( "xat", 1, fcnXat, QObject::tr( "Geometry" ), "", true )
Expand All @@ -854,6 +867,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 Expand Up @@ -887,7 +901,7 @@ QgsExpression::QgsExpression( const QString& expr )
: mExpression( expr )
, mRowNumber( 0 )
, mScale( 0 )

{
initGeomCalculator();

Expand All @@ -902,7 +916,6 @@ QgsExpression::QgsExpression( const QString& expr )
QgsExpression::~QgsExpression()
{
delete mRootNode;
delete mCalc;
}

QStringList QgsExpression::referencedColumns()
Expand Down Expand Up @@ -1041,6 +1054,56 @@ void QgsExpression::acceptVisitor( QgsExpression::Visitor& v )
mRootNode->accept( v );
}

QString QgsExpression::replaceExpressionText( QString action, QgsFeature &feat,
QgsVectorLayer* layer,
const QMap<QString, QVariant> *substitutionMap )
{
QString expr_action;

int index = 0;
while ( index < action.size() )
{
QRegExp rx = QRegExp( "\\[%([^\\]]+)%\\]" );

int pos = rx.indexIn( action, index );
if ( pos < 0 )
break;

int start = index;
index = pos + rx.matchedLength();
QString to_replace = rx.cap( 1 ).trimmed();
QgsDebugMsg( "Found expression: " + to_replace );

if ( substitutionMap && substitutionMap->contains( to_replace ) )
{
expr_action += action.mid( start, pos - start ) + substitutionMap->value( to_replace ).toString();
continue;
}

QgsExpression exp( to_replace );
if ( exp.hasParserError() )
{
QgsDebugMsg( "Expression parser error: " + exp.parserErrorString() );
expr_action += action.mid( start, index - start );
continue;
}

QVariant result = exp.evaluate( &feat, layer->pendingFields() );
if ( exp.hasEvalError() )
{
QgsDebugMsg( "Expression parser eval error: " + exp.evalErrorString() );
expr_action += action.mid( start, index - start );
continue;
}

QgsDebugMsg( "Expression result is: " + result.toString() );
expr_action += action.mid( start, pos - start ) + result.toString();
}

expr_action += action.mid( index );
return expr_action;
}


QgsExpression::Node* QgsExpression::Node::createFromOgcFilter( QDomElement &element, QString &errorMessage )
{
Expand Down
1 change: 0 additions & 1 deletion src/core/qgsexpression.h
Expand Up @@ -532,7 +532,6 @@ class CORE_EXPORT QgsExpression
int mRowNumber;
double mScale;

void initGeomCalculator();
QgsDistanceArea mCalc;
};

Expand Down

0 comments on commit 1f1448d

Please sign in to comment.