Skip to content

Commit

Permalink
Fix a bunch of clazy/clang warnings in interpolated line renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Sep 21, 2021
1 parent cd2a17f commit cc240e1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 38 deletions.
Expand Up @@ -60,7 +60,7 @@ Sets the single color to define the coloring
Returns the color corresponding to the magnitude
%End

void setColoringMethod( const QgsInterpolatedLineColor::ColoringMethod &coloringMethod );
void setColoringMethod( ColoringMethod coloringMethod );
%Docstring
Sets the coloring method used

Expand Down Expand Up @@ -232,7 +232,7 @@ Returns the stroke width used to render
.. versionadded:: 3.20
%End

void setWidthUnit( const QgsUnitTypes::RenderUnit &strokeWidthUnit );
void setWidthUnit( QgsUnitTypes::RenderUnit strokeWidthUnit );
%Docstring
Sets the unit of the stroke width
%End
Expand Down Expand Up @@ -331,7 +331,7 @@ Creates the symbol layer
virtual bool canCauseArtifactsBetweenAdjacentTiles() const;


void setExpressionsStringForWidth( QString start, QString end );
void setExpressionsStringForWidth( const QString &start, const QString &end );
%Docstring
Sets the expressions (as string) that define the extremety values af the line feature for width
%End
Expand All @@ -346,7 +346,7 @@ Returns the epression related to the start extremity value for width
Returns the expression related to the end extremity value for width
%End

void setWidthUnit( const QgsUnitTypes::RenderUnit &strokeWidthUnit );
void setWidthUnit( QgsUnitTypes::RenderUnit strokeWidthUnit );
%Docstring
Sets the width unit
%End
Expand All @@ -366,7 +366,7 @@ Sets the interpolated width used to render the width of lines, ``see`` :py:class
Returns the interpolated width used to render the width of lines, see ``:py:class:`QgsInterpolatedLineWidth```
%End

void setExpressionsStringForColor( QString start, QString end );
void setExpressionsStringForColor( const QString &start, const QString &end );
%Docstring
Sets the expressions (as string) that define the extremety values af the line feature for color
%End
Expand Down
44 changes: 18 additions & 26 deletions src/core/symbology/qgsinterpolatedlinerenderer.cpp
Expand Up @@ -41,7 +41,7 @@ QgsInterpolatedLineColor QgsInterpolatedLineRenderer::interpolatedColor() const
return mStrokeColoring;
}

void QgsInterpolatedLineRenderer::setWidthUnit( const QgsUnitTypes::RenderUnit &strokeWidthUnit )
void QgsInterpolatedLineRenderer::setWidthUnit( QgsUnitTypes::RenderUnit strokeWidthUnit )
{
mStrokeWidthUnit = strokeWidthUnit;
}
Expand All @@ -51,7 +51,7 @@ QgsUnitTypes::RenderUnit QgsInterpolatedLineRenderer::widthUnit() const
return mStrokeWidthUnit;
}

void QgsInterpolatedLineRenderer::renderInDeviceCoordinate( double valueColor1, double valueColor2, double valueWidth1, double valueWidth2, const QPointF &p1, const QPointF &p2, QgsRenderContext &context ) const
void QgsInterpolatedLineRenderer::renderInDeviceCoordinates( double valueColor1, double valueColor2, double valueWidth1, double valueWidth2, QPointF p1, QPointF p2, QgsRenderContext &context ) const
{
QPainter *painter = context.painter();
QgsScopedQPainterState painterState( painter );
Expand Down Expand Up @@ -237,7 +237,7 @@ void QgsInterpolatedLineRenderer::render( double value1, double value2, const Qg
QPointF p1 = mapToPixel.transform( point1 ).toQPointF();
QPointF p2 = mapToPixel.transform( point2 ).toQPointF();

renderInDeviceCoordinate( value1, value2, value1, value2, p1, p2, context );
renderInDeviceCoordinates( value1, value2, value1, value2, p1, p2, context );
}

void QgsInterpolatedLineRenderer::render( double valueColor1, double valueColor2, double valueWidth1, double valueWidth2, const QgsPointXY &pt1, const QgsPointXY &pt2, QgsRenderContext &context ) const
Expand All @@ -257,15 +257,15 @@ void QgsInterpolatedLineRenderer::render( double valueColor1, double valueColor2
QPointF p1 = mapToPixel.transform( point1 ).toQPointF();
QPointF p2 = mapToPixel.transform( point2 ).toQPointF();

renderInDeviceCoordinate( valueColor1, valueColor2, valueWidth1, valueWidth2, p1, p2, context );
renderInDeviceCoordinates( valueColor1, valueColor2, valueWidth1, valueWidth2, p1, p2, context );
}

void QgsInterpolatedLineRenderer::setSelected( bool selected )
{
mSelected = selected;
}

void QgsInterpolatedLineRenderer::adjustLine( const double &value, const double &value1, const double &value2, double &width, double &adjusting ) const
void QgsInterpolatedLineRenderer::adjustLine( const double value, const double value1, const double value2, double &width, double &adjusting ) const
{
if ( value > mStrokeWidth.maximumValue() )
{
Expand Down Expand Up @@ -355,10 +355,8 @@ double QgsInterpolatedLineWidth::strokeWidth( double value ) const
return fixedStrokeWidth();
}

QDomElement QgsInterpolatedLineWidth::writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const
QDomElement QgsInterpolatedLineWidth::writeXml( QDomDocument &doc, const QgsReadWriteContext & ) const
{
Q_UNUSED( context );

QDomElement elem = doc.createElement( QStringLiteral( "mesh-stroke-width" ) );

elem.setAttribute( QStringLiteral( "width-varying" ), mIsWidthVariable ? 1 : 0 );
Expand All @@ -373,10 +371,8 @@ QDomElement QgsInterpolatedLineWidth::writeXml( QDomDocument &doc, const QgsRead
return elem;
}

void QgsInterpolatedLineWidth::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
void QgsInterpolatedLineWidth::readXml( const QDomElement &elem, const QgsReadWriteContext & )
{
Q_UNUSED( context );

mIsWidthVariable = elem.attribute( QStringLiteral( "width-varying" ) ).toInt();
mFixedWidth = elem.attribute( QStringLiteral( "fixed-width" ) ).toDouble();
mMinimumValue = elem.attribute( QStringLiteral( "minimum-value" ) ).toDouble();
Expand Down Expand Up @@ -429,7 +425,7 @@ void QgsInterpolatedLineWidth::setFixedStrokeWidth( double fixedWidth )

void QgsInterpolatedLineWidth::updateLinearFormula() const
{
if ( mMaximumWidth - mMinimumWidth != 0 )
if ( !qgsDoubleNear( mMaximumWidth, mMinimumWidth ) )
mLinearCoef = ( mMaximumWidth - mMinimumWidth ) / ( mMaximumValue - mMinimumValue ) ;
else
mLinearCoef = 0;
Expand Down Expand Up @@ -504,10 +500,8 @@ QColor QgsInterpolatedLineColor::singleColor() const
return mSingleColor;
}

QDomElement QgsInterpolatedLineColor::writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const
QDomElement QgsInterpolatedLineColor::writeXml( QDomDocument &doc, const QgsReadWriteContext & ) const
{
Q_UNUSED( context );

QDomElement elem = doc.createElement( QStringLiteral( "mesh-stroke-color" ) );

elem.setAttribute( QStringLiteral( "single-color" ), QgsSymbolLayerUtils::encodeColor( mSingleColor ) );
Expand All @@ -517,10 +511,8 @@ QDomElement QgsInterpolatedLineColor::writeXml( QDomDocument &doc, const QgsRead
return elem;
}

void QgsInterpolatedLineColor::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
void QgsInterpolatedLineColor::readXml( const QDomElement &elem, const QgsReadWriteContext & )
{
Q_UNUSED( context );

QDomElement shaderElem = elem.firstChildElement( QStringLiteral( "colorrampshader" ) );
mColorRampShader.readXml( shaderElem );

Expand Down Expand Up @@ -555,7 +547,7 @@ void QgsInterpolatedLineColor::graduatedColors( double value1, double value2, QL

}

void QgsInterpolatedLineColor::setColoringMethod( const QgsInterpolatedLineColor::ColoringMethod &coloringMethod )
void QgsInterpolatedLineColor::setColoringMethod( QgsInterpolatedLineColor::ColoringMethod coloringMethod )
{
mColoringMethod = coloringMethod;
}
Expand Down Expand Up @@ -592,7 +584,7 @@ int QgsInterpolatedLineColor::itemColorIndexInf( double value ) const

int newInd = ( indInf + indSup ) / 2;

if ( itemList.at( newInd ).value == std::numeric_limits<double>::quiet_NaN() )
if ( std::isnan( itemList.at( newInd ).value ) )
return -1;

if ( itemList.at( newInd ).value <= value )
Expand All @@ -602,7 +594,7 @@ int QgsInterpolatedLineColor::itemColorIndexInf( double value ) const
}
}

void QgsInterpolatedLineColor::graduatedColorsExact( double value1, double value2, QList<double> &breakValues, QList<QColor> &breakColors, QList<QLinearGradient> &gradients ) const
void QgsInterpolatedLineColor::graduatedColorsExact( double value1, double value2, QList<double> &breakValues, QList<QColor> &breakColors, const QList<QLinearGradient> &gradients ) const
{
Q_ASSERT( mColorRampShader.colorRampType() == QgsColorRampShader::Exact );
Q_ASSERT( breakValues.isEmpty() );
Expand Down Expand Up @@ -952,7 +944,7 @@ void QgsInterpolatedLineSymbolLayer::drawPreviewIcon( QgsSymbolRenderContext &co
double max = std::max( mLineRender.interpolatedLineWidth().maximumValue(), mLineRender.interpolatedColor().colorRampShader().maximumValue() );

double totalLength = geometry.length();
if ( totalLength == 0 )
if ( qgsDoubleNear( totalLength, 0 ) )
return;

double variation = ( max - min ) / totalLength;
Expand All @@ -968,14 +960,14 @@ void QgsInterpolatedLineSymbolLayer::drawPreviewIcon( QgsSymbolRenderContext &co
QPointF vectDist = p2 - p1;
lengthFromStart += sqrt( pow( vectDist.x(), 2 ) + pow( vectDist.y(), 2 ) );
double v2 = min + variation * lengthFromStart;
mLineRender.renderInDeviceCoordinate( v1, v2, v1, v2, p1, p2, context.renderContext() );
mLineRender.renderInDeviceCoordinates( v1, v2, v1, v2, p1, p2, context.renderContext() );
}

renderPolyline( points, context );
}


void QgsInterpolatedLineSymbolLayer::setExpressionsStringForWidth( QString start, QString end )
void QgsInterpolatedLineSymbolLayer::setExpressionsStringForWidth( const QString &start, const QString &end )
{
mStartWidthExpressionString = start;
mEndWidthExpressionString = end;
Expand All @@ -991,7 +983,7 @@ QString QgsInterpolatedLineSymbolLayer::endValueExpressionForWidth() const
return mEndWidthExpressionString;
}

void QgsInterpolatedLineSymbolLayer::setWidthUnit( const QgsUnitTypes::RenderUnit &strokeWidthUnit )
void QgsInterpolatedLineSymbolLayer::setWidthUnit( QgsUnitTypes::RenderUnit strokeWidthUnit )
{
mLineRender.mStrokeWidthUnit = strokeWidthUnit;
}
Expand All @@ -1005,7 +997,7 @@ void QgsInterpolatedLineSymbolLayer::setInterpolatedWidth( const QgsInterpolated

QgsInterpolatedLineWidth QgsInterpolatedLineSymbolLayer::interpolatedWidth() const { return mLineRender.interpolatedLineWidth();}

void QgsInterpolatedLineSymbolLayer::setExpressionsStringForColor( QString start, QString end )
void QgsInterpolatedLineSymbolLayer::setExpressionsStringForColor( const QString &start, const QString &end )
{
mStartColorExpressionString = start;
mEndColorExpressionString = end;
Expand Down
14 changes: 7 additions & 7 deletions src/core/symbology/qgsinterpolatedlinerenderer.h
Expand Up @@ -70,7 +70,7 @@ class CORE_EXPORT QgsInterpolatedLineColor
* Sets the coloring method used
* \since QGIS 3.20
*/
void setColoringMethod( const QgsInterpolatedLineColor::ColoringMethod &coloringMethod );
void setColoringMethod( ColoringMethod coloringMethod );

//! Returns the coloring method used
QgsInterpolatedLineColor::ColoringMethod coloringMethod() const;
Expand Down Expand Up @@ -111,7 +111,7 @@ class CORE_EXPORT QgsInterpolatedLineColor
//! Returns the index of the color ramp shader with value inferior to value
int itemColorIndexInf( double value ) const;

void graduatedColorsExact( double value1, double value2, QList<double> &breakValues, QList<QColor> &breakColors, QList<QLinearGradient> &gradients ) const;
void graduatedColorsExact( double value1, double value2, QList<double> &breakValues, QList<QColor> &breakColors, const QList<QLinearGradient> &gradients ) const;
void graduatedColorsInterpolated( double value1, double value2, QList<double> &breakValues, QList<QColor> &breakColors, QList<QLinearGradient> &gradients ) const;
void graduatedColorsDiscrete( double value1, double value2, QList<double> &breakValues, QList<QColor> &breakColors, QList<QLinearGradient> &gradients ) const;
};
Expand Down Expand Up @@ -211,7 +211,7 @@ class CORE_EXPORT QgsInterpolatedLineRenderer
QgsInterpolatedLineWidth interpolatedLineWidth() const;

//! Sets the unit of the stroke width
void setWidthUnit( const QgsUnitTypes::RenderUnit &strokeWidthUnit );
void setWidthUnit( QgsUnitTypes::RenderUnit strokeWidthUnit );

/**
* Returns the unit of the stroke width
Expand Down Expand Up @@ -254,7 +254,7 @@ class CORE_EXPORT QgsInterpolatedLineRenderer
QgsInterpolatedLineWidth mStrokeWidth;
QgsInterpolatedLineColor mStrokeColoring;
QgsUnitTypes::RenderUnit mStrokeWidthUnit = QgsUnitTypes::RenderMillimeters;
void adjustLine( const double &value, const double &value1, const double &value2, double &width, double &adjusting ) const;
void adjustLine( double value, double value1, double value2, double &width, double &adjusting ) const;
bool mSelected = false;

/**
Expand Down Expand Up @@ -299,7 +299,7 @@ class CORE_EXPORT QgsInterpolatedLineSymbolLayer : public QgsLineSymbolLayer
bool canCauseArtifactsBetweenAdjacentTiles() const override;

//! Sets the expressions (as string) that define the extremety values af the line feature for width
void setExpressionsStringForWidth( QString start, QString end );
void setExpressionsStringForWidth( const QString &start, const QString &end );

//! Returns the epression related to the start extremity value for width
QString startValueExpressionForWidth() const;
Expand All @@ -308,7 +308,7 @@ class CORE_EXPORT QgsInterpolatedLineSymbolLayer : public QgsLineSymbolLayer
QString endValueExpressionForWidth() const;

//! Sets the width unit
void setWidthUnit( const QgsUnitTypes::RenderUnit &strokeWidthUnit );
void setWidthUnit( QgsUnitTypes::RenderUnit strokeWidthUnit );

//! Returns the width unit
QgsUnitTypes::RenderUnit widthUnit() const;
Expand All @@ -320,7 +320,7 @@ class CORE_EXPORT QgsInterpolatedLineSymbolLayer : public QgsLineSymbolLayer
QgsInterpolatedLineWidth interpolatedWidth() const;

//! Sets the expressions (as string) that define the extremety values af the line feature for color
void setExpressionsStringForColor( QString start, QString end );
void setExpressionsStringForColor( const QString &start, const QString &end );

//! Returns the epression related to the start extremity value for width for color
QString startValueExpressionForColor() const;
Expand Down

0 comments on commit cc240e1

Please sign in to comment.