@@ -56,6 +56,7 @@ class TestQgsLabelingEngine : public QObject
56
56
void testTouchingParts ();
57
57
void testMergingLinesWithForks ();
58
58
void testCurvedLabelsWithTinySegments ();
59
+ void testCurvedLabelCorrectLinePlacement ();
59
60
void testLabelBoundary ();
60
61
void testLabelBlockingRegion ();
61
62
void testLabelRotationWithReprojection ();
@@ -1037,6 +1038,72 @@ void TestQgsLabelingEngine::testCurvedLabelsWithTinySegments()
1037
1038
QVERIFY ( imageCheck ( QStringLiteral ( " label_curved_label_small_segments" ), img, 20 ) );
1038
1039
}
1039
1040
1041
+ void TestQgsLabelingEngine::testCurvedLabelCorrectLinePlacement ()
1042
+ {
1043
+ // test drawing curved labels when input linestring has many small segments
1044
+ QgsPalLayerSettings settings;
1045
+ setDefaultLabelParams ( settings );
1046
+
1047
+ QgsTextFormat format = settings.format ();
1048
+ format.setSize ( 20 );
1049
+ format.setColor ( QColor ( 0 , 0 , 0 ) );
1050
+ settings.setFormat ( format );
1051
+
1052
+ settings.fieldName = QStringLiteral ( " 'XXXXXXXXXXXXXXXXXXXXXXXXXX'" );
1053
+ settings.isExpression = true ;
1054
+ settings.placement = QgsPalLayerSettings::Curved;
1055
+ settings.placementFlags = QgsPalLayerSettings::AboveLine | QgsPalLayerSettings::MapOrientation;
1056
+ settings.maxCurvedCharAngleIn = 99 ;
1057
+ settings.maxCurvedCharAngleOut = 99 ;
1058
+
1059
+ std::unique_ptr< QgsVectorLayer> vl2 ( new QgsVectorLayer ( QStringLiteral ( " LineString?crs=epsg:4326&field=id:integer" ), QStringLiteral ( " vl" ), QStringLiteral ( " memory" ) ) );
1060
+ vl2->setRenderer ( new QgsNullSymbolRenderer () );
1061
+
1062
+ QgsFeature f;
1063
+ f.setAttributes ( QgsAttributes () << 1 );
1064
+ // Geometry which roughly curves around from "1 oclock" anticlockwise to 6 oclock.
1065
+ QgsGeometry g ( QgsGeometry::fromWkt ( QStringLiteral ( " LineString (0.30541596873255172 0.3835845896147404, -0.08989391401451696 0.21831379117811278, -0.33668341708542704 -0.01619207146845336, -0.156895589056393 -0.20714684533780003, 0.02735901730876611 -0.21496370742601911)" ) ) );
1066
+ f.setGeometry ( g );
1067
+ QVERIFY ( vl2->dataProvider ()->addFeature ( f ) );
1068
+
1069
+ vl2->setLabeling ( new QgsVectorLayerSimpleLabeling ( settings ) ); // TODO: this should not be necessary!
1070
+ vl2->setLabelsEnabled ( true );
1071
+
1072
+ // make a fake render context
1073
+ QSize size ( 640 , 480 );
1074
+ QgsMapSettings mapSettings;
1075
+ mapSettings.setDestinationCrs ( vl2->crs () );
1076
+
1077
+ mapSettings.setOutputSize ( size );
1078
+ mapSettings.setExtent ( g.boundingBox () );
1079
+ mapSettings.setLayers ( QList<QgsMapLayer *>() << vl2.get () );
1080
+ mapSettings.setOutputDpi ( 96 );
1081
+
1082
+ QgsLabelingEngineSettings engineSettings = mapSettings.labelingEngineSettings ();
1083
+ engineSettings.setFlag ( QgsLabelingEngineSettings::UsePartialCandidates, false );
1084
+ engineSettings.setFlag ( QgsLabelingEngineSettings::DrawLabelRectOnly, true );
1085
+ // engineSettings.setFlag( QgsLabelingEngineSettings::DrawCandidates, true );
1086
+ mapSettings.setLabelingEngineSettings ( engineSettings );
1087
+
1088
+ QgsMapRendererSequentialJob job ( mapSettings );
1089
+ job.start ();
1090
+ job.waitForFinished ();
1091
+
1092
+ QImage img = job.renderedImage ();
1093
+ QVERIFY ( imageCheck ( QStringLiteral ( " label_curved_label_above_1" ), img, 20 ) );
1094
+
1095
+ // and below...
1096
+ settings.placementFlags = QgsPalLayerSettings::BelowLine | QgsPalLayerSettings::MapOrientation;
1097
+ vl2->setLabeling ( new QgsVectorLayerSimpleLabeling ( settings ) ); // TODO: this should not be necessary!
1098
+
1099
+ QgsMapRendererSequentialJob job2 ( mapSettings );
1100
+ job2.start ();
1101
+ job2.waitForFinished ();
1102
+
1103
+ img = job2.renderedImage ();
1104
+ QVERIFY ( imageCheck ( QStringLiteral ( " label_curved_label_below_1" ), img, 20 ) );
1105
+ }
1106
+
1040
1107
void TestQgsLabelingEngine::testLabelBoundary ()
1041
1108
{
1042
1109
// test that no labels are drawn outside of the specified label boundary
0 commit comments