Added horizontal legend for a small number of series on the chart

This commit is contained in:
Yury Shuvakin
2022-08-26 13:45:04 +03:00
parent fdaca40a06
commit 2a960893d0

View File

@@ -71,11 +71,12 @@ ColumnLayout {
id: legendDelegate
RowLayout {
width: ListView.view.width
width: ListView.view ? ListView.view.width : 200
height: 60
property Controls.ChartView chartItem: undefined
property color seriesColor: "black"
property bool horizontal: true
Controls.CheckBox {
id: checkSeries
@@ -87,7 +88,7 @@ ColumnLayout {
chartItem.series(modelData).color = "transparent"
}
}
Layout.fillWidth: true
Layout.fillWidth: !horizontal
}
Rectangle {
@@ -99,7 +100,8 @@ ColumnLayout {
}
Component.onCompleted: {
chartItem = ListView.view.chartItem
chartItem = ListView.view ? ListView.view.chartItem : parent.chartItem
horizontal = !ListView.view
seriesColor = chartItem.series(modelData).color
checkSeries.text = chartItem.series(modelData).name
}
@@ -114,6 +116,7 @@ ColumnLayout {
property string yLabel: ""
property Controls.ChartView chart: chartView
property int seriesCount: 0
property bool horizontalLegend: true
ColumnLayout {
spacing: -20
@@ -140,6 +143,21 @@ ColumnLayout {
Layout.bottomMargin: 10
}
RowLayout {
visible: horizontalLegend
spacing: 20
property Controls.ChartView chartItem: chart
Repeater {
model: seriesCount
delegate: legendDelegate
}
Layout.topMargin: 20
Layout.leftMargin: 20
}
Layout.fillWidth: true
Layout.fillHeight: true
}
@@ -148,10 +166,11 @@ ColumnLayout {
clip: true
model: seriesCount
delegate: legendDelegate
visible: !horizontalLegend
property Controls.ChartView chartItem: chart
Layout.preferredWidth: 300
Layout.preferredWidth: 180
Layout.fillHeight: true
}
}
@@ -232,6 +251,7 @@ ColumnLayout {
Component.onCompleted: {
item.xLabel = Qt.binding(function() { return qsTr("Time, s") })
item.yLabel = Qt.binding(function() { return qsTr("Voltage, V") })
item.horizontalLegend = false
}
}