QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
EditPositionDialog.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Controls
3import QtQuick.Layouts
4import QtQuick.Dialogs
5
6import QGroundControl
7import QGroundControl.Controls
8import QGroundControl.FactControls
9
10QGCPopupDialog {
11 id: root
12 title: qsTr("Edit Position")
13 buttons: Dialog.Close
14
15 property alias coordinate: controller.coordinate
16 property var altitudeFact: null
17 property int altitudeFrame: QGroundControl.AltitudeFrameNone
18
19 property real _margin: ScreenTools.defaultFontPixelWidth / 2
20 property real _textFieldWidth: ScreenTools.defaultFontPixelWidth * 20
21 property bool _showGeographic: coordinateSystemCombo.comboBox.currentIndex === 0
22 property bool _showDMS: coordinateSystemCombo.comboBox.currentIndex === 1
23 property bool _showUTM: coordinateSystemCombo.comboBox.currentIndex === 2
24 property bool _showMGRS: coordinateSystemCombo.comboBox.currentIndex === 3
25 property bool _showVehicle: coordinateSystemCombo.comboBox.currentIndex === 4
26 property bool _supportsAltitude: altitudeFact !== null
27
28 function _isFiniteAltitude(value) {
29 const numericValue = Number(value)
30 return !isNaN(numericValue) && isFinite(numericValue)
31 }
32
33 TransformPositionController {
34 id: controller
35
36 Component.onCompleted: initValues()
37 }
38
39 ColumnLayout {
40 spacing: _margin
41
42 LabelledComboBox {
43 id: coordinateSystemCombo
44 Layout.fillWidth: true
45 label: qsTr("Coordinate System")
46 model: globals.activeVehicle ?
47 [ qsTr("Geographic"), qsTr("Degrees Minutes Seconds"), qsTr("Universal Transverse Mercator"), qsTr("Military Grid Reference"), qsTr("Vehicle Position") ] :
48 [ qsTr("Geographic"), qsTr("Degrees Minutes Seconds"), qsTr("Universal Transverse Mercator"), qsTr("Military Grid Reference") ]
49
50 Component.onCompleted: comboBox.currentIndex = controller.defaultCoordinateSystem
51 }
52
53 LabelledFactTextField {
54 label: qsTr("Latitude")
55 fact: controller.latitude
56 textFieldPreferredWidth: _textFieldWidth
57 Layout.fillWidth: true
58 visible: _showGeographic
59 }
60
61 LabelledFactTextField {
62 label: qsTr("Longitude")
63 fact: controller.longitude
64 textFieldPreferredWidth: _textFieldWidth
65 Layout.fillWidth: true
66 visible: _showGeographic
67 }
68
69 LabelledFactTextField {
70 label: qsTr("Latitude")
71 fact: controller.latitudeDMS
72 textFieldPreferredWidth: _textFieldWidth
73 Layout.fillWidth: true
74 visible: _showDMS
75 }
76
77 LabelledFactTextField {
78 label: qsTr("Longitude")
79 fact: controller.longitudeDMS
80 textFieldPreferredWidth: _textFieldWidth
81 Layout.fillWidth: true
82 visible: _showDMS
83 }
84
85 LabelledFactTextField {
86 label: qsTr("Zone")
87 fact: controller.zone
88 textFieldPreferredWidth: _textFieldWidth
89 Layout.fillWidth: true
90 visible: _showUTM
91 }
92
93 LabelledFactComboBox {
94 label: qsTr("Hemisphere")
95 fact: controller.hemisphere
96 indexModel: false
97 Layout.fillWidth: true
98 visible: _showUTM
99 }
100
101 LabelledFactTextField {
102 label: qsTr("Easting")
103 fact: controller.easting
104 textFieldPreferredWidth: _textFieldWidth
105 Layout.fillWidth: true
106 visible: _showUTM
107 }
108
109 LabelledFactTextField {
110 label: qsTr("Northing")
111 fact: controller.northing
112 textFieldPreferredWidth: _textFieldWidth
113 Layout.fillWidth: true
114 visible: _showUTM
115 }
116
117 LabelledFactTextField {
118 label: qsTr("MGRS")
119 fact: controller.mgrs
120 visible: _showMGRS
121 textFieldPreferredWidth: _textFieldWidth
122 Layout.fillWidth: true
123 }
124
125 LabelledLabel {
126 label: qsTr("Latitude")
127 labelText: globals.activeVehicle ? globals.activeVehicle.coordinate.latitude.toFixed(7) : ""
128 Layout.fillWidth: true
129 visible: _showVehicle
130 }
131
132 LabelledLabel {
133 label: qsTr("Longitude")
134 labelText: globals.activeVehicle ? globals.activeVehicle.coordinate.longitude.toFixed(7) : ""
135 Layout.fillWidth: true
136 visible: _showVehicle
137 }
138
139 LabelledLabel {
140 label: qsTr("Alt (AMSL)")
141 labelText: globals.activeVehicle ? globals.activeVehicle.altitudeAMSL.valueString + " " + globals.activeVehicle.altitudeAMSL.units : ""
142 Layout.fillWidth: true
143 visible: _showVehicle && _supportsAltitude && altitudeFrame === QGroundControl.AltitudeFrameAbsolute
144 }
145
146 LabelledLabel {
147 label: qsTr("Alt (Rel)")
148 labelText: globals.activeVehicle ? globals.activeVehicle.altitudeRelative.valueString + " " + globals.activeVehicle.altitudeRelative.units : ""
149 Layout.fillWidth: true
150 visible: _showVehicle && _supportsAltitude && altitudeFrame === QGroundControl.AltitudeFrameRelative
151 }
152
153 LabelledLabel {
154 label: qsTr("Alt (AGL)")
155 labelText: globals.activeVehicle ? globals.activeVehicle.altitudeAboveTerr.valueString + " " + globals.activeVehicle.altitudeAboveTerr.units : ""
156 Layout.fillWidth: true
157 visible: _showVehicle && _supportsAltitude && (altitudeFrame === QGroundControl.AltitudeFrameTerrain || altitudeFrame === QGroundControl.AltitudeFrameCalcAboveTerrain)
158 }
159
160 QGCCheckBox {
161 id: setPositionCheckBox
162 text: qsTr("Set position from vehicle")
163 checked: true
164 visible: _showVehicle
165 }
166
167 QGCCheckBox {
168 id: setAltitudeCheckBox
169 text: qsTr("Set altitude from vehicle")
170 checked: false
171 visible: _showVehicle && _supportsAltitude
172 }
173
174 LabelledButton {
175 label: qsTr("Set position")
176 buttonText: qsTr("Move")
177 onClicked: {
178 let positionValid = true
179 if (_showGeographic)
180 controller.setFromGeo()
181 else if (_showDMS)
182 positionValid = controller.setFromDMS()
183 else if (_showUTM)
184 positionValid = controller.setFromUTM()
185 else if (_showMGRS)
186 positionValid = controller.setFromMGRS()
187 else if (_showVehicle) {
188 if (setPositionCheckBox.checked)
189 controller.setFromVehicle()
190 if (setAltitudeCheckBox.checked && _supportsAltitude && globals.activeVehicle) {
191 let sourceAltitude = NaN
192
193 if (altitudeFrame === QGroundControl.AltitudeFrameRelative)
194 sourceAltitude = globals.activeVehicle.altitudeRelative.rawValue
195 else if (altitudeFrame === QGroundControl.AltitudeFrameAbsolute)
196 sourceAltitude = globals.activeVehicle.altitudeAMSL.rawValue
197 else if (altitudeFrame === QGroundControl.AltitudeFrameTerrain || altitudeFrame === QGroundControl.AltitudeFrameCalcAboveTerrain)
198 sourceAltitude = globals.activeVehicle.altitudeAboveTerr.rawValue
199
200 if (_isFiniteAltitude(sourceAltitude))
201 altitudeFact.rawValue = sourceAltitude
202 }
203 }
204 if (!positionValid) {
205 QGroundControl.showMessageDialog(root, qsTr("Edit Position"), qsTr("Invalid coordinate. Check the entered values and try again."))
206 return
207 }
208 root.close()
209 }
210 }
211 }
212}