Skip to content
Permalink
Browse files

Remove use of $map special column

Now replaced by @map_id variable. But don't panic, old expressions
with $map will still work!

Also adds a deprecated group for expression functions, which aren't
shown in the builder. $map added to deprecated group
  • Loading branch information
nyalldawson committed Sep 7, 2015
1 parent 829ff50 commit 183f4017887c5e248c3901612c85fd46eb99d602
@@ -40,7 +40,8 @@ static QgsExpressionContext _getExpressionContext( const void* context )
{
QgsExpressionContext expContext;
expContext << QgsExpressionContextUtils::globalScope()
<< QgsExpressionContextUtils::projectScope();
<< QgsExpressionContextUtils::projectScope()
<< QgsExpressionContextUtils::mapSettingsScope( QgisApp::instance()->mapCanvas()->mapSettings() );

const QgsVectorLayer* layer = ( const QgsVectorLayer* ) context;
if ( layer )
@@ -542,6 +543,7 @@ void QgsDiagramProperties::on_mFindMaximumValueButton_clicked()
QgsExpressionContext context;
context << QgsExpressionContextUtils::globalScope()
<< QgsExpressionContextUtils::projectScope()
<< QgsExpressionContextUtils::mapSettingsScope( QgisApp::instance()->mapCanvas()->mapSettings() )
<< QgsExpressionContextUtils::layerScope( mLayer );

exp.prepare( &context );
@@ -793,6 +795,7 @@ void QgsDiagramProperties::showAddAttributeExpressionDialog()
QgsExpressionContext context;
context << QgsExpressionContextUtils::globalScope()
<< QgsExpressionContextUtils::projectScope()
<< QgsExpressionContextUtils::mapSettingsScope( QgisApp::instance()->mapCanvas()->mapSettings() )
<< QgsExpressionContextUtils::layerScope( mLayer );

QgsExpressionBuilderDialog dlg( mLayer, expression, this, "generic", context );
@@ -42,7 +42,8 @@ static QgsExpressionContext _getExpressionContext( const void* context )
{
QgsExpressionContext expContext;
expContext << QgsExpressionContextUtils::globalScope()
<< QgsExpressionContextUtils::projectScope();
<< QgsExpressionContextUtils::projectScope()
<< QgsExpressionContextUtils::mapSettingsScope( QgisApp::instance()->mapCanvas()->mapSettings() );

const QgsVectorLayer* layer = ( const QgsVectorLayer* ) context;
if ( layer )
@@ -22,6 +22,8 @@
#include "qgsmaplayerregistry.h"
#include "qgsmaprenderer.h"
#include "qgsvectorlayer.h"
#include "qgisapp.h"
#include "qgsmapcanvas.h"

#include <QColorDialog>
#include <QFontDatabase>
@@ -208,6 +210,7 @@ void QgsLabelPropertyDialog::setDataDefinedValues( const QgsPalLayerSettings &la
QgsExpressionContext context;
context << QgsExpressionContextUtils::globalScope()
<< QgsExpressionContextUtils::projectScope()
<< QgsExpressionContextUtils::mapSettingsScope( QgisApp::instance()->mapCanvas()->mapSettings() )
<< QgsExpressionContextUtils::layerScope( vlayer );
context.setFeature( mCurLabelFeat );

@@ -15,6 +15,8 @@
#include "qgsstatisticalsummarydockwidget.h"
#include "qgsstatisticalsummary.h"
#include "qgsmaplayerregistry.h"
#include "qgisapp.h"
#include "qgsmapcanvas.h"
#include <QTableWidget>
#include <QAction>
#include <QSettings>
@@ -42,7 +44,8 @@ static QgsExpressionContext _getExpressionContext( const void* context )
{
QgsExpressionContext expContext;
expContext << QgsExpressionContextUtils::globalScope()
<< QgsExpressionContextUtils::projectScope();
<< QgsExpressionContextUtils::projectScope()
<< QgsExpressionContextUtils::mapSettingsScope( QgisApp::instance()->mapCanvas()->mapSettings() );

const QgsStatisticalSummaryDockWidget* widget = ( const QgsStatisticalSummaryDockWidget* ) context;
if ( widget )
@@ -348,6 +348,7 @@ void QgsVectorLayerProperties::insertExpression()
QgsExpressionContext context;
context << QgsExpressionContextUtils::globalScope()
<< QgsExpressionContextUtils::projectScope()
<< QgsExpressionContextUtils::mapSettingsScope( QgisApp::instance()->mapCanvas()->mapSettings() )
<< QgsExpressionContextUtils::layerScope( layer );

QgsExpressionBuilderDialog dlg( layer, selText.replace( QChar::ParagraphSeparator, '\n' ), this, "generic", context );
@@ -236,9 +236,6 @@ QgsMapSettings QgsComposerMap::mapSettings( const QgsRectangle& extent, const QS
jobMapSettings.setExpressionContext( *context );
delete context;

//update $map variable. Use QgsComposerItem's id since that is user-definable
QgsExpression::setSpecialColumn( "$map", QgsComposerItem::id() );

// composer-specific overrides of flags
jobMapSettings.setFlag( QgsMapSettings::ForceVectorOutput ); // force vector output (no caching of marker images etc.)
jobMapSettings.setFlag( QgsMapSettings::DrawEditingInfo, false );
@@ -2128,6 +2125,8 @@ QgsExpressionContext* QgsComposerMap::createExpressionContext() const
//have a QgsMapSettings object available when the context is required, so we manually
//add the same variables here
QgsExpressionContextScope* scope = new QgsExpressionContextScope( tr( "Map Settings" ) );

//use QgsComposerItem's id, not map item's ID, since that is user-definable
scope->addVariable( QgsExpressionContextScope::StaticVariable( "map_id", QgsComposerItem::id(), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( "map_rotation", mMapRotation, true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( "map_scale", scale(), true ) );
@@ -859,6 +859,16 @@ static QVariant fcnRowNumber( const QVariantList&, const QgsExpressionContext* c
//when above is removed - return QVariant()
}

static QVariant fcnMapId( const QVariantList&, const QgsExpressionContext* context, QgsExpression* )
{
if ( context && context->hasVariable( "map_id" ) )
return context->variable( "map_id" );

Q_NOWARN_DEPRECATED_PUSH
return QgsExpression::specialColumn( "$map" );
Q_NOWARN_DEPRECATED_POP
}

#define FEAT_FROM_CONTEXT(c, f) if (!c || !c->hasVariable(QgsExpressionContext::EXPR_FEATURE)) return QVariant(); \
QgsFeature f = qvariant_cast<QgsFeature>( c->variable( QgsExpressionContext::EXPR_FEATURE ) );

@@ -1605,7 +1615,7 @@ static QVariant fncColorCmyka( const QVariantList &values, const QgsExpressionCo
return QgsSymbolLayerV2Utils::encodeColor( color );
}

static QVariant fcnSpecialColumn( const QVariantList& values, const QgsExpressionContext* /*f*/, QgsExpression* parent )
static QVariant fcnSpecialColumn( const QVariantList& values, const QgsExpressionContext*, QgsExpression* parent )
{
QString varName = getStringValue( values.at( 0 ), parent );
return QgsExpression::specialColumn( varName );
@@ -1971,6 +1981,7 @@ const QList<QgsExpression::Function*>& QgsExpression::Functions()
<< new StaticFunction( "$id", 0, fcnFeatureId, "Record" )
<< new StaticFunction( "$currentfeature", 0, fcnFeature, "Record" )
<< new StaticFunction( "$scale", 0, fcnScale, "Record" )
<< new StaticFunction( "$map", 0, fcnMapId, "deprecated" )
<< new StaticFunction( "uuid", 0, fcnUuid, "Record", QString(), false, QStringList(), false, QStringList() << "$uuid" )
<< new StaticFunction( "get_feature", 3, fcnGetFeature, "Record", QString(), false, QStringList(), false, QStringList() << "getFeature" )
<< new StaticFunction( "layer_property", 2, fcnGetLayerProperty, "General" )
@@ -2052,7 +2063,6 @@ bool QgsExpression::hasSpecialColumn( const QString& name )
lst << qMakePair( QString( "$atlasfeatureid" ), QString( "Atlas" ) );
lst << qMakePair( QString( "$atlasgeometry" ), QString( "Atlas" ) );
lst << qMakePair( QString( "$atlasfeature" ), QString( "Atlas" ) );
lst << qMakePair( QString( "$map" ), QString( "Composer" ) );

QList< QPair<QString, QString> >::const_iterator it = lst.constBegin();
for ( ; it != lst.constEnd(); ++it )
@@ -3171,6 +3181,11 @@ void QgsExpression::initVariableHelp()
gVariableHelpTexts.insert( "item_top", QCoreApplication::translate( "variable_help", "Top position of composer item (in mm)." ) );
gVariableHelpTexts.insert( "item_width", QCoreApplication::translate( "variable_help", "Width of composer item (in mm)." ) );
gVariableHelpTexts.insert( "item_height", QCoreApplication::translate( "variable_help", "Height of composer item (in mm)." ) );

//map settings item variables
gVariableHelpTexts.insert( "map_id", QCoreApplication::translate( "variable_help", "ID of current map destination. This will be 'canvas' for canvas renders, and the item ID for composer map renders." ) );
gVariableHelpTexts.insert( "map_rotation", QCoreApplication::translate( "variable_help", "Current rotation of map." ) );
gVariableHelpTexts.insert( "map_scale", QCoreApplication::translate( "variable_help", "Current scale of map." ) );
}

QString QgsExpression::variableHelpText( const QString &variableName, bool showValue, const QVariant &value )
@@ -636,6 +636,7 @@ QgsExpressionContextScope* QgsExpressionContextUtils::mapSettingsScope( const Qg
QgsExpressionContextScope* scope = new QgsExpressionContextScope( QObject::tr( "Map Settings" ) );

//add known map settings context variables
scope->addVariable( QgsExpressionContextScope::StaticVariable( "map_id", "canvas", true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( "map_rotation", mapSettings.rotation(), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( "map_scale", mapSettings.scale(), true ) );

@@ -469,6 +469,8 @@ void QgsExpressionBuilderWidget::updateFunctionTree()
QString name = func->name();
if ( name.startsWith( "_" ) ) // do not display private functions
continue;
if ( func->group() == "deprecated" ) // don't show deprecated functions
continue;
if ( func->isContextual() )
{
//don't show contextual functions by default - it's up the the QgsExpressionContext
@@ -222,6 +222,8 @@ void QgsHtmlAnnotationItem::setFeatureForMapPosition()
context << QgsExpressionContextUtils::globalScope()
<< QgsExpressionContextUtils::projectScope()
<< QgsExpressionContextUtils::layerScope( mVectorLayer );
if ( mMapCanvas )
context.appendScope( QgsExpressionContextUtils::mapSettingsScope( mMapCanvas->mapSettings() ) );
context.setFeature( mFeature );
QString newtext = QgsExpression::replaceExpressionText( mHtmlSource, &context );
mWebView->setHtml( newtext );
@@ -658,10 +658,6 @@ void QgsMapCanvas::refreshMap()
// from now on we can accept refresh requests again
mRefreshScheduled = false;

//update $map variable to canvas
QgsExpression::setSpecialColumn( "$map", tr( "canvas" ) );
mExpressionContextScope.setVariable( "map_id", "canvas" );

//build the expression context
QgsExpressionContext expressionContext;
expressionContext << QgsExpressionContextUtils::globalScope()
@@ -101,6 +101,9 @@ QString QgsMapTip::fetchFeature( QgsMapLayer *layer, QgsPoint &mapPosition, QgsM
context << QgsExpressionContextUtils::globalScope()
<< QgsExpressionContextUtils::projectScope()
<< QgsExpressionContextUtils::layerScope( vlayer );
if ( mpMapCanvas )
context.appendScope( QgsExpressionContextUtils::mapSettingsScope( mpMapCanvas->mapSettings() ) );

context.setFeature( feature );
return QgsExpression::replaceExpressionText( vlayer->displayField(), &context );
}
@@ -374,7 +374,9 @@ static QgsExpressionContext _getExpressionContext( const void* context )
{
QgsExpressionContext expContext;
expContext << QgsExpressionContextUtils::globalScope()
<< QgsExpressionContextUtils::projectScope();
<< QgsExpressionContextUtils::projectScope()
//TODO - use actual map canvas settings
<< QgsExpressionContextUtils::mapSettingsScope( QgsMapSettings() );

const QgsVectorLayer* layer = ( const QgsVectorLayer* ) context;
if ( layer )
@@ -383,7 +383,9 @@ static QgsExpressionContext _getExpressionContext( const void* context )
{
QgsExpressionContext expContext;
expContext << QgsExpressionContextUtils::globalScope()
<< QgsExpressionContextUtils::projectScope();
<< QgsExpressionContextUtils::projectScope()
//TODO - use actual map canvas settings
<< QgsExpressionContextUtils::mapSettingsScope( QgsMapSettings() );

const QgsVectorLayer* layer = ( const QgsVectorLayer* ) context;
if ( layer )
@@ -35,7 +35,9 @@ static QgsExpressionContext _getExpressionContext( const void* context )
{
QgsExpressionContext expContext;
expContext << QgsExpressionContextUtils::globalScope()
<< QgsExpressionContextUtils::projectScope();
<< QgsExpressionContextUtils::projectScope()
//TODO - use actual map canvas settings
<< QgsExpressionContextUtils::mapSettingsScope( QgsMapSettings() );

const QgsVectorLayer* layer = ( const QgsVectorLayer* ) context;
if ( layer )
@@ -402,7 +402,9 @@ static QgsExpressionContext _getExpressionContext( const void* context )
{
QgsExpressionContext expContext;
expContext << QgsExpressionContextUtils::globalScope()
<< QgsExpressionContextUtils::projectScope();
<< QgsExpressionContextUtils::projectScope()
//TODO - use actual map canvas settings
<< QgsExpressionContextUtils::mapSettingsScope( QgsMapSettings() );

const QgsVectorLayer* layer = ( const QgsVectorLayer* ) context;
if ( layer )
@@ -508,6 +508,8 @@ void QgsRuleBasedRendererV2Widget::countFeatures()
QgsExpressionContext context;
context << QgsExpressionContextUtils::globalScope()
<< QgsExpressionContextUtils::projectScope()
//TODO - use actual map canvas settings
<< QgsExpressionContextUtils::mapSettingsScope( QgsMapSettings() )
<< QgsExpressionContextUtils::layerScope( mLayer );

renderContext.setExpressionContext( context );
@@ -630,6 +632,8 @@ void QgsRendererRulePropsDialog::buildExpression()
QgsExpressionContext context;
context << QgsExpressionContextUtils::globalScope()
<< QgsExpressionContextUtils::projectScope()
//TODO - use actual map canvas settings
<< QgsExpressionContextUtils::mapSettingsScope( QgsMapSettings() )
<< QgsExpressionContextUtils::layerScope( mLayer );

QgsExpressionBuilderDialog dlg( mLayer, editFilter->text(), this, "generic", context );
@@ -650,6 +654,8 @@ void QgsRendererRulePropsDialog::testFilter()
QgsExpressionContext context;
context << QgsExpressionContextUtils::globalScope()
<< QgsExpressionContextUtils::projectScope()
//TODO - use actual map canvas settings
<< QgsExpressionContextUtils::mapSettingsScope( QgsMapSettings() )
<< QgsExpressionContextUtils::layerScope( mLayer );

if ( !filter.prepare( &context ) )
@@ -82,7 +82,9 @@ static QgsExpressionContext _getExpressionContext( const void* context )
{
QgsExpressionContext expContext;
expContext << QgsExpressionContextUtils::globalScope()
<< QgsExpressionContextUtils::projectScope();
<< QgsExpressionContextUtils::projectScope()
//TODO - use actual map canvas settings
<< QgsExpressionContextUtils::mapSettingsScope( QgsMapSettings() );

const QgsVectorLayer* layer = ( const QgsVectorLayer* ) context;
if ( layer )
@@ -56,7 +56,9 @@ static QgsExpressionContext _getExpressionContext( const void* context )

QgsExpressionContext expContext;
expContext << QgsExpressionContextUtils::globalScope()
<< QgsExpressionContextUtils::projectScope();
<< QgsExpressionContextUtils::projectScope()
//TODO - use actual map canvas settings
<< QgsExpressionContextUtils::mapSettingsScope( QgsMapSettings() );

const QgsVectorLayer* layer = widget->vectorLayer();
if ( layer )
@@ -376,7 +376,9 @@ static QgsExpressionContext _getExpressionContext( const void* context )
//otherwise create a default symbol context
QgsExpressionContext expContext;
expContext << QgsExpressionContextUtils::globalScope()
<< QgsExpressionContextUtils::projectScope();
<< QgsExpressionContextUtils::projectScope()
//TODO - use actual map canvas settings
<< QgsExpressionContextUtils::mapSettingsScope( QgsMapSettings() );

const QgsVectorLayer* layer = widget->layer();
if ( layer )

0 comments on commit 183f401

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