diff --git a/src/MissionManager/QGCMapPolygonTest.cc b/src/MissionManager/QGCMapPolygonTest.cc index 91bc90a0dd68ca56aceee6fdb221f1ed492b8a65..a493cccccda46ea9b0d98cec16993e2ccb856c8a 100644 --- a/src/MissionManager/QGCMapPolygonTest.cc +++ b/src/MissionManager/QGCMapPolygonTest.cc @@ -219,3 +219,38 @@ void QGCMapPolygonTest::_testKMLLoad(void) QVERIFY(!_mapPolygon->loadKMLOrSHPFile(QStringLiteral(":/unittest/PolygonBadCoordinatesNode.kml"))); checkExpectedMessageBox(); } + +void QGCMapPolygonTest::_testSelectVertex(void) +{ + // Create polygon + foreach (auto vertex, _polyPoints) { + _mapPolygon->appendVertex(vertex); + } + + QVERIFY(_mapPolygon->selectedVertex() == -1); + QVERIFY(_mapPolygon->count() == _polyPoints.count()); + + // Test deselect + _mapPolygon->selectVertex(-1); + QVERIFY(_mapPolygon->selectedVertex() == -1); + // Test out of bounds + _mapPolygon->selectVertex(_polyPoints.count()); + QVERIFY(_mapPolygon->selectedVertex() == -1); + // Simple select test + _mapPolygon->selectVertex(_polyPoints.count() - 1); + QVERIFY(_mapPolygon->selectedVertex() == _polyPoints.count() - 1); + // Keep selected test + _mapPolygon->selectVertex(0); + _mapPolygon->removeVertex(_polyPoints.count() - 1); + QVERIFY(_mapPolygon->selectedVertex() == 0); + // Deselect if selected vertex removed + _mapPolygon->appendVertex(_polyPoints[_polyPoints.count() - 1]); + _mapPolygon->selectVertex(_polyPoints.count() - 1); + _mapPolygon->removeVertex(_polyPoints.count() - 1); + QVERIFY(_mapPolygon->selectedVertex() == -1); + // Shift selected index down if removed index < selected index + _mapPolygon->appendVertex(_polyPoints[_polyPoints.count() - 1]); + _mapPolygon->selectVertex(_polyPoints.count() - 1); + _mapPolygon->removeVertex(0); + QVERIFY(_mapPolygon->selectedVertex() == _mapPolygon->count() - 1); +} diff --git a/src/MissionManager/QGCMapPolygonTest.h b/src/MissionManager/QGCMapPolygonTest.h index a5a09886b7294af65f254656c27da5c41a1eca1f..835482b9bdd975356519c7f9428000857e6bfb8f 100644 --- a/src/MissionManager/QGCMapPolygonTest.h +++ b/src/MissionManager/QGCMapPolygonTest.h @@ -17,18 +17,19 @@ class QGCMapPolygonTest : public UnitTest { Q_OBJECT - + public: QGCMapPolygonTest(void); protected: void init(void) final; void cleanup(void) final; - + private slots: void _testDirty(void); void _testVertexManipulation(void); void _testKMLLoad(void); + void _testSelectVertex(void); private: enum { diff --git a/src/MissionManager/QGCMapPolylineTest.cc b/src/MissionManager/QGCMapPolylineTest.cc index 02bd2bdaf8c3c736416de7873ea89d1214a78c92..92afce337d89942c70fb5506a0f6cbf15c246580 100644 --- a/src/MissionManager/QGCMapPolylineTest.cc +++ b/src/MissionManager/QGCMapPolylineTest.cc @@ -200,3 +200,38 @@ void QGCMapPolylineTest::_testKMLLoad(void) checkExpectedMessageBox(); } #endif + +void QGCMapPolylineTest::_testSelectVertex(void) +{ + // Create polyline + foreach (auto vertex, _linePoints) { + _mapPolyline->appendVertex(vertex); + } + + QVERIFY(_mapPolyline->selectedVertex() == -1); + QVERIFY(_mapPolyline->count() == _linePoints.count()); + + // Test deselect + _mapPolyline->selectVertex(-1); + QVERIFY(_mapPolyline->selectedVertex() == -1); + // Test out of bounds + _mapPolyline->selectVertex(_linePoints.count()); + QVERIFY(_mapPolyline->selectedVertex() == -1); + // Simple select test + _mapPolyline->selectVertex(_linePoints.count() - 1); + QVERIFY(_mapPolyline->selectedVertex() == _linePoints.count() - 1); + // Keep selected test + _mapPolyline->selectVertex(0); + _mapPolyline->removeVertex(_linePoints.count() - 1); + QVERIFY(_mapPolyline->selectedVertex() == 0); + // Deselect if selected vertex removed + _mapPolyline->appendVertex(_linePoints[_linePoints.count() - 1]); + _mapPolyline->selectVertex(_linePoints.count() - 1); + _mapPolyline->removeVertex(_linePoints.count() - 1); + QVERIFY(_mapPolyline->selectedVertex() == -1); + // Shift selected index down if removed index < selected index + _mapPolyline->appendVertex(_linePoints[_linePoints.count() - 1]); + _mapPolyline->selectVertex(_linePoints.count() - 1); + _mapPolyline->removeVertex(0); + QVERIFY(_mapPolyline->selectedVertex() == _mapPolyline->count() - 1); +} diff --git a/src/MissionManager/QGCMapPolylineTest.h b/src/MissionManager/QGCMapPolylineTest.h index a2c8caa54f2ae13a4f403cb0757a96cde66ec26a..873c6d4cbc8f070cd1b65fa81e8df99bd9e63b8f 100644 --- a/src/MissionManager/QGCMapPolylineTest.h +++ b/src/MissionManager/QGCMapPolylineTest.h @@ -17,18 +17,19 @@ class QGCMapPolylineTest : public UnitTest { Q_OBJECT - + public: QGCMapPolylineTest(void); protected: void init(void) final; void cleanup(void) final; - + private slots: void _testDirty(void); void _testVertexManipulation(void); // void _testKMLLoad(void); + void _testSelectVertex(void); private: enum {