Warning, /plasma/libksysguard/faces/facepackages/textonly/contents/ui/GroupedText.qml is written in an unsupported language. File is not indexed.
0001 /*
0002 SPDX-FileCopyrightText: 2020 Arjen Hiemstra <ahiemstra@heimr.nl>
0003
0004 SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006
0007 import QtQuick
0008 import QtQuick.Layouts
0009
0010 import org.kde.kirigami as Kirigami
0011 import org.kde.quickcharts as Charts
0012 import org.kde.quickcharts.controls as ChartsControls
0013 import org.kde.ksysguard.sensors as Sensors
0014 import org.kde.ksysguard.formatter as Formatter
0015
0016 ColumnLayout {
0017 id: root
0018
0019 property var totalSensorIds
0020 property var highPrioritySensorIds
0021 property var lowPrioritySensorIds
0022 property bool showGroups: false
0023 property var colorSource
0024 property real totalHeight
0025 property int updateRateLimit
0026 property var sensorLabels
0027
0028 readonly property real contentWidth: {
0029 let w = 0
0030 for (let i in children) {
0031 let child = children[i]
0032 if (child.hasOwnProperty("preferredWidth")) {
0033 w = Math.max(w, child.preferredWidth)
0034 }
0035 }
0036 return w
0037 }
0038
0039 readonly property bool hasGroups: showGroups && root.totalSensorIds.length > 0
0040
0041 Layout.minimumHeight: hasGroups ? Kirigami.Units.gridUnit * 3 : Kirigami.Units.gridUnit
0042
0043 Repeater {
0044 model: root.hasGroups ? root.totalSensorIds : 1
0045
0046 ColumnLayout {
0047 property string title
0048 property var sensors: []
0049 property bool useFullName: true
0050 property var colorSource
0051
0052 readonly property alias preferredWidth: legend.preferredWidth
0053
0054 Kirigami.Heading {
0055 Layout.fillWidth: true
0056 text: groupSensor.formattedValue
0057 level: 3
0058 horizontalAlignment: Text.AlignLeft
0059 opacity: (root.y + parent.y + y + height) < root.totalHeight ? 1 : 0
0060 visible: text.length > 0
0061 elide: Text.ElideRight
0062 }
0063
0064 ChartsControls.Legend {
0065 id: legend
0066
0067 Layout.fillWidth: true
0068 Layout.fillHeight: true
0069 Layout.maximumHeight: implicitHeight
0070 Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter
0071
0072 horizontalSpacing: Kirigami.Units.gridUnit
0073 verticalSpacing: Kirigami.Units.smallSpacing
0074
0075 model: {
0076 if (!root.hasGroups) {
0077 return root.highPrioritySensors.concat(root.lowPrioritySensors)
0078 }
0079
0080 let result = []
0081 for (let i = 0; i < root.highPrioritySensors.length; ++i) {
0082 if (root.highPrioritySensors[i].name.startsWith(groupSensor.value)) {
0083 result.push(root.highPrioritySensors[i])
0084 }
0085 }
0086 for (let i = 0; i < root.lowPrioritySensors.length; ++i) {
0087 if (root.lowPrioritySensors[i].name.startsWith(groupSensor.value)) {
0088 result.push(root.lowPrioritySensors[i])
0089 }
0090 }
0091 return result
0092 }
0093
0094 delegate: ChartsControls.LegendDelegate {
0095 name: root.sensorLabels[modelData.sensorId] || (root.showGroups ? modelData.shortName : modelData.name)
0096 shortName: root.sensorLabels[modelData.sensorId] || modelData.shortName
0097 value: modelData.formattedValue
0098 color: root.colorSource.map[modelData.sensorId]
0099
0100 maximumValueWidth: {
0101 var unit = modelData.unit
0102 return Formatter.Formatter.maximumLength(unit, legend.font)
0103 }
0104
0105 ChartsControls.LegendLayout.minimumWidth: minimumWidth
0106 ChartsControls.LegendLayout.preferredWidth: preferredWidth
0107 ChartsControls.LegendLayout.maximumWidth: Math.max(preferredWidth, Kirigami.Units.gridUnit * 17)
0108 }
0109 }
0110
0111 Sensors.Sensor {
0112 id: groupSensor
0113 sensorId: root.hasGroups ? modelData : ""
0114 updateRateLimit: root.updateRateLimit
0115 }
0116 }
0117 }
0118
0119 property var highPrioritySensors: []
0120 property var lowPrioritySensors: []
0121
0122 Instantiator {
0123 model: root.highPrioritySensorIds
0124
0125 Sensors.Sensor { sensorId: modelData; updateRateLimit: root.updateRateLimit }
0126
0127 onObjectAdded: (index, object) => {
0128 root.highPrioritySensors.push(object)
0129 root.highPrioritySensors = root.highPrioritySensors
0130 }
0131 onObjectRemoved: (index, object) => {
0132 root.highPrioritySensors.splice(root.highPrioritySensors.indexOf(object), 1)
0133 root.highPrioritySensors = root.highPrioritySensors
0134 }
0135 }
0136
0137 Instantiator {
0138 model: root.lowPrioritySensorIds
0139
0140 Sensors.Sensor { sensorId: modelData; updateRateLimit: root.updateRateLimit }
0141
0142 onObjectAdded: (index, object) => {
0143 root.lowPrioritySensors.push(object)
0144 root.lowPrioritySensors = root.lowPrioritySensors
0145 }
0146 onObjectRemoved: (index, object) => {
0147 root.lowPrioritySensors.splice(root.lowPrioritySensors.indexOf(object), 1)
0148 root.lowPrioritySensors = root.lowPrioritySensors
0149 }
0150 }
0151 }