Skip to content
Permalink
Browse files

Fixed the rebasing-mess

  • Loading branch information
homann committed Sep 4, 2012
1 parent e83dce5 commit 1f1448d4144cfb02f73b3596e8fd7429ac33e60f
Showing with 65 additions and 3 deletions.
  1. +65 −2 src/core/qgsexpression.cpp
  2. +0 −1 src/core/qgsexpression.h
@@ -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()
@@ -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 )
@@ -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" ) )
;
}

@@ -887,7 +901,7 @@ QgsExpression::QgsExpression( const QString& expr )
: mExpression( expr )
, mRowNumber( 0 )
, mScale( 0 )

{
initGeomCalculator();

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

QStringList QgsExpression::referencedColumns()
@@ -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 )
{
@@ -532,7 +532,6 @@ class CORE_EXPORT QgsExpression
int mRowNumber;
double mScale;

void initGeomCalculator();
QgsDistanceArea mCalc;
};

0 comments on commit 1f1448d

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