@@ -55,6 +55,7 @@ class TestQgsLabelingEngine : public QObject
55
55
void testAdjacentParts ();
56
56
void testLabelBoundary ();
57
57
void testLabelBlockingRegion ();
58
+ void testLabelRotationWithReprojection ();
58
59
59
60
private:
60
61
QgsVectorLayer *vl = nullptr ;
@@ -1010,5 +1011,63 @@ void TestQgsLabelingEngine::testLabelBlockingRegion()
1010
1011
QVERIFY ( imageCheck ( QStringLiteral ( " label_blocking_boundary_geometry" ), img, 20 ) );
1011
1012
}
1012
1013
1014
+ void TestQgsLabelingEngine::testLabelRotationWithReprojection ()
1015
+ {
1016
+ // test combination of map rotation with reprojected layer
1017
+ QgsPalLayerSettings settings;
1018
+ setDefaultLabelParams ( settings );
1019
+
1020
+ QgsTextFormat format = settings.format ();
1021
+ format.setSize ( 20 );
1022
+ format.setColor ( QColor ( 0 , 0 , 0 ) );
1023
+ settings.setFormat ( format );
1024
+
1025
+ settings.fieldName = QStringLiteral ( " 'X'" );
1026
+ settings.isExpression = true ;
1027
+ settings.placement = QgsPalLayerSettings::OverPoint;
1028
+
1029
+ std::unique_ptr< QgsVectorLayer> vl2 ( new QgsVectorLayer ( QStringLiteral ( " Point?crs=epsg:4326&field=id:integer" ), QStringLiteral ( " vl" ), QStringLiteral ( " memory" ) ) );
1030
+ vl2->setRenderer ( new QgsNullSymbolRenderer () );
1031
+
1032
+ QgsFeature f;
1033
+ f.setAttributes ( QgsAttributes () << 1 );
1034
+ f.setGeometry ( QgsGeometry::fromPointXY ( QgsPointXY ( -6.250851540391068 , 53.335006994584944 ) ) );
1035
+ QVERIFY ( vl2->dataProvider ()->addFeature ( f ) );
1036
+ f.setAttributes ( QgsAttributes () << 2 );
1037
+ f.setGeometry ( QgsGeometry::fromPointXY ( QgsPointXY ( -21.950014487179544 , 64.150023619739216 ) ) );
1038
+ QVERIFY ( vl2->dataProvider ()->addFeature ( f ) );
1039
+ f.setAttributes ( QgsAttributes () << 3 );
1040
+ f.setGeometry ( QgsGeometry::fromPointXY ( QgsPointXY ( -0.118667702475932 , 51.5019405883275 ) ) );
1041
+ QVERIFY ( vl2->dataProvider ()->addFeature ( f ) );
1042
+
1043
+ vl2->setLabeling ( new QgsVectorLayerSimpleLabeling ( settings ) ); // TODO: this should not be necessary!
1044
+ vl2->setLabelsEnabled ( true );
1045
+
1046
+ // make a fake render context
1047
+ QSize size ( 640 , 480 );
1048
+ QgsMapSettings mapSettings;
1049
+ QgsCoordinateReferenceSystem tgtCrs ( QStringLiteral ( " EPSG:3857" ) );
1050
+ mapSettings.setDestinationCrs ( tgtCrs );
1051
+
1052
+ mapSettings.setOutputSize ( size );
1053
+ mapSettings.setExtent ( QgsRectangle ( -4348530.5 , 5618594.3 , 2516176.1 , 12412237.9 ) );
1054
+ mapSettings.setRotation ( 60 );
1055
+ mapSettings.setLayers ( QList<QgsMapLayer *>() << vl2.get () );
1056
+ mapSettings.setOutputDpi ( 96 );
1057
+
1058
+ QgsLabelingEngineSettings engineSettings = mapSettings.labelingEngineSettings ();
1059
+ engineSettings.setFlag ( QgsLabelingEngineSettings::UsePartialCandidates, false );
1060
+ engineSettings.setFlag ( QgsLabelingEngineSettings::DrawLabelRectOnly, true );
1061
+ // engineSettings.setFlag( QgsLabelingEngineSettings::DrawCandidates, true );
1062
+ mapSettings.setLabelingEngineSettings ( engineSettings );
1063
+
1064
+ QgsMapRendererSequentialJob job ( mapSettings );
1065
+ job.start ();
1066
+ job.waitForFinished ();
1067
+
1068
+ QImage img = job.renderedImage ();
1069
+ QVERIFY ( imageCheck ( QStringLiteral ( " label_rotate_with_reproject" ), img, 20 ) );
1070
+ }
1071
+
1013
1072
QGSTEST_MAIN ( TestQgsLabelingEngine )
1014
1073
#include " testqgslabelingengine.moc"
0 commit comments