6import QGroundControl.Controls
8// We implement our own TabBar to get around the fact that QtQuick.Controls TabBar does not
9// support hiding tabs. This version supports hiding tabs by setting the visible property
10// on the QGCTabButton instances.
12 property int currentIndex: 0
17 property bool _preventCurrentIndexBindingLoop: false
18 property var _buttons: []
20 function _updateButtons() {
22 for (var i = 0; i < control.children.length; i++) {
23 if (control.children[i].hasOwnProperty("checkable")) {
24 btns.push(control.children[i])
28 buttonGroup.buttons = _buttons
29 _selectCurrentIndexButton()
32 function _selectCurrentIndexButton() {
33 if (_buttons.length === 0) return
35 _preventCurrentIndexBindingLoop = true
37 if (control.currentIndex === -1) {
38 for (var i = 0; i < _buttons.length; i++) {
39 _buttons[i].checked = false
42 let index = Math.min(Math.max(control.currentIndex, 0), _buttons.length - 1)
43 if (_buttons[index].visible) {
44 _buttons[index].checked = true
46 // Select the first visible tab if the current index is not visible
48 for (var j = 0; j < _buttons.length; j++) {
49 if (_buttons[j].visible) {
50 _buttons[j].checked = true
56 // Sync currentIndex to the actually-selected button so it never remains stale
57 if (control.currentIndex !== index) {
58 control.currentIndex = index
62 _preventCurrentIndexBindingLoop = false
65 Component.onCompleted: _updateButtons()
66 onChildrenChanged: _updateButtons()
67 onCurrentIndexChanged: _selectCurrentIndexButton()
68 onVisibleChildrenChanged: _selectCurrentIndexButton()
73 onCheckedButtonChanged: {
74 if (control._preventCurrentIndexBindingLoop) return
76 for (var i = 0; i < control._buttons.length; i++) {
77 if (control._buttons[i] === checkedButton) {
78 control.currentIndex = i