Differential D28487 Diff 79120 applets/systemmonitor/systemmonitor/faces/table/contents/ui/FullRepresentation.qml
Changeset View
Changeset View
Standalone View
Standalone View
applets/systemmonitor/systemmonitor/faces/table/contents/ui/FullRepresentation.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 | * | ||||
6 | * This program is free software; you can redistribute it and/or | ||||
7 | * modify it under the terms of the GNU General Public License as | ||||
8 | * published by the Free Software Foundation; either version 2 of | ||||
9 | * the License or (at your option) version 3 or any later version | ||||
10 | * accepted by the membership of KDE e.V. (or its successor approved | ||||
11 | * by the membership of KDE e.V.), which shall act as a proxy | ||||
12 | * defined in Section 14 of version 3 of the license. | ||||
13 | * | ||||
14 | * This program is distributed in the hope that it will be useful, | ||||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
17 | * GNU General Public License for more details. | ||||
18 | * | ||||
19 | * You should have received a copy of the GNU General Public License | ||||
20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
21 | */ | ||||
22 | | ||||
23 | import QtQuick 2.12 | ||||
24 | import QtQuick.Controls 2.2 | ||||
25 | import QtQuick.Layouts 1.2 | ||||
26 | | ||||
27 | import QtQml.Models 2.12 | ||||
28 | | ||||
29 | import org.kde.kirigami 2.2 as Kirigami | ||||
30 | | ||||
31 | import org.kde.ksysguard.sensors 1.0 as Sensors2 | ||||
32 | | ||||
33 | import org.kde.plasma.core 2.0 as PlasmaCore | ||||
34 | import org.kde.quickcharts 1.0 as Charts | ||||
35 | | ||||
36 | ColumnLayout { | ||||
37 | id: root | ||||
38 | | ||||
39 | Layout.minimumWidth: Kirigami.Units.gridUnit * 8 | ||||
40 | Layout.minimumHeight: Kirigami.Units.gridUnit * 4 | ||||
41 | | ||||
42 | Layout.preferredWidth: Kirigami.Units.gridUnit * 16 | ||||
43 | Layout.preferredHeight: Kirigami.Units.gridUnit * 18 | ||||
44 | | ||||
45 | opacity: y + height <= parent.height | ||||
46 | | ||||
47 | RowLayout { | ||||
48 | Layout.fillHeight: false | ||||
49 | Kirigami.Heading { | ||||
50 | id: heading | ||||
51 | text: plasmoid.configuration.title | ||||
52 | level: 2 | ||||
53 | elide: Text.ElideRight | ||||
54 | Layout.fillHeight: true | ||||
55 | } | ||||
56 | | ||||
57 | Charts.LineChart { | ||||
58 | Layout.fillWidth: true | ||||
59 | Layout.fillHeight: true | ||||
60 | fillOpacity: 0 | ||||
61 | | ||||
62 | xRange { from: 0; to: 50; automatic: false } | ||||
63 | yRange { from: 0; to: 100; automatic: false } | ||||
64 | | ||||
65 | visible: plasmoid.configuration.totalSensor !== "" | ||||
66 | | ||||
67 | smooth: true | ||||
68 | colorSource: Charts.SingleValueSource { value: root.Kirigami.Theme.textColor} | ||||
69 | lineWidth: 1 | ||||
70 | direction: Charts.XYChart.ZeroAtEnd | ||||
71 | | ||||
72 | valueSources: [ | ||||
73 | Charts.ModelHistorySource { | ||||
74 | model: Sensors2.SensorDataModel { sensors: [ plasmoid.configuration.totalSensor ] } | ||||
75 | column: 0; | ||||
76 | row: 0 | ||||
77 | roleName: "Value"; | ||||
78 | maximumHistory: 50 | ||||
79 | } | ||||
80 | ] | ||||
81 | } | ||||
82 | } | ||||
83 | | ||||
84 | RowLayout { | ||||
85 | id: header | ||||
86 | y: -height | ||||
87 | Layout.fillWidth: true | ||||
88 | visible: plasmoid.nativeInterface.faceConfiguration.showTableHeaders | ||||
89 | Repeater { | ||||
90 | model: Sensors2.HeadingHelperModel { | ||||
91 | id: headingHelperModel | ||||
92 | | ||||
93 | sourceModel: tableView.model | ||||
94 | } | ||||
95 | Kirigami.Heading { | ||||
96 | id: heading | ||||
97 | level: 4 | ||||
98 | Layout.fillWidth: true | ||||
99 | //FIXME: why +2 is necessary? | ||||
100 | Layout.preferredWidth: metrics.width+2 | ||||
101 | Layout.maximumWidth: x > 0 ? metrics.width+2 : -1 | ||||
102 | TextMetrics{ | ||||
103 | id: metrics | ||||
104 | font: heading.font | ||||
105 | text: heading.text | ||||
106 | } | ||||
107 | text: model.display | ||||
108 | elide: Text.ElideRight | ||||
109 | horizontalAlignment: index > 0 ? Text.AlignRight : Text.AlignLeft | ||||
110 | } | ||||
111 | } | ||||
112 | } | ||||
113 | TableView { | ||||
114 | id: tableView | ||||
115 | | ||||
116 | Layout.fillHeight: true | ||||
117 | Layout.fillWidth: true | ||||
118 | | ||||
119 | model: topModel | ||||
120 | interactive: false | ||||
121 | columnSpacing: Kirigami.Units.smallSpacing | ||||
122 | clip: true | ||||
123 | | ||||
124 | property int dataColumnWidth: Kirigami.Units.gridUnit * 5 | ||||
125 | | ||||
126 | columnWidthProvider: function (column) { | ||||
127 | return header.children[column].width; | ||||
128 | } | ||||
129 | | ||||
130 | delegate: Label { | ||||
131 | // Not visible to not change contentHeight | ||||
132 | opacity: y + height <= tableView.height | ||||
133 | text: model.display != undefined ? model.display : "" | ||||
134 | horizontalAlignment: model.alignment == (Text.AlignRight + Text.AlignVCenter) ? Text.AlignRight : Text.AlignLeft | ||||
135 | elide: Text.ElideRight | ||||
136 | verticalAlignment: Text.AlignVCenter | ||||
137 | } | ||||
138 | | ||||
139 | //See https://codereview.qt-project.org/c/qt/qtdeclarative/+/262876 | ||||
140 | onWidthChanged: Qt.callLater(function() {if (tableView.columns > 0) { | ||||
141 | tableView.forceLayout() | ||||
142 | }}); | ||||
143 | | ||||
144 | PlasmaCore.SortFilterModel { | ||||
145 | id: topModel | ||||
146 | filterKeyColumn: 0 // name | ||||
147 | filterRegExp: ".+" | ||||
148 | | ||||
149 | sortColumn: plasmoid.nativeInterface.faceConfiguration.sortColumn | ||||
150 | sortRole: "Value" | ||||
151 | sortOrder: plasmoid.nativeInterface.faceConfiguration.sortDescending ? Qt.DescendingOrder : Qt.AscendingOrder | ||||
152 | | ||||
153 | sourceModel: Sensors2.SensorDataModel { | ||||
154 | id: dataModel | ||||
155 | sensors: plasmoid.configuration.sensorIds | ||||
156 | onSensorsChanged: { | ||||
157 | //note: this re sets the models in order to make the table work with any new role | ||||
158 | tableView.model = null; | ||||
159 | topModel.sourceModel = null; | ||||
160 | topModel.sourceModel = dataModel; | ||||
161 | tableView.model = topModel; | ||||
162 | } | ||||
163 | } | ||||
164 | } | ||||
165 | } | ||||
166 | } |