20#include "valueconverter.h"
22#include "kspread_locale.h"
23#include "valueparser.h"
31TDELocale* ValueConverter::locale()
33 return parser->locale();
36Value ValueConverter::asBoolean (
const Value &value)
const
40 switch (value.
type()) {
54 val = parser->tryParseBool (value.
asString(), &ok);
59 val = asBoolean (value.
element (0, 0));
61 case Value::CellRange:
72Value ValueConverter::asInteger (
const Value &value)
const
77 switch (value.
type()) {
91 val.
setValue ((
int) parser->tryParseNumber
97 val = asInteger (value.
element (0, 0));
99 case Value::CellRange:
110Value ValueConverter::asFloat (
const Value &value)
const
115 switch (value.
type()) {
129 val = parser->tryParseNumber (value.
asString(), &ok);
134 val = asFloat (value.
element (0, 0));
136 case Value::CellRange:
151 return asFloat (value);
154Value ValueConverter::asString (
const Value &value)
const
162 TQChar decimal_point;
164 switch (value.
type()) {
170 parser->locale()->translate (
"False"));
175 if (fmt == Value::fmt_Percent)
176 val = TQString::number (value.
asInteger() * 100) +
" %";
177 else if (fmt == Value::fmt_DateTime)
178 val = parser->locale()->formatDateTime (value.
asDateTime());
179 else if (fmt == Value::fmt_Date)
180 val = parser->locale()->formatDate (value.
asDate());
181 else if (fmt == Value::fmt_Time)
182 val = parser->locale()->formatTime (value.
asTime());
184 val = TQString::number (value.
asInteger());
189 if (fmt == Value::fmt_DateTime)
190 val = parser->locale()->formatDateTime (value.
asDateTime());
191 else if (fmt == Value::fmt_Date)
192 val = parser->locale()->formatDate (value.
asDate(),
true);
193 else if (fmt == Value::fmt_Time)
194 val = parser->locale()->formatTime (value.
asTime());
198 s = TQString::number (value.
asFloat(),
'g', 10);
199 decimal_point = parser->locale()->decimalSymbol()[0];
200 if (decimal_point && ((pos = s.find (
'.')) != -1))
201 s = s.replace (pos, 1, decimal_point);
202 if (fmt == Value::fmt_Percent)
211 val = asString (value.
element (0, 0));
213 case Value::CellRange:
224Value ValueConverter::asDateTime (
const Value &value)
const
229 switch (value.
type()) {
231 val.
setValue (TQDateTime::currentDateTime());
235 val.
setValue (TQDateTime::currentDateTime());
247 val = parser->tryParseDate (value.
asString(), &ok);
253 val = asDateTime (value.
element (0, 0));
255 case Value::CellRange:
265Value ValueConverter::asDate (
const Value &value)
const
270 switch (value.
type()) {
272 val.
setValue (TQDate::currentDate());
276 val.
setValue (TQDate::currentDate());
287 val = parser->tryParseDate (value.
asString(), &ok);
292 val = asDate (value.
element (0, 0));
294 case Value::CellRange:
304Value ValueConverter::asTime (
const Value &value)
const
309 switch (value.
type()) {
311 val.
setValue (TQTime::currentTime());
315 val.
setValue (TQTime::currentTime());
326 val = parser->tryParseTime (value.
asString(), &ok);
331 val = asTime (value.
element (0, 0));
333 case Value::CellRange:
Value asNumeric(const Value &value) const
convert to a numeric value - not necessarily float
ValueConverter(ValueParser *parser)
constructor
The ValueParser parses a text input from the user, generating Value in the desired format.
Provides a wrapper for cell value.
Value element(unsigned column, unsigned row) const
Return an element in the array value.
void setFormat(Format fmt)
Sets format information for this value.
Format format() const
Returns the format of the value (i.e.
void setValue(const Value &v)
Sets this value to another value.
TQDate asDate() const
Returns the date representation of this value.
Type type() const
Returns the type of the value.
double asFloat() const
Returns the floating-point value of this value.
long asInteger() const
Returns the integer value of this value.
TQString errorMessage() const
Returns error message associated with this value.
TQDateTime asDateTime() const
Returns the date/time representation of this value.
TQString asString() const
Returns the string value of this value.
static const Value & errorVALUE()
Returns constant reference to VALUE!
TQTime asTime() const
Returns the time representation of this value.
bool asBoolean() const
Returns the boolean value of this value.