Skip to content

Commit

Permalink
Fix cppcheck warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 29, 2022
1 parent 3527257 commit 6b8d53a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/core/layertree/qgslayertreemodellegendnode.cpp
Expand Up @@ -91,11 +91,13 @@ QgsLayerTreeModelLegendNode::ItemMetrics QgsLayerTreeModelLegendNode::draw( cons
const QStringList lines = settings.evaluateItemText( data( Qt::DisplayRole ).toString(), ctx->context->expressionContext() );

const QgsTextDocument textDocument = f.allowHtmlFormatting() ? QgsTextDocument::fromHtml( lines ) : QgsTextDocument::fromPlainText( lines );
// cppcheck-suppress autoVariables
ctx->textDocument = &textDocument;

std::optional< QgsScopedRenderContextScaleToPixels > scaleToPx( *ctx->context );
const QgsTextDocumentMetrics textDocumentMetrics = QgsTextDocumentMetrics::calculateMetrics( textDocument, f, *ctx->context,
ctx->context->flags() & Qgis::RenderContextFlag::ApplyScalingWorkaroundForTextRendering ? QgsTextRenderer::FONT_WORKAROUND_SCALE : 1 );
( ctx->context->flags() & Qgis::RenderContextFlag::ApplyScalingWorkaroundForTextRendering ) ? QgsTextRenderer::FONT_WORKAROUND_SCALE : 1 );
// cppcheck-suppress autoVariables
ctx->textDocumentMetrics = &textDocumentMetrics;
scaleToPx.reset();

Expand Down Expand Up @@ -194,13 +196,13 @@ QSizeF QgsLayerTreeModelLegendNode::drawSymbolText( const QgsLegendSettings &set

const QgsTextFormat format = settings.style( QgsLegendStyle::SymbolLabel ).textFormat();

const double dotsPerMM = ctx->context->scaleFactor();
const double dotsPerMM = context->scaleFactor();
QgsScopedRenderContextScaleToPixels scaleToPx( *context );

// TODO when no metrics
// TODO --- line spacing!!!

const QSizeF documentSize = ctx->textDocumentMetrics->documentSize( Qgis::TextLayoutMode::RectangleCapHeightBased, Qgis::TextOrientation::Horizontal );
const QSizeF documentSize = ctx ? ctx->textDocumentMetrics->documentSize( Qgis::TextLayoutMode::RectangleCapHeightBased, Qgis::TextOrientation::Horizontal ) : QSizeF();
const QSizeF labelSizeMM( documentSize / dotsPerMM );

double labelXMin = 0.0;
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgslegendrenderer.cpp
Expand Up @@ -687,7 +687,7 @@ int QgsLegendRenderer::setColumns( QList<LegendComponentGroup> &componentGroups
return targetNumberColumns;
}

QSizeF QgsLegendRenderer::drawTitle( QgsRenderContext &context, double top, Qt::AlignmentFlag halignment, double legendWidth )
QSizeF QgsLegendRenderer::drawTitle( QgsRenderContext &context, double top, Qt::AlignmentFlag halignment, double legendWidth ) const
{
QSizeF size( 0, 0 );
if ( mSettings.title().isEmpty() )
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgslegendrenderer.h
Expand Up @@ -257,7 +257,7 @@ class CORE_EXPORT QgsLegendRenderer
*
* If \a context is NULLPTR, no painting will be attempted, but the required size will still be calculated and returned.
*/
QSizeF drawTitle( QgsRenderContext &context, double top, Qt::AlignmentFlag halignment = Qt::AlignLeft, double legendWidth = 0 );
QSizeF drawTitle( QgsRenderContext &context, double top, Qt::AlignmentFlag halignment = Qt::AlignLeft, double legendWidth = 0 ) const;

/**
* Draws an \a group and return its actual size, using the specified render \a context.
Expand Down

0 comments on commit 6b8d53a

Please sign in to comment.