1 | /* |
2 | * Copyright (C) 2008-2009 Petri Damstén <damu@iki.fi> |
3 | * |
4 | * This program is free software; you can redistribute it and/or modify |
5 | * it under the terms of the GNU Library General Public License as |
6 | * published by the Free Software Foundation; either version 2, or |
7 | * (at your option) any later version. |
8 | * |
9 | * This program 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 |
12 | * GNU General Public License for more details |
13 | * |
14 | * You should have received a copy of the GNU Library General Public |
15 | * License along with this program; if not, write to the |
16 | * Free Software Foundation, Inc., |
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
18 | */ |
19 | |
20 | #ifndef KUNITCONVERSION_CONVERTER_H |
21 | #define KUNITCONVERSION_CONVERTER_H |
22 | |
23 | #include <kunitconversion/value.h> |
24 | #include <kunitconversion/kunitconversion_export.h> |
25 | #include <QtCore/QVariant> |
26 | |
27 | namespace KUnitConversion |
28 | { |
29 | enum CategoryId { |
30 | InvalidCategory = -1, LengthCategory, AreaCategory, VolumeCategory, TemperatureCategory, |
31 | VelocityCategory, MassCategory, PressureCategory, EnergyCategory, CurrencyCategory, |
32 | PowerCategory, TimeCategory, FuelEfficiencyCategory, DensityCategory, AccelerationCategory, |
33 | AngleCategory, FrequencyCategory, ForceCategory |
34 | }; |
35 | enum UnitId { |
36 | InvalidUnit = -1, NoUnit = 0, Percent = 1, |
37 | // Area |
38 | SquareYottameter = 1000, SquareZettameter, SquareExameter, SquarePetameter, SquareTerameter, |
39 | SquareGigameter, SquareMegameter, SquareKilometer, SquareHectometer, SquareDecameter, |
40 | SquareMeter, SquareDecimeter, SquareCentimeter, SquareMillimeter, SquareMicrometer, |
41 | SquareNanometer, SquarePicometer, SquareFemtometer, SquareAttometer, SquareZeptometer, |
42 | SquareYoctometer, Acre, , SquareInch, SquareMile, |
43 | |
44 | // Length |
45 | Yottameter = 2000, Zettameter, Exameter, Petameter, Terameter, Gigameter, Megameter, |
46 | Kilometer, Hectometer, Decameter, Meter, Decimeter, Centimeter, Millimeter, Micrometer, |
47 | Nanometer, Picometer, Femtometer, Attometer, Zeptometer, Yoctometer, Inch, , Yard, |
48 | Mile, NauticalMile, LightYear, Parsec, AstronomicalUnit, Thou, Angstrom, |
49 | |
50 | // Volume |
51 | CubicYottameter = 3000, CubicZettameter, CubicExameter, CubicPetameter, CubicTerameter, |
52 | CubicGigameter, CubicMegameter, CubicKilometer, CubicHectometer, CubicDecameter, CubicMeter, |
53 | CubicDecimeter, CubicCentimeter, CubicMillimeter, CubicMicrometer, CubicNanometer, |
54 | CubicPicometer, CubicFemtometer, CubicAttometer, CubicZeptometer, CubicYoctometer, |
55 | Yottaliter, Zettaliter, Exaliter, Petaliter, Teraliter, Gigaliter, Megaliter, Kiloliter, |
56 | Hectoliter, Decaliter, Liter, Deciliter, Centiliter, Milliliter, Microliter, Nanoliter, |
57 | Picoliter, Femtoliter, Attoliter, Zeptoliter, Yoctoliter, , CubicInch, CubicMile, |
58 | FluidOunce, Cup, GallonUS, PintImperial, |
59 | |
60 | // Mass |
61 | Yottagram = 4000, Zettagram, Exagram, Petagram, Teragram, Gigagram, Megagram, Kilogram, |
62 | Hectogram, Decagram, Gram, Decigram, Centigram, Milligram, Microgram, Nanogram, Picogram, |
63 | Femtogram, Attogram, Zeptogram, Yoctogram, Ton, Carat, Pound, Ounce, TroyOunce, MassNewton, |
64 | Kilonewton, |
65 | |
66 | // Pressure |
67 | Yottapascal = 5000, Zettapascal, Exapascal, Petapascal, Terapascal, Gigapascal, Megapascal, |
68 | Kilopascal, Hectopascal, Decapascal, Pascal, Decipascal, Centipascal, Millipascal, |
69 | Micropascal, Nanopascal, Picopascal, Femtopascal, Attopascal, Zeptopascal, Yoctopascal, |
70 | Bar, Millibar, Decibar, Torr, TechnicalAtmosphere, Atmosphere, PoundForcePerSquareInch, |
71 | InchesOfMercury, MillimetersOfMercury, |
72 | |
73 | // Temperature |
74 | Kelvin = 6000, Celsius, Fahrenheit, Rankine, Delisle, TemperatureNewton, Reaumur, Romer, |
75 | |
76 | // Energy |
77 | Yottajoule = 7000, Zettajoule, Exajoule, Petajoule, Terajoule, Gigajoule, Megajoule, |
78 | Kilojoule, Hectojoule, Decajoule, Joule, Decijoule, Centijoule, Millijoule, Microjoule, |
79 | Nanojoule, Picojoule, Femtojoule, Attojoule, Zeptojoule, Yoctojoule, GuidelineDailyAmount, |
80 | Electronvolt, Rydberg, Kilocalorie, PhotonWavelength, KiloJoulePerMole, JoulePerMole, |
81 | |
82 | // Currency |
83 | Eur = 8000, Ats, Bef, Nlg, Fim, Frf, Dem, Iep, Itl, Luf, Pte, Esp, Grd, Sit, Cyp, Mtl, Skk, |
84 | Usd, Jpy, Bgn, Czk, Dkk, Eek, Gbp, Huf, Ltl, Lvl, Pln, Ron, Sek, Chf, Nok, Hrk, Rub, Try, |
85 | Aud, Brl, Cad, Cny, Hkd, Idr, Inr, Krw, Mxn, Myr, Nzd, Php, Sgd, Thb, Zar, |
86 | |
87 | // Velocity |
88 | MeterPerSecond = 9000, KilometerPerHour, MilePerHour, , InchPerSecond, Knot, |
89 | Mach, SpeedOfLight, Beaufort, |
90 | |
91 | // Power |
92 | Yottawatt = 10000, Zettawatt, Exawatt, Petawatt, Terawatt, Gigawatt, Megawatt, Kilowatt, |
93 | Hectowatt, Decawatt, Watt, Deciwatt, Centiwatt, Milliwatt, Microwatt, Nanowatt, Picowatt, |
94 | Femtowatt, Attowatt, Zeptowatt, Yoctowatt, Horsepower, |
95 | |
96 | // Time |
97 | Yottasecond = 11000, Zettasecond, Exasecond, Petasecond, Terasecond, Gigasecond, Megasecond, |
98 | Kilosecond, Hectosecond, Decasecond, Second, Decisecond, Centisecond, Millisecond, |
99 | Microsecond, Nanosecond, Picosecond, Femtosecond, Attosecond, Zeptosecond, Yoctosecond, |
100 | Minute, Hour, Day, Week, JulianYear, LeapYear, Year, |
101 | |
102 | // FuelEfficiency |
103 | LitersPer100Kilometers = 12000, MilePerUsGallon, MilePerImperialGallon, KilometrePerLitre, |
104 | |
105 | // Density |
106 | YottakilogramsPerCubicMeter = 13000, ZettakilogramPerCubicMeter, ExakilogramPerCubicMeter, |
107 | PetakilogramPerCubicMeter, TerakilogramPerCubicMeter, GigakilogramPerCubicMeter, |
108 | MegakilogramPerCubicMeter, KilokilogramPerCubicMeter, HectokilogramsPerCubicMeter, |
109 | DecakilogramsPerCubicMeter, KilogramsPerCubicMeter, DecikilogramsPerCubicMeter, |
110 | CentikilogramsPerCubicMeter, MillikilogramsPerCubicMeter, MicrokilogramsPerCubicMeter, |
111 | NanokilogramsPerCubicMeter, PicokilogramsPerCubicMeter, FemtokilogramsPerCubicMeter, |
112 | AttokilogramsPerCubicMeter, ZeptokilogramsPerCubicMeter, YoctokilogramsPerCubicMeter, |
113 | KilogramPerLiter, GramPerLiter, GramPerMilliliter, |
114 | OuncePerCubicInch, , OuncePerCubicYard, |
115 | PoundPerCubicInch, , PoundPerCubicYard, |
116 | |
117 | // Acceleration |
118 | MetresPerSecondSquared = 14000, FeetPerSecondSquared, StandardGravity, |
119 | |
120 | // Force |
121 | Yottanewton = 15000, Zettanewton, Exanewton, Petanewton, Teranewton, Giganewton, Meganewton, |
122 | KilonewtonForce, Hectonewton, Decanewton, Newton, Decinewton, Centinewton, Millinewton, Micronewton, |
123 | Nanonewton, Piconewton, Femtonewton, Attonewton, Zeptonewton, Yoctonewton, Dyne, Kilopond, |
124 | PoundForce, Poundal, |
125 | |
126 | // Angle |
127 | Degree = 16000, Radian, Gradian, ArcMinute, ArcSecond, |
128 | |
129 | // Frequency |
130 | Yottahertz = 17000, Zettahertz, Exahertz, Petahertz, Terahertz, Gigahertz, Megahertz, |
131 | Kilohertz, Hectohertz, Decahertz, Hertz, Decihertz, Centihertz, Millihertz, Microhertz, |
132 | Nanohertz, Picohertz, Femtohertz, Attohertz, Zeptohertz, Yoctohertz, RPM |
133 | }; |
134 | |
135 | class UnitCategory; |
136 | |
137 | class ConverterPrivate; |
138 | class KUNITCONVERSION_EXPORT Converter : public QObject |
139 | { |
140 | Q_OBJECT |
141 | public: |
142 | explicit Converter(QObject* parent = 0); |
143 | ~Converter(); |
144 | |
145 | /** |
146 | * Convert value to another unit. |
147 | * |
148 | * @param value value to convert |
149 | * @param toUnit unit to convert to. If empty default unit is used. |
150 | * @return converted value |
151 | **/ |
152 | Value convert(const Value& value, const QString& toUnit = QString()) const; |
153 | Value convert(const Value& value, int toUnit) const; |
154 | Value convert(const Value& value, UnitPtr toUnit) const; |
155 | |
156 | /** |
157 | * Find unit category for unit. |
158 | * |
159 | * @param unit unit to find category for. |
160 | * @return unit category for unit |
161 | **/ |
162 | UnitCategory* categoryForUnit(const QString& unit) const; |
163 | |
164 | /** |
165 | * Find unit for string unit. |
166 | * |
167 | * @param unitString unit string to find unit for. |
168 | * @return unit for string unit |
169 | **/ |
170 | UnitPtr unit(const QString& unitString) const; |
171 | |
172 | /** |
173 | * Find unit for unit enum. |
174 | * |
175 | * @param unit unit enum to find unit for. |
176 | * @return unit for string unit |
177 | **/ |
178 | UnitPtr unit(int unitId) const; |
179 | |
180 | /** |
181 | * Find unit category. |
182 | * |
183 | * @param category name of the category to find (length, area, mass, etc.). |
184 | * @return unit category named category or invalid category. |
185 | **/ |
186 | UnitCategory* category(const QString& category) const; |
187 | |
188 | /** |
189 | * Find unit category. |
190 | * |
191 | * @param categoryId id of the category to find (LengthCategory, AreaCategory, etc.). |
192 | * @return unit category which id is categoryId or invalid category. |
193 | **/ |
194 | UnitCategory* category(int categoryId) const; |
195 | |
196 | /** |
197 | * Returns a list of all unit categories. |
198 | * |
199 | * @return list of unit categories. |
200 | **/ |
201 | QList<UnitCategory*> categories() const; |
202 | |
203 | private: |
204 | ConverterPrivate *d; |
205 | }; |
206 | |
207 | } // KUnitConversion namespace |
208 | |
209 | #endif |
210 | |