QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
LoggingCategoriesDialog.qml
Go to the documentation of this file.
1import QGroundControl
2import QGroundControl.Controls
3import QGroundControl.Logging
4import QtQuick
5import QtQuick.Layouts
6
7QGCPopupDialog {
8 id: catDialog
9
10 readonly property var _filteredModel: QGCLoggingCategoryManager.filteredFlatModel
11
12 buttons: Dialog.Close
13 title: qsTr("Logging Categories")
14
15 QGCPalette { id: qgcPal; colorGroupEnabled: enabled }
16
17 QGCCheckBoxSlider {
18 id: _measureSlider
19 visible: false
20 }
21
22 ColumnLayout {
23 SettingsGroupLayout {
24 Layout.fillWidth: true
25 heading: qsTr("Search")
26
27 RowLayout {
28 Layout.fillWidth: true
29 spacing: ScreenTools.defaultFontPixelHeight / 2
30
31 QGCTextField {
32 id: searchText
33 Layout.fillWidth: true
34 placeholderText: qsTr("Filter categories…")
35
36 onTextChanged: _searchDebounce.restart()
37
38 Timer {
39 id: _searchDebounce
40 interval: 200
41 repeat: false
42 onTriggered: QGCLoggingCategoryManager.setFilterText(searchText.text)
43 }
44 }
45
46 QGCButton {
47 text: qsTr("Clear")
48 onClicked: searchText.text = ""
49 }
50 }
51 }
52
53 SettingsGroupLayout {
54 Layout.fillWidth: true
55 heading: qsTr("Active Categories")
56 showDividers: false
57
58 Repeater {
59 model: QGCLoggingCategoryManager.enabledCategories
60
61 QGCCheckBoxSlider {
62 required property string modelData
63
64 Layout.fillWidth: true
65 checked: true
66 text: modelData
67 onToggled: {
68 // Display uses "ADSB.*" but manager stores "ADSB." — strip trailing *
69 const key = modelData.endsWith(".*") ? modelData.slice(0, -1) : modelData
70 QGCLoggingCategoryManager.setCategoryEnabled(key, false)
71 }
72 }
73 }
74
75 QGCButton {
76 text: qsTr("Reset All")
77
78 onClicked: QGCLoggingCategoryManager.disableAllCategories()
79 }
80 }
81
82 // Category list (no search)
83 SettingsGroupLayout {
84 Layout.fillWidth: true
85 heading: qsTr("Categories")
86 visible: searchText.text === ""
87
88 TreeView {
89 id: treeView
90 Layout.preferredWidth: _maxRowWidth
91 Layout.maximumHeight: ScreenTools.defaultFontPixelHeight * 40
92 Layout.preferredHeight: contentHeight > 0 ? Math.min(contentHeight, ScreenTools.defaultFontPixelHeight * 40)
93 : ScreenTools.defaultFontPixelHeight * 30
94 rowSpacing: ScreenTools.defaultFontPixelHeight * 0.25
95 model: QGCLoggingCategoryManager.treeModel
96 clip: true
97
98 property real _maxRowWidth: ScreenTools.defaultFontPixelWidth
99
100 delegate: RowLayout {
101 id: treeViewRowLayout
102 implicitWidth: treeView._maxRowWidth
103 spacing: ScreenTools.defaultFontPixelWidth * 0.5
104
105 required property int depth
106 required property bool expanded
107 required property string fullName
108 required property bool hasChildren
109 required property bool categoryEnabled
110 required property int row
111 required property string shortName
112 required property TreeView treeView
113
114 Component.onCompleted: _calcMaxRowWidth();
115 TableView.onReused: _calcMaxRowWidth();
116
117 function _calcMaxRowWidth() {
118 let indentWidth = treeViewRowLayout.depth > 0 ? rowIndent.width : 0
119 let arrowWidth = treeViewRowLayout.hasChildren ? expandArrow.width : 0
120 let checkBoxSliderWidth = _measureSlider.width + ScreenTools.defaultFontPixelWidth * treeViewRowLayout.shortName.length
121 let spacing = (rowIndent.visible ? treeViewRowLayout.spacing : 0) + (treeViewRowLayout.hasChildren ? treeViewRowLayout.spacing : 0)
122 let rowWidth = indentWidth + arrowWidth + checkBoxSliderWidth + spacing
123 //console.log("update", treeViewRowLayout.fullName, indentWidth, arrowWidth, checkBoxSliderWidth, spacing, rowWidth, treeView._maxRowWidth)
124 if (rowWidth > treeView._maxRowWidth) {
125 treeView._maxRowWidth = rowWidth
126 }
127 }
128
129 Item {
130 id: rowIndent
131 Layout.preferredWidth: ScreenTools.defaultFontPixelWidth * treeViewRowLayout.depth
132 Layout.preferredHeight: 1
133 visible: treeViewRowLayout.depth > 0
134 }
135
136 QGCColoredImage {
137 id: expandArrow
138 Layout.preferredWidth: ScreenTools.defaultFontPixelHeight * 0.5
139 Layout.preferredHeight: Layout.preferredWidth
140 color: qgcPal.text
141 fillMode: Image.PreserveAspectFit
142 rotation: treeViewRowLayout.expanded ? 0 : -90
143 source: "/qmlimages/arrow-down.png"
144 visible: treeViewRowLayout.hasChildren
145
146 QGCMouseArea {
147 anchors.fill: parent
148 anchors.margins: -ScreenTools.defaultFontPixelWidth
149
150 onClicked: treeView.toggleExpanded(treeViewRowLayout.row)
151 }
152 }
153
154 QGCCheckBoxSlider {
155 id: checkBoxSlider
156 Layout.fillWidth: true
157 text: treeViewRowLayout.shortName
158 checked: treeViewRowLayout.categoryEnabled
159 onToggled: QGCLoggingCategoryManager.setCategoryEnabled(treeViewRowLayout.fullName, checked)
160 }
161 }
162 }
163 }
164
165 // Flat filtered view (with search)
166 SettingsGroupLayout {
167 heading: qsTr("Search Results")
168 visible: searchText.text !== ""
169
170 QGCListView {
171 id: searchResultsView
172 Layout.preferredWidth: _maxRowWidth
173 Layout.preferredHeight: Math.min(contentHeight, ScreenTools.defaultFontPixelHeight * 40)
174 clip: true
175 model: _filteredModel
176 spacing: ScreenTools.defaultFontPixelHeight * 0.25
177
178 property real _maxRowWidth: ScreenTools.defaultFontPixelWidth
179
180 delegate: QGCCheckBoxSlider {
181 required property bool categoryEnabled
182 required property string fullName
183
184 width: searchResultsView._maxRowWidth
185 text: fullName
186 checked: categoryEnabled
187 onToggled: QGCLoggingCategoryManager.setCategoryEnabled(fullName, checked)
188
189 Component.onCompleted: _updateMaxWidth()
190 ListView.onReused: _updateMaxWidth()
191
192 function _updateMaxWidth() {
193 let rowWidth = _measureSlider.width + ScreenTools.defaultFontPixelWidth * fullName.length
194 if (rowWidth > searchResultsView._maxRowWidth) {
195 searchResultsView._maxRowWidth = rowWidth
196 }
197 }
198 }
199 }
200
201 QGCLabel {
202 color: qgcPal.colorGrey
203 text: qsTr("No matching categories")
204 visible: searchResultsView.count === 0 && searchText.text !== ""
205 }
206 }
207 }
208}