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 _showUTM: coordinateSystemCombo.comboBox.currentIndex === 1
23 property bool _showMGRS: coordinateSystemCombo.comboBox.currentIndex === 2
24 property bool _showVehicle: coordinateSystemCombo.comboBox.currentIndex === 3
25 property bool _supportsAltitude: altitudeFact !== null
26
27 function _isFiniteAltitude(value) {
28 const numericValue = Number(value)
29 return !isNaN(numericValue) && isFinite(numericValue)
30 }
31
32 TransformPositionController {
33 id: controller
34
35 Component.onCompleted: initValues()
36 }
37
38 ColumnLayout {
39 spacing: _margin
40
41 LabelledComboBox {
42 id: coordinateSystemCombo
43 Layout.fillWidth: true
44 label: qsTr("Coordinate System")
45 model: globals.activeVehicle ?
46 [ qsTr("Geographic"), qsTr("Universal Transverse Mercator"), qsTr("Military Grid Reference"), qsTr("Vehicle Position") ] :
47 [ qsTr("Geographic"), qsTr("Universal Transverse Mercator"), qsTr("Military Grid Reference") ]
48 }
49
50 LabelledFactTextField {
51 label: qsTr("Latitude")
52 fact: controller.latitude
53 textFieldPreferredWidth: _textFieldWidth
54 Layout.fillWidth: true
55 visible: _showGeographic
56 }
57
58 LabelledFactTextField {
59 label: qsTr("Longitude")
60 fact: controller.longitude
61 textFieldPreferredWidth: _textFieldWidth
62 Layout.fillWidth: true
63 visible: _showGeographic
64 }
65
66 LabelledFactTextField {
67 label: qsTr("Zone")
68 fact: controller.zone
69 textFieldPreferredWidth: _textFieldWidth
70 Layout.fillWidth: true
71 visible: _showUTM
72 }
73
74 LabelledFactComboBox {
75 label: qsTr("Hemisphere")
76 fact: controller.hemisphere
77 indexModel: false
78 Layout.fillWidth: true
79 visible: _showUTM
80 }
81
82 LabelledFactTextField {
83 label: qsTr("Easting")
84 fact: controller.easting
85 textFieldPreferredWidth: _textFieldWidth
86 Layout.fillWidth: true
87 visible: _showUTM
88 }
89
90 LabelledFactTextField {
91 label: qsTr("Northing")
92 fact: controller.northing
93 textFieldPreferredWidth: _textFieldWidth
94 Layout.fillWidth: true
95 visible: _showUTM
96 }
97
98 LabelledFactTextField {
99 label: qsTr("MGRS")
100 fact: controller.mgrs
101 visible: _showMGRS
102 textFieldPreferredWidth: _textFieldWidth
103 Layout.fillWidth: true
104 }
105
106 LabelledLabel {
107 label: qsTr("Latitude")
108 labelText: globals.activeVehicle ? globals.activeVehicle.coordinate.latitude.toFixed(7) : ""
109 Layout.fillWidth: true
110 visible: _showVehicle
111 }
112
113 LabelledLabel {
114 label: qsTr("Longitude")
115 labelText: globals.activeVehicle ? globals.activeVehicle.coordinate.longitude.toFixed(7) : ""
116 Layout.fillWidth: true
117 visible: _showVehicle
118 }
119
120 LabelledLabel {
121 label: qsTr("Alt (AMSL)")
122 labelText: globals.activeVehicle ? globals.activeVehicle.altitudeAMSL.valueString + " " + globals.activeVehicle.altitudeAMSL.units : ""
123 Layout.fillWidth: true
124 visible: _showVehicle && _supportsAltitude && altitudeFrame === QGroundControl.AltitudeFrameAbsolute
125 }
126
127 LabelledLabel {
128 label: qsTr("Alt (Rel)")
129 labelText: globals.activeVehicle ? globals.activeVehicle.altitudeRelative.valueString + " " + globals.activeVehicle.altitudeRelative.units : ""
130 Layout.fillWidth: true
131 visible: _showVehicle && _supportsAltitude && altitudeFrame === QGroundControl.AltitudeFrameRelative
132 }
133
134 LabelledLabel {
135 label: qsTr("Alt (AGL)")
136 labelText: globals.activeVehicle ? globals.activeVehicle.altitudeAboveTerr.valueString + " " + globals.activeVehicle.altitudeAboveTerr.units : ""
137 Layout.fillWidth: true
138 visible: _showVehicle && _supportsAltitude && (altitudeFrame === QGroundControl.AltitudeFrameTerrain || altitudeFrame === QGroundControl.AltitudeFrameCalcAboveTerrain)
139 }
140
141 QGCCheckBox {
142 id: setPositionCheckBox
143 text: qsTr("Set position from vehicle")
144 checked: true
145 visible: _showVehicle
146 }
147
148 QGCCheckBox {
149 id: setAltitudeCheckBox
150 text: qsTr("Set altitude from vehicle")
151 checked: false
152 visible: _showVehicle && _supportsAltitude
153 }
154
155 LabelledButton {
156 label: qsTr("Set position")
157 buttonText: qsTr("Move")
158 onClicked: {
159 if (_showGeographic)
160 controller.setFromGeo()
161 else if (_showUTM)
162 controller.setFromUTM()
163 else if (_showMGRS)
164 controller.setFromMGRS()
165 else if (_showVehicle) {
166 if (setPositionCheckBox.checked)
167 controller.setFromVehicle()
168 if (setAltitudeCheckBox.checked && _supportsAltitude && globals.activeVehicle) {
169 let sourceAltitude = NaN
170
171 if (altitudeFrame === QGroundControl.AltitudeFrameRelative)
172 sourceAltitude = globals.activeVehicle.altitudeRelative.rawValue
173 else if (altitudeFrame === QGroundControl.AltitudeFrameAbsolute)
174 sourceAltitude = globals.activeVehicle.altitudeAMSL.rawValue
175 else if (altitudeFrame === QGroundControl.AltitudeFrameTerrain || altitudeFrame === QGroundControl.AltitudeFrameCalcAboveTerrain)
176 sourceAltitude = globals.activeVehicle.altitudeAboveTerr.rawValue
177
178 if (_isFiniteAltitude(sourceAltitude))
179 altitudeFact.rawValue = sourceAltitude
180 }
181 }
182 root.close()
183 }
184 }
185 }
186}