MAVLinkChart.qml 5.37 KB
Newer Older
Gus Grubba's avatar
Gus Grubba committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
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)

23
    property var chartController:   null
Gus Grubba's avatar
Gus Grubba committed
24
    property var seriesColors:      ["#00E04B","#DE8500","#F32836","#BFBFBF","#536DFF","#EECC44"]
Gus Grubba's avatar
Gus Grubba committed
25

26 27 28 29
    function addDimension(field) {
        if(!chartController) {
            chartController = controller.createChart()
        }
Gus Grubba's avatar
Gus Grubba committed
30
        var color   = chartView.seriesColors[chartView.count]
Gus Grubba's avatar
Gus Grubba committed
31 32 33 34
        var serie   = createSeries(ChartView.SeriesTypeLine, field.label)
        serie.axisX = axisX
        serie.axisY = axisY
        serie.useOpenGL = true
Gus Grubba's avatar
Gus Grubba committed
35
        serie.color = color
Gus Grubba's avatar
Gus Grubba committed
36
        serie.width = 1
37
        chartController.addSeries(field, serie)
Gus Grubba's avatar
Gus Grubba committed
38 39 40
    }

    function delDimension(field) {
41 42 43 44 45 46 47 48
        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
49 50 51
    }

    DateTimeAxis {
52
        id:                         axisX
53 54
        min:                        chartController ? chartController.rangeXMin : new Date()
        max:                        chartController ? chartController.rangeXMax : new Date()
Gus Grubba's avatar
Gus Grubba committed
55 56
        visible:                    chartController !== null
        format:                     "<br/>mm:ss.zzz"
57 58 59
        tickCount:                  5
        gridVisible:                true
        labelsFont.family:          "Fixed"
60
        labelsFont.pointSize:       ScreenTools.smallFontPointSize
Gus Grubba's avatar
Gus Grubba committed
61
        labelsColor:                qgcPal.text
Gus Grubba's avatar
Gus Grubba committed
62 63 64
    }

    ValueAxis {
65 66 67
        id:                         axisY
        min:                        chartController ? chartController.rangeYMin : 0
        max:                        chartController ? chartController.rangeYMax : 0
Gus Grubba's avatar
Gus Grubba committed
68
        visible:                    chartController !== null
69 70
        lineVisible:                false
        labelsFont.family:          "Fixed"
71
        labelsFont.pointSize:       ScreenTools.smallFontPointSize
Gus Grubba's avatar
Gus Grubba committed
72
        labelsColor:                qgcPal.text
Gus Grubba's avatar
Gus Grubba committed
73 74
    }

Gus Grubba's avatar
Gus Grubba committed
75
    Row {
76 77 78 79 80 81 82
        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
83
        spacing:                    ScreenTools.defaultFontPixelWidth  * 2
Gus Grubba's avatar
Gus Grubba committed
84
        visible:                    chartController !== null
Gus Grubba's avatar
Gus Grubba committed
85
        GridLayout {
86 87 88
            columns:                2
            columnSpacing:          ScreenTools.defaultFontPixelWidth
            rowSpacing:             ScreenTools.defaultFontPixelHeight * 0.25
Gus Grubba's avatar
Gus Grubba committed
89
            anchors.verticalCenter: parent.verticalCenter
Gus Grubba's avatar
Gus Grubba committed
90
            QGCLabel {
91
                text:               qsTr("Scale:");
Gus Grubba's avatar
Gus Grubba committed
92 93 94
                Layout.alignment:   Qt.AlignVCenter
            }
            QGCComboBox {
95
                Layout.minimumWidth: ScreenTools.defaultFontPixelWidth * 10
96
                Layout.maximumWidth: ScreenTools.defaultFontPixelWidth * 10
97 98 99 100
                height:             ScreenTools.defaultFontPixelHeight
                model:              controller.timeScales
                currentIndex:       chartController ? chartController.rangeXIndex : 0
                onActivated:        { if(chartController) chartController.rangeXIndex = index; }
Gus Grubba's avatar
Gus Grubba committed
101 102 103
                Layout.alignment:   Qt.AlignVCenter
            }
            QGCLabel {
104
                text:               qsTr("Range:");
Gus Grubba's avatar
Gus Grubba committed
105 106 107
                Layout.alignment:   Qt.AlignVCenter
            }
            QGCComboBox {
108
                Layout.minimumWidth: ScreenTools.defaultFontPixelWidth * 10
109
                Layout.maximumWidth: ScreenTools.defaultFontPixelWidth * 10
110
                height:             ScreenTools.defaultFontPixelHeight
Gus Grubba's avatar
Gus Grubba committed
111
                model:              controller.rangeList
112 113
                currentIndex:       chartController ? chartController.rangeYIndex : 0
                onActivated:        { if(chartController) chartController.rangeYIndex = index; }
Gus Grubba's avatar
Gus Grubba committed
114 115 116
                Layout.alignment:   Qt.AlignVCenter
            }
        }
117
        ColumnLayout {
Gus Grubba's avatar
Gus Grubba committed
118
            anchors.verticalCenter: parent.verticalCenter
119 120 121 122 123
            Repeater {
                model:              chartController ? chartController.chartFields : []
                QGCLabel {
                    text:           modelData.label
                    color:          chartView.series(index).color
124
                    font.pointSize: ScreenTools.smallFontPointSize
125 126 127
                }
            }
        }
Gus Grubba's avatar
Gus Grubba committed
128 129
    }
}