Skip to content
Permalink
Browse files

Show variables from symbol scope in symbol layer widget expression

builders. (This lets users know they are available).

Also swap some variable names to static strings for speed.
  • Loading branch information
nyalldawson committed Jan 27, 2016
1 parent 9b6fa0d commit fe95e4eeeaeaf9fe323061628f34d17541a9430e
@@ -388,11 +388,20 @@ class QgsExpressionContext
*/
void setOriginalValueVariable( const QVariant& value );

//! Inbuilt variable name for fields storage
static const QString EXPR_FIELDS;
//! Inbuilt variable name for feature storage
static const QString EXPR_FEATURE;
//! Inbuilt variable name for @value original value variable
static const QString EXPR_ORIGINAL_VALUE;
//! Inbuilt variable name for symbol color variable
static const QString EXPR_SYMBOL_COLOR;
//! Inbuilt variable name for symbol angle variable
static const QString EXPR_SYMBOL_ANGLE;
//! Inbuilt variable name for geometry part count variable
static const QString EXPR_GEOMETRY_PART_COUNT;
//! Inbuilt variable name for geometry part number variable
static const QString EXPR_GEOMETRY_PART_NUM;
};

/** \ingroup core
@@ -35,6 +35,8 @@ const QString QgsExpressionContext::EXPR_FEATURE( "_feature_" );
const QString QgsExpressionContext::EXPR_ORIGINAL_VALUE( "value" );
const QString QgsExpressionContext::EXPR_SYMBOL_COLOR( "symbol_color" );
const QString QgsExpressionContext::EXPR_SYMBOL_ANGLE( "symbol_angle" );
const QString QgsExpressionContext::EXPR_GEOMETRY_PART_COUNT( "geometry_part_count" );
const QString QgsExpressionContext::EXPR_GEOMETRY_PART_NUM( "geometry_part_num" );

//
// QgsExpressionContextScope
@@ -423,11 +423,20 @@ class CORE_EXPORT QgsExpressionContext
*/
void setOriginalValueVariable( const QVariant& value );

//! Inbuilt variable name for fields storage
static const QString EXPR_FIELDS;
//! Inbuilt variable name for feature storage
static const QString EXPR_FEATURE;
//! Inbuilt variable name for @value original value variable
static const QString EXPR_ORIGINAL_VALUE;
//! Inbuilt variable name for symbol color variable
static const QString EXPR_SYMBOL_COLOR;
//! Inbuilt variable name for symbol angle variable
static const QString EXPR_SYMBOL_ANGLE;
//! Inbuilt variable name for geometry part count variable
static const QString EXPR_GEOMETRY_PART_COUNT;
//! Inbuilt variable name for geometry part number variable
static const QString EXPR_GEOMETRY_PART_NUM;

private:

@@ -717,8 +717,8 @@ void QgsSymbolV2::renderFeature( const QgsFeature& feature, QgsRenderContext& co
{
context.expressionContext().appendScope( mSymbolRenderContext->expressionContextScope() );
QgsExpressionContextUtils::updateSymbolScope( this, mSymbolRenderContext->expressionContextScope() );
mSymbolRenderContext->expressionContextScope()->setVariable( "geometry_part_count", segmentizedGeometry->geometry()->partCount() );
mSymbolRenderContext->expressionContextScope()->setVariable( "geometry_part_num", 1 );
mSymbolRenderContext->expressionContextScope()->setVariable( QgsExpressionContext::EXPR_GEOMETRY_PART_COUNT, segmentizedGeometry->geometry()->partCount() );
mSymbolRenderContext->expressionContextScope()->setVariable( QgsExpressionContext::EXPR_GEOMETRY_PART_NUM, 1 );
}

switch ( QgsWKBTypes::flatType( segmentizedGeometry->geometry()->wkbType() ) )
@@ -786,7 +786,7 @@ void QgsSymbolV2::renderFeature( const QgsFeature& feature, QgsRenderContext& co

for ( int i = 0; i < mp->numGeometries(); ++i )
{
mSymbolRenderContext->expressionContextScope()->setVariable( "geometry_part_num", i + 1 );
mSymbolRenderContext->expressionContextScope()->setVariable( QgsExpressionContext::EXPR_GEOMETRY_PART_NUM, i + 1 );

const QgsPointV2* point = static_cast< const QgsPointV2* >( mp->geometryN( i ) );
_getPoint( pt, context, point );
@@ -815,7 +815,7 @@ void QgsSymbolV2::renderFeature( const QgsFeature& feature, QgsRenderContext& co

for ( unsigned int i = 0; i < num; ++i )
{
mSymbolRenderContext->expressionContextScope()->setVariable( "geometry_part_num", i + 1 );
mSymbolRenderContext->expressionContextScope()->setVariable( QgsExpressionContext::EXPR_GEOMETRY_PART_NUM, i + 1 );

if ( geomCollection )
{
@@ -848,7 +848,7 @@ void QgsSymbolV2::renderFeature( const QgsFeature& feature, QgsRenderContext& co

for ( unsigned int i = 0; i < num; ++i )
{
mSymbolRenderContext->expressionContextScope()->setVariable( "geometry_part_num", i + 1 );
mSymbolRenderContext->expressionContextScope()->setVariable( QgsExpressionContext::EXPR_GEOMETRY_PART_NUM, i + 1 );

if ( geomCollection )
{
@@ -122,10 +122,10 @@ static QgsExpressionContext _getExpressionContext( const void* context )
if ( widget->layer() )
expContext << QgsExpressionContextUtils::layerScope( widget->layer() );

expContext.lastScope()->addVariable( QgsExpressionContextScope::StaticVariable( "geometry_part_count", 1, true ) );
expContext.lastScope()->addVariable( QgsExpressionContextScope::StaticVariable( "geometry_part_num", 1, true ) );
expContext.lastScope()->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_GEOMETRY_PART_COUNT, 1, true ) );
expContext.lastScope()->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_GEOMETRY_PART_NUM, 1, true ) );

expContext.setHighlightedVariables( QStringList() << "geometry_part_num" );
expContext.setHighlightedVariables( QStringList() << QgsExpressionContext::EXPR_GEOMETRY_PART_NUM );

return expContext;
}
@@ -75,12 +75,21 @@ static QgsExpressionContext _getExpressionContext( const void* context )
if ( layer )
expContext << QgsExpressionContextUtils::layerScope( layer );

expContext.lastScope()->addVariable( QgsExpressionContextScope::StaticVariable( "geometry_part_count", 1, true ) );
expContext.lastScope()->addVariable( QgsExpressionContextScope::StaticVariable( "geometry_part_num", 1, true ) );
QgsExpressionContextScope* symbolScope = QgsExpressionContextUtils::updateSymbolScope( nullptr, new QgsExpressionContextScope() );
if ( const QgsSymbolLayerV2* symbolLayer = const_cast< QgsSymbolLayerV2Widget* >( widget )->symbolLayer() )
{
//cheat a bit - set the symbol color variable to match the symbol layer's color (when we should really be using the *symbols*
//color, but that's not accessible here). 99% of the time these will be the same anyway
symbolScope->setVariable( QgsExpressionContext::EXPR_SYMBOL_COLOR, symbolLayer->color() );
}
expContext << symbolScope;
expContext.lastScope()->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_GEOMETRY_PART_COUNT, 1, true ) );
expContext.lastScope()->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_GEOMETRY_PART_NUM, 1, true ) );

//TODO - show actual value
expContext.setOriginalValueVariable( QVariant() );
expContext.setHighlightedVariables( QStringList() << QgsExpressionContext::EXPR_ORIGINAL_VALUE << "geometry_part_count" << "geometry_part_num" );
expContext.setHighlightedVariables( QStringList() << QgsExpressionContext::EXPR_ORIGINAL_VALUE << QgsExpressionContext::EXPR_SYMBOL_COLOR
<< QgsExpressionContext::EXPR_GEOMETRY_PART_COUNT << QgsExpressionContext::EXPR_GEOMETRY_PART_NUM );

return expContext;
}

0 comments on commit fe95e4e

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