Skip to content

Commit

Permalink
Finish implementation of @value context variable
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Oct 1, 2015
1 parent 5cfdea5 commit a8f8cfe
Show file tree
Hide file tree
Showing 15 changed files with 226 additions and 67 deletions.
7 changes: 7 additions & 0 deletions python/core/qgsexpressioncontext.sip
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,13 @@ class QgsExpressionContext
*/
QgsFields fields() const;

/** Sets the original value variable value for the context.
* @param value value for original value variable. This usually represents the an original widget
* value before any data defined overrides have been applied.
* @note added in QGIS 2.12
*/
void setOriginalValueVariable( const QVariant& value );

};

/** \ingroup core
Expand Down
7 changes: 7 additions & 0 deletions python/core/symbology-ng/qgssymbolv2.sip
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,13 @@ class QgsSymbolV2RenderContext
QgsRenderContext& renderContext();
//void setRenderContext( QgsRenderContext& c );

/** Sets the original value variable value for data defined symbology
* @param value value for original value variable. This usually represents the symbol property value
* before any data defined overrides have been applied.
* @note added in QGIS 2.12
*/
void setOriginalValueVariable( const QVariant& value );

QgsSymbolV2::OutputUnit outputUnit() const;
void setOutputUnit( QgsSymbolV2::OutputUnit u );

Expand Down
4 changes: 4 additions & 0 deletions src/app/qgslabelinggui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ static QgsExpressionContext _getExpressionContext( const void* context )
if ( layer )
expContext << QgsExpressionContextUtils::layerScope( layer );

//TODO - show actual value
expContext.setOriginalValueVariable( QVariant() );
expContext.setHighlightedVariables( QStringList() << QgsExpressionContext::EXPR_ORIGINAL_VALUE );

return expContext;
}

Expand Down
9 changes: 9 additions & 0 deletions src/core/qgsexpressioncontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

const QString QgsExpressionContext::EXPR_FIELDS( "_fields_" );
const QString QgsExpressionContext::EXPR_FEATURE( "_feature_" );
const QString QgsExpressionContext::EXPR_ORIGINAL_VALUE( "value" );

//
// QgsExpressionContextScope
Expand Down Expand Up @@ -413,6 +414,14 @@ QgsFields QgsExpressionContext::fields() const
return qvariant_cast<QgsFields>( variable( QgsExpressionContext::EXPR_FIELDS ) );
}

void QgsExpressionContext::setOriginalValueVariable( const QVariant &value )
{
if ( mStack.isEmpty() )
mStack.append( new QgsExpressionContextScope() );

mStack.last()->setVariable( QgsExpressionContext::EXPR_ORIGINAL_VALUE, value );
}


//
// QgsExpressionContextUtils
Expand Down
8 changes: 8 additions & 0 deletions src/core/qgsexpressioncontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,16 @@ class CORE_EXPORT QgsExpressionContext
*/
QgsFields fields() const;

/** Sets the original value variable value for the context.
* @param value value for original value variable. This usually represents the an original widget
* value before any data defined overrides have been applied.
* @note added in QGIS 2.12
*/
void setOriginalValueVariable( const QVariant& value );

static const QString EXPR_FIELDS;
static const QString EXPR_FEATURE;
static const QString EXPR_ORIGINAL_VALUE;

private:

Expand Down
137 changes: 72 additions & 65 deletions src/core/qgspallabeling.cpp

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/core/qgspallabeling.h
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ class CORE_EXPORT QgsPalLayerSettings
* @returns true/false whether result is null or invalid
* @note not available in python bindings
*/
bool dataDefinedEvaluate( QgsPalLayerSettings::DataDefinedProperties p, QVariant& exprVal, const QgsExpressionContext* context = 0 ) const;
bool dataDefinedEvaluate( QgsPalLayerSettings::DataDefinedProperties p, QVariant& exprVal, QgsExpressionContext* context = 0, QVariant originalValue = QVariant() ) const;

/** Whether data definition is active
*/
Expand Down Expand Up @@ -624,7 +624,7 @@ class CORE_EXPORT QgsPalLayerSettings
// convenience data defined evaluation function
bool dataDefinedValEval( DataDefinedValueType valType,
QgsPalLayerSettings::DataDefinedProperties p,
QVariant& exprVal, const QgsExpressionContext& context );
QVariant& exprVal, QgsExpressionContext &context, QVariant originalValue = QVariant() );

void parseTextStyle( QFont& labelFont,
QgsPalLayerSettings::SizeUnit fontunits,
Expand Down
15 changes: 15 additions & 0 deletions src/core/symbology-ng/qgsellipsesymbollayerv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,14 @@ void QgsEllipseSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2Rend
bool ok;
if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_OUTLINE_WIDTH ) )
{
context.setOriginalValueVariable( mOutlineWidth );
double width = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_OUTLINE_WIDTH, context, mOutlineWidth ).toDouble();
width = QgsSymbolLayerV2Utils::convertToPainterUnits( context.renderContext(), width, mOutlineWidthUnit, mOutlineWidthMapUnitScale );
mPen.setWidthF( width );
}
if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_OUTLINE_STYLE ) )
{
context.setOriginalValueVariable( QgsSymbolLayerV2Utils::encodePenStyle( mPen.style() ) );
QString styleString = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_OUTLINE_STYLE, context, QVariant(), &ok ).toString();
if ( ok )
{
Expand All @@ -222,12 +224,14 @@ void QgsEllipseSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2Rend
}
if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_FILL_COLOR ) )
{
context.setOriginalValueVariable( QgsSymbolLayerV2Utils::encodeColor( mBrush.color() ) );
QString colorString = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_FILL_COLOR, context, QVariant(), &ok ).toString();
if ( ok )
mBrush.setColor( QgsSymbolLayerV2Utils::decodeColor( colorString ) );
}
if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_OUTLINE_COLOR ) )
{
context.setOriginalValueVariable( QgsSymbolLayerV2Utils::encodeColor( mPen.color() ) );
QString colorString = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_OUTLINE_COLOR, context, QVariant(), &ok ).toString();
if ( ok )
mPen.setColor( QgsSymbolLayerV2Utils::decodeColor( colorString ) );
Expand All @@ -239,6 +243,7 @@ void QgsEllipseSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2Rend
QString symbolName = mSymbolName;
if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_SYMBOL_NAME ) )
{
context.setOriginalValueVariable( mSymbolName );
symbolName = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_SYMBOL_NAME, context, mSymbolName ).toString();
}
preparePath( symbolName, context, &scaledWidth, &scaledHeight, context.feature() );
Expand All @@ -260,6 +265,7 @@ void QgsEllipseSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2Rend
double rotation = 0.0;
if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_ROTATION ) )
{
context.setOriginalValueVariable( mAngle );
rotation = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_ROTATION, context, mAngle ).toDouble() + mLineAngle;
}
else if ( !qgsDoubleNear( mAngle + mLineAngle, 0.0 ) )
Expand Down Expand Up @@ -462,6 +468,7 @@ void QgsEllipseSymbolLayerV2::preparePath( const QString& symbolName, QgsSymbolV

if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_WIDTH ) ) //1. priority: data defined setting on symbol layer le
{
context.setOriginalValueVariable( mSymbolWidth );
width = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_WIDTH, context, mSymbolWidth ).toDouble();
}
else if ( context.renderHints() & QgsSymbolV2::DataDefinedSizeScale ) //2. priority: is data defined size on symbol level
Expand All @@ -481,6 +488,7 @@ void QgsEllipseSymbolLayerV2::preparePath( const QString& symbolName, QgsSymbolV
double height = 0;
if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_HEIGHT ) ) //1. priority: data defined setting on symbol layer level
{
context.setOriginalValueVariable( mSymbolHeight );
height = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_HEIGHT, context, mSymbolHeight ).toDouble();
}
else if ( context.renderHints() & QgsSymbolV2::DataDefinedSizeScale ) //2. priority: is data defined size on symbol level
Expand Down Expand Up @@ -565,6 +573,7 @@ bool QgsEllipseSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFa

if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_WIDTH ) ) //1. priority: data defined setting on symbol layer le
{
context->setOriginalValueVariable( mSymbolWidth );
symbolWidth = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_WIDTH, *context, mSymbolWidth ).toDouble();
}
else if ( context->renderHints() & QgsSymbolV2::DataDefinedSizeScale ) //2. priority: is data defined size on symbol level
Expand All @@ -580,6 +589,7 @@ bool QgsEllipseSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFa
double symbolHeight = mSymbolHeight;
if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_HEIGHT ) ) //1. priority: data defined setting on symbol layer level
{
context->setOriginalValueVariable( mSymbolHeight );
symbolHeight = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_HEIGHT, *context, mSymbolHeight ).toDouble();
}
else if ( context->renderHints() & QgsSymbolV2::DataDefinedSizeScale ) //2. priority: is data defined size on symbol level
Expand All @@ -596,6 +606,7 @@ bool QgsEllipseSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFa

if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_OUTLINE_WIDTH ) )
{
context->setOriginalValueVariable( mOutlineWidth );
outlineWidth = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_OUTLINE_WIDTH, *context, mOutlineWidth ).toDouble();
}
if ( mOutlineWidthUnit == QgsSymbolV2::MM )
Expand All @@ -608,6 +619,7 @@ bool QgsEllipseSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFa
QColor fc = mFillColor;
if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_FILL_COLOR ) )
{
context->setOriginalValueVariable( QgsSymbolLayerV2Utils::encodeColor( mFillColor ) );
QString colorString = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_FILL_COLOR, *context, QVariant(), &ok ).toString();
if ( ok )
fc = QgsSymbolLayerV2Utils::decodeColor( colorString );
Expand All @@ -617,6 +629,7 @@ bool QgsEllipseSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFa
QColor oc = mOutlineColor;
if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_OUTLINE_COLOR ) )
{
context->setOriginalValueVariable( QgsSymbolLayerV2Utils::encodeColor( mOutlineColor ) );
QString colorString = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_OUTLINE_COLOR, *context, QVariant(), &ok ).toString();
if ( ok )
oc = QgsSymbolLayerV2Utils::decodeColor( colorString );
Expand All @@ -626,6 +639,7 @@ bool QgsEllipseSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFa
QString symbolName = mSymbolName;
if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_SYMBOL_NAME ) )
{
context->setOriginalValueVariable( mSymbolName );
symbolName = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_SYMBOL_NAME, *context, mSymbolName ).toString();
}

Expand All @@ -639,6 +653,7 @@ bool QgsEllipseSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFa
double rotation = 0.0;
if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_ROTATION ) )
{
context->setOriginalValueVariable( mAngle );
rotation = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_ROTATION, *context, mAngle ).toDouble() + mLineAngle;
}
else if ( !qgsDoubleNear( mAngle + mLineAngle, 0.0 ) )
Expand Down
Loading

0 comments on commit a8f8cfe

Please sign in to comment.