diff --git a/src/MissionManager/SimpleMissionItem.cc b/src/MissionManager/SimpleMissionItem.cc index bbebc91..20de9b0 100644 --- a/src/MissionManager/SimpleMissionItem.cc +++ b/src/MissionManager/SimpleMissionItem.cc @@ -743,6 +743,10 @@ void SimpleMissionItem::_setDefaultsForCommand(void) // No need to carry across previous lat/lon _missionItem._param5Fact.setRawValue(0); _missionItem._param6Fact.setRawValue(0); + } else if ((specifiesCoordinate() || isStandaloneCoordinate()) && _missionItem._param5Fact.rawValue().toDouble() == 0 && _missionItem._param6Fact.rawValue().toDouble() == 0) { + // We switched from a command without a coordinate to a command with a coordinate. Use the hint. + _missionItem._param5Fact.setRawValue(_mapCenterHint.latitude()); + _missionItem._param6Fact.setRawValue(_mapCenterHint.longitude()); } // Set global defaults first, then if there are param defaults they will get reset diff --git a/src/MissionManager/SimpleMissionItem.h b/src/MissionManager/SimpleMissionItem.h index 9f36320..aa97b71 100644 --- a/src/MissionManager/SimpleMissionItem.h +++ b/src/MissionManager/SimpleMissionItem.h @@ -49,6 +49,11 @@ public: Q_PROPERTY(QmlObjectListModel* textFieldFacts READ textFieldFacts CONSTANT) Q_PROPERTY(QmlObjectListModel* nanFacts READ nanFacts CONSTANT) + /// This should be called before changing the command. It is needed if the command changes + /// from an item which does not include a coordinate to an item which requires a coordinate. + /// It uses this value to set that new coordinate. + Q_INVOKABLE void setMapCenterHintForCommandChange(QGeoCoordinate mapCenter) { _mapCenterHint = mapCenter; }; + /// Scans the loaded items for additional section settings /// @param visualItems List of all visual items /// @param scanIndex Index to start scanning from @@ -162,6 +167,7 @@ private: bool _rawEdit; bool _dirty; bool _ignoreDirtyChangeSignals; + QGeoCoordinate _mapCenterHint; SpeedSection* _speedSection; CameraSection* _cameraSection; diff --git a/src/PlanView/MissionItemEditor.qml b/src/PlanView/MissionItemEditor.qml index baeb59f..9307a70 100644 --- a/src/PlanView/MissionItemEditor.qml +++ b/src/PlanView/MissionItemEditor.qml @@ -204,7 +204,8 @@ Rectangle { id: commandDialog MissionCommandDialog { - missionItem: _root.missionItem + missionItem: _root.missionItem + map: _root.map } } diff --git a/src/QmlControls/MissionCommandDialog.qml b/src/QmlControls/MissionCommandDialog.qml index 03532af..9bc925a 100644 --- a/src/QmlControls/MissionCommandDialog.qml +++ b/src/QmlControls/MissionCommandDialog.qml @@ -20,6 +20,7 @@ QGCViewDialog { id: root property var missionItem + property var map property var _vehicle: QGroundControl.multiVehicleManager.activeVehicle @@ -96,6 +97,7 @@ QGCViewDialog { MouseArea { anchors.fill: parent onClicked: { + missionItem.setMapCenterHintForCommandChange(map.center) missionItem.command = mavCmdInfo.command root.reject() }