Skip to content

Commit

Permalink
Add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn authored and nyalldawson committed Jan 24, 2025
1 parent 0cc4cbd commit 4f7d903
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions tests/src/core/testqgslabelingengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class TestQgsLabelingEngine : public QgsTest
void parallelOverrun();
void testDataDefinedLabelAllParts();
void testDataDefinedPlacementPositionPoint();
void testDataDefinedLabelTabs();
void testVerticalOrientation();
void testVerticalOrientationLetterLineSpacing();
void testRotationBasedOrientationPoint();
Expand Down Expand Up @@ -5185,6 +5186,64 @@ void TestQgsLabelingEngine::testDataDefinedPlacementPositionPoint()
vl->setLabeling( nullptr );
}

void TestQgsLabelingEngine::testDataDefinedLabelTabs()
{
// test curved label rendering with tab characters
QgsPalLayerSettings settings;
setDefaultLabelParams( settings );

QgsTextFormat format = settings.format();
format.setSize( 30 );
format.setColor( QColor( 0, 0, 0 ) );
format.setTabStopDistance( 28 );
format.setTabStopDistanceUnit( Qgis::RenderUnit::Millimeters );
settings.setFormat( format );
settings.dataDefinedProperties().setProperty( QgsPalLayerSettings::Property::TabStopDistance, QgsProperty::fromExpression( QStringLiteral( "48" ) ) );

settings.fieldName = QStringLiteral( "'test of\ttab\ttext'" );
settings.isExpression = true;
settings.placement = Qgis::LabelPlacement::Horizontal;
settings.labelPerPart = false;
settings.lineSettings().setLineAnchorPercent( 0.5 );
settings.lineSettings().setAnchorType( QgsLabelLineSettings::AnchorType::Strict );
settings.lineSettings().setPlacementFlags( Qgis::LabelLinePlacementFlag::AboveLine | Qgis::LabelLinePlacementFlag::MapOrientation );
settings.lineSettings().setAnchorTextPoint( QgsLabelLineSettings::AnchorTextPoint::CenterOfText );

std::unique_ptr<QgsVectorLayer> vl2( new QgsVectorLayer( QStringLiteral( "LineString?crs=epsg:3946&field=id:integer" ), QStringLiteral( "vl" ), QStringLiteral( "memory" ) ) );
vl2->setRenderer( new QgsNullSymbolRenderer() );

QgsFeature f;
f.setAttributes( QgsAttributes() << 1 );
f.setGeometry( QgsGeometry::fromWkt( QStringLiteral( "LineString (190000 5000010, 190100 5000000, 190200 5000000)" ) ) );
QVERIFY( vl2->dataProvider()->addFeature( f ) );

vl2->setLabeling( new QgsVectorLayerSimpleLabeling( settings ) ); // TODO: this should not be necessary!
vl2->setLabelsEnabled( true );

// make a fake render context
const QSize size( 640, 480 );
QgsMapSettings mapSettings;
mapSettings.setLabelingEngineSettings( createLabelEngineSettings() );
mapSettings.setDestinationCrs( vl2->crs() );

mapSettings.setOutputSize( size );
mapSettings.setExtent( f.geometry().boundingBox() );
mapSettings.setLayers( QList<QgsMapLayer *>() << vl2.get() );
mapSettings.setOutputDpi( 96 );

QgsLabelingEngineSettings engineSettings = mapSettings.labelingEngineSettings();
engineSettings.setFlag( Qgis::LabelingFlag::UsePartialCandidates, false );
engineSettings.setFlag( Qgis::LabelingFlag::DrawCandidates, true );
mapSettings.setLabelingEngineSettings( engineSettings );

QgsMapRendererSequentialJob job( mapSettings );
job.start();
job.waitForFinished();

QImage img = job.renderedImage();
QGSVERIFYIMAGECHECK( "data_defined_tabs", "data_defined_tabs", img, QString(), 20, QSize( 0, 0 ), 2 );
}

void TestQgsLabelingEngine::testVerticalOrientation()
{
const QSize size( 640, 480 );
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4f7d903

Please sign in to comment.