QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
ConfigParamCell.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Layouts
3
4import QGroundControl
5import QGroundControl.Controls
6import QGroundControl.FactControls
7
8/// Cell for one row-definition cell (see PX4ConfigRows.js). The control comes from the parameter metadata: a combo box
9/// for a list of choices, a slider per bit for a bitmask, otherwise a text field. A parameter that needs a reboot shows
10/// a muted hint, which turns into a warning once the value differs from when the page first showed it.
11QGCCaptionCell {
12 id: control
13
14 required property var cell
15 /// factFor(name) returns the parameter's Fact, or null when the vehicle does not have it
16 required property var factFor
17 /// Shared by the page's cells: each parameter's value when the page first showed it
18 required property var initialValues
19 /// Prefix of the test hook objectNames
20 property string objectNamePrefix: ""
21 /// Created left of the combo box, such as a marker for the selected choice
22 property Component enumLeading
23 /// Created right of the text field, such as a button
24 property Component numberTrailing
25 /// Replaces the metadata choices with [{ label, value }], for offering only some of them
26 property var enumChoices: null
27 /// Extra content after the control, before the threshold bar, reboot hint and note
28 property alias extraData: extraLayout.data
29
30 readonly property var fact: cell.param ? factFor(cell.param) : null
31 readonly property bool isBitmask: fact ? fact.bitmaskStrings.length > 0 : false
32 readonly property bool isEnum: fact ? !isBitmask && fact.enumStrings.length > 0 : false
33 readonly property bool isNumber: fact ? !isBitmask && !isEnum : false
34 readonly property bool _rebootPending: fact !== null && fact.vehicleRebootRequired &&
35 _initialValue !== undefined && fact.rawValue !== _initialValue
36
37 property var _initialValue: undefined
38
39 caption: cell.label
40
41 QGCPalette { id: qgcPal }
42
43 RowLayout {
44 spacing: ScreenTools.defaultFontPixelWidth
45 visible: control.isEnum
46
47 Loader {
48 sourceComponent: control.enumLeading
49 visible: item !== null
50 }
51
52 FactComboBox {
53 Layout.fillWidth: true
54 Layout.maximumWidth: ScreenTools.defaultFontPixelWidth * 50
55 fact: control.fact
56 indexModel: false
57 sizeToContents: true
58 visible: !control.enumChoices
59 }
60
61 ConfigChoiceComboBox {
62 Layout.fillWidth: true
63 Layout.maximumWidth: ScreenTools.defaultFontPixelWidth * 50
64 fact: control.fact
65 choices: control.enumChoices ? control.enumChoices : []
66 visible: control.enumChoices !== null
67 }
68 }
69
70 ColumnLayout {
71 Layout.fillWidth: true
72 Layout.maximumWidth: ScreenTools.defaultFontPixelWidth * 36
73 spacing: ScreenTools.defaultFontPixelHeight * 0.25
74 visible: control.isBitmask
75
76 Repeater {
77 model: control.isBitmask ? control.fact.bitmaskStrings : []
78
79 FactBitMaskCheckBoxSlider {
80 objectName: control.objectNamePrefix + "_bit_" + control.fact.name + "_" + index
81 Layout.fillWidth: true
82 text: modelData
83 fact: control.fact
84 bitMask: control.fact.bitmaskValues[index]
85
86 required property int index
87 required property string modelData
88 }
89 }
90 }
91
92 RowLayout {
93 spacing: ScreenTools.defaultFontPixelWidth
94 visible: control.isNumber
95
96 FactTextField {
97 Layout.preferredWidth: ScreenTools.defaultFontPixelWidth * 14
98 fact: control.fact
99 }
100
101 Loader {
102 sourceComponent: control.numberTrailing
103 visible: item !== null
104 }
105 }
106
107 ColumnLayout {
108 id: extraLayout
109 spacing: ScreenTools.defaultFontPixelHeight * 0.25
110 visible: children.length > 0
111 }
112
113 BatteryThresholdBar {
114 // visibleRows only keeps this cell when all three parameters exist
115 visible: control.cell.thresholdBar !== undefined
116 emergency: control.cell.thresholdBar ? control.factFor(control.cell.thresholdBar[0]).rawValue : 0
117 critical: control.cell.thresholdBar ? control.factFor(control.cell.thresholdBar[1]).rawValue : 0
118 low: control.cell.thresholdBar ? control.factFor(control.cell.thresholdBar[2]).rawValue : 0
119 }
120
121 QGCChip {
122 objectName: control.objectNamePrefix + "_rebootChip_" + (control.cell.param !== undefined ? control.cell.param : "")
123 text: control._rebootPending ? qsTr("Reboot required") : qsTr("Applies after reboot")
124 textColor: control._rebootPending ? qgcPal.warningText : qgcPal.textSecondary
125 visible: control.fact ? control.fact.vehicleRebootRequired : false
126 }
127
128 ConfigNote {
129 Layout.preferredWidth: Math.min(implicitWidth, ScreenTools.defaultFontPixelWidth * 20)
130 text: control.cell.note !== undefined ? control.cell.note : ""
131 }
132
133 Component.onCompleted: {
134 if (!fact) {
135 return
136 }
137 if (!(cell.param in initialValues)) {
138 initialValues[cell.param] = fact.rawValue
139 }
140 _initialValue = initialValues[cell.param]
141 }
142}