You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
650 lines
19 KiB
650 lines
19 KiB
15 years ago
|
/* This file is part of the KDE project
|
||
|
Copyright 2004 Tomas Mecir <mecirt@gmail.com>
|
||
|
Copyright (C) 1998-2004 KSpread Team <koffice-devel@kde.org>
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License as published by the Free Software Foundation; either
|
||
|
version 2 of the License, or (at your option) any later version.
|
||
|
|
||
|
This library is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
* Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
#include "valueformatter.h"
|
||
|
|
||
|
#include "kspread_cell.h"
|
||
|
#include "kspread_locale.h"
|
||
|
#include "kspread_util.h"
|
||
|
#include "valueconverter.h"
|
||
|
|
||
|
#include <kcalendarsystem.h>
|
||
|
#include <kdebug.h>
|
||
12 years ago
|
#include <tdelocale.h>
|
||
15 years ago
|
|
||
|
#include <float.h>
|
||
|
#include <math.h>
|
||
|
|
||
|
using namespace KSpread;
|
||
|
|
||
|
ValueFormatter::ValueFormatter (ValueConverter *conv) : converter( conv )
|
||
|
{
|
||
|
}
|
||
|
|
||
14 years ago
|
TQString ValueFormatter::formatText (Cell *cell, FormatType fmtType)
|
||
15 years ago
|
{
|
||
|
if (cell->hasError ())
|
||
|
return errorFormat (cell);
|
||
|
|
||
14 years ago
|
TQString str;
|
||
15 years ago
|
|
||
|
Format::FloatFormat floatFormat =
|
||
|
cell->format()->floatFormat (cell->column(), cell->row());
|
||
|
int precision = cell->format()->precision (cell->column(), cell->row());
|
||
14 years ago
|
TQString prefix = cell->format()->prefix (cell->column(), cell->row());
|
||
|
TQString postfix = cell->format()->postfix (cell->column(), cell->row());
|
||
15 years ago
|
Format::Currency currency;
|
||
|
bool valid = cell->format()->currencyInfo(currency);
|
||
14 years ago
|
TQString currencySymbol = valid ? currency.symbol : TQString();
|
||
15 years ago
|
|
||
|
return formatText (cell->value(), fmtType, precision,
|
||
|
floatFormat, prefix, postfix, currencySymbol);
|
||
|
}
|
||
|
|
||
14 years ago
|
TQString ValueFormatter::formatText (const Value &value,
|
||
15 years ago
|
FormatType fmtType, int precision, Format::FloatFormat floatFormat,
|
||
14 years ago
|
const TQString &prefix, const TQString &postfix, const TQString ¤cySymbol)
|
||
15 years ago
|
{
|
||
|
//if we have an array, use its first element
|
||
|
if (value.isArray())
|
||
|
return formatText (value.element (0, 0), fmtType, precision,
|
||
|
floatFormat, prefix, postfix, currencySymbol);
|
||
|
|
||
14 years ago
|
TQString str;
|
||
15 years ago
|
|
||
|
//step 1: determine formatting that will be used
|
||
|
fmtType = determineFormatting (value, fmtType);
|
||
|
|
||
|
//step 2: format the value !
|
||
|
|
||
|
//text
|
||
|
if (fmtType == Text_format)
|
||
|
{
|
||
|
str = converter->asString (value).asString();
|
||
|
if (!str.isEmpty() && str[0]=='\'' )
|
||
|
str = str.mid(1);
|
||
|
}
|
||
|
|
||
|
//date
|
||
|
else if (formatIsDate (fmtType))
|
||
|
str = dateFormat (value.asDate(), fmtType);
|
||
|
|
||
|
//time
|
||
|
else if (formatIsTime (fmtType))
|
||
|
str = timeFormat (value.asDateTime(), fmtType);
|
||
|
|
||
|
//fraction
|
||
|
else if (formatIsFraction (fmtType))
|
||
|
str = fractionFormat (value.asFloat(), fmtType);
|
||
|
|
||
|
//another
|
||
|
else
|
||
|
{
|
||
|
//some cell parameters ...
|
||
|
double v = converter->asFloat (value).asFloat();
|
||
|
|
||
|
// Always unsigned ?
|
||
|
if ((floatFormat == Format::AlwaysUnsigned) && (v < 0.0))
|
||
|
v *= -1.0;
|
||
|
|
||
|
// Make a string out of it.
|
||
|
str = createNumberFormat (v, precision, fmtType,
|
||
|
(floatFormat == Format::AlwaysSigned), currencySymbol);
|
||
|
|
||
|
// Remove trailing zeros and the decimal point if necessary
|
||
|
// unless the number has no decimal point
|
||
|
if (precision == -1)
|
||
|
{
|
||
14 years ago
|
TQChar decimal_point = converter->locale()->decimalSymbol()[0];
|
||
15 years ago
|
if ( decimal_point.isNull() )
|
||
|
decimal_point = '.';
|
||
|
|
||
|
removeTrailingZeros (str, decimal_point);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (!prefix.isEmpty())
|
||
|
str = prefix + ' ' + str;
|
||
|
|
||
|
if( !postfix.isEmpty())
|
||
|
str += ' ' + postfix;
|
||
|
|
||
|
//kdDebug() << "ValueFormatter says: " << str << endl;
|
||
|
return str;
|
||
|
}
|
||
|
|
||
|
FormatType ValueFormatter::determineFormatting (const Value &value,
|
||
|
FormatType fmtType)
|
||
|
{
|
||
|
//if the cell value is a string, then we want to display it as-is,
|
||
|
//no matter what, same if the cell is empty
|
||
|
if (value.isString () || (value.format() == Value::fmt_None))
|
||
|
return Text_format;
|
||
|
//same if we're supposed to display string, no matter what we actually got
|
||
|
if (fmtType == Text_format)
|
||
|
return Text_format;
|
||
|
|
||
|
//now, everything depends on whether the formatting is Generic or not
|
||
|
if (fmtType == Generic_format)
|
||
|
{
|
||
|
//here we decide based on value's format...
|
||
|
Value::Format fmt = value.format();
|
||
|
switch (fmt) {
|
||
|
case Value::fmt_None:
|
||
|
fmtType = Text_format;
|
||
|
break;
|
||
|
case Value::fmt_Boolean:
|
||
|
fmtType = Text_format;
|
||
|
break;
|
||
|
case Value::fmt_Number:
|
||
|
if (value.asFloat() > 1e+10)
|
||
|
fmtType = Scientific_format;
|
||
|
else
|
||
|
fmtType = Number_format;
|
||
|
break;
|
||
|
case Value::fmt_Percent:
|
||
|
fmtType = Percentage_format;
|
||
|
break;
|
||
|
case Value::fmt_Money:
|
||
|
fmtType = Money_format;
|
||
|
break;
|
||
|
case Value::fmt_DateTime:
|
||
|
fmtType = TextDate_format;
|
||
|
break;
|
||
|
case Value::fmt_Date:
|
||
|
fmtType = ShortDate_format;
|
||
|
break;
|
||
|
case Value::fmt_Time:
|
||
|
fmtType = Time_format;
|
||
|
break;
|
||
|
case Value::fmt_String:
|
||
|
//this should never happen
|
||
|
fmtType = Text_format;
|
||
|
break;
|
||
|
};
|
||
|
return fmtType;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
//we'll mostly want to use the given formatting, the only exception
|
||
|
//being Boolean values
|
||
|
|
||
|
//TODO: is this correct? We may also want to convert bools to 1s and 0s
|
||
|
//if we want to display a number...
|
||
|
|
||
|
//TODO: what to do about Custom formatting? We don't support it as of now,
|
||
|
// but we'll have it ... one day, that is ...
|
||
|
if (value.isBoolean())
|
||
|
return Text_format;
|
||
|
else
|
||
|
return fmtType;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
void ValueFormatter::removeTrailingZeros (TQString &str, TQChar decimal_point)
|
||
15 years ago
|
{
|
||
14 years ago
|
if (str.find (decimal_point) < 0)
|
||
15 years ago
|
//no decimal point -> nothing to do
|
||
|
return;
|
||
|
|
||
|
int start = 0;
|
||
|
int cslen = converter->locale()->currencySymbol().length();
|
||
14 years ago
|
if (str.find ('%') != -1)
|
||
15 years ago
|
start = 2;
|
||
14 years ago
|
else if (str.find (converter->locale()->currencySymbol()) ==
|
||
15 years ago
|
((int) (str.length() - cslen)))
|
||
|
start = cslen + 1;
|
||
14 years ago
|
else if ((start = str.find ('E')) != -1)
|
||
15 years ago
|
start = str.length() - start;
|
||
|
else
|
||
|
start = 0;
|
||
|
|
||
|
int i = str.length() - start;
|
||
|
bool bFinished = false;
|
||
|
while ( !bFinished && i > 0 )
|
||
|
{
|
||
14 years ago
|
TQChar ch = str[i - 1];
|
||
15 years ago
|
if (ch == '0')
|
||
|
str.remove (--i,1);
|
||
|
else
|
||
|
{
|
||
|
bFinished = true;
|
||
|
if (ch == decimal_point)
|
||
|
str.remove (--i, 1);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
TQString ValueFormatter::createNumberFormat ( double value, int precision,
|
||
|
FormatType fmt, bool alwaysSigned, const TQString& currencySymbol)
|
||
15 years ago
|
{
|
||
|
// if precision is -1, ask for a huge number of decimals, we'll remove
|
||
|
// the zeros later. Is 8 ok ?
|
||
|
// Stefan: No. Use maximum possible decimal precision (DBL_DIG) instead.
|
||
|
int p = (precision == -1) ? 8 : precision;
|
||
14 years ago
|
TQString localizedNumber;
|
||
15 years ago
|
int pos = 0;
|
||
|
|
||
|
//multiply value by 100 for percentage format
|
||
|
if (fmt == Percentage_format)
|
||
|
value *= 100;
|
||
|
|
||
|
// this will avoid displaying negative zero, i.e "-0.0000"
|
||
|
if( fabs( value ) < DBL_EPSILON ) value = 0.0;
|
||
|
|
||
|
// round the number, based on desired precision if not scientific is chosen
|
||
|
//(scientific has relative precision)
|
||
|
if( fmt != Scientific_format )
|
||
|
{
|
||
|
double m[] = { 1, 10, 100, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10 };
|
||
|
double mm = (p > 10) ? pow(10.0,p) : m[p];
|
||
|
bool neg = value < 0;
|
||
|
value = floor( fabs(value)*mm + 0.5 ) / mm;
|
||
|
if( neg ) value = -value;
|
||
|
}
|
||
|
|
||
14 years ago
|
TQChar decimal_point;
|
||
15 years ago
|
switch (fmt)
|
||
|
{
|
||
|
case Number_format:
|
||
|
localizedNumber = converter->locale()->formatNumber(value, p);
|
||
|
break;
|
||
|
case Percentage_format:
|
||
|
localizedNumber = converter->locale()->formatNumber (value, p)+ " %";
|
||
|
break;
|
||
|
case Money_format:
|
||
|
localizedNumber = converter->locale()->formatMoney (value,
|
||
|
currencySymbol.isEmpty() ? converter->locale()->currencySymbol() : currencySymbol, p );
|
||
|
break;
|
||
|
case Scientific_format:
|
||
|
decimal_point = converter->locale()->decimalSymbol()[0];
|
||
14 years ago
|
localizedNumber = TQString::number (value, 'E', p);
|
||
14 years ago
|
if ((pos = localizedNumber.find ('.')) != -1)
|
||
|
localizedNumber = localizedNumber.replace (pos, 1, decimal_point);
|
||
15 years ago
|
break;
|
||
|
default :
|
||
|
//other formatting?
|
||
|
// This happens with Custom_format...
|
||
|
kdDebug(36001)<<"Wrong usage of ValueFormatter::createNumberFormat fmt=" << fmt << "\n";
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
//prepend positive sign if needed
|
||
|
if (alwaysSigned && value >= 0 )
|
||
|
if (converter->locale()->positiveSign().isEmpty())
|
||
|
localizedNumber='+'+localizedNumber;
|
||
|
|
||
|
return localizedNumber;
|
||
|
}
|
||
|
|
||
14 years ago
|
TQString ValueFormatter::fractionFormat (double value, FormatType fmtType)
|
||
15 years ago
|
{
|
||
|
double result = value - floor(value);
|
||
|
int index;
|
||
|
int limit = 0;
|
||
|
|
||
|
/* return w/o fraction part if not necessary */
|
||
|
if (result == 0)
|
||
14 years ago
|
return TQString::number(value);
|
||
15 years ago
|
|
||
|
switch (fmtType) {
|
||
|
case fraction_half:
|
||
|
index = 2;
|
||
|
break;
|
||
|
case fraction_quarter:
|
||
|
index = 4;
|
||
|
break;
|
||
|
case fraction_eighth:
|
||
|
index = 8;
|
||
|
break;
|
||
|
case fraction_sixteenth:
|
||
|
index = 16;
|
||
|
break;
|
||
|
case fraction_tenth:
|
||
|
index = 10;
|
||
|
break;
|
||
|
case fraction_hundredth:
|
||
|
index = 100;
|
||
|
break;
|
||
|
case fraction_one_digit:
|
||
|
index = 3;
|
||
|
limit = 9;
|
||
|
break;
|
||
|
case fraction_two_digits:
|
||
|
index = 4;
|
||
|
limit = 99;
|
||
|
break;
|
||
|
case fraction_three_digits:
|
||
|
index = 5;
|
||
|
limit = 999;
|
||
|
break;
|
||
|
default:
|
||
|
kdDebug(36001) << "Error in Fraction format\n";
|
||
14 years ago
|
return TQString::number(value);
|
||
15 years ago
|
break;
|
||
|
} /* switch */
|
||
|
|
||
|
|
||
|
/* handle halves, quarters, tenths, ... */
|
||
|
|
||
|
if (fmtType != fraction_three_digits
|
||
|
&& fmtType != fraction_two_digits
|
||
|
&& fmtType != fraction_one_digit) {
|
||
|
double calc = 0;
|
||
|
int index1 = 0;
|
||
|
double diff = result;
|
||
|
for (int i = 1; i <= index; i++) {
|
||
|
calc = i * 1.0 / index;
|
||
|
if (fabs(result - calc) < diff) {
|
||
|
index1 = i;
|
||
|
diff = fabs(result - calc);
|
||
|
}
|
||
|
}
|
||
13 years ago
|
if( index1 == 0 ) return TQString("%1").arg( floor(value) );
|
||
|
if( index1 == index ) return TQString("%1").arg( floor(value)+1 );
|
||
15 years ago
|
if( floor(value) == 0)
|
||
13 years ago
|
return TQString("%1/%2").arg( index1 ).arg( index );
|
||
15 years ago
|
|
||
14 years ago
|
return TQString("%1 %2/%3")
|
||
13 years ago
|
.arg( floor(value) )
|
||
|
.arg( index1 )
|
||
|
.arg( index );
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
|
/* handle fraction_one_digit, fraction_two_digit
|
||
|
* and fraction_three_digit style */
|
||
|
|
||
|
double precision, denominator, numerator;
|
||
|
|
||
|
do {
|
||
|
double val1 = result;
|
||
|
double val2 = rint(result);
|
||
|
double inter2 = 1;
|
||
|
double inter4, p, q;
|
||
|
inter4 = p = q = 0;
|
||
|
|
||
|
precision = pow(10.0, -index);
|
||
|
numerator = val2;
|
||
|
denominator = 1;
|
||
|
|
||
|
while (fabs(numerator/denominator - result) > precision) {
|
||
|
val1 = (1 / (val1 - val2));
|
||
|
val2 = rint(val1);
|
||
|
p = val2 * numerator + inter2;
|
||
|
q = val2 * denominator + inter4;
|
||
|
inter2 = numerator;
|
||
|
inter4 = denominator;
|
||
|
numerator = p;
|
||
|
denominator = q;
|
||
|
}
|
||
|
index--;
|
||
|
} while (fabs(denominator) > limit);
|
||
|
|
||
|
denominator = fabs(denominator);
|
||
|
numerator = fabs(numerator);
|
||
|
|
||
|
if (denominator == numerator)
|
||
14 years ago
|
return TQString().setNum(floor(value + 1));
|
||
15 years ago
|
else
|
||
|
{
|
||
|
if ( floor(value) == 0 )
|
||
13 years ago
|
return TQString("%1/%2").arg(numerator).arg(denominator);
|
||
15 years ago
|
else
|
||
14 years ago
|
return TQString("%1 %2/%3")
|
||
13 years ago
|
.arg(floor(value))
|
||
|
.arg(numerator)
|
||
|
.arg(denominator);
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
TQString ValueFormatter::timeFormat (const TQDateTime &dt, FormatType fmtType)
|
||
15 years ago
|
{
|
||
|
if (fmtType == Time_format)
|
||
|
return converter->locale()->formatTime(dt.time(), false);
|
||
|
|
||
|
if (fmtType == SecondeTime_format)
|
||
|
return converter->locale()->formatTime(dt.time(), true);
|
||
|
|
||
|
int h = dt.time().hour();
|
||
|
int m = dt.time().minute();
|
||
|
int s = dt.time().second();
|
||
|
|
||
14 years ago
|
TQString hour = ( h < 10 ? "0" + TQString::number(h) : TQString::number(h) );
|
||
|
TQString minute = ( m < 10 ? "0" + TQString::number(m) : TQString::number(m) );
|
||
|
TQString second = ( s < 10 ? "0" + TQString::number(s) : TQString::number(s) );
|
||
15 years ago
|
bool pm = (h > 12);
|
||
14 years ago
|
TQString AMPM( pm ? i18n("PM"):i18n("AM") );
|
||
15 years ago
|
|
||
|
if (fmtType == Time_format1) { // 9 : 01 AM
|
||
14 years ago
|
return TQString("%1:%2 %3")
|
||
13 years ago
|
.arg((pm ? h - 12 : h),2)
|
||
|
.arg(minute,2)
|
||
|
.arg(AMPM);
|
||
15 years ago
|
}
|
||
|
|
||
|
if (fmtType == Time_format2) { //9:01:05 AM
|
||
14 years ago
|
return TQString("%1:%2:%3 %4")
|
||
13 years ago
|
.arg((pm ? h-12 : h),2)
|
||
|
.arg(minute,2)
|
||
|
.arg(second,2)
|
||
|
.arg(AMPM);
|
||
15 years ago
|
}
|
||
|
|
||
|
if (fmtType == Time_format3) {
|
||
14 years ago
|
return TQString("%1 %2 %3 %4 %5 %6") // 9 h 01 min 28 s
|
||
13 years ago
|
.arg(hour,2)
|
||
|
.arg(i18n("h"))
|
||
|
.arg(minute,2)
|
||
|
.arg(i18n("min"))
|
||
|
.arg(second,2)
|
||
|
.arg(i18n("s"));
|
||
15 years ago
|
}
|
||
|
|
||
|
if (fmtType == Time_format4) { // 9:01
|
||
13 years ago
|
return TQString("%1:%2").arg(hour, 2).arg(minute, 2);
|
||
15 years ago
|
}
|
||
|
|
||
|
if (fmtType == Time_format5) { // 9:01:12
|
||
13 years ago
|
return TQString("%1:%2:%3").arg(hour, 2).arg(minute, 2).arg(second, 2);
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
TQDate d1(dt.date());
|
||
|
TQDate d2( 1899, 12, 31 );
|
||
15 years ago
|
int d = d2.daysTo( d1 ) + 1;
|
||
|
|
||
|
h += d * 24;
|
||
|
|
||
|
if (fmtType == Time_format6)
|
||
|
{ // [mm]:ss
|
||
|
m += (h * 60);
|
||
13 years ago
|
return TQString("%1:%2").arg(m, 1).arg(second, 2);
|
||
15 years ago
|
}
|
||
|
if (fmtType == Time_format7) { // [h]:mm:ss
|
||
13 years ago
|
return TQString("%1:%2:%3").arg(h, 1).arg(minute, 2).arg(second, 2);
|
||
15 years ago
|
}
|
||
|
if (fmtType == Time_format8)
|
||
|
{ // [h]:mm
|
||
|
m += (h * 60);
|
||
13 years ago
|
return TQString("%1:%2").arg(h, 1).arg(minute, 2);
|
||
15 years ago
|
}
|
||
|
|
||
|
return converter->locale()->formatTime( dt.time(), false );
|
||
|
}
|
||
|
|
||
14 years ago
|
TQString ValueFormatter::dateFormat (const TQDate &date, FormatType fmtType)
|
||
15 years ago
|
{
|
||
14 years ago
|
TQString tmp;
|
||
15 years ago
|
if (fmtType == ShortDate_format) {
|
||
|
tmp = converter->locale()->formatDate(date, true);
|
||
|
}
|
||
|
else if (fmtType == TextDate_format) {
|
||
|
tmp = converter->locale()->formatDate(date, false);
|
||
|
}
|
||
|
else if (fmtType == date_format1) { /*18-Feb-99 */
|
||
14 years ago
|
tmp = TQString().sprintf("%02d", date.day());
|
||
15 years ago
|
tmp += "-" + converter->locale()->calendar()->monthString(date, true) + "-";
|
||
14 years ago
|
tmp += TQString::number(date.year()).right(2);
|
||
15 years ago
|
}
|
||
|
else if (fmtType == date_format2) { /*18-Feb-1999 */
|
||
14 years ago
|
tmp = TQString().sprintf("%02d", date.day());
|
||
15 years ago
|
tmp += "-" + converter->locale()->calendar()->monthString(date, true) + "-";
|
||
14 years ago
|
tmp += TQString::number(date.year());
|
||
15 years ago
|
}
|
||
|
else if (fmtType == date_format3) { /*18-Feb */
|
||
14 years ago
|
tmp = TQString().sprintf("%02d", date.day());
|
||
15 years ago
|
tmp += "-" + converter->locale()->calendar()->monthString(date, true);
|
||
|
}
|
||
|
else if (fmtType == date_format4) { /*18-05 */
|
||
14 years ago
|
tmp = TQString().sprintf("%02d", date.day());
|
||
|
tmp += "-" + TQString().sprintf("%02d", date.month() );
|
||
15 years ago
|
}
|
||
|
else if (fmtType == date_format5) { /*18/05/00 */
|
||
14 years ago
|
tmp = TQString().sprintf("%02d", date.day());
|
||
|
tmp += "/" + TQString().sprintf("%02d", date.month()) + "/";
|
||
|
tmp += TQString::number(date.year()).right(2);
|
||
15 years ago
|
}
|
||
|
else if (fmtType == date_format6) { /*18/05/1999 */
|
||
14 years ago
|
tmp = TQString().sprintf("%02d", date.day());
|
||
|
tmp += "/" + TQString().sprintf("%02d", date.month()) + "/";
|
||
|
tmp += TQString::number(date.year());
|
||
15 years ago
|
}
|
||
|
else if (fmtType == date_format7) { /*Feb-99 */
|
||
|
tmp = converter->locale()->calendar()->monthString(date, true) + "-";
|
||
14 years ago
|
tmp += TQString::number(date.year()).right(2);
|
||
15 years ago
|
}
|
||
|
else if (fmtType == date_format8) { /*February-99 */
|
||
|
tmp = converter->locale()->calendar()->monthString(date, false) + "-";
|
||
14 years ago
|
tmp += TQString::number(date.year()).right(2);
|
||
15 years ago
|
}
|
||
|
else if (fmtType == date_format9) { /*February-1999 */
|
||
|
tmp = converter->locale()->calendar()->monthString(date, false) + "-";
|
||
14 years ago
|
tmp += TQString::number(date.year());
|
||
15 years ago
|
}
|
||
|
else if (fmtType == date_format10) { /*F-99 */
|
||
13 years ago
|
tmp = converter->locale()->calendar()->monthString(date, false).at(0) + "-";
|
||
14 years ago
|
tmp += TQString::number(date.year()).right(2);
|
||
15 years ago
|
}
|
||
|
else if (fmtType == date_format11) { /*18/Feb */
|
||
14 years ago
|
tmp = TQString().sprintf("%02d", date.day()) + "/";
|
||
15 years ago
|
tmp += converter->locale()->calendar()->monthString(date, true);
|
||
|
}
|
||
|
else if (fmtType == date_format12) { /*18/02 */
|
||
14 years ago
|
tmp = TQString().sprintf("%02d", date.day()) + "/";
|
||
|
tmp += TQString().sprintf("%02d", date.month());
|
||
15 years ago
|
}
|
||
|
else if (fmtType == date_format13) { /*18/Feb/1999 */
|
||
14 years ago
|
tmp = TQString().sprintf("%02d", date.day());
|
||
15 years ago
|
tmp += "/" + converter->locale()->calendar()->monthString(date, true) + "/";
|
||
14 years ago
|
tmp += TQString::number(date.year());
|
||
15 years ago
|
}
|
||
|
else if (fmtType == date_format14) { /*2000/Feb/18 */
|
||
14 years ago
|
tmp = TQString::number(date.year());
|
||
15 years ago
|
tmp += "/" + converter->locale()->calendar()->monthString(date, true) + "/";
|
||
14 years ago
|
tmp += TQString().sprintf("%02d", date.day());
|
||
15 years ago
|
}
|
||
|
else if (fmtType == date_format15) { /*2000-Feb-18 */
|
||
14 years ago
|
tmp = TQString::number(date.year());
|
||
15 years ago
|
tmp += "-" + converter->locale()->calendar()->monthString(date, true) + "-";
|
||
14 years ago
|
tmp += TQString().sprintf("%02d", date.day());
|
||
15 years ago
|
}
|
||
|
else if (fmtType == date_format16) { /*2000-02-18 */
|
||
14 years ago
|
tmp = TQString::number(date.year());
|
||
|
tmp += "-" + TQString().sprintf("%02d", date.month()) + "-";
|
||
|
tmp += TQString().sprintf("%02d", date.day());
|
||
15 years ago
|
}
|
||
|
else if (fmtType == date_format17) { /*2 february 2000 */
|
||
14 years ago
|
tmp = TQString().sprintf("%d", date.day());
|
||
15 years ago
|
tmp += " " + converter->locale()->calendar()->monthString(date, false) + " ";
|
||
14 years ago
|
tmp += TQString::number(date.year());
|
||
15 years ago
|
}
|
||
|
else if (fmtType == date_format18) { /*02/18/1999 */
|
||
14 years ago
|
tmp = TQString().sprintf("%02d", date.month());
|
||
|
tmp += "/" + TQString().sprintf("%02d", date.day());
|
||
|
tmp += "/" + TQString::number(date.year());
|
||
15 years ago
|
}
|
||
|
else if (fmtType == date_format19) { /*02/18/99 */
|
||
14 years ago
|
tmp = TQString().sprintf("%02d", date.month());
|
||
|
tmp += "/" + TQString().sprintf("%02d", date.day());
|
||
|
tmp += "/" + TQString::number(date.year()).right(2);
|
||
15 years ago
|
}
|
||
|
else if (fmtType == date_format20) { /*Feb/18/99 */
|
||
|
tmp = converter->locale()->calendar()->monthString(date, true);
|
||
14 years ago
|
tmp += "/" + TQString().sprintf("%02d", date.day());
|
||
|
tmp += "/" + TQString::number(date.year()).right(2);
|
||
15 years ago
|
}
|
||
|
else if (fmtType == date_format21) { /*Feb/18/1999 */
|
||
|
tmp = converter->locale()->calendar()->monthString(date, true);
|
||
14 years ago
|
tmp += "/" + TQString().sprintf("%02d", date.day());
|
||
|
tmp += "/" + TQString::number(date.year());
|
||
15 years ago
|
}
|
||
|
else if (fmtType == date_format22) { /*Feb-1999 */
|
||
|
tmp = converter->locale()->calendar()->monthString(date, true) + "-";
|
||
14 years ago
|
tmp += TQString::number(date.year());
|
||
15 years ago
|
}
|
||
|
else if (fmtType == date_format23) { /*1999 */
|
||
14 years ago
|
tmp = TQString::number(date.year());
|
||
15 years ago
|
}
|
||
|
else if (fmtType == date_format24) { /*99 */
|
||
14 years ago
|
tmp = TQString::number(date.year()).right(2);
|
||
15 years ago
|
}
|
||
|
else if (fmtType == date_format25) { /*2000/02/18 */
|
||
14 years ago
|
tmp = TQString::number(date.year());
|
||
|
tmp += "/" + TQString().sprintf("%02d", date.month());
|
||
|
tmp += "/" + TQString().sprintf("%02d", date.day());
|
||
15 years ago
|
}
|
||
|
else if (fmtType == date_format26) { /*2000/Feb/18 */
|
||
14 years ago
|
tmp = TQString::number(date.year());
|
||
15 years ago
|
tmp += "/" + converter->locale()->calendar()->monthString(date, true);
|
||
14 years ago
|
tmp += "/" + TQString().sprintf("%02d", date.day());
|
||
15 years ago
|
}
|
||
|
else
|
||
|
tmp = converter->locale()->formatDate(date, true);
|
||
|
|
||
|
// Missing compared with gnumeric:
|
||
|
// "m/d/yy h:mm", /* 20 */
|
||
|
// "m/d/yyyy h:mm", /* 21 */
|
||
|
// "mmm/ddd/yy", /* 12 */
|
||
|
// "mmm/ddd/yyyy", /* 13 */
|
||
|
// "mm/ddd/yy", /* 14 */
|
||
|
// "mm/ddd/yyyy", /* 15 */
|
||
|
|
||
|
return tmp;
|
||
|
}
|
||
|
|
||
14 years ago
|
TQString ValueFormatter::errorFormat (Cell *cell)
|
||
15 years ago
|
{
|
||
14 years ago
|
TQString err;
|
||
15 years ago
|
if (cell->testFlag (Cell::Flag_ParseError))
|
||
|
err = "#" + i18n ("Parse") + "!";
|
||
|
else if ( cell->testFlag (Cell::Flag_CircularCalculation))
|
||
|
err = "#" + i18n ("Circle") + "!";
|
||
|
else if ( cell->testFlag (Cell::Flag_DependancyError))
|
||
|
err = "#" + i18n ("Depend") + "!";
|
||
|
else
|
||
|
{
|
||
|
err = "####";
|
||
|
kdDebug(36001) << "Unhandled error type." << endl;
|
||
|
}
|
||
|
return err;
|
||
|
}
|
||
|
|