mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-06 00:07:29 -04:00
Cleanup code
This commit is contained in:
parent
c2f8e7fb66
commit
0803809b51
@ -101,12 +101,12 @@ QgsLayerTreeModelLegendNode::ItemMetrics QgsLayerTreeModelLegendNode::draw( cons
|
||||
ctx->textDocumentMetrics = &textDocumentMetrics;
|
||||
scaleToPx.reset();
|
||||
|
||||
//const double textHeight = textDocumentMetrics.documentSize( Qgis::TextLayoutMode::Legend, Qgis::TextOrientation::Horizontal ).height() / ctx->context->scaleFactor();
|
||||
const double textHeight = textDocumentMetrics.firstLineCapHeight() / ctx->context->scaleFactor();
|
||||
|
||||
// itemHeight here is not really item height, it is only for symbol
|
||||
// vertical alignment purpose, i.e. OK take single line height
|
||||
// if there are more lines, those run under the symbol
|
||||
// also note that we explicitly use the first line cap height here, in order to match the Qgis::TextLayoutMode::RectangleCapHeightBased mode
|
||||
// used when rendering the symbol text
|
||||
const double textHeight = textDocumentMetrics.firstLineCapHeight() / ctx->context->scaleFactor();
|
||||
const double itemHeight = std::max( static_cast< double >( ctx && ctx->patchSize.height() > 0 ? ctx->patchSize.height() : settings.symbolSize().height() ), textHeight );
|
||||
|
||||
ItemMetrics im;
|
||||
@ -196,13 +196,28 @@ QSizeF QgsLayerTreeModelLegendNode::drawSymbolText( const QgsLegendSettings &set
|
||||
|
||||
const QgsTextFormat format = settings.style( QgsLegendStyle::SymbolLabel ).textFormat();
|
||||
|
||||
// TODO QGIS 4.0 -- make these all mandatory
|
||||
std::optional< QgsTextDocument > tempDocument;
|
||||
const QgsTextDocument *document = ctx->textDocument;
|
||||
if ( !document )
|
||||
{
|
||||
const QStringList lines = settings.evaluateItemText( data( Qt::DisplayRole ).toString(), context->expressionContext() );
|
||||
tempDocument.emplace( format.allowHtmlFormatting() ? QgsTextDocument::fromHtml( lines ) : QgsTextDocument::fromPlainText( lines ) );
|
||||
document = &tempDocument.value();
|
||||
}
|
||||
|
||||
std::optional< QgsTextDocumentMetrics > tempMetrics;
|
||||
const QgsTextDocumentMetrics *metrics = ctx->textDocumentMetrics;
|
||||
if ( !metrics )
|
||||
{
|
||||
tempMetrics.emplace( QgsTextDocumentMetrics::calculateMetrics( *document, format, *context ) );
|
||||
metrics = &tempMetrics.value();
|
||||
}
|
||||
|
||||
const double dotsPerMM = context->scaleFactor();
|
||||
QgsScopedRenderContextScaleToPixels scaleToPx( *context );
|
||||
|
||||
// TODO when no metrics
|
||||
// TODO --- line spacing!!!
|
||||
|
||||
const QSizeF documentSize = ctx ? ctx->textDocumentMetrics->documentSize( Qgis::TextLayoutMode::RectangleCapHeightBased, Qgis::TextOrientation::Horizontal ) : QSizeF();
|
||||
const QSizeF documentSize = metrics->documentSize( Qgis::TextLayoutMode::RectangleCapHeightBased, Qgis::TextOrientation::Horizontal );
|
||||
const QSizeF labelSizeMM( documentSize / dotsPerMM );
|
||||
|
||||
double labelXMin = 0.0;
|
||||
@ -247,7 +262,7 @@ QSizeF QgsLayerTreeModelLegendNode::drawSymbolText( const QgsLegendSettings &set
|
||||
QgsTextRenderer::drawDocument( QRectF( labelXMin * dotsPerMM, std::round( labelYMM * dotsPerMM ),
|
||||
( labelXMax - labelXMin )* dotsPerMM,
|
||||
std::max( symbolSizeMM.height(), labelSizeMM.height() ) * dotsPerMM ),
|
||||
format, *ctx->textDocument, *ctx->textDocumentMetrics, *context, halign, Qgis::TextVerticalAlignment::Top,
|
||||
format, *document, *metrics, *context, halign, Qgis::TextVerticalAlignment::Top,
|
||||
0, Qgis::TextLayoutMode::RectangleCapHeightBased );
|
||||
}
|
||||
|
||||
|
@ -22,8 +22,6 @@
|
||||
#include "qgsrendercontext.h"
|
||||
#include "qgsexpressioncontextutils.h"
|
||||
#include "qgstextrenderer.h"
|
||||
#include "qgstextdocument.h"
|
||||
#include "qgstextdocumentmetrics.h"
|
||||
#include <QJsonObject>
|
||||
#include <QPainter>
|
||||
|
||||
@ -942,7 +940,7 @@ QSizeF QgsLegendRenderer::drawLayerTitle( QgsLayerTreeLayer *nodeLayer, QgsRende
|
||||
}
|
||||
const double sideMargin = mSettings.style( nodeLegendStyle( nodeLayer ) ).margin( QgsLegendStyle::Left );
|
||||
|
||||
size.rheight() = ( overallTextHeight /* ( - QgsTextRenderer::fontMetrics( context, layerFormat ).descent() ) */ ) / dotsPerMM;
|
||||
size.rheight() = overallTextHeight / dotsPerMM;
|
||||
size.rwidth() = overallTextWidth / dotsPerMM + sideMargin *
|
||||
( mSettings.style( nodeLegendStyle( nodeLayer ) ).alignment() == Qt::AlignHCenter ? 2 : 1 );
|
||||
|
||||
@ -984,12 +982,9 @@ QSizeF QgsLegendRenderer::drawGroupTitle( QgsLayerTreeGroup *nodeGroup, QgsRende
|
||||
}
|
||||
|
||||
const double sideMargin = mSettings.style( nodeLegendStyle( nodeGroup ) ).margin( QgsLegendStyle::Left );
|
||||
|
||||
// should this be after scaling????1
|
||||
const double dotsPerMM = context.scaleFactor();
|
||||
|
||||
|
||||
size.rheight() = ( overallTextHeight /*- QgsTextRenderer::fontMetrics( context, groupFormat ).descent()*/ ) / dotsPerMM;
|
||||
size.rheight() = overallTextHeight / dotsPerMM;
|
||||
size.rwidth() = overallTextWidth / dotsPerMM + sideMargin *
|
||||
( mSettings.style( nodeLegendStyle( nodeGroup ) ).alignment() == Qt::AlignHCenter ? 2 : 1 );
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user