Changeset View
Changeset View
Standalone View
Standalone View
sensors/declarative/ExtendedLegend.qml
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright 2019 Marco Martin <mart@kde.org> | ||||
3 | * Copyright 2019 David Edmundson <davidedmundson@kde.org> | ||||
4 | * Copyright 2019 Arjen Hiemstra <ahiemstra@heimr.nl> | ||||
5 | * Copyright 2019 Kai Uwe Broulik <kde@broulik.de> | ||||
6 | * | ||||
7 | * This program is free software; you can redistribute it and/or modify | ||||
8 | * it under the terms of the GNU Library General Public License as | ||||
9 | * published by the Free Software Foundation; either version 2, or | ||||
10 | * (at your option) any later version. | ||||
11 | * | ||||
12 | * This program is distributed in the hope that it will be useful, | ||||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
15 | * GNU General Public License for more details | ||||
16 | * | ||||
17 | * You should have received a copy of the GNU Library General Public | ||||
18 | * License along with this program; if not, write to the | ||||
19 | * Free Software Foundation, Inc., | ||||
20 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
21 | */ | ||||
22 | | ||||
23 | import QtQuick 2.9 | ||||
24 | import QtQuick.Layouts 1.1 | ||||
25 | | ||||
26 | import org.kde.kirigami 2.8 as Kirigami | ||||
27 | | ||||
28 | import org.kde.ksysguard.formatter 1.0 | ||||
29 | import org.kde.ksysguard.sensors 1.0 | ||||
30 | | ||||
31 | import org.kde.quickcharts 1.0 as Charts | ||||
32 | import org.kde.quickcharts.controls 1.0 as ChartsControls | ||||
33 | | ||||
34 | ChartsControls.Legend { | ||||
35 | id: legend | ||||
36 | | ||||
37 | property alias textOnlySensorIds: textOnlySensorsRepeater.model | ||||
38 | property var sourceModel | ||||
39 | property var colorSource | ||||
40 | | ||||
41 | flow: GridLayout.TopToBottom | ||||
42 | | ||||
43 | Layout.maximumHeight: implicitHeight | ||||
44 | Layout.maximumWidth: parent.width | ||||
45 | | ||||
46 | spacing: Kirigami.Units.smallSpacing | ||||
47 | | ||||
48 | valueVisible: true | ||||
49 | valueWidth: units.gridUnit * 2 | ||||
50 | formatValue: function(input, index) { | ||||
51 | return Formatter.formatValueShowNull(input, sourceModel.data(sourceModel.index(0, index), SensorDataModel.Unit)) | ||||
52 | } | ||||
53 | | ||||
54 | Repeater { | ||||
55 | id: textOnlySensorsRepeater | ||||
56 | delegate: ChartsControls.LegendDelegate { | ||||
57 | name: sensor.shortName | ||||
58 | value: sensor.formattedValue || "" | ||||
59 | colorVisible: false | ||||
60 | | ||||
61 | layoutWidth: legend.width | ||||
62 | valueWidth: units.gridUnit * 2 | ||||
63 | | ||||
64 | Sensor { | ||||
65 | id: sensor | ||||
66 | sensorId: modelData | ||||
67 | } | ||||
68 | } | ||||
69 | } | ||||
70 | } |