@@ -195,6 +195,74 @@ void TestMapTools::testSplitting()
195195 delete splitTool;
196196}
197197
198+ void TestMapTools::testValidSplit ()
199+ {
200+ // splitting environment setup
201+ SplittingMapTool *splitTool = new SplittingMapTool ();
202+
203+ QString projectDir = TestUtils::testDataDir () + " /planes" ;
204+ QString projectTempDir = QDir::tempPath () + " /" + QUuid::createUuid ().toString ();
205+ QString projectName = " quickapp_project.qgs" ;
206+
207+ QVERIFY ( InputUtils::cpDir ( projectDir, projectTempDir ) );
208+
209+ QgsProject *project = new QgsProject ();
210+
211+ QVERIFY ( project->read ( projectTempDir + " /" + projectName ) );
212+
213+ QgsMapLayer *sectorL = project->mapLayersByName ( QStringLiteral ( " FlySector" ) ).at ( 0 );
214+ QgsVectorLayer *flySectorLayer = static_cast <QgsVectorLayer *>( sectorL );
215+
216+ QVERIFY ( flySectorLayer && flySectorLayer->isValid () );
217+
218+ InputMapCanvasMap canvas;
219+ InputMapSettings *ms = canvas.mapSettings ();
220+ ms->setProject ( project );
221+ ms->setDestinationCrs ( project->crs () );
222+ ms->setOutputSize ( QSize ( 600 , 1096 ) );
223+ ms->setLayers ( project->layers <QgsMapLayer *>().toList () );
224+
225+ QgsRectangle extent = QgsRectangle ( -107.54331499504026226 , 21.62302175066136556 , -72.73224633912816728 , 51.49933451998575151 );
226+ ms->setExtent ( extent );
227+
228+ splitTool->setMapSettings ( ms );
229+
230+ // set feature to split
231+ int fidToSplit = 1 ;
232+ QgsFeature featureToSplit = flySectorLayer->getFeature ( fidToSplit );
233+ FeatureLayerPair pairToSplit ( featureToSplit, flySectorLayer );
234+ splitTool->setFeatureToSplit ( pairToSplit );
235+
236+ // not enough points
237+ QCOMPARE ( splitTool->commitSplit (), SplittingMapTool::Failed );
238+
239+ // line doesnt intersect feature
240+ splitTool->addPoint ( QgsPoint ( -104.751 , 32.448 ) );
241+ QCOMPARE ( splitTool->commitSplit (), SplittingMapTool::Failed );
242+
243+ // valid split line, endpoints outside and line intersects feature
244+ splitTool->addPoint ( QgsPoint ( -120.844 , 32.592 ) );
245+ QCOMPARE ( splitTool->commitSplit (), SplittingMapTool::Success );
246+
247+ // line doesnt intersect feature
248+ splitTool->removePoint ();
249+ splitTool->removePoint ();
250+ splitTool->addPoint ( QgsPoint ( -130.0 , 10.0 ) );
251+ splitTool->addPoint ( QgsPoint ( -140.0 , 15.0 ) );
252+ QCOMPARE ( splitTool->commitSplit (), SplittingMapTool::InvalidSplit );
253+
254+ // endpoint inside feature boundary
255+ QgsPointXY centerPoint = featureToSplit.geometry ().centroid ().asPoint ();
256+ splitTool->removePoint ();
257+ splitTool->removePoint ();
258+ splitTool->addPoint ( QgsPoint ( centerPoint.x (), centerPoint.y () ) );
259+ splitTool->addPoint ( QgsPoint ( -120.844 , 32.592 ) );
260+ QCOMPARE ( splitTool->commitSplit (), SplittingMapTool::InvalidSplit );
261+
262+ delete project;
263+ delete splitTool;
264+ }
265+
198266void TestMapTools::testRecording ()
199267{
200268 RecordingMapTool *recordTool = new RecordingMapTool ();
0 commit comments