2import QGroundControl.Controls
3import QGroundControl.LogManager
9 objectName: "settingsPage_AppLogViewer"
11 readonly property real _indicatorWidth: ScreenTools.defaultFontPixelWidth * 0.4
12 readonly property real _margin: ScreenTools.defaultFontPixelWidth
13 readonly property real _cellLeftMargin: _margin * 0.3
14 readonly property real _cellRightMargin: _cellLeftMargin
15 readonly property real _rowHeight: ScreenTools.defaultFontPixelHeight * 1.6
17 function _levelColor(lvl) {
19 case LogEntry.Debug: return qgcPal.colorGrey
20 case LogEntry.Info: return qgcPal.text
21 case LogEntry.Warning: return qgcPal.colorOrange
22 case LogEntry.Critical: return qgcPal.colorRed
23 case LogEntry.Fatal: return qgcPal.colorRed
24 default: return qgcPal.text
31 colorGroupEnabled: enabled
38 // ── Column header ────────────────────────────────────────
39 HorizontalHeaderView {
42 Layout.fillWidth: true
47 required property var display
49 color: qgcPal.windowShade
50 implicitHeight: headerLabel.contentHeight + ScreenTools.defaultFontPixelHeight * 0.4
51 implicitWidth: headerLabel.contentWidth + ScreenTools.defaultFontPixelWidth * 2
56 anchors.left: parent.left
57 anchors.leftMargin: _margin * 0.5
58 anchors.verticalCenter: parent.verticalCenter
60 font.family: ScreenTools.fixedFontFamily
61 font.pointSize: ScreenTools.defaultFontPointSize
62 text: parent.display ?? ""
66 anchors.bottom: parent.bottom
67 color: qgcPal.groupBorder
73 anchors.right: parent.right
74 color: qgcPal.groupBorder
81 // ── Log table ────────────────────────────────────────────
84 Layout.fillHeight: true
85 Layout.fillWidth: true
86 boundsBehavior: Flickable.StopAtBounds
90 model: LogManager.model
91 resizableColumns: true
94 readonly property real minMessageColumnWidthInChars: 40
96 columnWidthProvider: function (col) {
97 const explicit_ = tableView.explicitColumnWidth(col)
101 const charWidth = ScreenTools.defaultFontPixelWidth
102 const compact = _cachedWidth < charWidth * 60
103 const catW = compact ? charWidth * 14 : charWidth * 22
104 const tsW = compact ? charWidth * 9 : charWidth * 12
105 const srcW = compact ? charWidth * 16 : charWidth * 22
107 case LogEntry.MessageColumn:
108 return Math.max(charWidth * minMessageColumnWidthInChars, _cachedWidth - catW - tsW - srcW)
109 case LogEntry.CategoryColumn:
111 case LogEntry.TimestampColumn:
113 case LogEntry.SourceColumn:
119 property bool _loadCompleted: false
120 property real _cachedWidth: 0
121 property bool _following: false
122 property bool _atBottom: false
124 function _updateAtBottom() {
125 if (!_loadCompleted) {
128 const maxY = contentHeight - height
132 _atBottom = (contentY >= maxY - _rowHeight)
134 // Stop following if user scrolls away from bottom
141 _cachedWidth = width;
142 _layoutTimer.restart();
145 onContentYChanged: _updateAtBottom()
146 onContentHeightChanged: _updateAtBottom()
147 onHeightChanged: _updateAtBottom()
149 Component.onCompleted: {
150 _cachedWidth = width;
151 _loadCompleted = true;
159 onTriggered: tableView.forceLayout()
162 delegate: Rectangle {
163 required property int column
164 required property var display
165 required property int level
166 required property int row
168 color: row % 2 === 0 ? qgcPal.window : qgcPal.windowShade
169 implicitHeight: _rowHeight
172 anchors.bottom: parent.bottom
173 anchors.left: parent.left
174 anchors.top: parent.top
175 color: root._levelColor(parent.level)
176 visible: parent.column === 0 && parent.level >= LogEntry.Warning
177 width: _indicatorWidth
181 anchors.left: parent.left
182 anchors.leftMargin: parent.column === 0 ? _indicatorWidth + _cellLeftMargin : _cellLeftMargin
183 anchors.right: parent.right
184 anchors.rightMargin: _cellRightMargin
185 anchors.verticalCenter: parent.verticalCenter
186 color: root._levelColor(parent.level)
187 elide: Text.ElideRight
188 font.family: ScreenTools.fixedFontFamily
189 font.pointSize: ScreenTools.defaultFontPointSize
190 text: parent.display ?? ""
195 x: tableView.contentX + (tableView.width - width) / 2
196 y: tableView.contentY + (tableView.height - height) / 2
197 color: qgcPal.colorGrey
198 text: qsTr("No log entries")
199 visible: tableView.rows === 0
207 if (tableView.rows > 0)
208 tableView.positionViewAtRow(tableView.rows - 1, TableView.AlignBottom);
213 function onRowsInserted() {
214 if (tableView._loadCompleted && tableView._following) {
215 scrollTimer.restart();
219 target: LogManager.model
223 // ── Separator ─────────────────────────────────────────────
225 Layout.fillWidth: true
226 Layout.preferredHeight: 1
227 color: qgcPal.groupBorder
230 // ── Filter bar ────────────────────────────────────────────
232 Layout.fillWidth: true
233 Layout.preferredHeight: filterRow.implicitHeight + _margin
234 color: qgcPal.windowShade
240 anchors.leftMargin: _margin
241 anchors.rightMargin: _margin
242 contentWidth: filterRow.width
243 flickableDirection: Flickable.HorizontalFlick
248 height: filterFlickable.height
249 spacing: _margin * 0.75
250 width: Math.max(filterFlickable.width, implicitWidth)
253 text: qsTr("Categories")
255 onClicked: filtersDialogFactory.open()
261 model: [qsTr("All Levels"), qsTr("Debug"), qsTr("Info"), qsTr("Warning"), qsTr("Critical"), qsTr("Fatal")]
264 Component.onCompleted: currentIndex = LogManager.model.filterLevel + 1
265 onActivated: index => {
266 LogManager.model.filterLevel = index - 1;
273 model: [qsTr("All Categories")].concat(LogManager.model.categoriesList)
276 onActivated: index => {
277 LogManager.model.filterCategory = index === 0 ? "" : model[index];
284 Layout.fillWidth: true
285 Layout.minimumWidth: _margin * 10
286 placeholderText: qsTr("Search…")
288 onTextChanged: LogManager.model.setFilterTextDeferred(text)
292 ToolTip.text: qsTr("Regex search")
293 ToolTip.visible: hovered
295 checked: LogManager.model.filterRegex
298 onClicked: LogManager.model.filterRegex = checked
302 color: qgcPal.colorRed
304 text: qsTr("\u26A0 Disk Error")
305 visible: LogManager.hasError
310 onClicked: LogManager.clearError()
317 onClicked: saveFileDialog.openForSave()
323 onClicked: LogManager.model.clear()
331 anchors.horizontalCenter: parent.horizontalCenter
332 anchors.topMargin: headerView.height + _margin
333 anchors.top: parent.top
334 text: qsTr("Show Latest")
335 visible: tableView._loadCompleted && !tableView._atBottom && tableView.rows > 0
339 tableView._following = true
340 tableView.positionViewAtRow(tableView.rows - 1, TableView.AlignBottom)
344 QGCPopupDialogFactory {
345 id: filtersDialogFactory
347 dialogComponent: Component {
348 LoggingCategoriesDialog {
356 readonly property var _suffixes: ["txt", "csv"]
358 defaultSuffix: _suffixes[QGroundControl.settingsManager.logManagerSettings.saveFormat.rawValue]
359 folder: QGroundControl.settingsManager.appSettings.logSavePath
360 title: qsTr("Save app log")
362 onAcceptedForSave: file => {
363 LogManager.writeMessages(file)