AppMessages.qml 8.74 KB
Newer Older
1 2
/****************************************************************************
 *
Gus Grubba's avatar
Gus Grubba committed
3
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 5 6 7 8
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/
9

10 11
import QtQuick                  2.3
import QtQuick.Controls         1.2
12
import QtQuick.Controls.Styles  1.4
13
import QtQuick.Dialogs          1.2
14
import QtQuick.Layouts          1.12
15

16
import QGroundControl               1.0
17 18
import QGroundControl.Palette       1.0
import QGroundControl.Controls      1.0
19 20
import QGroundControl.FactSystem    1.0
import QGroundControl.FactControls  1.0
21 22 23
import QGroundControl.Controllers   1.0
import QGroundControl.ScreenTools   1.0

24 25
Item {
    id:         _root
Nate Weibley's avatar
Nate Weibley committed
26

27 28
    property bool loaded: false

29 30 31
    Component {
        id: filtersDialogComponent
        QGCViewDialog {
32
            QGCFlickable {
33 34
                anchors.fill: parent

35 36
                contentHeight:  categoryColumn.height
                clip:           true
37

38 39 40 41 42 43
                ColumnLayout {
                    anchors.fill: parent
                    RowLayout {
                        spacing: ScreenTools.defaultFontPixelHeight / 2
                        Layout.alignment: Qt.AlignVCenter
                        Layout.fillHeight: true
44 45
                        Layout.fillWidth: true

46 47 48
                        QGCLabel {
                            text: qsTr("Search:")
                        }
49

50 51 52 53 54 55
                        QGCTextField {
                            id: searchText
                            text: ""
                            Layout.fillWidth: true
                            enabled: true
                        }
56

57 58 59 60 61
                        QGCButton {
                            text: qsTr("Clear")
                            onClicked: searchText.text = ""
                        }
                    }
62

63 64 65 66 67 68 69
                    Row {
                        spacing:    ScreenTools.defaultFontPixelHeight / 2
                        QGCButton {
                            text: qsTr("Clear All")
                            onClicked: categoryRepeater.setAllLogs(false)
                        }
                    }
70 71 72

                    Column {
                        id:         categoryColumn
73 74
                        spacing:    ScreenTools.defaultFontPixelHeight / 2

75 76 77 78 79 80 81 82 83
                        Repeater {
                            id:     categoryRepeater
                            model:  QGroundControl.loggingCategories()

                            function setAllLogs(value) {
                                var logCategories = QGroundControl.loggingCategories()
                                for (var category of logCategories) {
                                    QGroundControl.setCategoryLoggingOn(category, value)
                                }
84
                                QGroundControl.updateLoggingFilterRules()
85 86 87 88 89 90 91 92 93 94 95 96 97
                                // Update model for repeater
                                categoryRepeater.model = undefined
                                categoryRepeater.model = QGroundControl.loggingCategories()
                            }

                            QGCCheckBox {
                                text:       modelData
                                visible:    searchText.text ? text.match(`(${searchText.text})`, "i") : true
                                checked:    QGroundControl.categoryLoggingOn(modelData)
                                onClicked:  {
                                    QGroundControl.setCategoryLoggingOn(modelData, checked)
                                    QGroundControl.updateLoggingFilterRules()
                                }
98 99 100
                            }
                        }
                    }
101 102
                }
            }
103 104
        }
    }
105

106
    Item {
107 108
        id:             panel
        anchors.fill:   parent
109 110

        Rectangle {
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
            id:              logwindow
            anchors.fill:    parent
            anchors.margins: ScreenTools.defaultFontPixelWidth
            color:           qgcPal.window

            Connections {
                target: debugMessageModel

                onDataChanged: {
                    // Keep the view in sync if the button is checked
                    if (loaded) {
                        if (followTail.checked) {
                            listview.positionViewAtEnd();
                        }
                    }
                }
127 128
            }

129 130 131 132 133 134 135
            Component {
                id: delegateItem
                Rectangle {
                    color:  index % 2 == 0 ? qgcPal.window : qgcPal.windowShade
                    height: Math.round(ScreenTools.defaultFontPixelHeight * 0.5 + field.height)
                    width:  listview.width

Don Gagne's avatar
Don Gagne committed
136 137 138 139 140
                    QGCLabel {
                        id:         field
                        text:       display
                        width:      parent.width
                        wrapMode:   Text.Wrap
141 142 143 144 145
                        anchors.verticalCenter: parent.verticalCenter
                    }
                }
            }

Don Gagne's avatar
Don Gagne committed
146
            QGCListView {
147 148 149 150 151 152 153 154 155 156 157 158 159 160
                Component.onCompleted: {
                    loaded = true
                }
                anchors.top:     parent.top
                anchors.left:    parent.left
                anchors.right:   parent.right
                anchors.bottom:  followTail.top
                anchors.bottomMargin: ScreenTools.defaultFontPixelWidth
                clip:            true
                id:              listview
                model:           debugMessageModel
                delegate:        delegateItem
            }

161
            QGCFileDialog {
162
                id:             writeDialog
163
                folder:         QGroundControl.settingsManager.appSettings.logSavePath
164
                nameFilters:    [qsTr("Log files (*.txt)"), qsTr("All Files (*)")]
165
                fileExtension:  qsTr("txt")
166 167
                selectExisting: false
                title:          qsTr("Select log save file")
168
                onAcceptedForSave: {
DonLakeFlyer's avatar
DonLakeFlyer committed
169
                    debugMessageModel.writeMessages(file);
170 171 172 173 174 175 176 177 178 179 180 181 182 183
                    visible = false;
                }
            }

            Connections {
                target:          debugMessageModel
                onWriteStarted:  writeButton.enabled = false;
                onWriteFinished: writeButton.enabled = true;
            }

            QGCButton {
                id:              writeButton
                anchors.bottom:  parent.bottom
                anchors.left:    parent.left
184
                onClicked:       writeDialog.openForSave()
185 186 187
                text:            qsTr("Save App Log")
            }

188
            QGCLabel {
189 190 191 192 193 194
                id:                 gstLabel
                anchors.left:       writeButton.right
                anchors.leftMargin: ScreenTools.defaultFontPixelWidth
                anchors.baseline:   gstCombo.baseline
                text:               qsTr("GStreamer Debug")
                visible:            QGroundControl.settingsManager.appSettings.gstDebugLevel.visible
195 196 197
            }

            FactComboBox {
198 199 200 201 202 203 204 205
                id:                 gstCombo
                anchors.left:       gstLabel.right
                anchors.leftMargin: ScreenTools.defaultFontPixelWidth / 2
                anchors.bottom:     parent.bottom
                width:              ScreenTools.defaultFontPixelWidth * 10
                model:              ["Disabled", "1", "2", "3", "4", "5", "6", "7", "8"]
                fact:               QGroundControl.settingsManager.appSettings.gstDebugLevel
                visible:            QGroundControl.settingsManager.appSettings.gstDebugLevel.visible
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
            }

            QGCButton {
                id:                     followTail
                anchors.right:          filterButton.left
                anchors.rightMargin:    ScreenTools.defaultFontPixelWidth
                anchors.bottom:         parent.bottom
                text:                   qsTr("Show Latest")
                checkable:              true
                checked:                true

                onCheckedChanged: {
                    if (checked && loaded) {
                        listview.positionViewAtEnd();
                    }
                }
            }

            QGCButton {
                id:             filterButton
                anchors.bottom: parent.bottom
                anchors.right:  parent.right
228
                text:           qsTr("Set Logging")
229
                onClicked:      mainWindow.showComponentDialog(filtersDialogComponent, qsTr("Turn on logging categories"), mainWindow.showDialogDefaultWidth, StandardButton.Close)
230 231
            }
        }
232 233
    }
}
234