Use QgsPropertys for interpolated line renderer start/end width/color

expressions instead of raw expressions

We can greatly simplify the code by doing so, as all the handling
of preparing and optimising QgsPropertys are done automatically
for symbol layers.
This commit is contained in:
Nyall Dawson 2021-09-21 11:28:30 +10:00
parent 9e68b4542b
commit 3474909739
7 changed files with 184 additions and 188 deletions

View File

@ -340,69 +340,97 @@ Creates the symbol layer
virtual bool isCompatibleWithSymbol( QgsSymbol *symbol ) const;
virtual QSet<QString> usedAttributes( const QgsRenderContext &context ) const;
virtual bool canCauseArtifactsBetweenAdjacentTiles() const;
void setExpressionsStringForWidth( const QString &start, const QString &end );
void setExpressionsStringForWidth( const QString &start, const QString &end ) /Deprecated/;
%Docstring
Sets the expressions (as string) that define the extremety values af the line feature for width
Sets the expressions (as string) that define the extremety values af the line feature for width.
.. deprecated::
use setDataDefinedProperty( :py:class:`QgsSymbolLayer`.PropertyLineStartWidthValue ) and setDataDefinedProperty( :py:class:`QgsSymbolLayer`.PropertyLineEndWidthValue ) instead
%End
QString startValueExpressionForWidth() const;
QString startValueExpressionForWidth() const /Deprecated/;
%Docstring
Returns the epression related to the start extremity value for width
Returns the epression related to the start extremity value for width.
.. deprecated::
use dataDefinedProperty( :py:class:`QgsSymbolLayer`.PropertyLineStartWidthValue ) instead.
%End
QString endValueExpressionForWidth() const;
QString endValueExpressionForWidth() const /Deprecated/;
%Docstring
Returns the expression related to the end extremity value for width
Returns the expression related to the end extremity value for width.
.. deprecated::
use dataDefinedProperty( :py:class:`QgsSymbolLayer`.PropertyLineEndWidthValue ) instead.
%End
void setWidthUnit( QgsUnitTypes::RenderUnit strokeWidthUnit );
%Docstring
Sets the width unit
Sets the width unit.
.. seealso:: :py:func:`widthUnit`
%End
QgsUnitTypes::RenderUnit widthUnit() const;
%Docstring
Returns the width unit
Returns the width unit.
.. seealso:: :py:func:`setWidthUnit`
%End
void setInterpolatedWidth( const QgsInterpolatedLineWidth &interpolatedLineWidth );
%Docstring
Sets the interpolated width used to render the width of lines, ``see`` :py:class:`QgsInterpolatedLineWidth`
Sets the interpolated width used to render the width of lines, ``see`` :py:class:`QgsInterpolatedLineWidth`.
.. seealso:: :py:func:`interpolatedWidth`
%End
QgsInterpolatedLineWidth interpolatedWidth() const;
%Docstring
Returns the interpolated width used to render the width of lines, see ``:py:class:`QgsInterpolatedLineWidth```
Returns the interpolated width used to render the width of lines, see ``:py:class:`QgsInterpolatedLineWidth```.
.. seealso:: :py:func:`setInterpolatedWidth`
%End
void setExpressionsStringForColor( const QString &start, const QString &end );
void setExpressionsStringForColor( const QString &start, const QString &end ) /Deprecated/;
%Docstring
Sets the expressions (as string) that define the extremety values af the line feature for color
Sets the expressions (as string) that define the extremety values af the line feature for color.
.. deprecated::
use setDataDefinedProperty( :py:class:`QgsSymbolLayer`.PropertyLineStartColorValue ) and setDataDefinedProperty( :py:class:`QgsSymbolLayer`.PropertyLineEndColorValue ) instead
%End
QString startValueExpressionForColor() const;
QString startValueExpressionForColor() const /Deprecated/;
%Docstring
Returns the epression related to the start extremity value for width for color
.. deprecated::
use dataDefinedProperty( :py:class:`QgsSymbolLayer`.PropertyLineStartColorValue ) instead.
%End
QString endValueExpressionForColor() const;
QString endValueExpressionForColor() const /Deprecated/;
%Docstring
Returns the expression related to the end extremity value for width for color
.. deprecated::
use dataDefinedProperty( :py:class:`QgsSymbolLayer`.PropertyLineEndColorValue ) instead.
%End
void setInterpolatedColor( const QgsInterpolatedLineColor &interpolatedLineColor );
%Docstring
Sets the interpolated color used to render the colors of lines, ``see`` :py:class:`QgsInterpolatedLineColor`
Sets the interpolated color used to render the colors of lines, ``see`` :py:class:`QgsInterpolatedLineColor`.
.. seealso:: :py:func:`interpolatedColor`
%End
QgsInterpolatedLineColor interpolatedColor() const;
%Docstring
Returns the interpolated color used to render the colors of lines, see ``:py:class:`QgsInterpolatedLineColor```
Returns the interpolated color used to render the colors of lines, see ``:py:class:`QgsInterpolatedLineColor```.
.. seealso:: :py:func:`setInterpolatedColor`
%End
private:

View File

@ -152,6 +152,10 @@ class QgsSymbolLayer
PropertyDashPatternOffset,
PropertyTrimStart,
PropertyTrimEnd,
PropertyLineStartWidthValue,
PropertyLineEndWidthValue,
PropertyLineStartColorValue,
PropertyLineEndColorValue,
};
static const QgsPropertiesDefinition &propertyDefinitions();

View File

@ -801,45 +801,12 @@ void QgsInterpolatedLineColor::graduatedColorsDiscrete( double value1, double va
QString QgsInterpolatedLineSymbolLayer::layerType() const {return QStringLiteral( "InterpolatedLine" );}
void QgsInterpolatedLineSymbolLayer::startRender( QgsSymbolRenderContext &context )
void QgsInterpolatedLineSymbolLayer::startRender( QgsSymbolRenderContext & )
{
// find out attribute index from name
mStartWidthAttributeIndex = -1; //mFields.lookupField( mStartWidthExpressionString );
mEndWidthAttributeIndex = -1; //mFields.lookupField( mEndWidthExpressionString );
mStartColorAttributeIndex = -1; //mFields.lookupField( mStartColorExpressionString );
mEndColorAttributeIndex = -1; //mFields.lookupField( mEndColorExpressionString );
if ( mStartWidthAttributeIndex == -1 )
{
mStartWidthExpression.reset( new QgsExpression( mStartWidthExpressionString ) );
mStartWidthExpression->prepare( &context.renderContext().expressionContext() );
}
if ( mEndWidthAttributeIndex == -1 )
{
mEndWithExpression.reset( new QgsExpression( mEndWidthExpressionString ) );
mEndWithExpression->prepare( &context.renderContext().expressionContext() );
}
if ( mStartColorAttributeIndex == -1 )
{
mStartColorExpression.reset( new QgsExpression( mStartColorExpressionString ) );
mStartColorExpression->prepare( &context.renderContext().expressionContext() );
}
if ( mEndColorAttributeIndex == -1 )
{
mEndColorExpression.reset( new QgsExpression( mEndColorExpressionString ) );
mEndColorExpression->prepare( &context.renderContext().expressionContext() );
}
}
void QgsInterpolatedLineSymbolLayer::stopRender( QgsSymbolRenderContext & )
{
mStartWidthExpression.reset();
mEndWithExpression.reset();
mStartColorExpression.reset();
mEndColorExpression.reset();
}
QgsInterpolatedLineSymbolLayer *QgsInterpolatedLineSymbolLayer::clone() const
@ -856,14 +823,14 @@ QgsSymbolLayer *QgsInterpolatedLineSymbolLayer::create( const QVariantMap &prope
symbolLayer.reset( new QgsInterpolatedLineSymbolLayer() );
if ( properties.contains( QStringLiteral( "start_width_expression" ) ) )
symbolLayer->mStartWidthExpressionString = properties.value( QStringLiteral( "start_width_expression" ) ).toString();
symbolLayer->setDataDefinedProperty( QgsSymbolLayer::PropertyLineStartWidthValue, QgsProperty::fromExpression( properties.value( QStringLiteral( "start_width_expression" ) ).toString() ) );
if ( properties.contains( QStringLiteral( "end_width_expression" ) ) )
symbolLayer->mEndWidthExpressionString = properties.value( QStringLiteral( "end_width_expression" ) ).toString();
symbolLayer->setDataDefinedProperty( QgsSymbolLayer::PropertyLineEndWidthValue, QgsProperty::fromExpression( properties.value( QStringLiteral( "end_width_expression" ) ).toString() ) );
if ( properties.contains( QStringLiteral( "start_color_expression" ) ) )
symbolLayer->mStartColorExpressionString = properties.value( QStringLiteral( "start_color_expression" ) ).toString();
symbolLayer->setDataDefinedProperty( QgsSymbolLayer::PropertyLineStartColorValue, QgsProperty::fromExpression( properties.value( QStringLiteral( "start_color_expression" ) ).toString() ) );
if ( properties.contains( QStringLiteral( "end_color_expression" ) ) )
symbolLayer->mEndColorExpressionString = properties.value( QStringLiteral( "end_color_expression" ) ).toString();
symbolLayer->setDataDefinedProperty( QgsSymbolLayer::PropertyLineEndColorValue, QgsProperty::fromExpression( properties.value( QStringLiteral( "end_color_expression" ) ).toString() ) );
if ( properties.contains( QStringLiteral( "line_width" ) ) )
symbolLayer->mLineRender.mStrokeWidth.setFixedStrokeWidth( properties.value( QStringLiteral( "line_width" ) ).toDouble() ) ;
@ -904,11 +871,6 @@ QVariantMap QgsInterpolatedLineSymbolLayer::properties() const
{
QVariantMap props;
props.insert( QStringLiteral( "start_width_expression" ), mStartWidthExpressionString );
props.insert( QStringLiteral( "end_width_expression" ), mEndWidthExpressionString );
props.insert( QStringLiteral( "start_color_expression" ), mStartColorExpressionString );
props.insert( QStringLiteral( "end_color_expression" ), mEndColorExpressionString );
// Line width varying
props.insert( QStringLiteral( "line_width" ), QString::number( mLineRender.mStrokeWidth.fixedStrokeWidth() ) );
props.insert( QStringLiteral( "line_width_unit" ), QgsUnitTypes::encodeUnit( mLineRender.widthUnit() ) );
@ -934,10 +896,6 @@ void QgsInterpolatedLineSymbolLayer::drawPreviewIcon( QgsSymbolRenderContext &co
: QgsStyle::defaultStyle()->defaultPatch( Qgis::SymbolType::Line, size ).geometry();
startRender( context );
mStartWidthAttributeIndex = -1;
mEndWidthAttributeIndex = -1;
mStartColorAttributeIndex = -1;
mEndColorAttributeIndex = -1;
double min = std::min( mLineRender.interpolatedLineWidth().minimumValue(), mLineRender.interpolatedColor().colorRampShader().minimumValue() );
double max = std::max( mLineRender.interpolatedLineWidth().maximumValue(), mLineRender.interpolatedColor().colorRampShader().maximumValue() );
@ -967,18 +925,25 @@ void QgsInterpolatedLineSymbolLayer::drawPreviewIcon( QgsSymbolRenderContext &co
void QgsInterpolatedLineSymbolLayer::setExpressionsStringForWidth( const QString &start, const QString &end )
{
mStartWidthExpressionString = start;
mEndWidthExpressionString = end;
if ( start.isEmpty() )
mDataDefinedProperties.setProperty( QgsSymbolLayer::PropertyLineStartWidthValue, QgsProperty() );
else
mDataDefinedProperties.setProperty( QgsSymbolLayer::PropertyLineStartWidthValue, QgsProperty::fromExpression( start ) );
if ( end.isEmpty() )
mDataDefinedProperties.setProperty( QgsSymbolLayer::PropertyLineEndWidthValue, QgsProperty() );
else
mDataDefinedProperties.setProperty( QgsSymbolLayer::PropertyLineEndWidthValue, QgsProperty::fromExpression( end ) );
}
QString QgsInterpolatedLineSymbolLayer::startValueExpressionForWidth() const
{
return mStartWidthExpressionString;
return mDataDefinedProperties.property( QgsSymbolLayer::PropertyLineStartWidthValue ).asExpression();
}
QString QgsInterpolatedLineSymbolLayer::endValueExpressionForWidth() const
{
return mEndWidthExpressionString;
return mDataDefinedProperties.property( QgsSymbolLayer::PropertyLineEndWidthValue ).asExpression();
}
void QgsInterpolatedLineSymbolLayer::setWidthUnit( QgsUnitTypes::RenderUnit strokeWidthUnit )
@ -997,18 +962,25 @@ QgsInterpolatedLineWidth QgsInterpolatedLineSymbolLayer::interpolatedWidth() con
void QgsInterpolatedLineSymbolLayer::setExpressionsStringForColor( const QString &start, const QString &end )
{
mStartColorExpressionString = start;
mEndColorExpressionString = end;
if ( start.isEmpty() )
mDataDefinedProperties.setProperty( QgsSymbolLayer::PropertyLineStartColorValue, QgsProperty() );
else
mDataDefinedProperties.setProperty( QgsSymbolLayer::PropertyLineStartColorValue, QgsProperty::fromExpression( start ) );
if ( end.isEmpty() )
mDataDefinedProperties.setProperty( QgsSymbolLayer::PropertyLineEndColorValue, QgsProperty() );
else
mDataDefinedProperties.setProperty( QgsSymbolLayer::PropertyLineEndColorValue, QgsProperty::fromExpression( end ) );
}
QString QgsInterpolatedLineSymbolLayer::startValueExpressionForColor() const
{
return mStartColorExpressionString;
return mDataDefinedProperties.property( QgsSymbolLayer::PropertyLineStartColorValue ).asExpression();
}
QString QgsInterpolatedLineSymbolLayer::endValueExpressionForColor() const
{
return mEndColorExpressionString;
return mDataDefinedProperties.property( QgsSymbolLayer::PropertyLineEndColorValue ).asExpression();
}
void QgsInterpolatedLineSymbolLayer::setInterpolatedColor( const QgsInterpolatedLineColor &interpolatedLineColor )
@ -1148,69 +1120,44 @@ void QgsInterpolatedLineSymbolLayer::render( const QVector< QPolygonF > &parts,
double startValColor = 0;
double variationPerMapUnitColor = 0;
QVariant val1WidthVariant;
QVariant val2WidthVariant;
QVariant val1ColorVariant;
QVariant val2ColorVariant;
bool ok = true;
if ( mLineRender.interpolatedLineWidth().isVariableWidth() )
{
if ( mStartWidthExpression )
if ( mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyLineStartWidthValue ) )
{
val1WidthVariant = mStartWidthExpression->evaluate( &context.expressionContext() );
ok |= mStartWidthExpression->hasEvalError();
startValWidth = mDataDefinedProperties.valueAsDouble( QgsSymbolLayer::PropertyLineStartWidthValue, context.expressionContext(), 0, &ok );
if ( !ok )
return;
}
//else
// val1WidthVariant = mFeature.attribute( mStartWidthAttributeIndex );
if ( mEndWithExpression )
double endValWidth = 0;
if ( mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyLineEndWidthValue ) )
{
val2WidthVariant = mEndWithExpression->evaluate( &context.expressionContext() );
ok |= mEndWithExpression->hasEvalError();
endValWidth = mDataDefinedProperties.valueAsDouble( QgsSymbolLayer::PropertyLineEndWidthValue, context.expressionContext(), 0, &ok );
if ( !ok )
return;
}
//else
// val2WidthVariant = mFeature.attribute( mEndWidthAttributeIndex );
if ( !ok )
return;
startValWidth = val1WidthVariant.toDouble( &ok );
if ( !ok )
return;
const double endValWidth = val2WidthVariant.toDouble( &ok );
if ( !ok )
return;
variationPerMapUnitWidth = ( endValWidth - startValWidth ) / totalLength;
}
if ( mLineRender.interpolatedColor().coloringMethod() == QgsInterpolatedLineColor::ColorRamp )
{
if ( mStartColorExpression )
if ( mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyLineStartColorValue ) )
{
val1ColorVariant = mStartColorExpression->evaluate( &context.expressionContext() );
ok |= mStartColorExpression->hasEvalError();
startValColor = mDataDefinedProperties.valueAsDouble( QgsSymbolLayer::PropertyLineStartColorValue, context.expressionContext(), 0, &ok );
if ( !ok )
return;
}
// else
// val1ColorVariant = mFeature.attribute( mStartColorAttributeIndex );
if ( mEndColorExpression )
double endValColor = 0;
if ( mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyLineEndColorValue ) )
{
val2ColorVariant = mEndColorExpression->evaluate( &context.expressionContext() );
ok |= mEndColorExpression->hasEvalError();
endValColor = mDataDefinedProperties.valueAsDouble( QgsSymbolLayer::PropertyLineEndColorValue, context.expressionContext(), 0, &ok );
if ( !ok )
return;
}
// else
// val2ColorVariant = mFeature.attribute( mEndColorAttributeIndex );
startValColor = val1ColorVariant.toDouble( &ok );
if ( !ok )
return;
const double endValColor = val2ColorVariant.toDouble( &ok );
if ( !ok )
return;
variationPerMapUnitColor = ( endValColor - startValColor ) / totalLength;
}
@ -1258,38 +1205,6 @@ bool QgsInterpolatedLineSymbolLayer::isCompatibleWithSymbol( QgsSymbol *symbol )
return symbol && symbol->type() == Qgis::SymbolType::Line;
}
QSet<QString> QgsInterpolatedLineSymbolLayer::usedAttributes( const QgsRenderContext & ) const
{
QSet<QString> attributes;
// mFirstValueExpression and mSecondValueExpression can contain either attribute name or an expression.
// Sometimes it is not possible to distinguish between those two,
// e.g. "a - b" can be both a valid attribute name or expression.
// Since we do not have access to fields here, try both options.
attributes << mStartWidthExpressionString;
attributes << mEndWidthExpressionString;
attributes << mStartColorExpressionString;
attributes << mEndColorExpressionString;
QgsExpression testExprStartWidth( mStartWidthExpressionString );
if ( !testExprStartWidth.hasParserError() )
attributes.unite( testExprStartWidth.referencedColumns() );
QgsExpression testExprEndWidth( mEndWidthExpressionString );
if ( !testExprEndWidth.hasParserError() )
attributes.unite( testExprEndWidth.referencedColumns() );
QgsExpression testExprStartColor( mEndWidthExpressionString );
if ( !testExprStartColor.hasParserError() )
attributes.unite( testExprStartColor.referencedColumns() );
QgsExpression testExprEndColor( mEndWidthExpressionString );
if ( !testExprEndColor.hasParserError() )
attributes.unite( testExprEndColor.referencedColumns() );
return attributes;
}
bool QgsInterpolatedLineSymbolLayer::canCauseArtifactsBetweenAdjacentTiles() const
{
return true;

View File

@ -304,43 +304,90 @@ class CORE_EXPORT QgsInterpolatedLineSymbolLayer : public QgsLineSymbolLayer
void stopFeatureRender( const QgsFeature &feature, QgsRenderContext &context ) override;
void renderPolyline( const QPolygonF &points, QgsSymbolRenderContext &context ) override;
bool isCompatibleWithSymbol( QgsSymbol *symbol ) const override;
QSet<QString> usedAttributes( const QgsRenderContext &context ) const override;
bool canCauseArtifactsBetweenAdjacentTiles() const override;
//! Sets the expressions (as string) that define the extremety values af the line feature for width
void setExpressionsStringForWidth( const QString &start, const QString &end );
/**
* Sets the expressions (as string) that define the extremety values af the line feature for width.
*
* \deprecated use setDataDefinedProperty( QgsSymbolLayer::PropertyLineStartWidthValue ) and setDataDefinedProperty( QgsSymbolLayer::PropertyLineEndWidthValue ) instead
*/
Q_DECL_DEPRECATED void setExpressionsStringForWidth( const QString &start, const QString &end ) SIP_DEPRECATED;
//! Returns the epression related to the start extremity value for width
QString startValueExpressionForWidth() const;
/**
* Returns the epression related to the start extremity value for width.
*
* \deprecated use dataDefinedProperty( QgsSymbolLayer::PropertyLineStartWidthValue ) instead.
*/
Q_DECL_DEPRECATED QString startValueExpressionForWidth() const SIP_DEPRECATED;
//! Returns the expression related to the end extremity value for width
QString endValueExpressionForWidth() const;
/**
* Returns the expression related to the end extremity value for width.
*
* \deprecated use dataDefinedProperty( QgsSymbolLayer::PropertyLineEndWidthValue ) instead.
*/
Q_DECL_DEPRECATED QString endValueExpressionForWidth() const SIP_DEPRECATED;
//! Sets the width unit
/**
* Sets the width unit.
*
* \see widthUnit()
*/
void setWidthUnit( QgsUnitTypes::RenderUnit strokeWidthUnit );
//! Returns the width unit
/**
* Returns the width unit.
*
* \see setWidthUnit()
*/
QgsUnitTypes::RenderUnit widthUnit() const;
//! Sets the interpolated width used to render the width of lines, \a see QgsInterpolatedLineWidth
/**
* Sets the interpolated width used to render the width of lines, \a see QgsInterpolatedLineWidth.
*
* \see interpolatedWidth()
*/
void setInterpolatedWidth( const QgsInterpolatedLineWidth &interpolatedLineWidth );
//! Returns the interpolated width used to render the width of lines, see \a QgsInterpolatedLineWidth
/**
* Returns the interpolated width used to render the width of lines, see \a QgsInterpolatedLineWidth.
*
* \see setInterpolatedWidth()
*/
QgsInterpolatedLineWidth interpolatedWidth() const;
//! Sets the expressions (as string) that define the extremety values af the line feature for color
void setExpressionsStringForColor( const QString &start, const QString &end );
/**
* Sets the expressions (as string) that define the extremety values af the line feature for color.
*
* \deprecated use setDataDefinedProperty( QgsSymbolLayer::PropertyLineStartColorValue ) and setDataDefinedProperty( QgsSymbolLayer::PropertyLineEndColorValue ) instead
*/
Q_DECL_DEPRECATED void setExpressionsStringForColor( const QString &start, const QString &end ) SIP_DEPRECATED;
//! Returns the epression related to the start extremity value for width for color
QString startValueExpressionForColor() const;
/**
* Returns the epression related to the start extremity value for width for color
*
* \deprecated use dataDefinedProperty( QgsSymbolLayer::PropertyLineStartColorValue ) instead.
*/
Q_DECL_DEPRECATED QString startValueExpressionForColor() const SIP_DEPRECATED;
//! Returns the expression related to the end extremity value for width for color
QString endValueExpressionForColor() const;
/**
* Returns the expression related to the end extremity value for width for color
*
* \deprecated use dataDefinedProperty( QgsSymbolLayer::PropertyLineEndColorValue ) instead.
*/
Q_DECL_DEPRECATED QString endValueExpressionForColor() const SIP_DEPRECATED;
//! Sets the interpolated color used to render the colors of lines, \a see QgsInterpolatedLineColor
/**
* Sets the interpolated color used to render the colors of lines, \a see QgsInterpolatedLineColor.
*
* \see interpolatedColor()
*/
void setInterpolatedColor( const QgsInterpolatedLineColor &interpolatedLineColor );
//! Returns the interpolated color used to render the colors of lines, see \a QgsInterpolatedLineColor
/**
* Returns the interpolated color used to render the colors of lines, see \a QgsInterpolatedLineColor.
*
* \see setInterpolatedColor()
*/
QgsInterpolatedLineColor interpolatedColor() const;
private:
@ -350,21 +397,6 @@ class CORE_EXPORT QgsInterpolatedLineSymbolLayer : public QgsLineSymbolLayer
QgsInterpolatedLineRenderer mLineRender;
QString mStartWidthExpressionString;
QString mEndWidthExpressionString;
QString mStartColorExpressionString;
QString mEndColorExpressionString;
int mStartWidthAttributeIndex = -1;
int mEndWidthAttributeIndex = -1;
int mStartColorAttributeIndex = -1;
int mEndColorAttributeIndex = -1;
std::unique_ptr<QgsExpression> mStartWidthExpression;
std::unique_ptr<QgsExpression> mEndWithExpression;
std::unique_ptr<QgsExpression> mStartColorExpression;
std::unique_ptr<QgsExpression> mEndColorExpression;
QVector< QPolygonF > mLineParts;
bool mRenderingFeature = false;

View File

@ -112,6 +112,10 @@ void QgsSymbolLayer::initPropertyDefinitions()
{ QgsSymbolLayer::PropertyDashPatternOffset, QgsPropertyDefinition( "dashPatternOffset", QObject::tr( "Dash pattern offset" ), QgsPropertyDefinition::DoublePositive, origin )},
{ QgsSymbolLayer::PropertyTrimStart, QgsPropertyDefinition( "trimStart", QObject::tr( "Start trim distance" ), QgsPropertyDefinition::DoublePositive, origin )},
{ QgsSymbolLayer::PropertyTrimEnd, QgsPropertyDefinition( "trimEnd", QObject::tr( "End trim distance" ), QgsPropertyDefinition::DoublePositive, origin )},
{ QgsSymbolLayer::PropertyLineStartWidthValue, QgsPropertyDefinition( "lineStartWidthValue", QObject::tr( "Line start width value" ), QgsPropertyDefinition::Double, origin )},
{ QgsSymbolLayer::PropertyLineEndWidthValue, QgsPropertyDefinition( "lineEndWidthValue", QObject::tr( "Line end width value" ), QgsPropertyDefinition::Double, origin )},
{ QgsSymbolLayer::PropertyLineStartColorValue, QgsPropertyDefinition( "lineStartColorValue", QObject::tr( "Line start color value" ), QgsPropertyDefinition::Double, origin )},
{ QgsSymbolLayer::PropertyLineEndColorValue, QgsPropertyDefinition( "lineEndColorValue", QObject::tr( "Line end color value" ), QgsPropertyDefinition::Double, origin )},
};
}

View File

@ -196,6 +196,10 @@ class CORE_EXPORT QgsSymbolLayer
PropertyDashPatternOffset, //!< Dash pattern offset,
PropertyTrimStart, //!< Trim distance from start of line (since QGIS 3.20)
PropertyTrimEnd, //!< Trim distance from end of line (since QGIS 3.20)
PropertyLineStartWidthValue, //!< Start line width for interpolated line renderer (since QGIS 3.22)
PropertyLineEndWidthValue, //!< End line width for interpolated line renderer (since QGIS 3.22)
PropertyLineStartColorValue, //!< Start line color for interpolated line renderer (since QGIS 3.22)
PropertyLineEndColorValue, //!< End line color for interpolated line renderer (since QGIS 3.22)
};
/**

View File

@ -127,8 +127,8 @@ void QgsInterpolatedLineSymbolLayerWidget::setSymbolLayer( QgsSymbolLayer *layer
whileBlocking( mWidthMethodComboBox )->setCurrentIndex( mWidthMethodComboBox->findData( interpolatedWidth.isVariableWidth() ) );
whileBlocking( mDoubleSpinBoxWidth )->setValue( interpolatedWidth.fixedStrokeWidth() );
whileBlocking( mWidthStartFieldExpression )->setExpression( mLayer->startValueExpressionForWidth() );
whileBlocking( mWidthEndFieldExpression )->setExpression( mLayer->endValueExpressionForWidth() );
whileBlocking( mWidthStartFieldExpression )->setExpression( mLayer->dataDefinedProperties().property( QgsSymbolLayer::PropertyLineStartWidthValue ).asExpression() );
whileBlocking( mWidthEndFieldExpression )->setExpression( mLayer->dataDefinedProperties().property( QgsSymbolLayer::PropertyLineEndWidthValue ).asExpression() );
setLineEditValue( mLineEditWidthMinValue, interpolatedWidth.minimumValue() );
setLineEditValue( mLineEditWidthMaxValue, interpolatedWidth.maximumValue() );
whileBlocking( mDoubleSpinBoxMinWidth )->setValue( interpolatedWidth.minimumWidth() );
@ -141,8 +141,8 @@ void QgsInterpolatedLineSymbolLayerWidget::setSymbolLayer( QgsSymbolLayer *layer
const QgsInterpolatedLineColor interpolatedColor = mLayer->interpolatedColor();
whileBlocking( mColorMethodComboBox )->setCurrentIndex( mColorMethodComboBox->findData( interpolatedColor.coloringMethod() ) );
whileBlocking( mColorStartFieldExpression )->setExpression( mLayer->startValueExpressionForWidth() );
whileBlocking( mColorEndFieldExpression )->setExpression( mLayer->endValueExpressionForWidth() );
whileBlocking( mColorStartFieldExpression )->setExpression( mLayer->dataDefinedProperties().property( QgsSymbolLayer::PropertyLineStartColorValue ).asExpression() );
whileBlocking( mColorEndFieldExpression )->setExpression( mLayer->dataDefinedProperties().property( QgsSymbolLayer::PropertyLineEndColorValue ).asExpression() );
whileBlocking( mColorRampShaderWidget )->setFromShader( interpolatedColor.colorRampShader() );
setLineEditValue( mLineEditColorMinValue, interpolatedColor.colorRampShader().minimumValue() );
setLineEditValue( mLineEditColorMaxValue, interpolatedColor.colorRampShader().maximumValue() );
@ -165,14 +165,23 @@ void QgsInterpolatedLineSymbolLayerWidget::apply()
if ( !mLayer )
return;
mLayer->setExpressionsStringForWidth( mWidthStartFieldExpression->currentField(), mWidthEndFieldExpression->currentField() );
bool isExpression = false;
QString fieldOrExpression = mWidthStartFieldExpression->currentField( &isExpression );
mLayer->setDataDefinedProperty( QgsSymbolLayer::PropertyLineStartWidthValue, isExpression ? QgsProperty::fromExpression( fieldOrExpression ) : QgsProperty::fromField( fieldOrExpression ) );
fieldOrExpression = mWidthEndFieldExpression->currentField( &isExpression );
mLayer->setDataDefinedProperty( QgsSymbolLayer::PropertyLineEndWidthValue, isExpression ? QgsProperty::fromExpression( fieldOrExpression ) : QgsProperty::fromField( fieldOrExpression ) );
mLayer->setInterpolatedWidth( interpolatedLineWidth() );
if ( mWidthMethodComboBox->currentData().toBool() )
mLayer->setWidthUnit( mWidthUnitSelectionVarying->unit() );
else
mLayer->setWidthUnit( mWidthUnitSelectionFixed->unit() );
mLayer->setExpressionsStringForColor( mColorStartFieldExpression->currentField(), mColorEndFieldExpression->currentField() );
fieldOrExpression = mColorStartFieldExpression->currentField( &isExpression );
mLayer->setDataDefinedProperty( QgsSymbolLayer::PropertyLineStartColorValue, isExpression ? QgsProperty::fromExpression( fieldOrExpression ) : QgsProperty::fromField( fieldOrExpression ) );
fieldOrExpression = mColorEndFieldExpression->currentField( &isExpression );
mLayer->setDataDefinedProperty( QgsSymbolLayer::PropertyLineEndColorValue, isExpression ? QgsProperty::fromExpression( fieldOrExpression ) : QgsProperty::fromField( fieldOrExpression ) );
mLayer->setInterpolatedColor( interpolatedLineColor() );
emit changed();