File indexing completed on 2024-04-28 16:21:38
0001 /* This file is part of the KDE project 0002 Copyright 2004 Tomas Mecir <mecirt@gmail.com> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License as published by the Free Software Foundation; either 0007 version 2 of the License, or (at your option) any later version. 0008 0009 This library is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LIB. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #ifndef CALLIGRA_SHEETS_VALUE_CONVERTER 0021 #define CALLIGRA_SHEETS_VALUE_CONVERTER 0022 0023 #include "Value.h" 0024 0025 namespace Calligra 0026 { 0027 namespace Sheets 0028 { 0029 class CalculationSettings; 0030 class ValueParser; 0031 0032 /** 0033 * \ingroup Value 0034 * Converts between the different Value types. 0035 */ 0036 class CALLIGRA_SHEETS_ODF_EXPORT ValueConverter 0037 { 0038 public: 0039 /** 0040 * Constructor. 0041 */ 0042 explicit ValueConverter(const ValueParser* parser); 0043 0044 /** 0045 * Returns the calculation settings this ValueFormatter uses. 0046 */ 0047 const CalculationSettings* settings() const; 0048 0049 /** 0050 * Converts \p value to a Value of boolean type. 0051 */ 0052 Value asBoolean(const Value& value, bool *ok = 0) const; 0053 0054 /** 0055 * Converts \p value to a Value of integer type. 0056 */ 0057 Value asInteger(const Value& value, bool *ok = 0) const; 0058 0059 /** 0060 * Converts \p value to a Value of floating point type. 0061 */ 0062 Value asFloat(const Value& value, bool* ok = 0) const; 0063 0064 /** 0065 * Converts \p value to a Value of complex number type. 0066 */ 0067 Value asComplex(const Value& value, bool *ok = 0) const; 0068 0069 /** 0070 * Converts \p value to a Value of number type, i.e. Values of integer and 0071 * complex number type stay as they are; all others are converted to the 0072 * floating point type. 0073 */ 0074 Value asNumeric(const Value& value, bool *ok = 0) const; 0075 0076 /** 0077 * Converts \p value to a Value of string type. 0078 */ 0079 Value asString(const Value& value) const; 0080 0081 /** 0082 * Converts \p value to a Value of date/time type. 0083 */ 0084 Value asDateTime(const Value& value, bool *ok = 0) const; 0085 0086 /** 0087 * Converts \p value to a Value of date type. 0088 */ 0089 Value asDate(const Value& value, bool *ok = 0) const; 0090 0091 /** 0092 * Converts \p value to a Value of time type. 0093 */ 0094 Value asTime(const Value& value, bool *ok = 0) const; 0095 0096 0097 bool toBoolean(const Value& value) const; 0098 int toInteger(const Value& value) const; 0099 Number toFloat(const Value& value) const; 0100 complex<Number> toComplex(const Value& value) const; 0101 QString toString(const Value& value) const; 0102 QDateTime toDateTime(const Value& value) const; 0103 QDate toDate(const Value& value) const; 0104 QTime toTime(const Value& value) const; 0105 0106 private: 0107 const ValueParser* m_parser; 0108 }; 0109 0110 } // namespace Sheets 0111 } // namespace Calligra 0112 0113 #endif //CALLIGRA_SHEETS_VALUE_CONVERTER