Changeset View
Changeset View
Standalone View
Standalone View
processcore/process_attribute.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | Copyright (c) 2019 David Edmundson <davidedmundson@kde.org> | ||||
3 | | ||||
4 | This library is free software; you can redistribute it and/or | ||||
5 | modify it under the terms of the GNU Library General Public | ||||
6 | License as published by the Free Software Foundation; either | ||||
7 | version 2 of the License, or (at your option) any later version. | ||||
8 | | ||||
9 | This library is distributed in the hope that it will be useful, | ||||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
12 | Library General Public License for more details. | ||||
13 | | ||||
14 | You should have received a copy of the GNU Library General Public License | ||||
15 | along with this library; see the file COPYING.LIB. If not, write to | ||||
16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||||
17 | Boston, MA 02110-1301, USA. | ||||
18 | */ | ||||
19 | | ||||
20 | #include "process_attribute.h" | ||||
21 | #include "processes.h" | ||||
22 | | ||||
23 | using namespace KSysGuard; | ||||
24 | | ||||
25 | class Q_DECL_HIDDEN KSysGuard::ProcessAttribute::Private | ||||
26 | { | ||||
27 | public: | ||||
28 | QString m_id; | ||||
29 | | ||||
30 | QString m_name; | ||||
31 | QString m_shortName; | ||||
32 | QString m_description; | ||||
33 | qreal m_min = 0; | ||||
34 | qreal m_max = 0; | ||||
35 | KSysGuard::Unit m_unit = KSysGuard::UnitInvalid; //Both a format hint and implies data type (i.e double/string) | ||||
36 | | ||||
37 | QHash<KSysGuard::Process *, QVariant> m_data; | ||||
38 | bool m_enabled = false; | ||||
39 | }; | ||||
40 | | ||||
41 | ProcessAttribute::ProcessAttribute(const QString &id, QObject *parent) | ||||
42 | : ProcessAttribute(id, QString(), parent) | ||||
43 | { | ||||
44 | } | ||||
45 | | ||||
46 | ProcessAttribute::ProcessAttribute(const QString &id, const QString &name, QObject *parent) | ||||
47 | : QObject(parent) | ||||
48 | , d(new Private) | ||||
49 | { | ||||
50 | d->m_id = id; | ||||
51 | d->m_name = name; | ||||
52 | } | ||||
53 | | ||||
54 | ProcessAttribute::~ProcessAttribute() | ||||
55 | { | ||||
56 | } | ||||
57 | | ||||
58 | QString ProcessAttribute::id() const | ||||
59 | { | ||||
60 | return d->m_id; | ||||
61 | } | ||||
62 | | ||||
63 | bool ProcessAttribute::enabled() const | ||||
64 | { | ||||
65 | return d->m_enabled; | ||||
66 | } | ||||
67 | | ||||
68 | void ProcessAttribute::setEnabled(const bool enabled) | ||||
69 | { | ||||
70 | if (d->m_enabled == enabled) { | ||||
71 | return; | ||||
72 | } | ||||
73 | d->m_enabled = enabled; | ||||
74 | emit enabledChanged(enabled); | ||||
75 | } | ||||
76 | | ||||
77 | QString ProcessAttribute::name() const | ||||
78 | { | ||||
79 | return d->m_name; | ||||
80 | } | ||||
81 | | ||||
82 | void ProcessAttribute::setName(const QString &name) | ||||
83 | { | ||||
84 | d->m_name = name; | ||||
85 | } | ||||
86 | | ||||
87 | QString ProcessAttribute::shortName() const | ||||
88 | { | ||||
89 | return d->m_shortName.isEmpty() ? d->m_name : d->m_shortName; | ||||
90 | } | ||||
91 | | ||||
92 | void ProcessAttribute::setShortName(const QString &name) | ||||
93 | { | ||||
94 | d->m_shortName = name; | ||||
95 | } | ||||
96 | | ||||
97 | QString ProcessAttribute::description() const | ||||
98 | { | ||||
99 | return d->m_description; | ||||
100 | } | ||||
101 | | ||||
102 | void ProcessAttribute::setDescription(const QString &description) | ||||
103 | { | ||||
104 | d->m_description = description; | ||||
105 | } | ||||
106 | | ||||
107 | qreal ProcessAttribute::min() const | ||||
108 | { | ||||
109 | return d->m_min; | ||||
110 | } | ||||
111 | | ||||
112 | void ProcessAttribute::setMin(const qreal min) | ||||
113 | { | ||||
114 | d->m_min = min; | ||||
115 | } | ||||
116 | | ||||
117 | qreal ProcessAttribute::max() const | ||||
118 | { | ||||
119 | return d->m_max; | ||||
120 | } | ||||
121 | | ||||
122 | void ProcessAttribute::setMax(const qreal max) | ||||
123 | { | ||||
124 | d->m_max = max; | ||||
125 | } | ||||
126 | | ||||
127 | KSysGuard::Unit ProcessAttribute::unit() const | ||||
128 | { | ||||
129 | return d->m_unit; | ||||
130 | } | ||||
131 | | ||||
132 | void ProcessAttribute::setUnit(KSysGuard::Unit unit) | ||||
133 | { | ||||
134 | d->m_unit = unit; | ||||
135 | } | ||||
136 | | ||||
137 | QVariant ProcessAttribute::data(KSysGuard::Process *process) | ||||
138 | { | ||||
139 | return d->m_data.value(process); | ||||
140 | } | ||||
141 | | ||||
142 | void ProcessAttribute::setData(KSysGuard::Process *process, const QVariant &value) | ||||
143 | { | ||||
144 | d->m_data[process] = value; | ||||
145 | emit dataChanged(process); | ||||
146 | } | ||||
147 | | ||||
148 | void ProcessAttribute::clearData(KSysGuard::Process *process) | ||||
149 | { | ||||
150 | d->m_data.remove(process); | ||||
151 | emit dataChanged(process); | ||||
152 | } |