Libksysguard

faces/import/ExtendedLegend.qml
1 /*
2  * Copyright 2019 Marco Martin <[email protected]>
3  * Copyright 2019 David Edmundson <[email protected]>
4  * Copyright 2019 Arjen Hiemstra <[email protected]>
5  * Copyright 2019 Kai Uwe Broulik <[email protected]>
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.faces.private 1.0
29 import org.kde.ksysguard.formatter 1.0
30 import org.kde.ksysguard.sensors 1.0
31 
32 import org.kde.quickcharts 1.0 as Charts
33 import org.kde.quickcharts.controls 1.0 as ChartsControls
34 
35 /**
36  * A legend control to be used in faces based on org.kde.quickcharts.Controls.Legend.
37  * It handles
38  * layouting and display of information depending on the available space. By default the current
39  * value of a sensor and its name are displayed, if it is shrunk the shortName is displayed instead.
40  *
41  * @since 5.19
42  */
43 ChartsControls.Legend {
44  id: legend
45 
46  /**
47  * A list of sensor ids that should be displayed in addition to those from sourceModel. Typically
48  * set to lowPrioritySensorIds from FaceController
49  */
50  property alias sensorIds: sensorsRepeater.model
51  /**
52  * The SensorDataModel that should be used to retrieve data about the sensors.
53  */
54  property SensorDataModel sourceModel
55  /**
56  * @deprecated since 5.21
57  * Has no effect
58  */
59  property var colorSource
60 
61  flow: GridLayout.TopToBottom
62 
63  Layout.maximumHeight: implicitHeight
64  Layout.maximumWidth: parent.width
65 
66  spacing: flow == GridLayout.TopToBottom ? Kirigami.Units.smallSpacing : Kirigami.Units.gridUnit
67 
68  valueVisible: true
69  valueWidth: Kirigami.Units.gridUnit * 2
70  formatValue: function(input, index) {
71  if (!sourceModel) {
72  return input
73  }
74 
75  return Formatter.formatValueShowNull(input, sourceModel.data(sourceModel.index(0, index), SensorDataModel.Unit))
76  }
77 
78  Binding on model {
79  when: !chart
80  value: QTransposeProxyModel {
81  sourceModel: legend.sourceModel
82  }
83  }
84  Binding on valueRole {
85  when: !chart
86  value: "Value"
87  }
88  Binding on nameRole {
89  when: !chart
90  value: "Name"
91  }
92  Binding on shortNameRole {
93  when: !chart
94  value: "ShortName"
95  }
96  Binding on colorRole {
97  when: !chart
98  value: "Color"
99  }
100 
101  Repeater {
102  id: sensorsRepeater
103  delegate: ChartsControls.LegendDelegate {
104  name: sensor.name
105  shortName: sensor.shortName
106  value: sensor.formattedValue || ""
107  colorVisible: false
108 
109  layoutWidth: legend.width
110  valueWidth: Kirigami.Units.gridUnit * 2
111 
112  Sensor {
113  id: sensor
114  sensorId: modelData
115  }
116  }
117  }
118 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Thu Mar 4 2021 23:09:25 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.