1 | /* |
2 | * Copyright (C) 2007-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_UNITCATEGORY_H |
21 | #define KUNITCONVERSION_UNITCATEGORY_H |
22 | |
23 | #include "value.h" |
24 | #include "unit.h" |
25 | #include <QtCore/QString> |
26 | #include <QtCore/QStringList> |
27 | #include <kurl.h> |
28 | #include "kunitconversion_export.h" |
29 | |
30 | namespace KUnitConversion |
31 | { |
32 | |
33 | class KUNITCONVERSION_EXPORT UnitCategory |
34 | { |
35 | public: |
36 | UnitCategory(int id); |
37 | virtual ~UnitCategory(); |
38 | |
39 | /** |
40 | * Returns name for the unit category. |
41 | * |
42 | * @return Translated name for category. |
43 | **/ |
44 | QString name() const; |
45 | |
46 | /** |
47 | * @return unit category description |
48 | **/ |
49 | QString description() const; |
50 | |
51 | /** |
52 | * @return unit category url for description |
53 | **/ |
54 | KUrl url() const; |
55 | |
56 | /** |
57 | * Returns default unit. |
58 | * |
59 | * @return default unit. |
60 | **/ |
61 | UnitPtr defaultUnit() const; |
62 | |
63 | /** |
64 | * Check if unit category has a unit. |
65 | * |
66 | * @return True if unit is found |
67 | **/ |
68 | bool hasUnit(const QString &unit) const; |
69 | |
70 | /** |
71 | * Return unit for string. |
72 | * |
73 | * @return Pointer to unit class. |
74 | **/ |
75 | UnitPtr unit(const QString& s) const; |
76 | |
77 | /** |
78 | * Return unit for unit enum. |
79 | * |
80 | * @return Pointer to unit class. |
81 | **/ |
82 | UnitPtr unit(int unitId) const; |
83 | |
84 | /** |
85 | * Return units in this category. |
86 | * |
87 | * @return list of units. |
88 | **/ |
89 | QList<UnitPtr> units() const; |
90 | |
91 | /** |
92 | * Return most common units in this category. |
93 | * |
94 | * @return list of units. |
95 | **/ |
96 | QList<UnitPtr> mostCommonUnits() const; |
97 | |
98 | /** |
99 | * Return all unit names, short names and unit synonyms in this category. |
100 | * |
101 | * @return list of units. |
102 | **/ |
103 | QStringList allUnits() const; |
104 | |
105 | /** |
106 | * Convert value to another unit. |
107 | * |
108 | * @param value value to convert |
109 | * @param toUnit unit to convert to. If empty default unit is used. |
110 | * @return converted value |
111 | **/ |
112 | Value convert(const Value& value, const QString& toUnit = QString()); |
113 | Value convert(const Value& value, int toUnit); |
114 | virtual Value convert(const Value& value, UnitPtr toUnit); |
115 | |
116 | /** |
117 | * @return category id. |
118 | **/ |
119 | int id() const; |
120 | |
121 | protected: |
122 | void setName(const QString& name); |
123 | void setDefaultUnit(UnitPtr defaultUnit); |
124 | void addUnitName(const QString& name); |
125 | void addUnitMapValues(UnitPtr unit, const QString& names); |
126 | void addIdMapValue(UnitPtr unit, int id); |
127 | void setDescription(const QString& desc); |
128 | void setUrl(const KUrl& url); |
129 | void setSymbolStringFormat(const KLocalizedString& symbolStringFormat); |
130 | void setMostCommonUnits(const QList<int>& units); |
131 | KLocalizedString symbolStringFormat() const; |
132 | |
133 | private: |
134 | friend class Unit; |
135 | class Private; |
136 | Private* const d; |
137 | }; |
138 | |
139 | } // KUnitConversion namespace |
140 | |
141 | #endif |
142 | |