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 _logLevelNames: LogManager.categoryLogLevelNames()
11 readonly property var _logLevelValues: LogManager.categoryLogLevelValues()
12 readonly property var _flatModel: QGCLoggingCategoryManager.flatModel
13 readonly property var _filteredModel: QGCLoggingCategoryManager.filteredFlatModel
14
15 buttons: Dialog.Close
16 title: qsTr("Logging Categories")
17
18 QGCPalette {
19 id: qgcPal
20
21 colorGroupEnabled: enabled
22 }
23
24 ColumnLayout {
25 width: maxContentAvailableWidth
26
27 SettingsGroupLayout {
28 Layout.fillWidth: true
29 heading: qsTr("Search")
30
31 RowLayout {
32 Layout.fillWidth: true
33 spacing: ScreenTools.defaultFontPixelHeight / 2
34
35 QGCTextField {
36 id: searchText
37
38 Layout.fillWidth: true
39 placeholderText: qsTr("Filter categories…")
40
41 onTextChanged: QGCLoggingCategoryManager.setFilterText(text)
42 }
43
44 QGCButton {
45 text: qsTr("Clear")
46
47 onClicked: searchText.text = ""
48 }
49 }
50 }
51
52 SettingsGroupLayout {
53 Layout.fillWidth: true
54 heading: qsTr("Active Categories")
55
56 Repeater {
57 model: _flatModel
58
59 QGCLabel {
60 required property bool enabled
61 required property string fullName
62 required property int logLevel
63
64 Layout.fillWidth: true
65 text: fullName + " (" + (_logLevelNames[_logLevelValues.indexOf(logLevel)] ?? qsTr("Warning")) + ")"
66 visible: enabled
67 }
68 }
69
70 QGCButton {
71 text: qsTr("Reset All")
72
73 onClicked: QGCLoggingCategoryManager.disableAllCategories()
74 }
75 }
76
77 // Tree view (no search)
78 SettingsGroupLayout {
79 Layout.fillWidth: true
80 heading: qsTr("Categories")
81 visible: searchText.text === ""
82
83 TreeView {
84 id: treeView
85
86 readonly property real _rowHeight: ScreenTools.defaultFontPixelHeight * 2.2
87
88 Layout.fillWidth: true
89 Layout.maximumHeight: ScreenTools.defaultFontPixelHeight * 40
90 Layout.preferredHeight: contentHeight > 0 ? Math.min(contentHeight, ScreenTools.defaultFontPixelHeight * 40)
91 : ScreenTools.defaultFontPixelHeight * 30
92 clip: true
93 model: QGCLoggingCategoryManager.treeModel
94
95 delegate: Item {
96 id: treeDelegate
97
98 readonly property real _indent: ScreenTools.defaultFontPixelWidth * 1.5
99
100 implicitHeight: treeView._rowHeight
101 implicitWidth: treeView.width
102
103 required property int depth
104 required property bool expanded
105 required property string fullName
106 required property bool hasChildren
107 required property int logLevel
108 required property int row
109 required property string shortName
110 required property TreeView treeView
111
112 RowLayout {
113 anchors.fill: parent
114 anchors.leftMargin: treeDelegate.depth * treeDelegate._indent
115 spacing: ScreenTools.defaultFontPixelWidth * 0.5
116
117 QGCLabel {
118 text: treeDelegate.expanded ? "\u25BE" : "\u25B8"
119 visible: treeDelegate.hasChildren
120
121 QGCMouseArea {
122 anchors.fill: parent
123 anchors.margins: -ScreenTools.defaultFontPixelWidth
124
125 onClicked: treeView.toggleExpanded(treeDelegate.row)
126 }
127 }
128
129 // Spacer when no expand arrow
130 Item {
131 implicitWidth: ScreenTools.defaultFontPixelWidth
132 visible: !treeDelegate.hasChildren
133 }
134
135 QGCLabel {
136 Layout.fillWidth: true
137 elide: Text.ElideRight
138 text: treeDelegate.shortName
139 }
140
141 QGCComboBox {
142 currentIndex: _logLevelValues.indexOf(treeDelegate.logLevel)
143 model: _logLevelNames
144 sizeToContents: true
145
146 onActivated: idx => {
147 const modelIndex = treeView.index(treeDelegate.row, 0);
148 treeView.model.setData(modelIndex, _logLevelValues[idx], LoggingCategoryTreeModel.LogLevelRole);
149 }
150 }
151 }
152 }
153
154 Component.onCompleted: _delayedExpand.start()
155
156 Timer {
157 id: _delayedExpand
158 interval: 0
159 onTriggered: treeView.expandRecursively(-1, -1)
160 }
161 }
162
163 QGCLabel {
164 color: qgcPal.colorGrey
165 text: qsTr("No categories registered")
166 visible: treeView.rows === 0
167 }
168 }
169
170 // Flat filtered view (with search)
171 SettingsGroupLayout {
172 Layout.fillWidth: true
173 heading: qsTr("Search Results")
174 visible: searchText.text !== ""
175
176 Repeater {
177 id: searchRepeater
178
179 model: _filteredModel
180
181 RowLayout {
182 required property string fullName
183 required property int index
184 required property int logLevel
185
186 Layout.fillWidth: true
187
188 QGCLabel {
189 Layout.fillWidth: true
190 text: fullName
191 }
192
193 QGCComboBox {
194 currentIndex: _logLevelValues.indexOf(logLevel)
195 model: _logLevelNames
196 sizeToContents: true
197
198 onActivated: idx => {
199 const sourceIndex = _filteredModel.mapToSource(_filteredModel.index(parent.index, 0));
200 _flatModel.setData(sourceIndex, _logLevelValues[idx], LoggingCategoryFlatModel.LogLevelRole);
201 }
202 }
203 }
204 }
205
206 QGCLabel {
207 color: qgcPal.colorGrey
208 text: qsTr("No matching categories")
209 visible: searchRepeater.count === 0 && searchText.text !== ""
210 }
211 }
212 }
213}