KUnitConversion 5.109.0
unit.h
1/*
2 * SPDX-FileCopyrightText: 2007-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#ifndef KUNITCONVERSION_UNIT_H
9#define KUNITCONVERSION_UNIT_H
10
11#include "kunitconversion/kunitconversion_export.h"
12
13#include <QExplicitlySharedDataPointer>
14#include <QString>
15
16namespace KUnitConversion
17{
18enum CategoryId {
19 InvalidCategory = -1,
20 LengthCategory,
21 AreaCategory,
22 VolumeCategory,
23 TemperatureCategory,
24 VelocityCategory,
25 MassCategory,
26 PressureCategory,
27 EnergyCategory,
28 CurrencyCategory,
29 PowerCategory,
30 TimeCategory,
31 FuelEfficiencyCategory,
32 DensityCategory,
33 AccelerationCategory,
34 AngleCategory,
35 FrequencyCategory,
36 ForceCategory,
38 ThermalConductivityCategory,
40 ThermalFluxCategory,
42 ThermalGenerationCategory,
44 VoltageCategory,
46 ElectricalCurrentCategory,
48 ElectricalResistanceCategory,
50 PermeabilityCategory,
52 BinaryDataCategory
53};
54
55enum UnitId {
56 InvalidUnit = -1,
57 NoUnit = 0,
58 Percent = 1,
59
60 // Area
61 SquareYottameter = 1000,
62 SquareZettameter,
63 SquareExameter,
64 SquarePetameter,
65 SquareTerameter,
66 SquareGigameter,
67 SquareMegameter,
68 SquareKilometer,
69 SquareHectometer,
70 SquareDecameter,
71 SquareMeter,
72 SquareDecimeter,
73 SquareCentimeter,
74 SquareMillimeter,
75 SquareMicrometer,
76 SquareNanometer,
77 SquarePicometer,
78 SquareFemtometer,
79 SquareAttometer,
80 SquareZeptometer,
81 SquareYoctometer,
82 Acre,
83 SquareFoot,
84 SquareInch,
85 SquareMile,
86
87 // Length
88 Yottameter = 2000,
89 Zettameter,
90 Exameter,
91 Petameter,
92 Terameter,
93 Gigameter,
94 Megameter,
95 Kilometer,
96 Hectometer,
97 Decameter,
98 Meter,
99 Decimeter,
100 Centimeter,
101 Millimeter,
102 Micrometer,
103 Nanometer,
104 Picometer,
105 Femtometer,
106 Attometer,
107 Zeptometer,
108 Yoctometer,
109 Inch,
110 Foot,
111 Yard,
112 Mile,
113 NauticalMile,
114 LightYear,
115 Parsec,
116 AstronomicalUnit,
117 Thou,
118 Angstrom,
119
120 // Volume
121 CubicYottameter = 3000,
122 CubicZettameter,
123 CubicExameter,
124 CubicPetameter,
125 CubicTerameter,
126 CubicGigameter,
127 CubicMegameter,
128 CubicKilometer,
129 CubicHectometer,
130 CubicDecameter,
131 CubicMeter,
132 CubicDecimeter,
133 CubicCentimeter,
134 CubicMillimeter,
135 CubicMicrometer,
136 CubicNanometer,
137 CubicPicometer,
138 CubicFemtometer,
139 CubicAttometer,
140 CubicZeptometer,
141 CubicYoctometer,
142 Yottaliter,
143 Zettaliter,
144 Exaliter,
145 Petaliter,
146 Teraliter,
147 Gigaliter,
148 Megaliter,
149 Kiloliter,
150 Hectoliter,
151 Decaliter,
152 Liter,
153 Deciliter,
154 Centiliter,
155 Milliliter,
156 Microliter,
157 Nanoliter,
158 Picoliter,
159 Femtoliter,
160 Attoliter,
161 Zeptoliter,
162 Yoctoliter,
163 CubicFoot,
164 CubicInch,
165 CubicMile,
166 FluidOunce,
167 Cup,
168 Teaspoon,
169 Tablespoon,
170 GallonUS,
171 PintImperial,
173 OilBarrel,
175 GallonImperial,
176 PintUS,
177
178 // Mass
179 Yottagram = 4000,
180 Zettagram,
181 Exagram,
182 Petagram,
183 Teragram,
184 Gigagram,
185 Megagram,
186 Kilogram,
187 Hectogram,
188 Decagram,
189 Gram,
190 Decigram,
191 Centigram,
192 Milligram,
193 Microgram,
194 Nanogram,
195 Picogram,
196 Femtogram,
197 Attogram,
198 Zeptogram,
199 Yoctogram,
200 Ton,
201 Carat,
202 Pound,
203 Ounce,
204 TroyOunce,
205 MassNewton,
206 Kilonewton,
207
209 Stone,
210
211 // Pressure
212 Yottapascal = 5000,
213 Zettapascal,
214 Exapascal,
215 Petapascal,
216 Terapascal,
217 Gigapascal,
218 Megapascal,
219 Kilopascal,
220 Hectopascal,
221 Decapascal,
222 Pascal,
223 Decipascal,
224 Centipascal,
225 Millipascal,
226 Micropascal,
227 Nanopascal,
228 Picopascal,
229 Femtopascal,
230 Attopascal,
231 Zeptopascal,
232 Yoctopascal,
233 Bar,
234 Millibar,
235 Decibar,
236 Torr,
237 TechnicalAtmosphere,
238 Atmosphere,
239 PoundForcePerSquareInch,
240 InchesOfMercury,
241 MillimetersOfMercury,
242
243 // Temperature
244 Kelvin = 6000,
245 Celsius,
246 Fahrenheit,
247 Rankine,
248 Delisle,
249 TemperatureNewton,
250 Reaumur,
251 Romer,
252
253 // Energy
254 Yottajoule = 7000,
255 Zettajoule,
256 Exajoule,
257 Petajoule,
258 Terajoule,
259 Gigajoule,
260 Megajoule,
261 Kilojoule,
262 Hectojoule,
263 Decajoule,
264 Joule,
265 Decijoule,
266 Centijoule,
267 Millijoule,
268 Microjoule,
269 Nanojoule,
270 Picojoule,
271 Femtojoule,
272 Attojoule,
273 Zeptojoule,
274 Yoctojoule,
275 GuidelineDailyAmount,
276 Electronvolt,
277 Rydberg,
278 Kilocalorie,
279 PhotonWavelength,
280 KiloJoulePerMole,
281 JoulePerMole,
283 Btu,
285 Erg,
286
287 // Currency
288 Eur = 8000,
289 Ats,
290 Bef,
291 Nlg,
292 Fim,
293 Frf,
294 Dem,
295 Iep,
296 Itl,
297 Luf,
298 Pte,
299 Esp,
300 Grd,
301 Sit,
302 Cyp,
303 Mtl,
304 Skk,
305 Usd,
306 Jpy,
307 Bgn,
308 Czk,
309 Dkk,
310 Eek,
311 Gbp,
312 Huf,
313 Ltl,
314 Lvl,
315 Pln,
316 Ron,
317 Sek,
318 Chf,
319 Nok,
320 Hrk,
321 Rub,
322 Try,
323 Aud,
324 Brl,
325 Cad,
326 Cny,
327 Hkd,
328 Idr,
329 Inr,
330 Krw,
331 Mxn,
332 Myr,
333 Nzd,
334 Php,
335 Sgd,
336 Thb,
337 Zar,
338 Ils,
339 Isk,
340
341 // Velocity
342 MeterPerSecond = 9000,
343 KilometerPerHour,
344 MilePerHour,
345 FootPerSecond,
346 InchPerSecond,
347 Knot,
348 Mach,
349 SpeedOfLight,
350 Beaufort,
351
352 // Power
353 Yottawatt = 10000,
354 Zettawatt,
355 Exawatt,
356 Petawatt,
357 Terawatt,
358 Gigawatt,
359 Megawatt,
360 Kilowatt,
361 Hectowatt,
362 Decawatt,
363 Watt,
364 Deciwatt,
365 Centiwatt,
366 Milliwatt,
367 Microwatt,
368 Nanowatt,
369 Picowatt,
370 Femtowatt,
371 Attowatt,
372 Zeptowatt,
373 Yoctowatt,
374 Horsepower,
376 DecibelKilowatt,
377 DecibelWatt,
378 DecibelMilliwatt,
379 DecibelMicrowatt,
380
381 // Time
382 Yottasecond = 11000,
383 Zettasecond,
384 Exasecond,
385 Petasecond,
386 Terasecond,
387 Gigasecond,
388 Megasecond,
389 Kilosecond,
390 Hectosecond,
391 Decasecond,
392 Second,
393 Decisecond,
394 Centisecond,
395 Millisecond,
396 Microsecond,
397 Nanosecond,
398 Picosecond,
399 Femtosecond,
400 Attosecond,
401 Zeptosecond,
402 Yoctosecond,
403 Minute,
404 Hour,
405 Day,
406 Week,
407 JulianYear,
408 LeapYear,
409 Year,
410
411 // FuelEfficiency
412 LitersPer100Kilometers = 12000,
413 MilePerUsGallon,
414 MilePerImperialGallon,
415 KilometrePerLitre,
416
417 // Density
418 YottakilogramsPerCubicMeter = 13000,
419 ZettakilogramPerCubicMeter,
420 ExakilogramPerCubicMeter,
421 PetakilogramPerCubicMeter,
422 TerakilogramPerCubicMeter,
423 GigakilogramPerCubicMeter,
424 MegakilogramPerCubicMeter,
425 KilokilogramPerCubicMeter,
426 HectokilogramsPerCubicMeter,
427 DecakilogramsPerCubicMeter,
428 KilogramsPerCubicMeter,
429 DecikilogramsPerCubicMeter,
430 CentikilogramsPerCubicMeter,
431 MillikilogramsPerCubicMeter,
432 MicrokilogramsPerCubicMeter,
433 NanokilogramsPerCubicMeter,
434 PicokilogramsPerCubicMeter,
435 FemtokilogramsPerCubicMeter,
436 AttokilogramsPerCubicMeter,
437 ZeptokilogramsPerCubicMeter,
438 YoctokilogramsPerCubicMeter,
439 KilogramPerLiter,
440 GramPerLiter,
441 GramPerMilliliter,
442 OuncePerCubicInch,
443 OuncePerCubicFoot,
444 OuncePerCubicYard,
445 PoundPerCubicInch,
446 PoundPerCubicFoot,
447 PoundPerCubicYard,
448
449 // Acceleration
450 MetresPerSecondSquared = 14000,
451 FeetPerSecondSquared,
452 StandardGravity,
453
454 // Force
455 Yottanewton = 15000,
456 Zettanewton,
457 Exanewton,
458 Petanewton,
459 Teranewton,
460 Giganewton,
461 Meganewton,
462 KilonewtonForce,
463 Hectonewton,
464 Decanewton,
465 Newton,
466 Decinewton,
467 Centinewton,
468 Millinewton,
469 Micronewton,
470 Nanonewton,
471 Piconewton,
472 Femtonewton,
473 Attonewton,
474 Zeptonewton,
475 Yoctonewton,
476 Dyne,
477 Kilopond,
478 PoundForce,
479 Poundal,
480
481 // Angle
482 Degree = 16000,
483 Radian,
484 Gradian,
485 ArcMinute,
486 ArcSecond,
487
488 // Frequency
489 Yottahertz = 17000,
490 Zettahertz,
491 Exahertz,
492 Petahertz,
493 Terahertz,
494 Gigahertz,
495 Megahertz,
496 Kilohertz,
497 Hectohertz,
498 Decahertz,
499 Hertz,
500 Decihertz,
501 Centihertz,
502 Millihertz,
503 Microhertz,
504 Nanohertz,
505 Picohertz,
506 Femtohertz,
507 Attohertz,
508 Zeptohertz,
509 Yoctohertz,
510 RPM,
511
512 // Thermal Conductivity
514 WattPerMeterKelvin = 18000,
516 BtuPerFootHourFahrenheit,
518 BtuPerSquareFootHourFahrenheitPerInch,
519
520 // Thermal Flux Density
522 WattPerSquareMeter = 19000,
524 BtuPerHourPerSquareFoot,
525
526 // Thermal Generation per volume
528 WattPerCubicMeter = 20000,
530 BtuPerHourPerCubicFoot,
531
532 // Voltage
534 Yottavolts = 30000,
536 Zettavolts,
538 Exavolts,
540 Petavolts,
542 Teravolts,
544 Gigavolts,
546 Megavolts,
548 Kilovolts,
550 Hectovolts,
552 Decavolts,
554 Volts,
556 Decivolts,
558 Centivolts,
560 Millivolts,
562 Microvolts,
564 Nanovolts,
566 Picovolts,
568 Femtovolts,
570 Attovolts,
572 Zeptovolts,
574 Yoctovolts,
576 Statvolts,
577
578 // Electrical Current
580 Yottaampere = 31000,
582 Zettaampere,
584 Exaampere,
586 Petaampere,
588 Teraampere,
590 Gigaampere,
592 Megaampere,
594 Kiloampere,
596 Hectoampere,
598 Decaampere,
600 Ampere,
602 Deciampere,
604 Centiampere,
606 Milliampere,
608 Microampere,
610 Nanoampere,
612 Picoampere,
614 Femtoampere,
616 Attoampere,
618 Zeptoampere,
620 Yoctoampere,
621
622 // Electrical Resistance
624 Yottaohms = 32000,
626 Zettaohms,
628 Exaohms,
630 Petaohms,
632 Teraohms,
634 Gigaohms,
636 Megaohms,
638 Kiloohms,
640 Hectoohms,
642 Decaohms,
644 Ohms,
646 Deciohms,
648 Centiohms,
650 Milliohms,
652 Microohms,
654 Nanoohms,
656 Picoohms,
658 Femtoohms,
660 Attoohms,
662 Zeptoohms,
664 Yoctoohms,
665
667 Darcy = 33000,
669 MiliDarcy,
671 PermeabilitySquareMicrometer,
672
674 Yobibyte = 34000,
676 Yobibit,
678 Yottabyte,
680 Yottabit,
682 Zebibyte,
684 Zebibit,
686 Zettabyte,
688 Zettabit,
690 Exbibyte,
692 Exbibit,
694 Exabyte,
696 Exabit,
698 Pebibyte,
700 Pebibit,
702 Petabyte,
704 Petabit,
706 Tebibyte,
708 Tebibit,
710 Terabyte,
712 Terabit,
714 Gibibyte,
716 Gibibit,
718 Gigabyte,
720 Gigabit,
722 Mebibyte,
724 Mebibit,
726 Megabyte,
728 Megabit,
730 Kibibyte,
732 Kibibit,
734 Kilobyte,
736 Kilobit,
738 Byte,
740 Bit
741};
742
743class UnitCategory;
744class UnitPrivate;
745
757class KUNITCONVERSION_EXPORT Unit
758{
759public:
764
768 Unit(const Unit &other);
769
770 // TODO KF6: remove virtual
771 virtual ~Unit();
772
776 Unit &operator=(const Unit &other);
777
778 // TODO KF6: de-inline
779#ifdef Q_COMPILER_RVALUE_REFS
784 Unit &operator=(Unit &&other)
785 {
786 swap(other);
787 return *this;
788 }
789#endif
790
791 // TODO KF6: remove
795 void swap(Unit &other)
796 {
797 d.swap(other.d);
798 }
799
803 bool operator==(const Unit &other) const;
804
808 bool operator!=(const Unit &other) const;
809
813 bool isNull() const;
814
818 bool isValid() const;
819
823 UnitId id() const;
824
828 CategoryId categoryId() const;
829
834
838 QString description() const;
839
843 QString symbol() const;
844
855 QString toString(qreal value, int fieldWidth = 0, char format = 'g', int precision = -1, const QChar &fillChar = QLatin1Char(' ')) const;
856
867 QString toSymbolString(qreal value, int fieldWidth = 0, char format = 'g', int precision = -1, const QChar &fillChar = QLatin1Char(' ')) const;
868
869protected:
870 qreal toDefault(qreal value) const;
871 qreal fromDefault(qreal value) const;
872
873private:
874 friend class UnitPrivate;
875 friend class UnitCategory;
876 friend class UnitCategoryPrivate;
877 friend class CurrencyCategoryPrivate;
878
879 KUNITCONVERSION_NO_EXPORT explicit Unit(UnitPrivate *dd);
880
881 KUNITCONVERSION_NO_EXPORT void setUnitMultiplier(qreal multiplier);
882
883 QExplicitlySharedDataPointer<UnitPrivate> d;
884};
885
886} // KUnitConversion namespace
887
888#endif
Class to define a category of units of measurement.
Definition unitcategory.h:35
Class to define a unit of measurement.
Definition unit.h:758
bool operator==(const Unit &other) const
QString symbol() const
Unit(const Unit &other)
Copy constructor, copy other to this.
void swap(Unit &other)
Swaps this Unit with other.
Definition unit.h:795
Unit()
Null constructor.
UnitId id() const
QString toString(qreal value, int fieldWidth=0, char format='g', int precision=-1, const QChar &fillChar=QLatin1Char(' ')) const
bool isValid() const
QString toSymbolString(qreal value, int fieldWidth=0, char format='g', int precision=-1, const QChar &fillChar=QLatin1Char(' ')) const
Unit & operator=(const Unit &other)
Assignment operator, assign other to this.
UnitCategory category() const
QString description() const
CategoryId categoryId() const
bool operator!=(const Unit &other) const