Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 684dd89
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
3 changes: 3 additions & 0 deletions python/core/qgsexpression.sip
Expand Up @@ -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 );

Expand Down
22 changes: 22 additions & 0 deletions src/core/qgsexpression.cpp
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/core/qgsexpression.h
Expand Up @@ -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; }

Expand Down
3 changes: 1 addition & 2 deletions src/core/qgsexpressionparser.yy
Expand Up @@ -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;
Expand Down

0 comments on commit 684dd89

Please sign in to comment.