Debian Codegraph @

src/core/components/controls/amd/fan/fixed/fanfixedqmlitem.cpp

raw symbols SCIP
1 // SPDX-License-Identifier: GPL-3.0-or-later
2 // Copyright 2019 Juan Palacios <[email protected]>
3
4 #include "fanfixedqmlitem.h"
5
6 #include "core/qmlcomponentregistry.h"
7 #include "fanfixed.h"
8 #include <QQmlApplicationEngine>
9 #include <QString>
10 #include <memory>
11
12 char const *const AMD::FanFixedQMLItem::trStrings[] = {
13 QT_TRANSLATE_NOOP("ControlModeQMLItem", "AMD_FAN_FIXED"),
14 };
15
16 class AMD::FanFixedQMLItem::Initializer final
17 : public QMLItem::Initializer
18 , public AMD::FanFixed::Exporter
19 {
20 public:
21 Initializer(IQMLComponentFactory const &qmlComponentFactory,
22 QQmlApplicationEngine &qmlEngine,
23 AMD::FanFixedQMLItem &qmlItem) noexcept
24 : QMLItem::Initializer(qmlComponentFactory, qmlEngine)
25 , outer_(qmlItem)
26 {
27 }
28
29 std::optional<std::reference_wrapper<Exportable::Exporter>>
30 provideExporter(Item const &) override
31 {
32 return {};
33 }
34
35 void takeActive(bool active) override;
36 void takeFanFixedValue(units::concentration::percent_t value) override;
37 void takeFanFixedFanStop(bool enabled) override;
38 void takeFanFixedFanStartValue(units::concentration::percent_t value) override;
39
40 private:
41 AMD::FanFixedQMLItem &outer_;
42 };
43
44 void AMD::FanFixedQMLItem::Initializer::takeActive(bool active)
45 {
46 outer_.takeActive(active);
47 }
48
49 void AMD::FanFixedQMLItem::Initializer::takeFanFixedValue(
50 units::concentration::percent_t value)
51 {
52 outer_.takeFanFixedValue(value);
53 }
54
55 void AMD::FanFixedQMLItem::Initializer::takeFanFixedFanStop(bool enabled)
56 {
57 outer_.takeFanFixedFanStop(enabled);
58 }
59
60 void AMD::FanFixedQMLItem::Initializer::takeFanFixedFanStartValue(
61 units::concentration::percent_t value)
62 {
63 outer_.takeFanFixedFanStartValue(value);
64 }
65
66 AMD::FanFixedQMLItem::FanFixedQMLItem() noexcept
67 {
68 setName(tr(AMD::FanFixed::ItemID.data()));
69 }
70
71 void AMD::FanFixedQMLItem::changeValue(int value)
72 {
73 if (value_ != value) {
74 value_ = value;
75 emit valueChanged(value_);
76 emit settingsChanged();
77 }
78 }
79
80 void AMD::FanFixedQMLItem::enableFanStop(bool enabled)
81 {
82 if (fanStop_ != enabled) {
83 fanStop_ = enabled;
84 emit fanStopChanged(fanStop_);
85 emit settingsChanged();
86 }
87 }
88
89 void AMD::FanFixedQMLItem::changeFanStartValue(int value)
90 {
91 if (fanStartValue_ != value) {
92 fanStartValue_ = value;
93 emit fanStartValueChanged(fanStartValue_);
94 emit settingsChanged();
95 }
96 }
97
98 void AMD::FanFixedQMLItem::activate(bool active)
99 {
100 takeActive(active);
101 }
102
103 std::optional<std::reference_wrapper<Importable::Importer>>
104 AMD::FanFixedQMLItem::provideImporter(Item const &)
105 {
106 return {};
107 }
108
109 std::optional<std::reference_wrapper<Exportable::Exporter>>
110 AMD::FanFixedQMLItem::provideExporter(Item const &)
111 {
112 return {};
113 }
114
115 bool AMD::FanFixedQMLItem::provideActive() const
116 {
117 return active_;
118 }
119
120 units::concentration::percent_t AMD::FanFixedQMLItem::provideFanFixedValue() const
121 {
122 return value_;
123 }
124
125 bool AMD::FanFixedQMLItem::provideFanFixedFanStop() const
126 {
127 return fanStop_;
128 }
129
130 units::concentration::percent_t
131 AMD::FanFixedQMLItem::provideFanFixedFanStartValue() const
132 {
133 return fanStartValue_;
134 }
135
136 void AMD::FanFixedQMLItem::takeActive(bool active)
137 {
138 active_ = active;
139 setVisible(active);
140 }
141
142 void AMD::FanFixedQMLItem::takeFanFixedValue(units::concentration::percent_t value)
143 {
144 auto newValue = static_cast<int>(value * 100);
145 if (value_ != newValue) {
146 value_ = newValue;
147 emit valueChanged(value_);
148 }
149 }
150
151 void AMD::FanFixedQMLItem::takeFanFixedFanStop(bool active)
152 {
153 if (fanStop_ != active) {
154 fanStop_ = active;
155 emit fanStopChanged(fanStop_);
156 }
157 }
158
159 void AMD::FanFixedQMLItem::takeFanFixedFanStartValue(
160 units::concentration::percent_t value)
161 {
162 auto newValue = static_cast<int>(value * 100);
163 if (fanStartValue_ != newValue) {
164 fanStartValue_ = newValue;
165 emit fanStartValueChanged(fanStartValue_);
166 }
167 }
168
169 std::unique_ptr<Exportable::Exporter>
170 AMD::FanFixedQMLItem::initializer(IQMLComponentFactory const &qmlComponentFactory,
171 QQmlApplicationEngine &qmlEngine)
172 {
173 return std::make_unique<AMD::FanFixedQMLItem::Initializer>(
174 qmlComponentFactory, qmlEngine, *this);
175 }
176
177 bool AMD::FanFixedQMLItem::register_()
178 {
179 QMLComponentRegistry::addQMLTypeRegisterer([]() {
180 qmlRegisterType<AMD::FanFixedQMLItem>("CoreCtrl.UIComponents", 1, 0,
181 AMD::FanFixed::ItemID.data());
182 });
183
184 QMLComponentRegistry::addQMLItemProvider(
185 AMD::FanFixed::ItemID, [](QQmlApplicationEngine &engine) {
186 QQmlComponent component(&engine,
187 QStringLiteral("qrc:/qml/AMDFanFixedForm.qml"));
188 return qobject_cast<QMLItem *>(component.create());
189 });
190
191 return true;
192 }
193
194 bool const AMD::FanFixedQMLItem::registered_ = AMD::FanFixedQMLItem::register_();