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 formatValue: function(input, index) {
59 if (!sourceModel) {
60 return input
61 }
62
63 return Formatter.formatValueShowNull(input, sourceModel.headerData(index, Qt.Horiztonal, SensorDataModel.Unit))
64 }
65
66 Binding on model {
67 when: !chart
68 value: QTransposeProxyModel {
69 sourceModel: legend.sourceModel
70 }
71 }
72 Binding on valueRole {
73 when: !chart
74 value: "Value"
75 }
76 Binding on nameRole {
77 when: !chart
78 value: "Name"
79 }
80 Binding on shortNameRole {
81 when: !chart
82 value: "ShortName"
83 }
84 Binding on colorRole {
85 when: !chart
86 value: "Color"
87 }
88
89 maximumValueWidth: function(input, index) {
90 if (!sourceModel) {
91 return -1
92 }
93
94 var unit = sourceModel.headerData(index, Qt.Horiztonal, SensorDataModel.Unit)
95 return Formatter.maximumLength(unit, legend.font)
96 }
97
98 Repeater {
99 id: sensorsRepeater
100 delegate: ChartsControls.LegendDelegate {
101 name: legend.sourceModel.sensorLabels[sensor.sensorId] || sensor.name
102 shortName: legend.sourceModel.sensorLabels[sensor.sensorId] || sensor.shortName
103 value: sensor.formattedValue || ""
104
105 indicator: Item { }
106
107 maximumValueWidth: legend.maximumValueWidth(sensor.value, index)
108
109 ChartsControls.LegendLayout.minimumWidth: minimumWidth
110 ChartsControls.LegendLayout.preferredWidth: preferredWidth
111 ChartsControls.LegendLayout.maximumWidth: Math.max(legend.maximumDelegateWidth, preferredWidth)
112
113 Sensor {
114 id: sensor
115 sensorId: modelData
116 updateRateLimit: legend.updateRateLimit
117 }
118 }
119 }
120}
QString name(StandardShortcut id)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Apr 27 2024 22:16:45 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.