KUnitConversion
converter.h
Go to the documentation of this file.
00001 /* 00002 * Copyright (C) 2008-2009 Petri Damstén <damu@iki.fi> 00003 * 00004 * This program is free software; you can redistribute it and/or modify 00005 * it under the terms of the GNU Library General Public License as 00006 * published by the Free Software Foundation; either version 2, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details 00013 * 00014 * You should have received a copy of the GNU Library General Public 00015 * License along with this program; if not, write to the 00016 * Free Software Foundation, Inc., 00017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00018 */ 00019 00020 #ifndef KUNITCONVERSION_CONVERTER_H 00021 #define KUNITCONVERSION_CONVERTER_H 00022 00023 #include <kunitconversion/value.h> 00024 #include <kunitconversion/kunitconversion_export.h> 00025 #include <QtCore/QVariant> 00026 00027 namespace KUnitConversion 00028 { 00029 enum CategoryId { 00030 InvalidCategory = -1, LengthCategory, AreaCategory, VolumeCategory, TemperatureCategory, 00031 VelocityCategory, MassCategory, PressureCategory, EnergyCategory, CurrencyCategory, 00032 PowerCategory, TimeCategory, FuelEfficiencyCategory, DensityCategory, AccelerationCategory, 00033 AngleCategory, FrequencyCategory, ForceCategory 00034 }; 00035 enum UnitId { 00036 InvalidUnit = -1, NoUnit = 0, Percent = 1, 00037 // Area 00038 SquareYottameter = 1000, SquareZettameter, SquareExameter, SquarePetameter, SquareTerameter, 00039 SquareGigameter, SquareMegameter, SquareKilometer, SquareHectometer, SquareDecameter, 00040 SquareMeter, SquareDecimeter, SquareCentimeter, SquareMillimeter, SquareMicrometer, 00041 SquareNanometer, SquarePicometer, SquareFemtometer, SquareAttometer, SquareZeptometer, 00042 SquareYoctometer, Acre, SquareFoot, SquareInch, SquareMile, 00043 00044 // Length 00045 Yottameter = 2000, Zettameter, Exameter, Petameter, Terameter, Gigameter, Megameter, 00046 Kilometer, Hectometer, Decameter, Meter, Decimeter, Centimeter, Millimeter, Micrometer, 00047 Nanometer, Picometer, Femtometer, Attometer, Zeptometer, Yoctometer, Inch, Foot, Yard, 00048 Mile, NauticalMile, LightYear, Parsec, AstronomicalUnit, Thou, 00049 00050 // Volume 00051 CubicYottameter = 3000, CubicZettameter, CubicExameter, CubicPetameter, CubicTerameter, 00052 CubicGigameter, CubicMegameter, CubicKilometer, CubicHectometer, CubicDecameter, CubicMeter, 00053 CubicDecimeter, CubicCentimeter, CubicMillimeter, CubicMicrometer, CubicNanometer, 00054 CubicPicometer, CubicFemtometer, CubicAttometer, CubicZeptometer, CubicYoctometer, 00055 Yottaliter, Zettaliter, Exaliter, Petaliter, Teraliter, Gigaliter, Megaliter, Kiloliter, 00056 Hectoliter, Decaliter, Liter, Deciliter, Centiliter, Milliliter, Microliter, Nanoliter, 00057 Picoliter, Femtoliter, Attoliter, Zeptoliter, Yoctoliter, CubicFoot, CubicInch, CubicMile, 00058 FluidOunce, Cup, GallonUS, PintImperial, 00059 00060 // Mass 00061 Yottagram = 4000, Zettagram, Exagram, Petagram, Teragram, Gigagram, Megagram, Kilogram, 00062 Hectogram, Decagram, Gram, Decigram, Centigram, Milligram, Microgram, Nanogram, Picogram, 00063 Femtogram, Attogram, Zeptogram, Yoctogram, Ton, Carat, Pound, Ounce, TroyOunce, MassNewton, 00064 Kilonewton, 00065 00066 // Pressure 00067 Yottapascal = 5000, Zettapascal, Exapascal, Petapascal, Terapascal, Gigapascal, Megapascal, 00068 Kilopascal, Hectopascal, Decapascal, Pascal, Decipascal, Centipascal, Millipascal, 00069 Micropascal, Nanopascal, Picopascal, Femtopascal, Attopascal, Zeptopascal, Yoctopascal, 00070 Bar, Millibar, Decibar, Torr, TechnicalAtmosphere, Atmosphere, PoundForcePerSquareInch, 00071 InchesOfMercury, MillimetersOfMercury, 00072 00073 // Temperature 00074 Kelvin = 6000, Celsius, Fahrenheit, Rankine, Delisle, TemperatureNewton, Reaumur, Romer, 00075 00076 // Energy 00077 Yottajoule = 7000, Zettajoule, Exajoule, Petajoule, Terajoule, Gigajoule, Megajoule, 00078 Kilojoule, Hectojoule, Decajoule, Joule, Decijoule, Centijoule, Millijoule, Microjoule, 00079 Nanojoule, Picojoule, Femtojoule, Attojoule, Zeptojoule, Yoctojoule, GuidelineDailyAmount, 00080 Electronvolt, Rydberg, Kilocalorie, PhotonWavelength, 00081 00082 // Currency 00083 Eur = 8000, Ats, Bef, Nlg, Fim, Frf, Dem, Iep, Itl, Luf, Pte, Esp, Grd, Sit, Cyp, Mtl, Skk, 00084 Usd, Jpy, Bgn, Czk, Dkk, Eek, Gbp, Huf, Ltl, Lvl, Pln, Ron, Sek, Chf, Nok, Hrk, Rub, Try, 00085 Aud, Brl, Cad, Cny, Hkd, Idr, Inr, Krw, Mxn, Myr, Nzd, Php, Sgd, Thb, Zar, 00086 00087 // Velocity 00088 MeterPerSecond = 9000, KilometerPerHour, MilePerHour, FootPerSecond, InchPerSecond, Knot, 00089 Mach, SpeedOfLight, Beaufort, 00090 00091 // Power 00092 Yottawatt = 10000, Zettawatt, Exawatt, Petawatt, Terawatt, Gigawatt, Megawatt, Kilowatt, 00093 Hectowatt, Decawatt, Watt, Deciwatt, Centiwatt, Milliwatt, Microwatt, Nanowatt, Picowatt, 00094 Femtowatt, Attowatt, Zeptowatt, Yoctowatt, Horsepower, 00095 00096 // Time 00097 Yottasecond = 11000, Zettasecond, Exasecond, Petasecond, Terasecond, Gigasecond, Megasecond, 00098 Kilosecond, Hectosecond, Decasecond, Second, Decisecond, Centisecond, Millisecond, 00099 Microsecond, Nanosecond, Picosecond, Femtosecond, Attosecond, Zeptosecond, Yoctosecond, 00100 Minute, Hour, Day, Week, JulianYear, LeapYear, Year, 00101 00102 // FuelEfficiency 00103 LitersPer100Kilometers = 12000, MilePerUsGallon, MilePerImperialGallon, KilometrePerLitre, 00104 00105 // Density 00106 YottakilogramsPerCubicMeter = 13000, ZettakilogramPerCubicMeter, ExakilogramPerCubicMeter, 00107 PetakilogramPerCubicMeter, TerakilogramPerCubicMeter, GigakilogramPerCubicMeter, 00108 MegakilogramPerCubicMeter, KilokilogramPerCubicMeter, HectokilogramsPerCubicMeter, 00109 DecakilogramsPerCubicMeter, KilogramsPerCubicMeter, DecikilogramsPerCubicMeter, 00110 CentikilogramsPerCubicMeter, MillikilogramsPerCubicMeter, MicrokilogramsPerCubicMeter, 00111 NanokilogramsPerCubicMeter, PicokilogramsPerCubicMeter, FemtokilogramsPerCubicMeter, 00112 AttokilogramsPerCubicMeter, ZeptokilogramsPerCubicMeter, YoctokilogramsPerCubicMeter, 00113 KilogramPerLiter, GramPerLiter, GramPerMilliliter, 00114 OuncePerCubicInch, OuncePerCubicFoot, OuncePerCubicYard, 00115 PoundPerCubicInch, PoundPerCubicFoot, PoundPerCubicYard, 00116 00117 // Acceleration 00118 MetresPerSecondSquared = 14000, FeetPerSecondSquared, StandardGravity, 00119 00120 // Force 00121 Yottanewton = 15000, Zettanewton, Exanewton, Petanewton, Teranewton, Giganewton, Meganewton, 00122 KilonewtonForce, Hectonewton, Decanewton, Newton, Decinewton, Centinewton, Millinewton, Micronewton, 00123 Nanonewton, Piconewton, Femtonewton, Attonewton, Zeptonewton, Yoctonewton, Dyne, Kilopond, 00124 PoundForce, Poundal, 00125 00126 // Angle 00127 Degree = 16000, Radian, Gradian, ArcMinute, ArcSecond, 00128 00129 // Frequency 00130 Yottahertz = 17000, Zettahertz, Exahertz, Petahertz, Terahertz, Gigahertz, Megahertz, 00131 Kilohertz, Hectohertz, Decahertz, Hertz, Decihertz, Centihertz, Millihertz, Microhertz, 00132 Nanohertz, Picohertz, Femtohertz, Attohertz, Zeptohertz, Yoctohertz, RPM 00133 }; 00134 00135 class UnitCategory; 00136 00137 class ConverterPrivate; 00138 class KUNITCONVERSION_EXPORT Converter : public QObject 00139 { 00140 Q_OBJECT 00141 public: 00142 explicit Converter(QObject* parent = 0); 00143 ~Converter(); 00144 00152 Value convert(const Value& value, const QString& toUnit = QString()) const; 00153 Value convert(const Value& value, int toUnit) const; 00154 Value convert(const Value& value, UnitPtr toUnit) const; 00155 00162 UnitCategory* categoryForUnit(const QString& unit) const; 00163 00170 UnitPtr unit(const QString& unitString) const; 00171 00178 UnitPtr unit(int unitId) const; 00179 00186 UnitCategory* category(const QString& category) const; 00187 00194 UnitCategory* category(int categoryId) const; 00195 00201 QList<UnitCategory*> categories() const; 00202 00203 private: 00204 ConverterPrivate *d; 00205 }; 00206 00207 } // KUnitConversion namespace 00208 00209 #endif
KDE 4.6 API Reference