Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 bd2d78c
Show file tree
Hide file tree
Showing 16 changed files with 33 additions and 1 deletion.
6 changes: 6 additions & 0 deletions python/core/qgsexpressioncontext.sip
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/app/qgsdiagramproperties.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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 );

Expand Down
1 change: 1 addition & 0 deletions src/app/qgslabelinggui.cpp
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/app/qgslabelpropertydialog.cpp
Expand Up @@ -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 );
Expand Down
1 change: 1 addition & 0 deletions src/app/qgsvectorlayerproperties.cpp
Expand Up @@ -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 );

Expand Down
1 change: 1 addition & 0 deletions src/core/qgsexpression.cpp
Expand Up @@ -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)." ) );
Expand Down
8 changes: 8 additions & 0 deletions src/core/qgsexpressioncontext.cpp
Expand Up @@ -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 ) );
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsexpressioncontext.h
Expand Up @@ -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 );

Expand Down
2 changes: 2 additions & 0 deletions src/gui/symbology-ng/qgscategorizedsymbolrendererv2widget.cpp
Expand Up @@ -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() );

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

expression->prepare( &context );
Expand Down
Expand Up @@ -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() );

Expand Down
1 change: 1 addition & 0 deletions src/gui/symbology-ng/qgsheatmaprendererwidget.cpp
Expand Up @@ -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() );

Expand Down
1 change: 1 addition & 0 deletions src/gui/symbology-ng/qgsrendererv2widget.cpp
Expand Up @@ -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() );

Expand Down
3 changes: 3 additions & 0 deletions src/gui/symbology-ng/qgsrulebasedrendererv2widget.cpp
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand All @@ -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 );
Expand Down
2 changes: 2 additions & 0 deletions src/gui/symbology-ng/qgssizescalewidget.cpp
Expand Up @@ -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() );

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

if ( ! expression.prepare( &context ) )
Expand Down
1 change: 1 addition & 0 deletions src/gui/symbology-ng/qgssymbollayerv2widget.cpp
Expand Up @@ -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() );

Expand Down
1 change: 1 addition & 0 deletions src/gui/symbology-ng/qgssymbolslistwidget.cpp
Expand Up @@ -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() );

Expand Down

0 comments on commit bd2d78c

Please sign in to comment.