1/* This file is part of the KDE project
2 Copyright 2004 Tomas Mecir <mecirt@gmail.com>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library 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 GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18*/
19
20#ifndef CALLIGRA_SHEETS_VALUE_CONVERTER
21#define CALLIGRA_SHEETS_VALUE_CONVERTER
22
23#include "Value.h"
24
25namespace Calligra
26{
27namespace Sheets
28{
29class CalculationSettings;
30class ValueParser;
31
32/**
33 * \ingroup Value
34 * Converts between the different Value types.
35 */
36class CALLIGRA_SHEETS_ODF_EXPORT ValueConverter
37{
38public:
39 /**
40 * Constructor.
41 */
42 explicit ValueConverter(const ValueParser* parser);
43
44 /**
45 * Returns the calculation settings this ValueFormatter uses.
46 */
47 const CalculationSettings* settings() const;
48
49 /**
50 * Converts \p value to a Value of boolean type.
51 */
52 Value asBoolean(const Value& value, bool *ok = 0) const;
53
54 /**
55 * Converts \p value to a Value of integer type.
56 */
57 Value asInteger(const Value& value, bool *ok = 0) const;
58
59 /**
60 * Converts \p value to a Value of floating point type.
61 */
62 Value asFloat(const Value& value, bool* ok = 0) const;
63
64 /**
65 * Converts \p value to a Value of complex number type.
66 */
67 Value asComplex(const Value& value, bool *ok = 0) const;
68
69 /**
70 * Converts \p value to a Value of number type, i.e. Values of integer and
71 * complex number type stay as they are; all others are converted to the
72 * floating point type.
73 */
74 Value asNumeric(const Value& value, bool *ok = 0) const;
75
76 /**
77 * Converts \p value to a Value of string type.
78 */
79 Value asString(const Value& value) const;
80
81 /**
82 * Converts \p value to a Value of date/time type.
83 */
84 Value asDateTime(const Value& value, bool *ok = 0) const;
85
86 /**
87 * Converts \p value to a Value of date type.
88 */
89 Value asDate(const Value& value, bool *ok = 0) const;
90
91 /**
92 * Converts \p value to a Value of time type.
93 */
94 Value asTime(const Value& value, bool *ok = 0) const;
95
96
97 bool toBoolean(const Value& value) const;
98 int toInteger(const Value& value) const;
99 Number toFloat(const Value& value) const;
100 complex<Number> toComplex(const Value& value) const;
101 QString toString(const Value& value) const;
102 QDateTime toDateTime(const Value& value) const;
103 QDate toDate(const Value& value) const;
104 QTime toTime(const Value& value) const;
105
106private:
107 const ValueParser* m_parser;
108};
109
110} // namespace Sheets
111} // namespace Calligra
112
113#endif //CALLIGRA_SHEETS_VALUE_CONVERTER
114