QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
LogViewerParametersTab.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Controls
3import QtQuick.Layouts
4
5import QGroundControl
6import QGroundControl.Controls
7
8/// Parameters tab for the Log Viewer.
9/// Owns all filter state; call applyFilter() after a log loads or clears.
10ColumnLayout {
11 id: control
12
13 required property var logParser
14
15 spacing: ScreenTools.defaultFontPixelHeight * 0.5
16
17 // -------------------------------------------------------------------------
18 // Internal state
19 // -------------------------------------------------------------------------
20 property string _parameterSearchText: ""
21 property bool _showOnlyChangedParameters: true
22 property var _filteredParameters: []
23
24 QGCPalette { id: qgcPal }
25
26 // -------------------------------------------------------------------------
27 // Public API
28 // -------------------------------------------------------------------------
29
30 /// Recompute the filtered parameter list. Call after log load or clear.
31 function applyFilter() {
32 const query = String(_parameterSearchText).trim().toLowerCase()
33 const onlyChanged = _showOnlyChangedParameters
34
35 const output = []
36 for (let i = 0; i < logParser.parameters.length; i++) {
37 const item = logParser.parameters[i]
38 // "Show only changed" filter: skip parameters that equal their system default
39 if (onlyChanged && item.hasDefault && item.isDefault) {
40 continue
41 }
42 if (query.length > 0) {
43 const name = String(item.name)
44 const desc = item.shortDescription ? String(item.shortDescription) : ""
45 const value = String(item.value)
46 if ((name + " " + value + " " + desc).toLowerCase().indexOf(query) === -1) {
47 continue
48 }
49 }
50 output.push(item)
51 }
52 _filteredParameters = output
53 }
54
55 // -------------------------------------------------------------------------
56 // UI
57 // -------------------------------------------------------------------------
58
59 RowLayout {
60 Layout.fillWidth: true
61 spacing: ScreenTools.defaultFontPixelWidth
62
63 QGCTextField {
64 id: _parameterSearchField
65 Layout.fillWidth: true
66 textColor: qgcPal.textPrimary
67 placeholderText: qsTr("Search parameters")
68
69 onTextChanged: {
70 control._parameterSearchText = text
71 if (text.trim().length === 0) {
72 _parameterSearchTimer.stop()
73 control.applyFilter()
74 } else {
75 _parameterSearchTimer.restart()
76 }
77 }
78
79 onAccepted: {
80 control._parameterSearchText = text
81 _parameterSearchTimer.stop()
82 control.applyFilter()
83 }
84 }
85
86 QGCCheckBoxSlider {
87 text: qsTr("Changed only")
88 checked: _showOnlyChangedParameters
89 onToggled: {
90 control._showOnlyChangedParameters = checked
91 control.applyFilter()
92 }
93 }
94 }
95
96 ScrollView {
97 Layout.fillWidth: true
98 Layout.fillHeight: true
99 clip: true
100
101 ListView {
102 anchors.fill: parent
103 model: _filteredParameters
104 spacing: ScreenTools.defaultFontPixelHeight * 0.1
105 clip: true
106 ScrollBar.vertical: ScrollBar { }
107
108 delegate: Rectangle {
109 width: ListView.view.width
110 height: _paramRow.implicitHeight + ScreenTools.defaultFontPixelHeight * 0.4
111 color: index % 2 === 0 ? qgcPal.windowCard : qgcPal.windowPanel
112 radius: 2
113
114 // Format value: use metadata decimalPlaces when available,
115 // fall back to isFloat heuristic. Show enum label when applicable.
116 readonly property string _formattedValue: {
117 const v = modelData.value
118 if (v === undefined || v === null) return qsTr("N/A")
119 const numV = Number(v)
120 // Enum: find matching label
121 const eStrs = modelData.enumStrings
122 const eVals = modelData.enumValues
123 if (eStrs && eVals && eStrs.length > 0 && eVals.length === eStrs.length) {
124 for (let ei = 0; ei < eVals.length; ei++) {
125 if (Number(eVals[ei]) === numV) {
126 return eStrs[ei] + " (" + Math.round(numV) + ")"
127 }
128 }
129 }
130 // Numeric: metadata decimalPlaces wins
131 const dp = (modelData.decimalPlaces !== undefined) ? modelData.decimalPlaces : -1
132 let formatted
133 if (dp >= 0) {
134 formatted = numV.toFixed(dp)
135 } else if (modelData.isFloat) {
136 formatted = numV.toFixed(6)
137 } else {
138 formatted = String(Math.round(numV))
139 }
140 const units = (modelData.units && modelData.units.length > 0) ? (" " + modelData.units) : ""
141 return formatted + units
142 }
143
144 readonly property string _defaultText: {
145 if (!modelData.hasDefault) return ""
146 const d = modelData.defaultValue
147 if (d === undefined || d === null) return ""
148 const numD = Number(d)
149 const dp = (modelData.decimalPlaces !== undefined) ? modelData.decimalPlaces : -1
150 let formatted
151 if (dp >= 0) {
152 formatted = numD.toFixed(dp)
153 } else if (modelData.isFloat) {
154 formatted = numD.toFixed(6)
155 } else {
156 formatted = String(Math.round(numD))
157 }
158 return qsTr(" (default: %1)").arg(formatted)
159 }
160
161 RowLayout {
162 id: _paramRow
163 anchors.verticalCenter: parent.verticalCenter
164 anchors.left: parent.left
165 anchors.right: parent.right
166 anchors.margins: ScreenTools.defaultFontPixelWidth * 0.5
167 spacing: ScreenTools.defaultFontPixelWidth * 0.5
168
169 // Changed-from-default indicator dot
170 Rectangle {
171 visible: modelData.hasDefault && !modelData.isDefault
172 width: ScreenTools.defaultFontPixelHeight * 0.5
173 height: width
174 radius: width / 2
175 color: qgcPal.colorOrange
176 Layout.alignment: Qt.AlignVCenter
177 }
178
179 // Spacer to keep alignment when dot is hidden
180 Item {
181 visible: !(modelData.hasDefault && !modelData.isDefault)
182 width: ScreenTools.defaultFontPixelHeight * 0.5
183 height: width
184 }
185
186 QGCLabel {
187 text: modelData.name
188 font.bold: modelData.hasDefault && !modelData.isDefault
189 Layout.preferredWidth: ScreenTools.defaultFontPixelWidth * 22
190 elide: Text.ElideRight
191 }
192
193 QGCLabel {
194 text: _formattedValue
195 Layout.preferredWidth: ScreenTools.defaultFontPixelWidth * 14
196 horizontalAlignment: Text.AlignRight
197 }
198
199 QGCLabel {
200 text: _defaultText
201 color: Qt.rgba(qgcPal.textPrimary.r, qgcPal.textPrimary.g, qgcPal.textPrimary.b, 0.6)
202 Layout.preferredWidth: ScreenTools.defaultFontPixelWidth * 16
203 elide: Text.ElideRight
204 }
205
206 QGCLabel {
207 text: modelData.shortDescription ? String(modelData.shortDescription) : ""
208 color: Qt.rgba(qgcPal.textPrimary.r, qgcPal.textPrimary.g, qgcPal.textPrimary.b, 0.6)
209 Layout.fillWidth: true
210 elide: Text.ElideRight
211 }
212 }
213 }
214 }
215 }
216
217 Timer {
218 id: _parameterSearchTimer
219 interval: 250
220 repeat: false
221 onTriggered: control.applyFilter()
222 }
223}