5import QGroundControl.Controls
6import QGroundControl.FactControls
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.
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
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
37 property var _initialValue: undefined
41 QGCPalette { id: qgcPal }
44 spacing: ScreenTools.defaultFontPixelWidth
45 visible: control.isEnum
48 sourceComponent: control.enumLeading
49 visible: item !== null
53 Layout.fillWidth: true
54 Layout.maximumWidth: ScreenTools.defaultFontPixelWidth * 50
58 visible: !control.enumChoices
61 ConfigChoiceComboBox {
62 Layout.fillWidth: true
63 Layout.maximumWidth: ScreenTools.defaultFontPixelWidth * 50
65 choices: control.enumChoices ? control.enumChoices : []
66 visible: control.enumChoices !== null
71 Layout.fillWidth: true
72 Layout.maximumWidth: ScreenTools.defaultFontPixelWidth * 36
73 spacing: ScreenTools.defaultFontPixelHeight * 0.25
74 visible: control.isBitmask
77 model: control.isBitmask ? control.fact.bitmaskStrings : []
79 FactBitMaskCheckBoxSlider {
80 objectName: control.objectNamePrefix + "_bit_" + control.fact.name + "_" + index
81 Layout.fillWidth: true
84 bitMask: control.fact.bitmaskValues[index]
86 required property int index
87 required property string modelData
93 spacing: ScreenTools.defaultFontPixelWidth
94 visible: control.isNumber
97 Layout.preferredWidth: ScreenTools.defaultFontPixelWidth * 14
102 sourceComponent: control.numberTrailing
103 visible: item !== null
109 spacing: ScreenTools.defaultFontPixelHeight * 0.25
110 visible: children.length > 0
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
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
129 Layout.preferredWidth: Math.min(implicitWidth, ScreenTools.defaultFontPixelWidth * 20)
130 text: control.cell.note !== undefined ? control.cell.note : ""
133 Component.onCompleted: {
137 if (!(cell.param in initialValues)) {
138 initialValues[cell.param] = fact.rawValue
140 _initialValue = initialValues[cell.param]