Skip to content
Snippets Groups Projects
MAVLinkChart.qml 5.37 KiB
Newer Older
  • Learn to ignore specific revisions
  • Gus Grubba's avatar
    Gus Grubba committed
    import QtQuick                      2.11
    import QtQuick.Controls             2.4
    import QtQuick.Layouts              1.11
    import QtCharts                     2.3
    
    import QGroundControl               1.0
    import QGroundControl.Palette       1.0
    import QGroundControl.Controls      1.0
    import QGroundControl.Controllers   1.0
    import QGroundControl.ScreenTools   1.0
    
    ChartView {
        id:                 chartView
        theme:              ChartView.ChartThemeDark
        antialiasing:       true
        animationOptions:   ChartView.NoAnimation
        legend.visible:     false
        backgroundColor:    qgcPal.window
        backgroundRoundness: 0
        margins.bottom:     ScreenTools.defaultFontPixelHeight * 1.5
        margins.top:        chartHeader.height + (ScreenTools.defaultFontPixelHeight * 2)
    
    
    Gus Grubba's avatar
    Gus Grubba committed
        property var seriesColors:      ["#00E04B","#DE8500","#F32836","#BFBFBF","#536DFF","#EECC44"]
    
        function addDimension(field) {
            if(!chartController) {
                chartController = controller.createChart()
            }
    
    Gus Grubba's avatar
    Gus Grubba committed
            var color   = chartView.seriesColors[chartView.count]
    
    Gus Grubba's avatar
    Gus Grubba committed
            var serie   = createSeries(ChartView.SeriesTypeLine, field.label)
            serie.axisX = axisX
            serie.axisY = axisY
            serie.useOpenGL = true
    
    Gus Grubba's avatar
    Gus Grubba committed
            serie.color = color
    
    Gus Grubba's avatar
    Gus Grubba committed
            serie.width = 1
    
            chartController.addSeries(field, serie)
    
    Gus Grubba's avatar
    Gus Grubba committed
        }
    
        function delDimension(field) {
    
            if(chartController) {
                chartView.removeSeries(field.series)
                chartController.delSeries(field)
                if(chartView.count === 0) {
                    controller.deleteChart(chartController)
                    chartController = null
                }
            }
    
    Gus Grubba's avatar
    Gus Grubba committed
        }
    
        DateTimeAxis {
    
            min:                        chartController ? chartController.rangeXMin : new Date()
            max:                        chartController ? chartController.rangeXMax : new Date()
    
    Gus Grubba's avatar
    Gus Grubba committed
            visible:                    chartController !== null
            format:                     "<br/>mm:ss.zzz"
    
            tickCount:                  5
            gridVisible:                true
            labelsFont.family:          "Fixed"
    
            labelsFont.pointSize:       ScreenTools.smallFontPointSize
    
    Gus Grubba's avatar
    Gus Grubba committed
            labelsColor:                qgcPal.text
    
    Gus Grubba's avatar
    Gus Grubba committed
        }
    
        ValueAxis {
    
            id:                         axisY
            min:                        chartController ? chartController.rangeYMin : 0
            max:                        chartController ? chartController.rangeYMax : 0
    
    Gus Grubba's avatar
    Gus Grubba committed
            visible:                    chartController !== null
    
            lineVisible:                false
            labelsFont.family:          "Fixed"
    
            labelsFont.pointSize:       ScreenTools.smallFontPointSize
    
    Gus Grubba's avatar
    Gus Grubba committed
            labelsColor:                qgcPal.text
    
    Gus Grubba's avatar
    Gus Grubba committed
        Row {
    
            id:                         chartHeader
            anchors.left:               parent.left
            anchors.leftMargin:         ScreenTools.defaultFontPixelWidth  * 4
            anchors.right:              parent.right
            anchors.rightMargin:        ScreenTools.defaultFontPixelWidth  * 4
            anchors.top:                parent.top
            anchors.topMargin:          ScreenTools.defaultFontPixelHeight * 1.5
    
    Gus Grubba's avatar
    Gus Grubba committed
            spacing:                    ScreenTools.defaultFontPixelWidth  * 2
    
    Gus Grubba's avatar
    Gus Grubba committed
            visible:                    chartController !== null
    
    Gus Grubba's avatar
    Gus Grubba committed
            GridLayout {
    
                columns:                2
                columnSpacing:          ScreenTools.defaultFontPixelWidth
                rowSpacing:             ScreenTools.defaultFontPixelHeight * 0.25
    
    Gus Grubba's avatar
    Gus Grubba committed
                anchors.verticalCenter: parent.verticalCenter
    
    Gus Grubba's avatar
    Gus Grubba committed
                QGCLabel {
    
    Gus Grubba's avatar
    Gus Grubba committed
                    Layout.alignment:   Qt.AlignVCenter
                }
                QGCComboBox {
    
                    Layout.minimumWidth: ScreenTools.defaultFontPixelWidth * 10
    
                    Layout.maximumWidth: ScreenTools.defaultFontPixelWidth * 10
    
                    height:             ScreenTools.defaultFontPixelHeight
                    model:              controller.timeScales
                    currentIndex:       chartController ? chartController.rangeXIndex : 0
                    onActivated:        { if(chartController) chartController.rangeXIndex = index; }
    
    Gus Grubba's avatar
    Gus Grubba committed
                    Layout.alignment:   Qt.AlignVCenter
                }
                QGCLabel {
    
    Gus Grubba's avatar
    Gus Grubba committed
                    Layout.alignment:   Qt.AlignVCenter
                }
                QGCComboBox {
    
                    Layout.minimumWidth: ScreenTools.defaultFontPixelWidth * 10
    
                    Layout.maximumWidth: ScreenTools.defaultFontPixelWidth * 10
    
                    height:             ScreenTools.defaultFontPixelHeight
    
    Gus Grubba's avatar
    Gus Grubba committed
                    model:              controller.rangeList
    
                    currentIndex:       chartController ? chartController.rangeYIndex : 0
                    onActivated:        { if(chartController) chartController.rangeYIndex = index; }
    
    Gus Grubba's avatar
    Gus Grubba committed
                    Layout.alignment:   Qt.AlignVCenter
                }
            }
    
    Gus Grubba's avatar
    Gus Grubba committed
                anchors.verticalCenter: parent.verticalCenter
    
                Repeater {
                    model:              chartController ? chartController.chartFields : []
                    QGCLabel {
                        text:           modelData.label
                        color:          chartView.series(index).color
    
                        font.pointSize: ScreenTools.smallFontPointSize