Libksysguard

ExtendedLegend.qml
1/*
2 SPDX-FileCopyrightText: 2019 Marco Martin <mart@kde.org>
3 SPDX-FileCopyrightText: 2019 David Edmundson <davidedmundson@kde.org>
4 SPDX-FileCopyrightText: 2019 Arjen Hiemstra <ahiemstra@heimr.nl>
5 SPDX-FileCopyrightText: 2019 Kai Uwe Broulik <kde@broulik.de>
6
7 SPDX-License-Identifier: LGPL-2.0-or-later
8*/
9
10import QtQuick
11import QtQuick.Layouts
12
13import org.kde.kirigami as Kirigami
14
15import org.kde.ksysguard.faces.private
16import org.kde.ksysguard.formatter
17import org.kde.ksysguard.sensors
18
19import org.kde.quickcharts as Charts
20import org.kde.quickcharts.controls as ChartsControls
21
22/**
23 * A legend control to be used in faces based on org.kde.quickcharts.Controls.Legend.
24 * It handles
25 * layouting and display of information depending on the available space. By default the current
26 * value of a sensor and its name are displayed, if it is shrunk the shortName is displayed instead.
27 *
28 * @since 5.19
29 */
30ChartsControls.Legend {
31 id: legend
32
33 /**
34 * A list of sensor ids that should be displayed in addition to those from sourceModel. Typically
35 * set to lowPrioritySensorIds from FaceController
36 */
37 property alias sensorIds: sensorsRepeater.model
38 /**
39 * The SensorDataModel that should be used to retrieve data about the sensors.
40 */
41 property SensorDataModel sourceModel
42 /**
43 * @deprecated since 5.21
44 * Has no effect
45 */
46 property var colorSource
47
48 property int updateRateLimit
49
50 Layout.maximumHeight: implicitHeight
51 Layout.maximumWidth: parent.width
52
53 horizontalSpacing: Kirigami.Units.gridUnit
54 verticalSpacing: Kirigami.Units.smallSpacing
55
56 maximumDelegateWidth: Kirigami.Units.gridUnit * 15
57
58 highlightEnabled: sourceModel.sensors.length > 1
59
60 formatValue: function(input, index) {
61 if (!sourceModel) {
62 return input
63 }
64
65 return Formatter.formatValueShowNull(input, sourceModel.headerData(index, Qt.Horiztonal, SensorDataModel.Unit))
66 }
67
68 Binding on model {
69 when: !chart
70 value: QTransposeProxyModel {
71 sourceModel: legend.sourceModel
72 }
73 }
74 Binding on valueRole {
75 when: !chart
76 value: "Value"
77 }
78 Binding on nameRole {
79 when: !chart
80 value: "Name"
81 }
82 Binding on shortNameRole {
83 when: !chart
84 value: "ShortName"
85 }
86 Binding on colorRole {
87 when: !chart
88 value: "Color"
89 }
90
91 maximumValueWidth: function(input, index) {
92 if (!sourceModel) {
93 return -1
94 }
95
96 var unit = sourceModel.headerData(index, Qt.Horiztonal, SensorDataModel.Unit)
97 return Formatter.maximumLength(unit, legend.font)
98 }
99
100 Repeater {
101 id: sensorsRepeater
102 delegate: ChartsControls.LegendDelegate {
103 name: legend.sourceModel.sensorLabels[sensor.sensorId] || sensor.name
104 shortName: legend.sourceModel.sensorLabels[sensor.sensorId] || sensor.shortName
105 value: sensor.formattedValue || ""
106
107 indicator: Item { }
108
109 maximumValueWidth: legend.maximumValueWidth(sensor.value, index)
110
111 ChartsControls.LegendLayout.minimumWidth: minimumWidth
112 ChartsControls.LegendLayout.preferredWidth: preferredWidth
113 ChartsControls.LegendLayout.maximumWidth: Math.max(legend.maximumDelegateWidth, preferredWidth)
114
115 Sensor {
116 id: sensor
117 sensorId: modelData
118 updateRateLimit: legend.updateRateLimit
119 }
120 }
121 }
122}
QString name(GameStandardAction id)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:02:48 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.