Commit 8c045428 authored by Arjen Hiemstra's avatar Arjen Hiemstra
Browse files

Add an option to group text-only items based on total sensors

This works for things where the sensor is prefixed by the group
name. It uses the value of the total sensors to then group the
high and low priority sensors together.
parent 895b9986
<?xml version="1.0" encoding="UTF-8"?>
<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
<kcfgfile name=""/>
<group name="General">
<entry name="groupByTotal" type="Bool">
<default>false</default>
</entry>
</group>
</kcfg>
[Config]
SupportsSensorsColors=true
SupportsTotalSensors=false
SupportsTotalSensors=true
SupportsLowPrioritySensors=true
......@@ -37,27 +37,13 @@ Faces.SensorFace {
Layout.minimumWidth: root.formFactor == Faces.SensorFace.Vertical ? Kirigami.Units.gridUnit : Kirigami.Units.gridUnit * 2
contentItem: ColumnLayout {
Repeater {
model: root.controller.highPrioritySensorIds
ChartsControls.LegendDelegate {
Layout.fillWidth: true
name: sensor.name
shortName: sensor.shortName
value: sensor.formattedValue
colorVisible: false
colorWidth: 0
layoutWidth: root.width
valueWidth: Kirigami.Units.gridUnit * 2
Sensors.Sensor {
id: sensor
sensorId: modelData
}
}
GroupedText {
totalSensorIds: root.controller.totalSensors
highPrioritySensorIds: root.controller.highPrioritySensorIds
lowPrioritySensorIds: []
showGroups: root.controller.faceConfiguration.groupByTotal
colorSource: root.colorSource
totalHeight: root.height
}
Item { Layout.fillWidth: true; Layout.fillHeight: true }
......
/*
* Copyright 2019 Marco Martin <mart@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import QtQuick 2.9
import QtQuick.Layouts 1.1
import QtQuick.Controls 2.2 as Controls
import org.kde.kirigami 2.8 as Kirigami
import org.kde.ksysguard.sensors 1.0 as Sensors
import org.kde.ksysguard.faces 1.0 as Faces
Kirigami.FormLayout {
id: root
property alias cfg_groupByTotal: groupCheckbox.checked
Controls.CheckBox {
id: groupCheckbox
text: i18n("Group sensors based on the value of the total sensors.")
}
}
......@@ -56,29 +56,13 @@ Faces.SensorFace {
Item { Layout.fillWidth: true; Layout.fillHeight: true }
Repeater {
model: root.controller.highPrioritySensorIds.concat(root.controller.lowPrioritySensorIds)
ChartsControls.LegendDelegate {
readonly property bool isTextOnly: index >= root.controller.highPrioritySensorIds.length
Layout.fillWidth: true
Layout.minimumHeight: isTextOnly ? 0 : implicitHeight
name: sensor.name
shortName: sensor.shortName
value: sensor.formattedValue
colorVisible: !isTextOnly
color: !isTextOnly ? root.colorSource.map[modelData] : "transparent"
layoutWidth: root.width
valueWidth: Kirigami.Units.gridUnit * 2
Sensors.Sensor {
id: sensor
sensorId: modelData
}
}
GroupedText {
totalSensorIds: root.controller.totalSensors
highPrioritySensorIds: root.controller.highPrioritySensorIds
lowPrioritySensorIds: root.controller.lowPrioritySensorIds
showGroups: root.controller.faceConfiguration.groupByTotal
colorSource: root.colorSource
totalHeight: root.height
}
Item { Layout.fillWidth: true; Layout.fillHeight: true }
......
/*
* Copyright 2020 Arjen Hiemstra <ahiemstra@heimr.nl>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import QtQuick 2.12
import QtQuick.Layouts 1.12
import org.kde.kirigami 2.8 as Kirigami
import org.kde.quickcharts.controls 1.0 as ChartsControls
import org.kde.ksysguard.sensors 1.0 as Sensors
ColumnLayout {
id: root
property var totalSensorIds
property var highPrioritySensorIds
property var lowPrioritySensorIds
property bool showGroups: false
property var colorSource
property real totalHeight
Repeater {
model: root.showGroups ? root.totalSensorIds : 1
ColumnLayout {
property string title
property var sensors: []
property bool useFullName: true
property var colorSource
Kirigami.Heading {
Layout.fillWidth: true
text: groupSensor.formattedValue
level: 3
horizontalAlignment: Text.AlignLeft
opacity: (root.y + parent.y + y + height) < root.totalHeight ? 1 : 0
visible: text.length > 0
elide: Text.ElideRight
}
Repeater {
model: {
if (!root.showGroups) {
return root.highPrioritySensors.concat(root.lowPrioritySensors)
}
let result = []
for (let i = 0; i < root.highPrioritySensors.length; ++i) {
if (root.highPrioritySensors[i].name.startsWith(groupSensor.value)) {
result.push(root.highPrioritySensors[i])
}
}
for (let i = 0; i < root.lowPrioritySensors.length; ++i) {
if (root.lowPrioritySensors[i].name.startsWith(groupSensor.value)) {
result.push(root.lowPrioritySensors[i])
}
}
return result
}
ChartsControls.LegendDelegate {
Layout.fillWidth: true
Layout.minimumHeight: implicitHeight
name: root.showGroups ? modelData.shortName : modelData.name
value: modelData.formattedValue
colorVisible: true
color: root.colorSource.map[modelData.sensorId]
layoutWidth: root.width
valueWidth: Kirigami.Units.gridUnit * 2
opacity: (root.y + parent.y + y + height) < root.totalHeight ? 1 : 0
}
}
Sensors.Sensor {
id: groupSensor
sensorId: root.showGroups ? modelData : ""
}
}
}
property var highPrioritySensors: []
property var lowPrioritySensors: []
Instantiator {
model: root.highPrioritySensorIds
Sensors.Sensor { sensorId: modelData }
onObjectAdded: root.highPrioritySensors.push(object)
onObjectRemoved: root.highPrioritySensors.splice(root.highPrioritySensors.indexOf(object), 1)
}
Instantiator {
model: root.lowPrioritySensorIds
Sensors.Sensor { sensorId: modelData }
onObjectAdded: root.lowPrioritySensors.push(object)
onObjectRemoved: root.lowPrioritySensors.splice(root.lowPrioritySensors.indexOf(object), 1)
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment