Skip to content
Permalink
Browse files

Ensure that select atlas variables are shown in expression builder

...even when they don't currently have a value assigned. This helps
users know which variables will be available in certain contexts.
  • Loading branch information
nyalldawson committed Sep 8, 2015
1 parent e8c3afa commit bd2d78cea926639cfe9adcbfd7d3e0972e7b0aa4
@@ -490,6 +490,12 @@ class QgsExpressionContextUtils
*/
static void setCompositionVariables( QgsComposition* composition, const QgsStringMap variables );

/** Creates a new scope which contains variables and functions relating to a QgsAtlasComposition.
* For instance, current page name and number.
* @param atlas source atlas. If null, a set of default atlas variables will be added to the scope.
*/
static QgsExpressionContextScope* atlasScope( const QgsAtlasComposition* atlas ) /Factory/;

/** Creates a new scope which contains variables and functions relating to a QgsComposerItem.
* For instance, item size and position.
* @param composerItem source composer item
@@ -41,6 +41,7 @@ static QgsExpressionContext _getExpressionContext( const void* context )
QgsExpressionContext expContext;
expContext << QgsExpressionContextUtils::globalScope()
<< QgsExpressionContextUtils::projectScope()
<< QgsExpressionContextUtils::atlasScope( 0 )
<< QgsExpressionContextUtils::mapSettingsScope( QgisApp::instance()->mapCanvas()->mapSettings() );

const QgsVectorLayer* layer = ( const QgsVectorLayer* ) context;
@@ -795,6 +796,7 @@ void QgsDiagramProperties::showAddAttributeExpressionDialog()
QgsExpressionContext context;
context << QgsExpressionContextUtils::globalScope()
<< QgsExpressionContextUtils::projectScope()
<< QgsExpressionContextUtils::atlasScope( 0 )
<< QgsExpressionContextUtils::mapSettingsScope( QgisApp::instance()->mapCanvas()->mapSettings() )
<< QgsExpressionContextUtils::layerScope( mLayer );

@@ -43,6 +43,7 @@ static QgsExpressionContext _getExpressionContext( const void* context )
QgsExpressionContext expContext;
expContext << QgsExpressionContextUtils::globalScope()
<< QgsExpressionContextUtils::projectScope()
<< QgsExpressionContextUtils::atlasScope( 0 )
<< QgsExpressionContextUtils::mapSettingsScope( QgisApp::instance()->mapCanvas()->mapSettings() );

const QgsVectorLayer* layer = ( const QgsVectorLayer* ) context;
@@ -210,6 +210,7 @@ void QgsLabelPropertyDialog::setDataDefinedValues( const QgsPalLayerSettings &la
QgsExpressionContext context;
context << QgsExpressionContextUtils::globalScope()
<< QgsExpressionContextUtils::projectScope()
<< QgsExpressionContextUtils::atlasScope( 0 )
<< QgsExpressionContextUtils::mapSettingsScope( QgisApp::instance()->mapCanvas()->mapSettings() )
<< QgsExpressionContextUtils::layerScope( vlayer );
context.setFeature( mCurLabelFeat );
@@ -348,6 +348,7 @@ void QgsVectorLayerProperties::insertExpression()
QgsExpressionContext context;
context << QgsExpressionContextUtils::globalScope()
<< QgsExpressionContextUtils::projectScope()
<< QgsExpressionContextUtils::atlasScope( 0 )
<< QgsExpressionContextUtils::mapSettingsScope( QgisApp::instance()->mapCanvas()->mapSettings() )
<< QgsExpressionContextUtils::layerScope( layer );

@@ -3230,6 +3230,7 @@ void QgsExpression::initVariableHelp()
gVariableHelpTexts.insert( "atlas_pagename", QCoreApplication::translate( "variable_help", "Current atlas page name." ) );
gVariableHelpTexts.insert( "atlas_feature", QCoreApplication::translate( "variable_help", "Current atlas feature (as feature object)." ) );
gVariableHelpTexts.insert( "atlas_featureid", QCoreApplication::translate( "variable_help", "Current atlas feature ID." ) );
gVariableHelpTexts.insert( "atlas_geometry", QCoreApplication::translate( "variable_help", "Current atlas feature geometry." ) );

//composer item variables
gVariableHelpTexts.insert( "item_id", QCoreApplication::translate( "variable_help", "Composer item user ID (not necessarily unique)." ) );
@@ -713,7 +713,15 @@ QgsExpressionContextScope* QgsExpressionContextUtils::atlasScope( const QgsAtlas
{
QgsExpressionContextScope* scope = new QgsExpressionContextScope( QObject::tr( "Atlas" ) );
if ( !atlas )
{
//add some dummy atlas variables. This is done so that as in certain contexts we want to show
//users that these variables are available even if they have no current value
scope->addVariable( QgsExpressionContextScope::StaticVariable( "atlas_pagename", QString(), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( "atlas_feature", QVariant::fromValue( QgsFeature() ), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( "atlas_featureid", 0, true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( "atlas_geometry", QVariant::fromValue( QgsGeometry() ), true ) );
return scope;
}

//add known atlas variables
scope->addVariable( QgsExpressionContextScope::StaticVariable( "atlas_totalfeatures", atlas->numFeatures(), true ) );
@@ -524,7 +524,7 @@ class CORE_EXPORT QgsExpressionContextUtils

/** Creates a new scope which contains variables and functions relating to a QgsAtlasComposition.
* For instance, current page name and number.
* @param atlas source atlas
* @param atlas source atlas. If null, a set of default atlas variables will be added to the scope.
*/
static QgsExpressionContextScope* atlasScope( const QgsAtlasComposition* atlas );

@@ -375,6 +375,7 @@ static QgsExpressionContext _getExpressionContext( const void* context )
QgsExpressionContext expContext;
expContext << QgsExpressionContextUtils::globalScope()
<< QgsExpressionContextUtils::projectScope()
<< QgsExpressionContextUtils::atlasScope( 0 )
//TODO - use actual map canvas settings
<< QgsExpressionContextUtils::mapSettingsScope( QgsMapSettings() );

@@ -668,6 +669,7 @@ void QgsCategorizedSymbolRendererV2Widget::addCategories()
QgsExpressionContext context;
context << QgsExpressionContextUtils::globalScope()
<< QgsExpressionContextUtils::projectScope()
<< QgsExpressionContextUtils::atlasScope( 0 )
<< QgsExpressionContextUtils::layerScope( mLayer );

expression->prepare( &context );
@@ -384,6 +384,7 @@ static QgsExpressionContext _getExpressionContext( const void* context )
QgsExpressionContext expContext;
expContext << QgsExpressionContextUtils::globalScope()
<< QgsExpressionContextUtils::projectScope()
<< QgsExpressionContextUtils::atlasScope( 0 )
//TODO - use actual map canvas settings
<< QgsExpressionContextUtils::mapSettingsScope( QgsMapSettings() );

@@ -36,6 +36,7 @@ static QgsExpressionContext _getExpressionContext( const void* context )
QgsExpressionContext expContext;
expContext << QgsExpressionContextUtils::globalScope()
<< QgsExpressionContextUtils::projectScope()
<< QgsExpressionContextUtils::atlasScope( 0 )
//TODO - use actual map canvas settings
<< QgsExpressionContextUtils::mapSettingsScope( QgsMapSettings() );

@@ -403,6 +403,7 @@ static QgsExpressionContext _getExpressionContext( const void* context )
QgsExpressionContext expContext;
expContext << QgsExpressionContextUtils::globalScope()
<< QgsExpressionContextUtils::projectScope()
<< QgsExpressionContextUtils::atlasScope( 0 )
//TODO - use actual map canvas settings
<< QgsExpressionContextUtils::mapSettingsScope( QgsMapSettings() );

@@ -508,6 +508,7 @@ void QgsRuleBasedRendererV2Widget::countFeatures()
QgsExpressionContext context;
context << QgsExpressionContextUtils::globalScope()
<< QgsExpressionContextUtils::projectScope()
<< QgsExpressionContextUtils::atlasScope( 0 )
//TODO - use actual map canvas settings
<< QgsExpressionContextUtils::mapSettingsScope( QgsMapSettings() )
<< QgsExpressionContextUtils::layerScope( mLayer );
@@ -632,6 +633,7 @@ void QgsRendererRulePropsDialog::buildExpression()
QgsExpressionContext context;
context << QgsExpressionContextUtils::globalScope()
<< QgsExpressionContextUtils::projectScope()
<< QgsExpressionContextUtils::atlasScope( 0 )
//TODO - use actual map canvas settings
<< QgsExpressionContextUtils::mapSettingsScope( QgsMapSettings() )
<< QgsExpressionContextUtils::layerScope( mLayer );
@@ -654,6 +656,7 @@ void QgsRendererRulePropsDialog::testFilter()
QgsExpressionContext context;
context << QgsExpressionContextUtils::globalScope()
<< QgsExpressionContextUtils::projectScope()
<< QgsExpressionContextUtils::atlasScope( 0 )
//TODO - use actual map canvas settings
<< QgsExpressionContextUtils::mapSettingsScope( QgsMapSettings() )
<< QgsExpressionContextUtils::layerScope( mLayer );
@@ -83,6 +83,7 @@ static QgsExpressionContext _getExpressionContext( const void* context )
QgsExpressionContext expContext;
expContext << QgsExpressionContextUtils::globalScope()
<< QgsExpressionContextUtils::projectScope()
<< QgsExpressionContextUtils::atlasScope( 0 )
//TODO - use actual map canvas settings
<< QgsExpressionContextUtils::mapSettingsScope( QgsMapSettings() );

@@ -228,6 +229,7 @@ void QgsSizeScaleWidget::computeFromLayerTriggered()
QgsExpressionContext context;
context << QgsExpressionContextUtils::globalScope()
<< QgsExpressionContextUtils::projectScope()
<< QgsExpressionContextUtils::atlasScope( 0 )
<< QgsExpressionContextUtils::layerScope( mLayer );

if ( ! expression.prepare( &context ) )
@@ -57,6 +57,7 @@ static QgsExpressionContext _getExpressionContext( const void* context )
QgsExpressionContext expContext;
expContext << QgsExpressionContextUtils::globalScope()
<< QgsExpressionContextUtils::projectScope()
<< QgsExpressionContextUtils::atlasScope( 0 )
//TODO - use actual map canvas settings
<< QgsExpressionContextUtils::mapSettingsScope( QgsMapSettings() );

@@ -377,6 +377,7 @@ static QgsExpressionContext _getExpressionContext( const void* context )
QgsExpressionContext expContext;
expContext << QgsExpressionContextUtils::globalScope()
<< QgsExpressionContextUtils::projectScope()
<< QgsExpressionContextUtils::atlasScope( 0 )
//TODO - use actual map canvas settings
<< QgsExpressionContextUtils::mapSettingsScope( QgsMapSettings() );

0 comments on commit bd2d78c

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