6import QGroundControl.Controls
10 objectName: "vehicleConfig_root"
12 z: QGroundControl.zOrderTopMost
14 // This need to block click event leakage to underlying map.
19 QGCPalette { id: qgcPal; colorGroupEnabled: true }
21 readonly property real _defaultTextHeight: ScreenTools.defaultFontPixelHeight
22 readonly property real _defaultTextWidth: ScreenTools.defaultFontPixelWidth
23 readonly property real _horizontalMargin: _defaultTextWidth / 2
24 readonly property real _verticalMargin: _defaultTextHeight / 2
25 readonly property real _buttonWidth: _defaultTextWidth * 18
26 readonly property string _armedVehicleText: qsTr("This operation cannot be performed while the vehicle is armed.")
28 property var _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle
29 property bool _vehicleArmed: _activeVehicle ? _activeVehicle.armed : false
30 property string _messagePanelText: qsTr("missing message panel text")
31 property bool _fullParameterVehicleAvailable: _activeVehicle && QGroundControl.multiVehicleManager.parameterReadyVehicleAvailable && !_activeVehicle.parameterManager.missingParameters
32 property var _corePlugin: QGroundControl.corePlugin
35 property int _selectedComponentIndex: -1 // -1 = summary or special button
36 property int _selectedSectionIndex: -1
37 property string _selectedSpecial: "" // "summary", "parameters", "firmware", "opticalflow"
38 property bool _showingPrereqMessage: false // Panel area shows prerequisite message instead of selected component
39 property var _expandedComponents: ({})
40 property int _expandedRevision: 0
41 property string _searchQuery: ""
42 property real _fullListWidth: 0 // Button column width with no search active
44 Binding on _fullListWidth {
45 when: vehicleConfigView._searchQuery.trim() === ""
46 value: buttonColumn.implicitWidth
47 restoreMode: Binding.RestoreNone
50 function _setExpanded(compIndex, value) {
51 _expandedComponents[compIndex] = value
55 function _isExpanded(compIndex) {
56 void _expandedRevision
57 return !!_expandedComponents[compIndex]
60 /// Translated display name for a section ID. JSON-driven components translate via the JSON
61 /// filename context; hand-coded components provide sectionDisplayName().
62 function _sectionDisplayName(component, sectionId) {
63 let context = _translationContext(component)
65 return qsTranslate(context, sectionId)
67 if (component && typeof component.sectionDisplayName === "function") {
68 return component.sectionDisplayName(sectionId)
73 /// Get the section ID for a sidebar entry.
74 function _sectionId(compIndex, sectionIndex) {
75 if (sectionIndex < 0 || !_fullParameterVehicleAvailable) return ""
76 var components = _activeVehicle.autopilotPlugin.vehicleComponents
77 if (compIndex < 0 || compIndex >= components.length) return ""
78 var secs = components[compIndex].sectionIds
79 if (sectionIndex < secs.length) return secs[sectionIndex]
83 /// Extract the translation context (JSON filename) from a component.
84 function _translationContext(component) {
85 if (!component || !component.vehicleConfigJson) return ""
86 var path = component.vehicleConfigJson.toString()
87 var slash = path.lastIndexOf("/")
88 return slash >= 0 ? path.substring(slash + 1) : path
91 function _componentMatchesSearch(component) {
92 if (_searchQuery.trim() === "") return true
93 var query = _searchQuery.toLowerCase().trim()
94 if (component.name.toLowerCase().indexOf(query) !== -1) return true
95 var context = _translationContext(component)
96 var secs = component.sectionIds
98 for (var i = 0; i < secs.length; i++) {
99 if (secs[i].toLowerCase().indexOf(query) !== -1) return true
100 let displayName = _sectionDisplayName(component, secs[i])
101 if (displayName !== secs[i] && displayName.toLowerCase().indexOf(query) !== -1) {
106 var keywords = component.sectionKeywords
108 for (var key in keywords) {
109 var terms = keywords[key]
110 for (var j = 0; j < terms.length; j++) {
111 if (terms[j].toLowerCase().indexOf(query) !== -1) return true
112 if (context && qsTranslate(context, terms[j]).toLowerCase().indexOf(query) !== -1) return true
116 var componentKeywords = component.searchKeywords
117 if (componentKeywords) {
118 for (var k = 0; k < componentKeywords.length; k++) {
119 if (componentKeywords[k].toLowerCase().indexOf(query) !== -1) {
127 function _sectionMatchesSearch(component, sectionId) {
128 if (_searchQuery.trim() === "") return true
129 var query = _searchQuery.toLowerCase().trim()
130 if (sectionId.toLowerCase().indexOf(query) !== -1) return true
131 var context = _translationContext(component)
132 let displayName = _sectionDisplayName(component, sectionId)
133 if (displayName !== sectionId && displayName.toLowerCase().indexOf(query) !== -1) {
136 var keywords = component.sectionKeywords
137 if (keywords && keywords[sectionId]) {
138 var terms = keywords[sectionId]
139 for (var i = 0; i < terms.length; i++) {
140 if (terms[i].toLowerCase().indexOf(query) !== -1) return true
141 if (context && qsTranslate(context, terms[i]).toLowerCase().indexOf(query) !== -1) return true
147 function _componentVisible(component) {
148 if (!component || component.setupSource.toString() === "") {
151 return _searchQuery.trim() === "" || _componentMatchesSearch(component)
154 function _anyComponentVisible() {
155 if (!_fullParameterVehicleAvailable) {
158 return _activeVehicle.autopilotPlugin.vehicleComponents.some(_componentVisible)
161 function showSummaryPanel() {
162 if (mainWindow.allowViewSwitch()) {
167 function _showSummaryPanel() {
168 _selectedSpecial = "summary"
169 _selectedComponentIndex = -1
170 _selectedSectionIndex = -1
171 if (_fullParameterVehicleAvailable) {
172 if (_activeVehicle.autopilotPlugin.vehicleComponents.length === 0) {
173 panelLoader.setSourceComponent(noComponentsVehicleSummaryComponent)
175 panelLoader.setSource("qrc:/qml/QGroundControl/VehicleSetup/VehicleSummary.qml")
177 } else if (QGroundControl.multiVehicleManager.parameterReadyVehicleAvailable) {
178 panelLoader.setSourceComponent(missingParametersVehicleSummaryComponent)
180 panelLoader.setSourceComponent(disconnectedVehicleAndParamsSummaryComponent)
184 function showPanel(specialName, qmlSource) {
185 if (mainWindow.allowViewSwitch()) {
186 _selectedSpecial = specialName
187 _selectedComponentIndex = -1
188 _selectedSectionIndex = -1
189 panelLoader.setSource(qmlSource)
193 function _navigateToComponent(compIndex, sectionIndex) {
194 if (!mainWindow.allowViewSwitch()) return
195 if (!_fullParameterVehicleAvailable) return
197 var components = _activeVehicle.autopilotPlugin.vehicleComponents
198 if (compIndex < 0 || compIndex >= components.length) return
199 var vehicleComponent = components[compIndex]
201 _selectedSpecial = ""
203 // If component opts in and root was clicked, auto-select first section
204 if (sectionIndex < 0 && vehicleComponent.showFirstSectionOnRootClick && vehicleComponent.sectionIds.length > 0) {
207 _selectedSectionIndex = sectionIndex
209 var autopilotPlugin = _activeVehicle.autopilotPlugin
210 var prereq = autopilotPlugin.prerequisiteSetup(vehicleComponent)
212 // Selection state still updates so the tree expands and highlights
213 // normally; only the panel area shows the prerequisite message
214 _selectedComponentIndex = compIndex
215 _showingPrereqMessage = true
216 _messagePanelText = qsTr("%1 setup must be completed prior to %2 setup.").arg(prereq).arg(vehicleComponent.name)
217 panelLoader.setSourceComponent(messagePanelComponent)
221 if (_selectedComponentIndex !== compIndex || _showingPrereqMessage) {
222 _selectedComponentIndex = compIndex
223 _showingPrereqMessage = false
224 panelLoader.setSource(vehicleComponent.setupSource, vehicleComponent)
227 // Apply section filter
228 if (panelLoader.item && typeof panelLoader.item.sectionIdFilter !== "undefined") {
229 panelLoader.item.sectionIdFilter = _sectionId(compIndex, sectionIndex)
233 function showParametersPanel() {
234 showPanel("parameters", "qrc:/qml/QGroundControl/VehicleSetup/SetupParameterEditor.qml")
237 function showVehicleComponentPanel(vehicleComponent) {
238 if (!mainWindow.allowViewSwitch()) return
239 if (!_fullParameterVehicleAvailable) return
241 var components = _activeVehicle.autopilotPlugin.vehicleComponents
242 for (var i = 0; i < components.length; i++) {
243 if (components[i] === vehicleComponent) {
244 _navigateToComponent(i, -1)
250 Component.onCompleted: _showSummaryPanel()
253 target: QGroundControl.corePlugin
254 function onShowAdvancedUIChanged(showAdvancedUI) {
255 if (!showAdvancedUI) {
262 target: QGroundControl.multiVehicleManager
263 function onParameterReadyVehicleAvailableChanged(parametersReady) {
264 if (parametersReady || _selectedSpecial === "summary" || _selectedSpecial !== "firmware") {
272 function onLoaded() {
273 if (panelLoader.item && typeof panelLoader.item.sectionIdFilter !== "undefined") {
274 panelLoader.item.sectionIdFilter = _sectionId(_selectedComponentIndex, _selectedSectionIndex)
280 target: panelLoader.item
281 ignoreUnknownSignals: true
283 function onComponentRequested(vehicleComponent) {
284 showVehicleComponentPanel(vehicleComponent)
289 id: noComponentsVehicleSummaryComponent
291 color: qgcPal.windowCard
293 anchors.margins: _defaultTextWidth * 2
295 verticalAlignment: Text.AlignVCenter
296 horizontalAlignment: Text.AlignHCenter
297 wrapMode: Text.WordWrap
298 font.pointSize: ScreenTools.mediumFontPointSize
299 text: qsTr("%1 does not currently support configuration of your vehicle. ").arg(QGroundControl.appName) +
300 "If your vehicle is already configured you can still Fly."
306 id: disconnectedVehicleAndParamsSummaryComponent
309 color: qgcPal.windowCard
311 anchors.centerIn: parent
312 spacing: ScreenTools.defaultFontPixelHeight
314 anchors.horizontalCenter: parent.horizontalCenter
315 width: disconnectedRect.width - _defaultTextWidth * 4
316 horizontalAlignment: Text.AlignHCenter
317 wrapMode: Text.WordWrap
318 font.pointSize: ScreenTools.largeFontPointSize
319 text: !_activeVehicle
320 ? qsTr("Vehicle configuration pages will display after you connect your vehicle and parameters have been downloaded.")
321 : (_activeVehicle.parameterManager.parameterDownloadSkipped
322 ? qsTr("Parameter download was skipped because the vehicle is armed. Configuration pages will be available after parameters are downloaded.")
323 : qsTr("Waiting for vehicle parameters to download…"))
326 anchors.horizontalCenter: parent.horizontalCenter
327 text: qsTr("Download Parameters")
328 visible: _activeVehicle && _activeVehicle.parameterManager.parameterDownloadSkipped
329 enabled: _activeVehicle && _activeVehicle.parameterManager.parameterDownloadSkipped && _activeVehicle.parameterManager.loadProgress === 0
330 onClicked: _activeVehicle.parameterManager.refreshAllParameters()
337 id: missingParametersVehicleSummaryComponent
340 color: qgcPal.windowCard
343 anchors.margins: _defaultTextWidth * 2
345 verticalAlignment: Text.AlignVCenter
346 horizontalAlignment: Text.AlignHCenter
347 wrapMode: Text.WordWrap
348 font.pointSize: ScreenTools.mediumFontPointSize
349 text: qsTr("Vehicle did not return the full parameter list. ") +
350 qsTr("As a result, the configuration pages are not available.")
356 id: messagePanelComponent
359 objectName: "vehicleConfig_messagePanel"
362 anchors.margins: _defaultTextWidth * 2
364 verticalAlignment: Text.AlignVCenter
365 horizontalAlignment: Text.AlignHCenter
366 wrapMode: Text.WordWrap
367 font.pointSize: ScreenTools.mediumFontPointSize
368 text: _messagePanelText
374 anchors.fill: leftPanel
375 anchors.margins: -_horizontalMargin * 2
376 color: qgcPal.windowPanel
377 border.color: qgcPal.borderSubtle
378 radius: ScreenTools.defaultBorderRadius
383 width: Math.max(buttonColumn.implicitWidth, _fullListWidth, ScreenTools.isMobile ? 0 : ScreenTools.defaultFontPixelWidth * 22)
384 anchors.topMargin: _verticalMargin * 1.5
385 anchors.bottomMargin: _verticalMargin * 1.5
386 anchors.top: parent.top
387 anchors.bottom: parent.bottom
388 anchors.leftMargin: _horizontalMargin * 3
389 anchors.left: parent.left
390 spacing: _verticalMargin / 2
394 objectName: "vehicleConfig_searchField"
395 Layout.fillWidth: true
396 placeholderText: qsTr("Search configuration...")
397 visible: _fullParameterVehicleAvailable
400 vehicleConfigView._searchQuery = text
405 objectName: "vehicleConfig_sidebarFlickable"
406 Layout.fillWidth: true
407 Layout.fillHeight: true
408 contentHeight: buttonColumn.height + _verticalMargin
409 flickableDirection: Flickable.VerticalFlick
420 objectName: "vehicleConfig_summary"
421 icon.source: "/qmlimages/VehicleSummaryIcon.png"
422 checked: vehicleConfigView._selectedSpecial === "summary"
423 text: qsTr("Overview")
424 Layout.fillWidth: true
425 visible: vehicleConfigView._searchQuery.trim() === ""
427 onClicked: showSummaryPanel()
430 // When the component group is empty only this divider shows, not the second one
432 objectName: "vehicleConfig_summaryDivider"
433 visible: summaryButton.visible &&
434 (vehicleConfigView._anyComponentVisible() || opticalFlowButton.visible ||
435 parametersButton.visible || firmwareButton.visible)
438 // Vehicle component tree
440 id: componentRepeater
441 model: _fullParameterVehicleAvailable ? _activeVehicle.autopilotPlugin.vehicleComponents : 0
446 Layout.fillWidth: true
448 required property int index
449 required property var modelData
451 property var comp: modelData
452 property string compName: comp ? comp.name : ""
453 property var compSectionIds: comp ? comp.sectionIds : []
454 property bool isSelected: vehicleConfigView._selectedComponentIndex === index && vehicleConfigView._selectedSpecial === ""
455 property bool hasSections: compSectionIds.length > 1
456 property bool isSearching: vehicleConfigView._searchQuery.trim() !== ""
457 property bool matchesSearch: comp ? vehicleConfigView._componentMatchesSearch(comp) : false
458 property bool isExpanded: hasSections && (isSearching ? matchesSearch : vehicleConfigView._isExpanded(index))
460 visible: vehicleConfigView._componentVisible(comp)
463 Layout.fillWidth: true
464 objectName: "vehicleConfig_comp_" + compColumn.compName.replace(/ /g, "")
465 icon.source: compColumn.comp ? compColumn.comp.iconResource : ""
466 setupComplete: compColumn.comp ? compColumn.comp.setupComplete : true
467 text: compColumn.compName
468 expandable: compColumn.hasSections
469 expanded: compColumn.isExpanded
470 checked: compColumn.isSelected && vehicleConfigView._selectedSectionIndex === -1
473 // Only a click on the already-selected component collapses it
474 const wasSelected = compColumn.isSelected
475 vehicleConfigView._navigateToComponent(compColumn.index, -1)
476 if (compColumn.hasSections) {
477 if (wasSelected && compColumn.isExpanded) {
478 vehicleConfigView._setExpanded(compColumn.index, false)
479 } else if (!compColumn.isExpanded) {
480 vehicleConfigView._setExpanded(compColumn.index, true)
486 if (!mainWindow.allowViewSwitch()) return
487 var expanding = !compColumn.isExpanded
488 vehicleConfigView._setExpanded(compColumn.index, expanding)
489 if (!expanding && compColumn.isSelected) {
490 vehicleConfigView._navigateToComponent(compColumn.index, -1)
497 model: compColumn.isExpanded ? compColumn.compSectionIds : []
501 objectName: "vehicleConfig_section_" + modelData.replace(/ /g, "")
502 Layout.fillWidth: true
503 padding: ScreenTools.defaultFontPixelWidth * 0.75
504 leftPadding: ScreenTools.defaultFontPixelWidth
505 hoverEnabled: !ScreenTools.isMobile
507 property int sectionIndex: index
508 property bool sectionChecked: compColumn.isSelected && vehicleConfigView._selectedSectionIndex === sectionIndex
509 property bool sectionSetupComplete: {
510 if (!compColumn.comp) {
513 // Referencing comp.setupComplete re-evaluates this binding whenever a
514 // setup trigger parameter changes, since sectionSetupComplete() is a
515 // plain function call which QML cannot otherwise track
516 void compColumn.comp.setupComplete
517 return typeof compColumn.comp.sectionSetupComplete === "function"
518 ? compColumn.comp.sectionSetupComplete(modelData)
521 property bool sectionMatchesSearch: {
522 if (!compColumn.isSearching) return true
523 return vehicleConfigView._sectionMatchesSearch(compColumn.comp, modelData)
525 property bool sectionContentVisible: {
526 if (!compColumn.isSelected) return true
527 if (!panelLoader.item) return true
528 if (typeof panelLoader.item.sectionVisible !== "function") return true
529 return panelLoader.item.sectionVisible(modelData)
531 property color textColor: qgcPal.textPrimary
532 visible: sectionMatchesSearch && sectionContentVisible
534 background: Rectangle {
535 color: sectionBtn.sectionChecked || sectionBtn.pressed ? qgcPal.accentSubtle : (sectionBtn.enabled && sectionBtn.hovered ? qgcPal.windowCard : "transparent")
536 border.width: sectionBtn.sectionChecked || sectionBtn.pressed ? 1 : 0
537 border.color: qgcPal.accent
538 radius: ScreenTools.defaultFontPixelWidth / 2
541 contentItem: RowLayout {
542 spacing: ScreenTools.defaultFontPixelWidth * 0.5
545 width: ScreenTools.defaultFontPixelWidth
548 color: sectionBtn.sectionSetupComplete ? qgcPal.colorGreen : qgcPal.colorOrange
549 visible: !sectionBtn.sectionSetupComplete
553 text: vehicleConfigView._sectionDisplayName(compColumn.comp, modelData)
554 color: sectionBtn.textColor
555 font.pointSize: ScreenTools.defaultFontPointSize * 0.9
556 horizontalAlignment: Text.AlignLeft
557 Layout.fillWidth: true
562 vehicleConfigView._navigateToComponent(compColumn.index, sectionIndex)
569 // Optical Flow (special)
571 id: opticalFlowButton
572 visible: _activeVehicle ? _activeVehicle.flowImageIndex > 0 : false
573 text: qsTr("Optical Flow")
574 Layout.fillWidth: true
575 checked: vehicleConfigView._selectedSpecial === "opticalflow"
576 onClicked: showPanel("opticalflow", "qrc:/qml/QGroundControl/VehicleSetup/OpticalFlowSensor.qml")
580 objectName: "vehicleConfig_componentsDivider"
581 visible: (vehicleConfigView._anyComponentVisible() || opticalFlowButton.visible) &&
582 (parametersButton.visible || firmwareButton.visible)
587 objectName: "vehicleConfig_parametersButton"
588 visible: QGroundControl.multiVehicleManager.parameterReadyVehicleAvailable &&
589 !_activeVehicle.usingHighLatencyLink &&
590 _corePlugin.showAdvancedUI &&
591 vehicleConfigView._searchQuery.trim() === ""
592 text: qsTr("Parameters")
593 Layout.fillWidth: true
594 icon.source: "/qmlimages/subMenuButtonImage.png"
595 checked: vehicleConfigView._selectedSpecial === "parameters"
596 onClicked: showPanel("parameters", "qrc:/qml/QGroundControl/VehicleSetup/SetupParameterEditor.qml")
601 objectName: "vehicleConfig_firmwareButton"
602 icon.source: "/qmlimages/FirmwareUpgradeIcon.png"
603 visible: !ScreenTools.isMobile && _corePlugin.options.showFirmwareUpgrade &&
604 vehicleConfigView._searchQuery.trim() === ""
605 text: qsTr("Firmware")
606 Layout.fillWidth: true
607 checked: vehicleConfigView._selectedSpecial === "firmware"
609 onClicked: showPanel("firmware", "qrc:/qml/QGroundControl/VehicleSetup/FirmwareUpgrade.qml")
617 objectName: "vehicleConfig_panelLoader"
618 anchors.topMargin: _verticalMargin
619 anchors.bottomMargin: _verticalMargin
620 anchors.leftMargin: _horizontalMargin * 4
621 anchors.rightMargin: _horizontalMargin
622 anchors.left: leftPanel.right
623 anchors.right: parent.right
624 anchors.top: parent.top
625 anchors.bottom: parent.bottom
627 function setSource(source, vehicleComponent) {
628 panelLoader.source = ""
629 panelLoader.vehicleComponent = vehicleComponent
630 panelLoader.source = source
633 function setSourceComponent(sourceComponent, vehicleComponent) {
634 panelLoader.sourceComponent = undefined
635 panelLoader.vehicleComponent = vehicleComponent
636 panelLoader.sourceComponent = sourceComponent
639 property var vehicleComponent