KUnitConversion

energy.cpp
1/*
2 * SPDX-FileCopyrightText: 2009 Petri Damstén <damu@iki.fi>
3 * SPDX-FileCopyrightText: 2014 John Layt <jlayt@kde.org>
4 *
5 * SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7
8#include "energy_p.h"
9#include "unit_p.h"
10
11#include <KLocalizedString>
12
13namespace KUnitConversion
14{
15class PhotoUnitPrivate : public UnitPrivate
16{
17public:
18 PhotoUnitPrivate(CategoryId categoryId,
19 UnitId id,
20 qreal multiplier,
21 const QString &symbol,
22 const QString &description,
23 const QString &matchString,
24 const KLocalizedString &symbolString,
25 const KLocalizedString &realString,
26 const KLocalizedString &integerString)
27 : UnitPrivate(categoryId, id, multiplier, symbol, description, matchString, symbolString, realString, integerString)
28 {
29 }
30
31 qreal toDefault(qreal value) const override
32 {
33 return (2.99792458e+08 * 6.62606896e-34) / (value * 1e-09);
34 }
35
36 qreal fromDefault(qreal value) const override
37 {
38 return ((2.99792458e+08 * 6.62606896e-34) / value) / 1e-09;
39 }
40};
41
42UnitCategory Energy::makeCategory()
43{
44 auto c = UnitCategoryPrivate::makeCategory(EnergyCategory, i18n("Energy"), i18n("Energy"));
45 auto d = UnitCategoryPrivate::get(c);
46 KLocalizedString symbolString = ki18nc("%1 value, %2 unit symbol (energy)", "%1 %2");
47
48 d->addUnit(UnitPrivate::makeUnit(EnergyCategory,
49 Yottajoule,
50 1e+24,
51 i18nc("energy unit symbol", "YJ"),
52 i18nc("unit description in lists", "yottajoules"),
53 i18nc("unit synonyms for matching user input", "yottajoule;yottajoules;YJ"),
54 symbolString,
55 ki18nc("amount in units (real)", "%1 yottajoules"),
56 ki18ncp("amount in units (integer)", "%1 yottajoule", "%1 yottajoules")));
57
58 d->addUnit(UnitPrivate::makeUnit(EnergyCategory,
59 Zettajoule,
60 1e+21,
61 i18nc("energy unit symbol", "ZJ"),
62 i18nc("unit description in lists", "zettajoules"),
63 i18nc("unit synonyms for matching user input", "zettajoule;zettajoules;ZJ"),
64 symbolString,
65 ki18nc("amount in units (real)", "%1 zettajoules"),
66 ki18ncp("amount in units (integer)", "%1 zettajoule", "%1 zettajoules")));
67
68 d->addUnit(UnitPrivate::makeUnit(EnergyCategory,
69 Exajoule,
70 1e+18,
71 i18nc("energy unit symbol", "EJ"),
72 i18nc("unit description in lists", "exajoules"),
73 i18nc("unit synonyms for matching user input", "exajoule;exajoules;EJ"),
74 symbolString,
75 ki18nc("amount in units (real)", "%1 exajoules"),
76 ki18ncp("amount in units (integer)", "%1 exajoule", "%1 exajoules")));
77
78 d->addUnit(UnitPrivate::makeUnit(EnergyCategory,
79 Petajoule,
80 1e+15,
81 i18nc("energy unit symbol", "PJ"),
82 i18nc("unit description in lists", "petajoules"),
83 i18nc("unit synonyms for matching user input", "petajoule;petajoules;PJ"),
84 symbolString,
85 ki18nc("amount in units (real)", "%1 petajoules"),
86 ki18ncp("amount in units (integer)", "%1 petajoule", "%1 petajoules")));
87
88 d->addUnit(UnitPrivate::makeUnit(EnergyCategory,
89 Terajoule,
90 1e+12,
91 i18nc("energy unit symbol", "TJ"),
92 i18nc("unit description in lists", "terajoules"),
93 i18nc("unit synonyms for matching user input", "terajoule;terajoules;TJ"),
94 symbolString,
95 ki18nc("amount in units (real)", "%1 terajoules"),
96 ki18ncp("amount in units (integer)", "%1 terajoule", "%1 terajoules")));
97
98 d->addUnit(UnitPrivate::makeUnit(EnergyCategory,
99 Gigajoule,
100 1e+09,
101 i18nc("energy unit symbol", "GJ"),
102 i18nc("unit description in lists", "gigajoules"),
103 i18nc("unit synonyms for matching user input", "gigajoule;gigajoules;GJ"),
104 symbolString,
105 ki18nc("amount in units (real)", "%1 gigajoules"),
106 ki18ncp("amount in units (integer)", "%1 gigajoule", "%1 gigajoules")));
107
108 d->addUnit(UnitPrivate::makeUnit(EnergyCategory,
109 Megajoule,
110 1e+06,
111 i18nc("energy unit symbol", "MJ"),
112 i18nc("unit description in lists", "megajoules"),
113 i18nc("unit synonyms for matching user input", "megajoule;megajoules;MJ"),
114 symbolString,
115 ki18nc("amount in units (real)", "%1 megajoules"),
116 ki18ncp("amount in units (integer)", "%1 megajoule", "%1 megajoules")));
117
118 d->addCommonUnit(UnitPrivate::makeUnit(EnergyCategory,
119 Kilojoule,
120 1000,
121 i18nc("energy unit symbol", "kJ"),
122 i18nc("unit description in lists", "kilojoules"),
123 i18nc("unit synonyms for matching user input", "kilojoule;kilojoules;kJ"),
124 symbolString,
125 ki18nc("amount in units (real)", "%1 kilojoules"),
126 ki18ncp("amount in units (integer)", "%1 kilojoule", "%1 kilojoules")));
127
128 d->addUnit(UnitPrivate::makeUnit(EnergyCategory,
129 Hectojoule,
130 100,
131 i18nc("energy unit symbol", "hJ"),
132 i18nc("unit description in lists", "hectojoules"),
133 i18nc("unit synonyms for matching user input", "hectojoule;hectojoules;hJ"),
134 symbolString,
135 ki18nc("amount in units (real)", "%1 hectojoules"),
136 ki18ncp("amount in units (integer)", "%1 hectojoule", "%1 hectojoules")));
137
138 d->addUnit(UnitPrivate::makeUnit(EnergyCategory,
139 Decajoule,
140 10,
141 i18nc("energy unit symbol", "daJ"),
142 i18nc("unit description in lists", "decajoules"),
143 i18nc("unit synonyms for matching user input", "decajoule;decajoules;daJ"),
144 symbolString,
145 ki18nc("amount in units (real)", "%1 decajoules"),
146 ki18ncp("amount in units (integer)", "%1 decajoule", "%1 decajoules")));
147
148 d->addDefaultUnit(UnitPrivate::makeUnit(EnergyCategory,
149 Joule,
150 1,
151 i18nc("energy unit symbol", "J"),
152 i18nc("unit description in lists", "joules"),
153 i18nc("unit synonyms for matching user input", "joule;joules;J"),
154 symbolString,
155 ki18nc("amount in units (real)", "%1 joules"),
156 ki18ncp("amount in units (integer)", "%1 joule", "%1 joules")));
157
158 d->addUnit(UnitPrivate::makeUnit(EnergyCategory,
159 Decijoule,
160 0.1,
161 i18nc("energy unit symbol", "dJ"),
162 i18nc("unit description in lists", "decijoules"),
163 i18nc("unit synonyms for matching user input", "decijoule;decijoules;dJ"),
164 symbolString,
165 ki18nc("amount in units (real)", "%1 decijoules"),
166 ki18ncp("amount in units (integer)", "%1 decijoule", "%1 decijoules")));
167
168 d->addUnit(UnitPrivate::makeUnit(EnergyCategory,
169 Centijoule,
170 0.01,
171 i18nc("energy unit symbol", "cJ"),
172 i18nc("unit description in lists", "centijoules"),
173 i18nc("unit synonyms for matching user input", "centijoule;centijoules;cJ"),
174 symbolString,
175 ki18nc("amount in units (real)", "%1 centijoules"),
176 ki18ncp("amount in units (integer)", "%1 centijoule", "%1 centijoules")));
177
178 d->addUnit(UnitPrivate::makeUnit(EnergyCategory,
179 Millijoule,
180 0.001,
181 i18nc("energy unit symbol", "mJ"),
182 i18nc("unit description in lists", "millijoules"),
183 i18nc("unit synonyms for matching user input", "millijoule;millijoules;mJ"),
184 symbolString,
185 ki18nc("amount in units (real)", "%1 millijoules"),
186 ki18ncp("amount in units (integer)", "%1 millijoule", "%1 millijoules")));
187
188 d->addUnit(UnitPrivate::makeUnit(EnergyCategory,
189 Microjoule,
190 1e-06,
191 i18nc("energy unit symbol", "µJ"),
192 i18nc("unit description in lists", "microjoules"),
193 i18nc("unit synonyms for matching user input", "microjoule;microjoules;µJ;uJ"),
194 symbolString,
195 ki18nc("amount in units (real)", "%1 microjoules"),
196 ki18ncp("amount in units (integer)", "%1 microjoule", "%1 microjoules")));
197
198 d->addUnit(UnitPrivate::makeUnit(EnergyCategory,
199 Nanojoule,
200 1e-09,
201 i18nc("energy unit symbol", "nJ"),
202 i18nc("unit description in lists", "nanojoules"),
203 i18nc("unit synonyms for matching user input", "nanojoule;nanojoules;nJ"),
204 symbolString,
205 ki18nc("amount in units (real)", "%1 nanojoules"),
206 ki18ncp("amount in units (integer)", "%1 nanojoule", "%1 nanojoules")));
207
208 d->addUnit(UnitPrivate::makeUnit(EnergyCategory,
209 Picojoule,
210 1e-12,
211 i18nc("energy unit symbol", "pJ"),
212 i18nc("unit description in lists", "picojoules"),
213 i18nc("unit synonyms for matching user input", "picojoule;picojoules;pJ"),
214 symbolString,
215 ki18nc("amount in units (real)", "%1 picojoules"),
216 ki18ncp("amount in units (integer)", "%1 picojoule", "%1 picojoules")));
217
218 d->addUnit(UnitPrivate::makeUnit(EnergyCategory,
219 Femtojoule,
220 1e-15,
221 i18nc("energy unit symbol", "fJ"),
222 i18nc("unit description in lists", "femtojoules"),
223 i18nc("unit synonyms for matching user input", "femtojoule;femtojoules;fJ"),
224 symbolString,
225 ki18nc("amount in units (real)", "%1 femtojoules"),
226 ki18ncp("amount in units (integer)", "%1 femtojoule", "%1 femtojoules")));
227
228 d->addUnit(UnitPrivate::makeUnit(EnergyCategory,
229 Attojoule,
230 1e-18,
231 i18nc("energy unit symbol", "aJ"),
232 i18nc("unit description in lists", "attojoules"),
233 i18nc("unit synonyms for matching user input", "attojoule;attojoules;aJ"),
234 symbolString,
235 ki18nc("amount in units (real)", "%1 attojoules"),
236 ki18ncp("amount in units (integer)", "%1 attojoule", "%1 attojoules")));
237
238 d->addUnit(UnitPrivate::makeUnit(EnergyCategory,
239 Zeptojoule,
240 1e-21,
241 i18nc("energy unit symbol", "zJ"),
242 i18nc("unit description in lists", "zeptojoules"),
243 i18nc("unit synonyms for matching user input", "zeptojoule;zeptojoules;zJ"),
244 symbolString,
245 ki18nc("amount in units (real)", "%1 zeptojoules"),
246 ki18ncp("amount in units (integer)", "%1 zeptojoule", "%1 zeptojoules")));
247
248 d->addUnit(UnitPrivate::makeUnit(EnergyCategory,
249 Yoctojoule,
250 1e-24,
251 i18nc("energy unit symbol", "yJ"),
252 i18nc("unit description in lists", "yoctojoules"),
253 i18nc("unit synonyms for matching user input", "yoctojoule;yoctojoules;yJ"),
254 symbolString,
255 ki18nc("amount in units (real)", "%1 yoctojoules"),
256 ki18ncp("amount in units (integer)", "%1 yoctojoule", "%1 yoctojoules")));
257
258 d->addCommonUnit(UnitPrivate::makeUnit(EnergyCategory,
259 GuidelineDailyAmount,
260 8.3736e+06,
261 i18nc("energy unit symbol", "GDA"),
262 i18nc("unit description in lists", "guideline daily amount"),
263 i18nc("unit synonyms for matching user input", "guideline daily amount;guideline daily amount;GDA"),
264 symbolString,
265 ki18nc("amount in units (real)", "%1 guideline daily amount"),
266 ki18ncp("amount in units (integer)", "%1 guideline daily amount", "%1 guideline daily amount")));
267
268 d->addUnit(UnitPrivate::makeUnit(EnergyCategory,
269 Electronvolt,
270 1.60218e-19,
271 i18nc("energy unit symbol", "eV"),
272 i18nc("unit description in lists", "electronvolts"),
273 i18nc("unit synonyms for matching user input", "electronvolt;electronvolts;eV"),
274 symbolString,
275 ki18nc("amount in units (real)", "%1 electronvolts"),
276 ki18ncp("amount in units (integer)", "%1 electronvolt", "%1 electronvolts")));
277
278 d->addUnit(UnitPrivate::makeUnit(EnergyCategory,
279 JoulePerMole,
280 1.66054238581e-24,
281 i18nc("energy unit symbol", "J/mol"),
282 i18nc("unit description in lists", "joule per mole"),
283 i18nc("unit synonyms for matching user input", "joule per mole;joulepermole;joulemol;jmol;j/mol"),
284 symbolString,
285 ki18nc("amount in units (real)", "%1 joules per mole"),
286 ki18ncp("amount in units (integer)", "%1 joule per mole", "%1 joules per mole")));
287
288 d->addUnit(UnitPrivate::makeUnit(EnergyCategory,
289 KiloJoulePerMole,
290 1.66054238581e-21,
291 i18nc("energy unit symbol", "kJ/mol"),
292 i18nc("unit description in lists", "kilojoule per mole"),
293 i18nc("unit synonyms for matching user input", "kilojoule per mole;kilojoulepermole;kilojoule per mole;kilojoulemol;kjmol;kj/mol"),
294 symbolString,
295 ki18nc("amount in units (real)", "%1 kilojoules per mole"),
296 ki18ncp("amount in units (integer)", "%1 kilojoule per mole", "%1 kilojoules per mole")));
297
298 d->addUnit(UnitPrivate::makeUnit(EnergyCategory,
299 Rydberg,
300 2.17987e-18,
301 i18nc("energy unit symbol", "Ry"),
302 i18nc("unit description in lists", "rydbergs"),
303 i18nc("unit synonyms for matching user input", "rydberg;rydbergs;Ry"),
304 symbolString,
305 ki18nc("amount in units (real)", "%1 rydbergs"),
306 ki18ncp("amount in units (integer)", "%1 rydberg", "%1 rydbergs")));
307
308 d->addCommonUnit(UnitPrivate::makeUnit(EnergyCategory,
309 Kilocalorie,
310 4186.8,
311 i18nc("energy unit symbol", "kcal"),
312 i18nc("unit description in lists", "kilocalories"),
313 i18nc("unit synonyms for matching user input", "kilocalorie;kilocalories;kcal"),
314 symbolString,
315 ki18nc("amount in units (real)", "%1 kilocalories"),
316 ki18ncp("amount in units (integer)", "%1 kilocalorie", "%1 kilocalories")));
317
318 d->addCommonUnit(UnitPrivate::makeUnit(EnergyCategory,
319 Btu,
320 1055.05585,
321 i18nc("energy unit symbol", "BTU"),
322 i18nc("unit description in lists", "British Thermal Unit"),
323 i18nc("unit synonyms for matching user input", "Btu;BTU;Btus;BTUs"),
324 symbolString,
325 ki18nc("amount in units (real)", "%1 BTU"),
326 ki18ncp("amount in units (integer)", "%1 BTU", "%1 BTU")));
327
328 d->addCommonUnit(UnitPrivate::makeUnit(EnergyCategory,
329 Erg,
330 1.0e-7,
331 i18nc("energy unit symbol", "Erg"),
332 i18nc("unit description in lists", "ergs"),
333 i18nc("unit synonyms for matching user input", "Erg;erg;Ergs;ergs"),
334 symbolString,
335 ki18nc("amount in units (real)", "%1 ergs"),
336 ki18ncp("amount in units (integer)", "%1 erg", "%1 erg")));
337
338 d->addUnit(UnitPrivate::makeUnit(new PhotoUnitPrivate(EnergyCategory,
339 PhotonWavelength,
340 1.0,
341 i18nc("energy unit symbol", "nm"),
342 i18nc("unit description in lists", "photon wavelength in nanometers"),
343 i18nc("unit synonyms for matching user input", "nm;photon wavelength"),
344 symbolString,
345 ki18nc("amount in units (real)", "%1 nanometers"),
346 ki18ncp("amount in units (integer)", "%1 nanometer", "%1 nanometers"))));
347
348 return c;
349}
350
351} // KUnitConversion namespace
QString i18nc(const char *context, const char *text, const TYPE &arg...)
KLocalizedString KI18N_EXPORT ki18ncp(const char *context, const char *singular, const char *plural)
KLocalizedString KI18N_EXPORT ki18nc(const char *context, const char *text)
QString i18n(const char *text, const TYPE &arg...)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:06:12 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.