Skip to content
Permalink
Browse files
Fix #9459 (layer fails to render when rule-based symbology make use o…
…f $atlasfeatureid)
  • Loading branch information
wonder-sk committed Feb 11, 2014
1 parent a37766e commit 684dd890a3359a2fb189b289b0bb65a42a9f4105
Showing with 29 additions and 2 deletions.
  1. +3 −0 python/core/qgsexpression.sip
  2. +22 −0 src/core/qgsexpression.cpp
  3. +3 −0 src/core/qgsexpression.h
  4. +1 −2 src/core/qgsexpressionparser.yy
@@ -57,6 +57,9 @@ class QgsExpression
static void unsetSpecialColumn( const QString& name );
//! Return the value of the given special column or a null QVariant if undefined
static QVariant specialColumn( const QString& name );
//! Check whether a special column exists
//! @note added in 2.2
static bool hasSpecialColumn( const QString& name );

void setScale( double scale );

@@ -1583,6 +1583,28 @@ QVariant QgsExpression::specialColumn( const QString& name )
return it.value();
}

bool QgsExpression::hasSpecialColumn( const QString& name )
{
static bool initialized = false;
if ( !initialized )
{
// Pre-register special columns that will exist within QGIS so that expressions that may use them are parsed correctly.
// This is really sub-optimal, we should get rid of the special columns and instead have contexts in which some values
// are defined and some are not ($rownum makes sense only in field calculator, $scale only when rendering, $page only for composer etc.)

QStringList lst;
lst << "$page" << "$feature" << "$numpages" << "$numfeatures" << "$atlasfeatureid" << "$atlasgeometry" << "$map";
foreach ( QString c, lst )
setSpecialColumn( c, QVariant() );

initialized = true;
}

if ( functionIndex( name ) != -1 )
return false;
return gmSpecialColumns.contains( name );
}

QList<QgsExpression::Function*> QgsExpression::specialColumns()
{
QList<Function*> defs;
@@ -147,6 +147,9 @@ class CORE_EXPORT QgsExpression
static void unsetSpecialColumn( const QString& name );
//! Return the value of the given special column or a null QVariant if undefined
static QVariant specialColumn( const QString& name );
//! Check whether a special column exists
//! @note added in 2.2
static bool hasSpecialColumn( const QString& name );

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

@@ -193,8 +193,7 @@ expression:
int fnIndex = QgsExpression::functionIndex(*$1);
if (fnIndex == -1)
{
QVariant userVar = QgsExpression::specialColumn( *$1 );
if ( userVar.isNull() )
if ( !QgsExpression::hasSpecialColumn( *$1 ) )
{
exp_error("Special column is not known");
YYERROR;

0 comments on commit 684dd89

Please sign in to comment.