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_VALUE_H
21#define KUNITCONVERSION_VALUE_H
22
23#include <QtCore/QString>
24#include "unit.h"
25#include "kunitconversion_export.h"
26
27class QVariant;
28
29namespace KUnitConversion
30{
31
32class KUNITCONVERSION_EXPORT Value
33{
34public:
35 Value();
36 Value(double n, UnitPtr u);
37 Value(double n, const QString& u);
38 Value(double n, int u);
39 Value(const QVariant& n, const QString& u);
40 ~Value();
41
42 /**
43 * Check if value is valid.
44 *
45 * @return True if value is valid
46 **/
47 bool isValid() const;
48
49 /**
50 * Convert value to a string
51 * @param fieldWidth width of the formatted field, padded by spaces.
52 * Positive value aligns right, negative aligns left
53 * @param format type of floating point formating, like in QString::arg
54 * @param precision number of digits after the decimal separator
55 * @param fillChar the character used to fill up the empty places when
56 * field width is greater than argument width
57 * @return value as a string
58 **/
59 QString toString(int fieldWidth = 0, char format = 'g', int precision = -1,
60 const QChar& fillChar = QLatin1Char(' ')) const;
61
62 /**
63 * Convert value to a string with symbol
64 * @param fieldWidth width of the formatted field, padded by spaces.
65 * Positive value aligns right, negative aligns left
66 * @param format type of floating point formating, like in QString::arg
67 * @param precision number of digits after the decimal separator
68 * @param fillChar the character used to fill up the empty places when
69 * field width is greater than argument width
70 * @return value as a string
71 **/
72 QString toSymbolString(int fieldWidth = 0, char format = 'g', int precision = -1,
73 const QChar& fillChar = QLatin1Char(' ')) const;
74
75 /**
76 * Number part of the value
77 **/
78 double number() const;
79
80 /**
81 * rounds value to decimal count
82 * @param decimals decimal count.
83 **/
84 Value& round(uint decimals);
85
86 /**
87 * Unit part of the value
88 **/
89 UnitPtr unit() const;
90
91 /**
92 * convert to another unit
93 **/
94 Value convertTo(UnitPtr unit) const;
95
96 /**
97 * convert to another unit
98 **/
99 Value convertTo(int unit) const;
100
101 /**
102 * convert to another unit
103 **/
104 Value convertTo(const QString& unit) const;
105
106 Value& operator=(const Value&);
107
108private:
109 class Private;
110 Private* const d;
111};
112
113} // KUnitConversion namespace
114
115#endif
116