Skip to content

Commit 684dd89

Browse files
committedFeb 11, 2014
Fix #9459 (layer fails to render when rule-based symbology make use of $atlasfeatureid)
1 parent a37766e commit 684dd89

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed
 

‎python/core/qgsexpression.sip

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ class QgsExpression
5757
static void unsetSpecialColumn( const QString& name );
5858
//! Return the value of the given special column or a null QVariant if undefined
5959
static QVariant specialColumn( const QString& name );
60+
//! Check whether a special column exists
61+
//! @note added in 2.2
62+
static bool hasSpecialColumn( const QString& name );
6063

6164
void setScale( double scale );
6265

‎src/core/qgsexpression.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1583,6 +1583,28 @@ QVariant QgsExpression::specialColumn( const QString& name )
15831583
return it.value();
15841584
}
15851585

1586+
bool QgsExpression::hasSpecialColumn( const QString& name )
1587+
{
1588+
static bool initialized = false;
1589+
if ( !initialized )
1590+
{
1591+
// Pre-register special columns that will exist within QGIS so that expressions that may use them are parsed correctly.
1592+
// This is really sub-optimal, we should get rid of the special columns and instead have contexts in which some values
1593+
// are defined and some are not ($rownum makes sense only in field calculator, $scale only when rendering, $page only for composer etc.)
1594+
1595+
QStringList lst;
1596+
lst << "$page" << "$feature" << "$numpages" << "$numfeatures" << "$atlasfeatureid" << "$atlasgeometry" << "$map";
1597+
foreach ( QString c, lst )
1598+
setSpecialColumn( c, QVariant() );
1599+
1600+
initialized = true;
1601+
}
1602+
1603+
if ( functionIndex( name ) != -1 )
1604+
return false;
1605+
return gmSpecialColumns.contains( name );
1606+
}
1607+
15861608
QList<QgsExpression::Function*> QgsExpression::specialColumns()
15871609
{
15881610
QList<Function*> defs;

‎src/core/qgsexpression.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ class CORE_EXPORT QgsExpression
147147
static void unsetSpecialColumn( const QString& name );
148148
//! Return the value of the given special column or a null QVariant if undefined
149149
static QVariant specialColumn( const QString& name );
150+
//! Check whether a special column exists
151+
//! @note added in 2.2
152+
static bool hasSpecialColumn( const QString& name );
150153

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

‎src/core/qgsexpressionparser.yy

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,7 @@ expression:
193193
int fnIndex = QgsExpression::functionIndex(*$1);
194194
if (fnIndex == -1)
195195
{
196-
QVariant userVar = QgsExpression::specialColumn( *$1 );
197-
if ( userVar.isNull() )
196+
if ( !QgsExpression::hasSpecialColumn( *$1 ) )
198197
{
199198
exp_error("Special column is not known");
200199
YYERROR;

0 commit comments

Comments
 (0)
Please sign in to comment.