MAVLinkChart.qml 5.54 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 24
    property var chartController:   null
    property int maxSeriesCount:    seriesColors.length
Gus Grubba's avatar
Gus Grubba committed
25
    property var seriesColors:      ["chartreuse", "darkturquoise", "chocolate", "thistle", "silver", "blue"]
Gus Grubba's avatar
Gus Grubba committed
26

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

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

    DateTimeAxis {
53
        id:                         axisX
54 55
        min:                        chartController ? chartController.rangeXMin : new Date()
        max:                        chartController ? chartController.rangeXMax : new Date()
Gus Grubba's avatar
Gus Grubba committed
56 57
        visible:                    chartController !== null
        format:                     "<br/>mm:ss.zzz"
58 59 60 61
        tickCount:                  5
        gridVisible:                true
        labelsFont.family:          "Fixed"
        labelsFont.pixelSize:       ScreenTools.smallFontPointSize
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 71
        lineVisible:                false
        labelsFont.family:          "Fixed"
        labelsFont.pixelSize:       ScreenTools.smallFontPointSize
Gus Grubba's avatar
Gus Grubba committed
72 73
    }

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