2
* Copyright (C) 2007-2009 Petri Damstén <damu@iki.fi>
3
* Copyright (C) 2014 John Layt <jlayt@kde.org>
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU Library General Public License as
7
* published by the Free Software Foundation; either version 2, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details
15
* You should have received a copy of the GNU Library General Public
16
* License along with this program; if not, write to the
17
* Free Software Foundation, Inc.,
18
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
#ifndef KUNITCONVERSION_UNIT_H
22
#define KUNITCONVERSION_UNIT_H
24
#include "kunitconversion/kunitconversion_export.h"
26
#include <QtCore/QString>
27
#include <QtCore/QExplicitlySharedDataPointer>
29
class KLocalizedString;
31
namespace KUnitConversion
47
FuelEfficiencyCategory,
61
SquareYottameter = 1000, SquareZettameter, SquareExameter, SquarePetameter, SquareTerameter,
62
SquareGigameter, SquareMegameter, SquareKilometer, SquareHectometer, SquareDecameter,
63
SquareMeter, SquareDecimeter, SquareCentimeter, SquareMillimeter, SquareMicrometer,
64
SquareNanometer, SquarePicometer, SquareFemtometer, SquareAttometer, SquareZeptometer,
65
SquareYoctometer, Acre, SquareFoot, SquareInch, SquareMile,
68
Yottameter = 2000, Zettameter, Exameter, Petameter, Terameter, Gigameter, Megameter,
69
Kilometer, Hectometer, Decameter, Meter, Decimeter, Centimeter, Millimeter, Micrometer,
70
Nanometer, Picometer, Femtometer, Attometer, Zeptometer, Yoctometer, Inch, Foot, Yard,
71
Mile, NauticalMile, LightYear, Parsec, AstronomicalUnit, Thou, Angstrom,
74
CubicYottameter = 3000, CubicZettameter, CubicExameter, CubicPetameter, CubicTerameter,
75
CubicGigameter, CubicMegameter, CubicKilometer, CubicHectometer, CubicDecameter, CubicMeter,
76
CubicDecimeter, CubicCentimeter, CubicMillimeter, CubicMicrometer, CubicNanometer,
77
CubicPicometer, CubicFemtometer, CubicAttometer, CubicZeptometer, CubicYoctometer,
78
Yottaliter, Zettaliter, Exaliter, Petaliter, Teraliter, Gigaliter, Megaliter, Kiloliter,
79
Hectoliter, Decaliter, Liter, Deciliter, Centiliter, Milliliter, Microliter, Nanoliter,
80
Picoliter, Femtoliter, Attoliter, Zeptoliter, Yoctoliter, CubicFoot, CubicInch, CubicMile,
81
FluidOunce, Cup, GallonUS, PintImperial,
84
Yottagram = 4000, Zettagram, Exagram, Petagram, Teragram, Gigagram, Megagram, Kilogram,
85
Hectogram, Decagram, Gram, Decigram, Centigram, Milligram, Microgram, Nanogram, Picogram,
86
Femtogram, Attogram, Zeptogram, Yoctogram, Ton, Carat, Pound, Ounce, TroyOunce, MassNewton,
90
Yottapascal = 5000, Zettapascal, Exapascal, Petapascal, Terapascal, Gigapascal, Megapascal,
91
Kilopascal, Hectopascal, Decapascal, Pascal, Decipascal, Centipascal, Millipascal,
92
Micropascal, Nanopascal, Picopascal, Femtopascal, Attopascal, Zeptopascal, Yoctopascal,
93
Bar, Millibar, Decibar, Torr, TechnicalAtmosphere, Atmosphere, PoundForcePerSquareInch,
94
InchesOfMercury, MillimetersOfMercury,
97
Kelvin = 6000, Celsius, Fahrenheit, Rankine, Delisle, TemperatureNewton, Reaumur, Romer,
100
Yottajoule = 7000, Zettajoule, Exajoule, Petajoule, Terajoule, Gigajoule, Megajoule,
101
Kilojoule, Hectojoule, Decajoule, Joule, Decijoule, Centijoule, Millijoule, Microjoule,
102
Nanojoule, Picojoule, Femtojoule, Attojoule, Zeptojoule, Yoctojoule, GuidelineDailyAmount,
103
Electronvolt, Rydberg, Kilocalorie, PhotonWavelength, KiloJoulePerMole, JoulePerMole,
106
Eur = 8000, Ats, Bef, Nlg, Fim, Frf, Dem, Iep, Itl, Luf, Pte, Esp, Grd, Sit, Cyp, Mtl, Skk,
107
Usd, Jpy, Bgn, Czk, Dkk, Eek, Gbp, Huf, Ltl, Lvl, Pln, Ron, Sek, Chf, Nok, Hrk, Rub, Try,
108
Aud, Brl, Cad, Cny, Hkd, Idr, Inr, Krw, Mxn, Myr, Nzd, Php, Sgd, Thb, Zar,
111
MeterPerSecond = 9000, KilometerPerHour, MilePerHour, FootPerSecond, InchPerSecond, Knot,
112
Mach, SpeedOfLight, Beaufort,
115
Yottawatt = 10000, Zettawatt, Exawatt, Petawatt, Terawatt, Gigawatt, Megawatt, Kilowatt,
116
Hectowatt, Decawatt, Watt, Deciwatt, Centiwatt, Milliwatt, Microwatt, Nanowatt, Picowatt,
117
Femtowatt, Attowatt, Zeptowatt, Yoctowatt, Horsepower,
120
Yottasecond = 11000, Zettasecond, Exasecond, Petasecond, Terasecond, Gigasecond, Megasecond,
121
Kilosecond, Hectosecond, Decasecond, Second, Decisecond, Centisecond, Millisecond,
122
Microsecond, Nanosecond, Picosecond, Femtosecond, Attosecond, Zeptosecond, Yoctosecond,
123
Minute, Hour, Day, Week, JulianYear, LeapYear, Year,
126
LitersPer100Kilometers = 12000, MilePerUsGallon, MilePerImperialGallon, KilometrePerLitre,
129
YottakilogramsPerCubicMeter = 13000, ZettakilogramPerCubicMeter, ExakilogramPerCubicMeter,
130
PetakilogramPerCubicMeter, TerakilogramPerCubicMeter, GigakilogramPerCubicMeter,
131
MegakilogramPerCubicMeter, KilokilogramPerCubicMeter, HectokilogramsPerCubicMeter,
132
DecakilogramsPerCubicMeter, KilogramsPerCubicMeter, DecikilogramsPerCubicMeter,
133
CentikilogramsPerCubicMeter, MillikilogramsPerCubicMeter, MicrokilogramsPerCubicMeter,
134
NanokilogramsPerCubicMeter, PicokilogramsPerCubicMeter, FemtokilogramsPerCubicMeter,
135
AttokilogramsPerCubicMeter, ZeptokilogramsPerCubicMeter, YoctokilogramsPerCubicMeter,
136
KilogramPerLiter, GramPerLiter, GramPerMilliliter,
137
OuncePerCubicInch, OuncePerCubicFoot, OuncePerCubicYard,
138
PoundPerCubicInch, PoundPerCubicFoot, PoundPerCubicYard,
141
MetresPerSecondSquared = 14000, FeetPerSecondSquared, StandardGravity,
144
Yottanewton = 15000, Zettanewton, Exanewton, Petanewton, Teranewton, Giganewton, Meganewton,
145
KilonewtonForce, Hectonewton, Decanewton, Newton, Decinewton, Centinewton, Millinewton, Micronewton,
146
Nanonewton, Piconewton, Femtonewton, Attonewton, Zeptonewton, Yoctonewton, Dyne, Kilopond,
150
Degree = 16000, Radian, Gradian, ArcMinute, ArcSecond,
153
Yottahertz = 17000, Zettahertz, Exahertz, Petahertz, Terahertz, Gigahertz, Megahertz,
154
Kilohertz, Hectohertz, Decahertz, Hertz, Decihertz, Centihertz, Millihertz, Microhertz,
155
Nanohertz, Picohertz, Femtohertz, Attohertz, Zeptohertz, Yoctohertz, RPM
162
* @short Class to define a unit of measurement
166
* This is a class to define a unit of measurement.
168
* @b license GNU-LGPL v.2 or later
170
* @see Converter, UnitCategory, Value
172
* @author Petri Damstén <damu@iki.fi>
173
* @author John Layt <jlayt@kde.org>
176
class KUNITCONVERSION_EXPORT Unit
185
* Copy constructor, copy @param other to this.
187
Unit(const Unit &other);
192
* Assignment operator, assign @param other to this.
194
Unit &operator=(const Unit &other);
196
#ifdef Q_COMPILER_RVALUE_REFS
198
* Move-assigns \a other to this Unit instance, transferring the
199
* ownership of the managed pointer to this instance.
201
Unit &operator=(Unit &&other) { swap(other); return *this; }
205
* Swaps this Unit with \a other. This function is very fast and never fails.
207
void swap(Unit &other) { d.swap(other.d); }
210
* @return Returns true if this Unit is equal to the @param other Unit.
212
bool operator==(const Unit &other) const;
215
* @return Returns true if this Unit is not equal to the @param other Unit.
217
bool operator!=(const Unit &other) const;
220
* @return returns true if this Unit is null
225
* @return if unit is valid.
227
bool isValid() const;
235
* @return category id.
237
CategoryId categoryId() const;
240
* @return unit category.
242
UnitCategory category() const;
245
* @return translated name for unit.
247
QString description() const;
250
* @return symbol for the unit.
252
QString symbol() const;
255
* @param value number value
256
* @param fieldWidth width of the formatted field, padded by spaces.
257
* Positive value aligns right, negative aligns left
258
* @param format type of floating point formating, like in QString::arg
259
* @param precision number of digits after the decimal separator
260
* @param fillChar the character used to fill up the empty places when
261
* field width is greater than argument width
262
* @return value + unit string
264
QString toString(qreal value, int fieldWidth = 0, char format = 'g', int precision = -1,
265
const QChar &fillChar = QLatin1Char(' ')) const;
268
* @param value number value
269
* @param fieldWidth width of the formatted field, padded by spaces.
270
* Positive value aligns right, negative aligns left
271
* @param format type of floating point formating, like in QString::arg
272
* @param precision number of digits after the decimal separator
273
* @param fillChar the character used to fill up the empty places when
274
* field width is greater than argument width
275
* @return value + unit string
277
QString toSymbolString(qreal value, int fieldWidth = 0, char format = 'g', int precision = -1,
278
const QChar &fillChar = QLatin1Char(' ')) const;
282
qreal toDefault(qreal value) const;
283
qreal fromDefault(qreal value) const;
286
friend class CustomUnit;
287
friend class UnitCategory;
288
friend class UnitCategoryPrivate;
289
friend class CurrencyCategoryPrivate;
291
Unit(UnitPrivate *dd);
292
void setUnitMultiplier(qreal multiplier);
294
QExplicitlySharedDataPointer<UnitPrivate> d;
297
#define U(id, m, s, d, sy, r, i) (KUnitConversion::Unit(*this, id, m, s, d, sy, r, i))
299
} // KUnitConversion namespace