Warning, /plasma/libksysguard/faces/import/ExtendedLegend.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 SPDX-FileCopyrightText: 2019 Marco Martin <mart@kde.org> 0003 SPDX-FileCopyrightText: 2019 David Edmundson <davidedmundson@kde.org> 0004 SPDX-FileCopyrightText: 2019 Arjen Hiemstra <ahiemstra@heimr.nl> 0005 SPDX-FileCopyrightText: 2019 Kai Uwe Broulik <kde@broulik.de> 0006 0007 SPDX-License-Identifier: LGPL-2.0-or-later 0008 */ 0009 0010 import QtQuick 0011 import QtQuick.Layouts 0012 0013 import org.kde.kirigami as Kirigami 0014 0015 import org.kde.ksysguard.faces.private 0016 import org.kde.ksysguard.formatter 0017 import org.kde.ksysguard.sensors 0018 0019 import org.kde.quickcharts as Charts 0020 import org.kde.quickcharts.controls as ChartsControls 0021 0022 /** 0023 * A legend control to be used in faces based on org.kde.quickcharts.Controls.Legend. 0024 * It handles 0025 * layouting and display of information depending on the available space. By default the current 0026 * value of a sensor and its name are displayed, if it is shrunk the shortName is displayed instead. 0027 * 0028 * @since 5.19 0029 */ 0030 ChartsControls.Legend { 0031 id: legend 0032 0033 /** 0034 * A list of sensor ids that should be displayed in addition to those from sourceModel. Typically 0035 * set to lowPrioritySensorIds from FaceController 0036 */ 0037 property alias sensorIds: sensorsRepeater.model 0038 /** 0039 * The SensorDataModel that should be used to retrieve data about the sensors. 0040 */ 0041 property SensorDataModel sourceModel 0042 /** 0043 * @deprecated since 5.21 0044 * Has no effect 0045 */ 0046 property var colorSource 0047 0048 property int updateRateLimit 0049 0050 Layout.maximumHeight: implicitHeight 0051 Layout.maximumWidth: parent.width 0052 0053 horizontalSpacing: Kirigami.Units.gridUnit 0054 verticalSpacing: Kirigami.Units.smallSpacing 0055 0056 maximumDelegateWidth: Kirigami.Units.gridUnit * 15 0057 0058 formatValue: function(input, index) { 0059 if (!sourceModel) { 0060 return input 0061 } 0062 0063 return Formatter.formatValueShowNull(input, sourceModel.headerData(index, Qt.Horiztonal, SensorDataModel.Unit)) 0064 } 0065 0066 Binding on model { 0067 when: !chart 0068 value: QTransposeProxyModel { 0069 sourceModel: legend.sourceModel 0070 } 0071 } 0072 Binding on valueRole { 0073 when: !chart 0074 value: "Value" 0075 } 0076 Binding on nameRole { 0077 when: !chart 0078 value: "Name" 0079 } 0080 Binding on shortNameRole { 0081 when: !chart 0082 value: "ShortName" 0083 } 0084 Binding on colorRole { 0085 when: !chart 0086 value: "Color" 0087 } 0088 0089 maximumValueWidth: function(input, index) { 0090 if (!sourceModel) { 0091 return -1 0092 } 0093 0094 var unit = sourceModel.headerData(index, Qt.Horiztonal, SensorDataModel.Unit) 0095 return Formatter.maximumLength(unit, legend.font) 0096 } 0097 0098 Repeater { 0099 id: sensorsRepeater 0100 delegate: ChartsControls.LegendDelegate { 0101 name: legend.sourceModel.sensorLabels[sensor.sensorId] || sensor.name 0102 shortName: legend.sourceModel.sensorLabels[sensor.sensorId] || sensor.shortName 0103 value: sensor.formattedValue || "" 0104 0105 indicator: Item { } 0106 0107 maximumValueWidth: legend.maximumValueWidth(sensor.value, index) 0108 0109 ChartsControls.LegendLayout.minimumWidth: minimumWidth 0110 ChartsControls.LegendLayout.preferredWidth: preferredWidth 0111 ChartsControls.LegendLayout.maximumWidth: Math.max(legend.maximumDelegateWidth, preferredWidth) 0112 0113 Sensor { 0114 id: sensor 0115 sensorId: modelData 0116 updateRateLimit: legend.updateRateLimit 0117 } 0118 } 0119 } 0120 }