KUnitConversion

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 WeightPerAreaCategory,
34 AccelerationCategory,
35 AngleCategory,
36 FrequencyCategory,
37 ForceCategory,
38 /** @since 5.27 */
39 ThermalConductivityCategory,
40 /** @since 5.27 */
41 ThermalFluxCategory,
42 /** @since 5.27 */
43 ThermalGenerationCategory,
44 /** @since 5.27 */
45 VoltageCategory,
46 /** @since 5.27 */
47 ElectricalCurrentCategory,
48 /** @since 5.27 */
49 ElectricalResistanceCategory,
50 /** @since 5.53 */
51 PermeabilityCategory,
52 /** @since 5.61 **/
53 BinaryDataCategory
54};
55
56enum UnitId {
57 InvalidUnit = -1,
58 NoUnit = 0,
59 Percent = 1,
60
61 // Area
62 SquareYottameter = 1000,
63 SquareZettameter,
64 SquareExameter,
65 SquarePetameter,
66 SquareTerameter,
67 SquareGigameter,
68 SquareMegameter,
69 SquareKilometer,
70 SquareHectometer,
71 SquareDecameter,
72 SquareMeter,
73 SquareDecimeter,
74 SquareCentimeter,
75 SquareMillimeter,
76 SquareMicrometer,
77 SquareNanometer,
78 SquarePicometer,
79 SquareFemtometer,
80 SquareAttometer,
81 SquareZeptometer,
82 SquareYoctometer,
83 Acre,
84 SquareFoot,
85 SquareInch,
86 SquareMile,
87
88 // Length
89 Yottameter = 2000,
90 Zettameter,
91 Exameter,
92 Petameter,
93 Terameter,
94 Gigameter,
95 Megameter,
96 Kilometer,
97 Hectometer,
98 Decameter,
99 Meter,
100 Decimeter,
101 Centimeter,
102 Millimeter,
103 Micrometer,
104 Nanometer,
105 Picometer,
106 Femtometer,
107 Attometer,
108 Zeptometer,
109 Yoctometer,
110 Inch,
111 Foot,
112 Yard,
113 Mile,
114 NauticalMile,
115 LightYear,
116 Parsec,
117 AstronomicalUnit,
118 Thou,
119 Angstrom,
120
121 // Volume
122 CubicYottameter = 3000,
123 CubicZettameter,
124 CubicExameter,
125 CubicPetameter,
126 CubicTerameter,
127 CubicGigameter,
128 CubicMegameter,
129 CubicKilometer,
130 CubicHectometer,
131 CubicDecameter,
132 CubicMeter,
133 CubicDecimeter,
134 CubicCentimeter,
135 CubicMillimeter,
136 CubicMicrometer,
137 CubicNanometer,
138 CubicPicometer,
139 CubicFemtometer,
140 CubicAttometer,
141 CubicZeptometer,
142 CubicYoctometer,
143 Yottaliter,
144 Zettaliter,
145 Exaliter,
146 Petaliter,
147 Teraliter,
148 Gigaliter,
149 Megaliter,
150 Kiloliter,
151 Hectoliter,
152 Decaliter,
153 Liter,
154 Deciliter,
155 Centiliter,
156 Milliliter,
157 Microliter,
158 Nanoliter,
159 Picoliter,
160 Femtoliter,
161 Attoliter,
162 Zeptoliter,
163 Yoctoliter,
164 CubicFoot,
165 CubicInch,
166 CubicMile,
167 FluidOunce,
168 Cup,
169 Teaspoon,
170 Tablespoon,
171 GallonUS,
172 PintImperial,
173 /** @since 5.53 */
174 OilBarrel,
175 /** @since 5.70 */
176 GallonImperial,
177 PintUS,
178
179 // Mass
180 Yottagram = 4000,
181 Zettagram,
182 Exagram,
183 Petagram,
184 Teragram,
185 Gigagram,
186 Megagram,
187 Kilogram,
188 Hectogram,
189 Decagram,
190 Gram,
191 Decigram,
192 Centigram,
193 Milligram,
194 Microgram,
195 Nanogram,
196 Picogram,
197 Femtogram,
198 Attogram,
199 Zeptogram,
200 Yoctogram,
201 Ton,
202 Carat,
203 Pound,
204 Ounce,
205 TroyOunce,
206 MassNewton,
207 Kilonewton,
208
209 /** @since 5.26 */
210 Stone,
211
212 // Pressure
213 Yottapascal = 5000,
214 Zettapascal,
215 Exapascal,
216 Petapascal,
217 Terapascal,
218 Gigapascal,
219 Megapascal,
220 Kilopascal,
221 Hectopascal,
222 Decapascal,
223 Pascal,
224 Decipascal,
225 Centipascal,
226 Millipascal,
227 Micropascal,
228 Nanopascal,
229 Picopascal,
230 Femtopascal,
231 Attopascal,
232 Zeptopascal,
233 Yoctopascal,
234 Bar,
235 Millibar,
236 Decibar,
237 Torr,
238 TechnicalAtmosphere,
239 Atmosphere,
240 PoundForcePerSquareInch,
241 InchesOfMercury,
242 MillimetersOfMercury,
243
244 // Temperature
245 Kelvin = 6000,
246 Celsius,
247 Fahrenheit,
248 Rankine,
249 Delisle,
250 TemperatureNewton,
251 Reaumur,
252 Romer,
253
254 // Energy
255 Yottajoule = 7000,
256 Zettajoule,
257 Exajoule,
258 Petajoule,
259 Terajoule,
260 Gigajoule,
261 Megajoule,
262 Kilojoule,
263 Hectojoule,
264 Decajoule,
265 Joule,
266 Decijoule,
267 Centijoule,
268 Millijoule,
269 Microjoule,
270 Nanojoule,
271 Picojoule,
272 Femtojoule,
273 Attojoule,
274 Zeptojoule,
275 Yoctojoule,
276 GuidelineDailyAmount,
277 Electronvolt,
278 Rydberg,
279 Kilocalorie,
280 PhotonWavelength,
281 KiloJoulePerMole,
282 JoulePerMole,
283 /** @since 5.27 */
284 Btu,
285 /** @since 5.27 */
286 Erg,
287
288 // Currency
289 Eur = 8000,
290 Ats,
291 Bef,
292 Nlg,
293 Fim,
294 Frf,
295 Dem,
296 Iep,
297 Itl,
298 Luf,
299 Pte,
300 Esp,
301 Grd,
302 Sit,
303 Cyp,
304 Mtl,
305 Skk,
306 Usd,
307 Jpy,
308 Bgn,
309 Czk,
310 Dkk,
311 Eek,
312 Gbp,
313 Huf,
314 Ltl,
315 Lvl,
316 Pln,
317 Ron,
318 Sek,
319 Chf,
320 Nok,
321 Hrk,
322 Rub,
323 Try,
324 Aud,
325 Brl,
326 Cad,
327 Cny,
328 Hkd,
329 Idr,
330 Inr,
331 Krw,
332 Mxn,
333 Myr,
334 Nzd,
335 Php,
336 Sgd,
337 Thb,
338 Zar,
339 Ils,
340 Isk,
341 Xpf, /// @since 6.9
342
343 // Velocity
344 MeterPerSecond = 9000,
345 KilometerPerHour,
346 MilePerHour,
347 FootPerSecond,
348 InchPerSecond,
349 Knot,
350 Mach,
351 SpeedOfLight,
352 Beaufort,
353
354 // Power
355 Yottawatt = 10000,
356 Zettawatt,
357 Exawatt,
358 Petawatt,
359 Terawatt,
360 Gigawatt,
361 Megawatt,
362 Kilowatt,
363 Hectowatt,
364 Decawatt,
365 Watt,
366 Deciwatt,
367 Centiwatt,
368 Milliwatt,
369 Microwatt,
370 Nanowatt,
371 Picowatt,
372 Femtowatt,
373 Attowatt,
374 Zeptowatt,
375 Yoctowatt,
376 Horsepower,
377 /** @since 5.62 */
378 DecibelKilowatt,
379 DecibelWatt,
380 DecibelMilliwatt,
381 DecibelMicrowatt,
382
383 // Time
384 Yottasecond = 11000,
385 Zettasecond,
386 Exasecond,
387 Petasecond,
388 Terasecond,
389 Gigasecond,
390 Megasecond,
391 Kilosecond,
392 Hectosecond,
393 Decasecond,
394 Second,
395 Decisecond,
396 Centisecond,
397 Millisecond,
398 Microsecond,
399 Nanosecond,
400 Picosecond,
401 Femtosecond,
402 Attosecond,
403 Zeptosecond,
404 Yoctosecond,
405 Minute,
406 Hour,
407 Day,
408 Week,
409 JulianYear,
410 LeapYear,
411 Year,
412
413 // FuelEfficiency
414 LitersPer100Kilometers = 12000,
415 MilePerUsGallon,
416 MilePerImperialGallon,
417 KilometrePerLitre,
418
419 // Density
420 YottakilogramsPerCubicMeter = 13000,
421 ZettakilogramPerCubicMeter,
422 ExakilogramPerCubicMeter,
423 PetakilogramPerCubicMeter,
424 TerakilogramPerCubicMeter,
425 GigakilogramPerCubicMeter,
426 MegakilogramPerCubicMeter,
427 KilokilogramPerCubicMeter,
428 HectokilogramsPerCubicMeter,
429 DecakilogramsPerCubicMeter,
430 KilogramsPerCubicMeter,
431 DecikilogramsPerCubicMeter,
432 CentikilogramsPerCubicMeter,
433 MillikilogramsPerCubicMeter,
434 MicrokilogramsPerCubicMeter,
435 NanokilogramsPerCubicMeter,
436 PicokilogramsPerCubicMeter,
437 FemtokilogramsPerCubicMeter,
438 AttokilogramsPerCubicMeter,
439 ZeptokilogramsPerCubicMeter,
440 YoctokilogramsPerCubicMeter,
441 KilogramPerLiter,
442 GramPerLiter,
443 GramPerMilliliter,
444 OuncePerCubicInch,
445 OuncePerCubicFoot,
446 OuncePerCubicYard,
447 PoundPerCubicInch,
448 PoundPerCubicFoot,
449 PoundPerCubicYard,
450
451 // Weight per area
452 GramsPerSquareMeter,
453 OuncesPerSquareYard,
454
455 // Acceleration
456 MetresPerSecondSquared = 14000,
457 FeetPerSecondSquared,
458 StandardGravity,
459
460 // Force
461 Yottanewton = 15000,
462 Zettanewton,
463 Exanewton,
464 Petanewton,
465 Teranewton,
466 Giganewton,
467 Meganewton,
468 KilonewtonForce,
469 Hectonewton,
470 Decanewton,
471 Newton,
472 Decinewton,
473 Centinewton,
474 Millinewton,
475 Micronewton,
476 Nanonewton,
477 Piconewton,
478 Femtonewton,
479 Attonewton,
480 Zeptonewton,
481 Yoctonewton,
482 Dyne,
483 Kilopond,
484 PoundForce,
485 Poundal,
486
487 // Angle
488 Degree = 16000,
489 Radian,
490 Gradian,
491 ArcMinute,
492 ArcSecond,
493
494 // Frequency
495 Yottahertz = 17000,
496 Zettahertz,
497 Exahertz,
498 Petahertz,
499 Terahertz,
500 Gigahertz,
501 Megahertz,
502 Kilohertz,
503 Hectohertz,
504 Decahertz,
505 Hertz,
506 Decihertz,
507 Centihertz,
508 Millihertz,
509 Microhertz,
510 Nanohertz,
511 Picohertz,
512 Femtohertz,
513 Attohertz,
514 Zeptohertz,
515 Yoctohertz,
516 RPM,
517
518 // Thermal Conductivity
519 /** @since 5.27 */
520 WattPerMeterKelvin = 18000,
521 /** @since 5.27 */
522 BtuPerFootHourFahrenheit,
523 /** @since 5.27 */
524 BtuPerSquareFootHourFahrenheitPerInch,
525
526 // Thermal Flux Density
527 /** @since 5.27 */
528 WattPerSquareMeter = 19000,
529 /** @since 5.27 */
530 BtuPerHourPerSquareFoot,
531
532 // Thermal Generation per volume
533 /** @since 5.27 */
534 WattPerCubicMeter = 20000,
535 /** @since 5.27 */
536 BtuPerHourPerCubicFoot,
537
538 // Voltage
539 /** @since 5.27 */
540 Yottavolts = 30000,
541 /** @since 5.27 */
542 Zettavolts,
543 /** @since 5.27 */
544 Exavolts,
545 /** @since 5.27 */
546 Petavolts,
547 /** @since 5.27 */
548 Teravolts,
549 /** @since 5.27 */
550 Gigavolts,
551 /** @since 5.27 */
552 Megavolts,
553 /** @since 5.27 */
554 Kilovolts,
555 /** @since 5.27 */
556 Hectovolts,
557 /** @since 5.27 */
558 Decavolts,
559 /** @since 5.27 */
560 Volts,
561 /** @since 5.27 */
562 Decivolts,
563 /** @since 5.27 */
564 Centivolts,
565 /** @since 5.27 */
566 Millivolts,
567 /** @since 5.27 */
568 Microvolts,
569 /** @since 5.27 */
570 Nanovolts,
571 /** @since 5.27 */
572 Picovolts,
573 /** @since 5.27 */
574 Femtovolts,
575 /** @since 5.27 */
576 Attovolts,
577 /** @since 5.27 */
578 Zeptovolts,
579 /** @since 5.27 */
580 Yoctovolts,
581 /** @since 5.27 */
582 Statvolts,
583
584 // Electrical Current
585 /** @since 5.27 */
586 Yottaampere = 31000,
587 /** @since 5.27 */
588 Zettaampere,
589 /** @since 5.27 */
590 Exaampere,
591 /** @since 5.27 */
592 Petaampere,
593 /** @since 5.27 */
594 Teraampere,
595 /** @since 5.27 */
596 Gigaampere,
597 /** @since 5.27 */
598 Megaampere,
599 /** @since 5.27 */
600 Kiloampere,
601 /** @since 5.27 */
602 Hectoampere,
603 /** @since 5.27 */
604 Decaampere,
605 /** @since 5.27 */
606 Ampere,
607 /** @since 5.27 */
608 Deciampere,
609 /** @since 5.27 */
610 Centiampere,
611 /** @since 5.27 */
612 Milliampere,
613 /** @since 5.27 */
614 Microampere,
615 /** @since 5.27 */
616 Nanoampere,
617 /** @since 5.27 */
618 Picoampere,
619 /** @since 5.27 */
620 Femtoampere,
621 /** @since 5.27 */
622 Attoampere,
623 /** @since 5.27 */
624 Zeptoampere,
625 /** @since 5.27 */
626 Yoctoampere,
627
628 // Electrical Resistance
629 /** @since 5.27 */
630 Yottaohms = 32000,
631 /** @since 5.27 */
632 Zettaohms,
633 /** @since 5.27 */
634 Exaohms,
635 /** @since 5.27 */
636 Petaohms,
637 /** @since 5.27 */
638 Teraohms,
639 /** @since 5.27 */
640 Gigaohms,
641 /** @since 5.27 */
642 Megaohms,
643 /** @since 5.27 */
644 Kiloohms,
645 /** @since 5.27 */
646 Hectoohms,
647 /** @since 5.27 */
648 Decaohms,
649 /** @since 5.27 */
650 Ohms,
651 /** @since 5.27 */
652 Deciohms,
653 /** @since 5.27 */
654 Centiohms,
655 /** @since 5.27 */
656 Milliohms,
657 /** @since 5.27 */
658 Microohms,
659 /** @since 5.27 */
660 Nanoohms,
661 /** @since 5.27 */
662 Picoohms,
663 /** @since 5.27 */
664 Femtoohms,
665 /** @since 5.27 */
666 Attoohms,
667 /** @since 5.27 */
668 Zeptoohms,
669 /** @since 5.27 */
670 Yoctoohms,
671
672 /** @since 5.53 */
673 Darcy = 33000,
674 /** @since 5.53 */
675 MiliDarcy,
676 /** @since 5.53 */
677 PermeabilitySquareMicrometer,
678
679 /** @since 5.61 */
680 Yobibyte = 34000,
681 /** @since 5.61 */
682 Yobibit,
683 /** @since 5.61 */
684 Yottabyte,
685 /** @since 5.61 */
686 Yottabit,
687 /** @since 5.61 */
688 Zebibyte,
689 /** @since 5.61 */
690 Zebibit,
691 /** @since 5.61 */
692 Zettabyte,
693 /** @since 5.61 */
694 Zettabit,
695 /** @since 5.61 */
696 Exbibyte,
697 /** @since 5.61 */
698 Exbibit,
699 /** @since 5.61 */
700 Exabyte,
701 /** @since 5.61 */
702 Exabit,
703 /** @since 5.61 */
704 Pebibyte,
705 /** @since 5.61 */
706 Pebibit,
707 /** @since 5.61 */
708 Petabyte,
709 /** @since 5.61 */
710 Petabit,
711 /** @since 5.61 */
712 Tebibyte,
713 /** @since 5.61 */
714 Tebibit,
715 /** @since 5.61 */
716 Terabyte,
717 /** @since 5.61 */
718 Terabit,
719 /** @since 5.61 */
720 Gibibyte,
721 /** @since 5.61 */
722 Gibibit,
723 /** @since 5.61 */
724 Gigabyte,
725 /** @since 5.61 */
726 Gigabit,
727 /** @since 5.61 */
728 Mebibyte,
729 /** @since 5.61 */
730 Mebibit,
731 /** @since 5.61 */
732 Megabyte,
733 /** @since 5.61 */
734 Megabit,
735 /** @since 5.61 */
736 Kibibyte,
737 /** @since 5.61 */
738 Kibibit,
739 /** @since 5.61 */
740 Kilobyte,
741 /** @since 5.61 */
742 Kilobit,
743 /** @since 5.61 */
744 Byte,
745 /** @since 5.61 */
746 Bit
747};
748
749class UnitCategory;
750class UnitPrivate;
751
752/**
753 * @short Class to define a unit of measurement
754 *
755 * This is a class to define a unit of measurement.
756 *
757 * @see Converter, UnitCategory, Value
758 *
759 * @author Petri Damstén <damu@iki.fi>
760 * @author John Layt <jlayt@kde.org>
761 */
762
763class KUNITCONVERSION_EXPORT Unit
764{
765public:
766 /**
767 * Null constructor
768 **/
769 Unit();
770
771 /**
772 * Copy constructor, copy @p other to this.
773 **/
774 Unit(const Unit &other);
775
776 ~Unit();
777
778 /**
779 * Assignment operator, assign @p other to this.
780 **/
781 Unit &operator=(const Unit &other);
782
783 /**
784 * Move-assigns @p other to this Unit instance, transferring the
785 * ownership of the managed pointer to this instance.
786 **/
787 Unit &operator=(Unit &&other);
788
789 /**
790 * @return @c true if this Unit is equal to the @p other Unit.
791 **/
792 bool operator==(const Unit &other) const;
793
794 /**
795 * @return @c true if this Unit is not equal to the @p other Unit.
796 **/
797 bool operator!=(const Unit &other) const;
798
799 /**
800 * @return returns true if this Unit is null
801 **/
802 bool isNull() const;
803
804 /**
805 * @return if unit is valid.
806 **/
807 bool isValid() const;
808
809 /**
810 * @return unit id.
811 **/
812 UnitId id() const;
813
814 /**
815 * @return category id.
816 **/
817 CategoryId categoryId() const;
818
819 /**
820 * @return unit category.
821 **/
822 UnitCategory category() const;
823
824 /**
825 * @return translated name for unit.
826 **/
827 QString description() const;
828
829 /**
830 * @return symbol for the unit.
831 **/
832 QString symbol() const;
833
834 /**
835 * @param value number value
836 * @param fieldWidth width of the formatted field, padded by spaces.
837 * Positive value aligns right, negative aligns left
838 * @param format type of floating point formatting, like in QString::arg
839 * @param precision number of digits after the decimal separator
840 * @param fillChar the character used to fill up the empty places when
841 * field width is greater than argument width
842 * @return value + unit string
843 **/
844 QString toString(qreal value, int fieldWidth = 0, char format = 'g', int precision = -1, const QChar &fillChar = QLatin1Char(' ')) const;
845
846 /**
847 * @param value number value
848 * @param fieldWidth width of the formatted field, padded by spaces.
849 * Positive value aligns right, negative aligns left
850 * @param format type of floating point formatting, like in QString::arg
851 * @param precision number of digits after the decimal separator
852 * @param fillChar the character used to fill up the empty places when
853 * field width is greater than argument width
854 * @return value + unit string
855 **/
856 QString toSymbolString(qreal value, int fieldWidth = 0, char format = 'g', int precision = -1, const QChar &fillChar = QLatin1Char(' ')) const;
857
858protected:
859 qreal toDefault(qreal value) const;
860 qreal fromDefault(qreal value) const;
861
862private:
863 friend class UnitPrivate;
864 friend class UnitCategory;
865 friend class UnitCategoryPrivate;
866 friend class CurrencyCategoryPrivate;
867
868 KUNITCONVERSION_NO_EXPORT explicit Unit(UnitPrivate *dd);
869
870 KUNITCONVERSION_NO_EXPORT void setUnitMultiplier(qreal multiplier);
871
873};
874
875} // KUnitConversion namespace
876
877Q_DECLARE_TYPEINFO(KUnitConversion::Unit, Q_RELOCATABLE_TYPE);
878
879#endif
Class to define a category of units of measurement.
Class to define a unit of measurement.
Definition unit.h:764
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.