Serial-Studio/assets/qml/Widgets/GraphDelegate.qml

118 lines
3.5 KiB
QML
Raw Normal View History

2020-10-18 06:50:26 -05:00
/*
* Copyright (c) 2020-2021 Alex Spataru <https://github.com/alex-spataru>
2020-10-18 06:50:26 -05:00
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
import QtQuick 2.12
import QtCharts 2.3
import SerialStudio 1.0
2020-10-18 06:50:26 -05:00
Window {
id: root
2020-10-18 06:50:26 -05:00
property int graphId: -1
spacing: -1
showIcon: false
visible: opacity > 0
opacity: enabled ? 1 : 0
borderColor: root.headerVisible ? "#517497" : "transparent"
title: Cpp_UI_GraphProvider.getDataset(graphId).title +
2021-08-21 03:20:55 -05:00
Cpp_UI_GraphProvider.getDataset(graphId).units.length > 0 ?
" (" + Cpp_UI_GraphProvider.getDataset(graphId).units + ")" : ""
2020-10-18 06:50:26 -05:00
Connections {
target: Cpp_UI_GraphProvider
2021-02-10 15:48:25 -05:00
2021-02-10 19:44:30 -05:00
//*! Optimize this function (this is the larger UI thread time consumer)
2020-10-18 06:50:26 -05:00
function onDataUpdated() {
// Cancel if window is not enabled
if (!root.enabled)
2020-10-18 06:50:26 -05:00
return
2021-02-09 21:03:20 -05:00
// Get min/max values
var point = Cpp_UI_GraphProvider.graphRange(graphId)
var min = point.x
var max = point.y
2020-10-18 06:50:26 -05:00
// Update axes only if needed
if (positionAxis.min !== min)
positionAxis.min = min
if (positionAxis.max !== max)
positionAxis.max = max
// Draw graph
Cpp_UI_GraphProvider.updateGraph(series, graphId)
2020-10-18 06:50:26 -05:00
}
}
ChartView {
2020-12-30 16:11:51 -06:00
antialiasing: true
2020-10-18 06:50:26 -05:00
anchors.fill: parent
legend.visible: false
backgroundRoundness: 0
enabled: root.enabled
visible: root.enabled
backgroundColor: root.backgroundColor
2020-10-18 06:50:26 -05:00
margins {
top: 0
bottom: 0
left: 0
right: 0
}
ValueAxis {
id: timeAxis
min: 0
labelFormat: " "
lineVisible: false
labelsVisible: false
2021-01-22 12:46:11 -05:00
gridLineColor: "#517497"
2020-10-18 06:50:26 -05:00
tickType: ValueAxis.TicksFixed
labelsFont.family: app.monoFont
max: Cpp_UI_GraphProvider.displayedPoints
2020-10-18 06:50:26 -05:00
}
ValueAxis {
id: positionAxis
min: 0
max: 1
lineVisible: false
2021-01-22 12:46:11 -05:00
labelsColor: "#517497"
gridLineColor: "#517497"
2020-10-18 06:50:26 -05:00
tickType: ValueAxis.TicksFixed
labelsFont.family: app.monoFont
}
LineSeries {
id: series
width: 2
axisX: timeAxis
useOpenGL: true
2021-01-22 12:46:11 -05:00
color: "#e6e0b2"
2020-10-18 06:50:26 -05:00
capStyle: Qt.RoundCap
axisYRight: positionAxis
}
}
}