Skip to content

Commit 4ed096b

Browse files
committed
Add test for unprojectible polygon labeling
See #15507
1 parent 11475c6 commit 4ed096b

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

tests/src/core/testqgslabelingengine.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class TestQgsLabelingEngine : public QObject
4747
void testSubstitutions();
4848
void testCapitalization();
4949
void testParticipatingLayers();
50+
void testRegisterFeatureUnprojectible();
5051

5152
private:
5253
QgsVectorLayer *vl = nullptr;
@@ -586,5 +587,42 @@ bool TestQgsLabelingEngine::imageCheck( const QString &testName, QImage &image,
586587
return resultFlag;
587588
}
588589

590+
// See https://issues.qgis.org/issues/15507
591+
void TestQgsLabelingEngine::testRegisterFeatureUnprojectible()
592+
{
593+
QgsPalLayerSettings settings;
594+
settings.fieldName = QString( "'aa label'" );
595+
settings.isExpression = true;
596+
settings.fitInPolygonOnly = true;
597+
598+
std::unique_ptr< QgsVectorLayer> vl2( new QgsVectorLayer( "polygon?crs=epsg:4326&field=id:integer", "vl", "memory" ) );
599+
QgsVectorLayerLabelProvider* provider = new QgsVectorLayerLabelProvider( vl2.get(), "test", true, &settings );
600+
QgsFeature f( vl2->fields(), 1 );
601+
602+
QString wkt1 = "POLYGON((0 0,8 0,8 -90,0 0))";
603+
f.setGeometry( QgsGeometry().fromWkt( wkt1 ) );
604+
605+
// make a fake render context
606+
QSize size( 640, 480 );
607+
QgsMapSettings mapSettings;
608+
QgsCoordinateReferenceSystem tgtCrs;
609+
tgtCrs.createFromString( "EPSG:3857" );
610+
mapSettings.setDestinationCrs( tgtCrs );
611+
612+
mapSettings.setOutputSize( size );
613+
mapSettings.setExtent( vl2->extent() );
614+
mapSettings.setLayers( QList<QgsMapLayer *>() << vl2.get() );
615+
mapSettings.setOutputDpi( 96 );
616+
QgsRenderContext context = QgsRenderContext::fromMapSettings( mapSettings );
617+
QSet<QString> attributes;
618+
QgsLabelingEngine engine;
619+
engine.setMapSettings( mapSettings );
620+
engine.addProvider( provider );
621+
provider->prepare( context, attributes );
622+
623+
provider->registerFeature( f, context );
624+
QCOMPARE( provider->mLabels.size(), 0 );
625+
}
626+
589627
QGSTEST_MAIN( TestQgsLabelingEngine )
590628
#include "testqgslabelingengine.moc"

0 commit comments

Comments
 (0)