mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-01 00:46:20 -05:00
[layout] When newline characters are entered as part of a legend item's text,
correctly respect these while rendering legend
This commit is contained in:
parent
2b7b776470
commit
6caa62a9ca
@ -53,15 +53,20 @@ QStringList QgsLegendSettings::evaluateItemText( const QString &text, const QgsE
|
|||||||
return splitStringForWrapping( textToRender );
|
return splitStringForWrapping( textToRender );
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList QgsLegendSettings::splitStringForWrapping( const QString &stringToSplt ) const
|
QStringList QgsLegendSettings::splitStringForWrapping( const QString &stringToSplit ) const
|
||||||
{
|
{
|
||||||
QStringList list;
|
const QStringList lines = stringToSplit.split( '\n' );
|
||||||
|
|
||||||
// If the string contains nothing then just return the string without splitting.
|
// If the string contains nothing then just return the string without splitting.
|
||||||
if ( wrapChar().count() == 0 )
|
if ( wrapChar().isEmpty() )
|
||||||
list << stringToSplt;
|
return lines;
|
||||||
else
|
|
||||||
list = stringToSplt.split( wrapChar() );
|
QStringList res;
|
||||||
return list;
|
for ( const QString &line : lines )
|
||||||
|
{
|
||||||
|
res.append( line.split( wrapChar() ) );
|
||||||
|
}
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define FONT_WORKAROUND_SCALE 10 //scale factor for upscaling fontsize and downscaling painter
|
#define FONT_WORKAROUND_SCALE 10 //scale factor for upscaling fontsize and downscaling painter
|
||||||
|
@ -131,6 +131,7 @@ class TestQgsLegendRenderer : public QObject
|
|||||||
void testModel();
|
void testModel();
|
||||||
|
|
||||||
void testBasic();
|
void testBasic();
|
||||||
|
void testMultiline();
|
||||||
void testEffects();
|
void testEffects();
|
||||||
void testBigMarker();
|
void testBigMarker();
|
||||||
|
|
||||||
@ -318,6 +319,26 @@ void TestQgsLegendRenderer::testBasic()
|
|||||||
QVERIFY( _verifyImage( testName, mReport ) );
|
QVERIFY( _verifyImage( testName, mReport ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TestQgsLegendRenderer::testMultiline()
|
||||||
|
{
|
||||||
|
QString testName = QStringLiteral( "legend_multiline" );
|
||||||
|
|
||||||
|
QgsLayerTreeModel legendModel( mRoot );
|
||||||
|
|
||||||
|
legendModel.findLegendNode( mVL1->id(), QString() );
|
||||||
|
|
||||||
|
QgsLayerTreeLayer *layer = legendModel.rootGroup()->findLayer( mVL1 );
|
||||||
|
layer->setCustomProperty( QStringLiteral( "legend/title-label" ), QStringLiteral( "some legend text\nwith newline\ncharacters in it" ) );
|
||||||
|
|
||||||
|
QgsLayerTreeModelLegendNode *embeddedNode = legendModel.legendNodeEmbeddedInParent( layer );
|
||||||
|
embeddedNode->setUserLabel( QString() );
|
||||||
|
|
||||||
|
QgsLegendSettings settings;
|
||||||
|
_setStandardTestFont( settings, QStringLiteral( "Bold" ) );
|
||||||
|
_renderLegend( testName, &legendModel, settings );
|
||||||
|
QVERIFY( _verifyImage( testName, mReport ) );
|
||||||
|
}
|
||||||
|
|
||||||
void TestQgsLegendRenderer::testEffects()
|
void TestQgsLegendRenderer::testEffects()
|
||||||
{
|
{
|
||||||
QString testName = QStringLiteral( "legend_effects" );
|
QString testName = QStringLiteral( "legend_effects" );
|
||||||
|
BIN
tests/testdata/control_images/legend/expected_legend_multiline/expected_legend_multiline.png
vendored
Normal file
BIN
tests/testdata/control_images/legend/expected_legend_multiline/expected_legend_multiline.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 19 KiB |
Loading…
x
Reference in New Issue
Block a user