kspread

valueformatter.h

00001 /* This file is part of the KDE project
00002    Copyright 2004 Tomas Mecir <mecirt@gmail.com>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #ifndef KSPREAD_VALUEFORMATTER
00021 #define KSPREAD_VALUEFORMATTER
00022 
00023 #include "kspread_format.h"
00024 
00025 #include <qdatetime.h>
00026 
00027 namespace KSpread
00028 {
00029 class Cell;
00030 class Value;
00031 class ValueConverter;
00032 
00038 class ValueFormatter {
00039  public:
00041   ValueFormatter (ValueConverter *converter);
00042 
00044   QString formatText (Cell *cell, FormatType fmtType);
00045 
00047   QString formatText (const Value &value,
00048       FormatType fmtType, int precision = -1,
00049       Format::FloatFormat floatFormat = Format::OnlyNegSigned,
00050       const QString &prefix = QString::null,
00051       const QString &postfix = QString::null,
00052       const QString &currencySymbol = QString::null);
00053 
00055   QString dateFormat (const QDate &_date, FormatType fmtType);
00056   
00058   QString timeFormat (const QDateTime &_time, FormatType fmtType);
00059   
00060  protected:
00061  
00062   ValueConverter* converter;
00063  
00066   FormatType determineFormatting (const Value &value,
00067       FormatType fmtType);
00068 
00070   QString createNumberFormat (long value, FormatType fmt, bool alwaysSigned,
00071                               const QString& currencySymbol);
00072   QString createNumberFormat (double value, int precision, FormatType fmt,
00073       bool alwaysSigned, const QString& currencySymbol);
00074   
00076   QString fractionFormat (double value, FormatType fmtType);
00077   
00078   QString errorFormat (Cell *cell);
00079 
00082   void removeTrailingZeros (QString &str, QChar decimal_point);
00083 };
00084 
00085 
00086 }  //namespace KSpread
00087 
00088 
00089 #endif  //KSPREAD_VALUEFORMATTER
KDE Home | KDE Accessibility Home | Description of Access Keys