diff --git a/src/MissionManager/MissionController.cc b/src/MissionManager/MissionController.cc index a45272535bfca4121107d478a87992cd4527d020..234dbf412ed03cd14a5e03a73245fc223c72255e 100644 --- a/src/MissionManager/MissionController.cc +++ b/src/MissionManager/MissionController.cc @@ -349,7 +349,7 @@ int MissionController::_nextSequenceNumber(void) } } -int MissionController::insertSimpleMissionItem(QGeoCoordinate coordinate, int i) +int MissionController::insertSimpleMissionItem(QGeoCoordinate coordinate, int visualItemIndex) { int sequenceNumber = _nextSequenceNumber(); SimpleMissionItem * newItem = new SimpleMissionItem(_controllerVehicle, _flyView, this); @@ -367,13 +367,13 @@ int MissionController::insertSimpleMissionItem(QGeoCoordinate coordinate, int i) double prevAltitude; int prevAltitudeMode; - if (_findPreviousAltitude(i, &prevAltitude, &prevAltitudeMode)) { + if (_findPreviousAltitude(visualItemIndex, &prevAltitude, &prevAltitudeMode)) { newItem->altitude()->setRawValue(prevAltitude); newItem->setAltitudeMode(static_cast(prevAltitudeMode)); } } newItem->setMissionFlightStatus(_missionFlightStatus); - _visualItems->insert(i, newItem); + _visualItems->insert(visualItemIndex, newItem); // We send the click coordinate through here to be able to set the planned home position from the user click location if needed _recalcAllWithClickCoordinate(coordinate); @@ -381,7 +381,7 @@ int MissionController::insertSimpleMissionItem(QGeoCoordinate coordinate, int i) return newItem->sequenceNumber(); } -int MissionController::insertROIMissionItem(QGeoCoordinate coordinate, int i) +int MissionController::insertROIMissionItem(QGeoCoordinate coordinate, int visualItemIndex) { int sequenceNumber = _nextSequenceNumber(); SimpleMissionItem * newItem = new SimpleMissionItem(_controllerVehicle, _flyView, this); @@ -395,18 +395,18 @@ int MissionController::insertROIMissionItem(QGeoCoordinate coordinate, int i) double prevAltitude; int prevAltitudeMode; - if (_findPreviousAltitude(i, &prevAltitude, &prevAltitudeMode)) { + if (_findPreviousAltitude(visualItemIndex, &prevAltitude, &prevAltitudeMode)) { newItem->altitude()->setRawValue(prevAltitude); newItem->setAltitudeMode(static_cast(prevAltitudeMode)); } - _visualItems->insert(i, newItem); + _visualItems->insert(visualItemIndex, newItem); _recalcAll(); return newItem->sequenceNumber(); } -int MissionController::insertComplexMissionItem(QString itemName, QGeoCoordinate mapCenterCoordinate, int i) +int MissionController::insertComplexMissionItem(QString itemName, QGeoCoordinate mapCenterCoordinate, int visualItemIndex) { ComplexMissionItem* newItem; @@ -425,10 +425,10 @@ int MissionController::insertComplexMissionItem(QString itemName, QGeoCoordinate return sequenceNumber; } - return _insertComplexMissionItemWorker(newItem, i); + return _insertComplexMissionItemWorker(newItem, visualItemIndex); } -int MissionController::insertComplexMissionItemFromKMLOrSHP(QString itemName, QString file, int i) +int MissionController::insertComplexMissionItemFromKMLOrSHP(QString itemName, QString file, int visualItemIndex) { ComplexMissionItem* newItem; @@ -443,10 +443,10 @@ int MissionController::insertComplexMissionItemFromKMLOrSHP(QString itemName, QS return _nextSequenceNumber(); } - return _insertComplexMissionItemWorker(newItem, i); + return _insertComplexMissionItemWorker(newItem, visualItemIndex); } -int MissionController::_insertComplexMissionItemWorker(ComplexMissionItem* complexItem, int i) +int MissionController::_insertComplexMissionItemWorker(ComplexMissionItem* complexItem, int visualItemIndex) { int sequenceNumber = _nextSequenceNumber(); bool surveyStyleItem = qobject_cast(complexItem) || @@ -482,10 +482,10 @@ int MissionController::_insertComplexMissionItemWorker(ComplexMissionItem* compl complexItem->setSequenceNumber(sequenceNumber); _initVisualItem(complexItem); - if (i == -1) { + if (visualItemIndex == -1) { _visualItems->append(complexItem); } else { - _visualItems->insert(i, complexItem); + _visualItems->insert(visualItemIndex, complexItem); } //-- Keep track of bounding box changes in complex items @@ -2227,3 +2227,16 @@ bool MissionController::isEmpty(void) const { return _visualItems->count() <= 1; } + +int MissionController::visualItemIndexFromSequenceNumber(int sequenceNumber) const +{ + for (int i=0; i<_visualItems->count(); i++) { + const VisualMissionItem* vi = _visualItems->value(i); + if (vi->sequenceNumber() == sequenceNumber) { + return i; + } + } + + qWarning() << "MissionController::getVisualItemIndex visual item not found"; + return 0; +} diff --git a/src/MissionManager/MissionController.h b/src/MissionManager/MissionController.h index 4deb2f9456e0b206d6f0f7446c8ea97dfc8c924a..892ff41eae37727190f714a995d8c84c8f608d05 100644 --- a/src/MissionManager/MissionController.h +++ b/src/MissionManager/MissionController.h @@ -103,28 +103,28 @@ public: Q_INVOKABLE void removeMissionItem(int index); /// Add a new simple mission item to the list - /// @param i: index to insert at + /// @param visualItemIndex: index to insert at /// @return Sequence number for new item - Q_INVOKABLE int insertSimpleMissionItem(QGeoCoordinate coordinate, int i); + Q_INVOKABLE int insertSimpleMissionItem(QGeoCoordinate coordinate, int visualItemIndex); /// Add a new ROI mission item to the list - /// @param i: index to insert at + /// @param visualItemIndex: index to insert at /// @return Sequence number for new item - Q_INVOKABLE int insertROIMissionItem(QGeoCoordinate coordinate, int i); + Q_INVOKABLE int insertROIMissionItem(QGeoCoordinate coordinate, int visualItemIndex); /// Add a new complex mission item to the list /// @param itemName: Name of complex item to create (from complexMissionItemNames) /// @param mapCenterCoordinate: coordinate for current center of map - /// @param i: index to insert at + /// @param visualItemIndex: index to insert at /// @return Sequence number for new item - Q_INVOKABLE int insertComplexMissionItem(QString itemName, QGeoCoordinate mapCenterCoordinate, int i); + Q_INVOKABLE int insertComplexMissionItem(QString itemName, QGeoCoordinate mapCenterCoordinate, int visualItemIndex); /// Add a new complex mission item to the list /// @param itemName: Name of complex item to create (from complexMissionItemNames) /// @param file: kml or shp file to load from shape from - /// @param i: index to insert at, -1 for end + /// @param visualItemIndex: index to insert at, -1 for end /// @return Sequence number for new item - Q_INVOKABLE int insertComplexMissionItemFromKMLOrSHP(QString itemName, QString file, int i); + Q_INVOKABLE int insertComplexMissionItemFromKMLOrSHP(QString itemName, QString file, int visualItemIndex); Q_INVOKABLE void resumeMission(int resumeIndex); @@ -135,6 +135,9 @@ public: /// @param sequenceNumber - index for new item, -1 to clear current item Q_INVOKABLE void setCurrentPlanViewIndex(int sequenceNumber, bool force); + /// Returns the index of this item in the visual item list + Q_INVOKABLE int visualItemIndexFromSequenceNumber(int sequenceNumber) const; + /// Determines if the mission has all data needed to be saved or sent to the vehicle. Currently the only case where this /// would return false is when it is still waiting on terrain data to determine correct altitudes. bool readyForSaveSend(void) const; @@ -280,7 +283,7 @@ private: void _initLoadedVisualItems(QmlObjectListModel* loadedVisualItems); CoordinateVector* _addWaypointLineSegment(CoordVectHashTable& prevItemPairHashTable, VisualItemPair& pair); void _addTimeDistance(bool vtolInHover, double hoverTime, double cruiseTime, double extraTime, double distance, int seqNum); - int _insertComplexMissionItemWorker(ComplexMissionItem* complexItem, int i); + int _insertComplexMissionItemWorker(ComplexMissionItem* complexItem, int visualItemIndex); void _warnIfTerrainFrameUsed(void); private: diff --git a/src/PlanView/PlanView.qml b/src/PlanView/PlanView.qml index a1fe01407d22cb16b2ea5e0ef5a6f55450418526..a7105f132521b08e418118fa01c3837516bb7d29 100644 --- a/src/PlanView/PlanView.qml +++ b/src/PlanView/PlanView.qml @@ -489,7 +489,7 @@ Item { z: QGroundControl.zOrderWaypointLines + 1 sourceItem: SplitIndicator { - onClicked: insertSimpleMissionItem(splitSegmentItem.coordinate, _missionController.currentPlanViewIndex) + onClicked: insertSimpleMissionItem(splitSegmentItem.coordinate, _missionController.visualItemIndexFromSequenceNumber(_missionController.currentPlanViewIndex)) } function _updateSplitCoord() {