KOffice – TDE office suite
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.

88 lines
2.6KB

  1. /* This file is part of the KDE project
  2. Copyright 2004 Tomas Mecir <mecirt@gmail.com>
  3. This library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Library General Public
  5. License as published by the Free Software Foundation; either
  6. version 2 of the License, or (at your option) any later version.
  7. This library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public License
  12. along with this library; see the file COPYING.LIB. If not, write to
  13. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  14. * Boston, MA 02110-1301, USA.
  15. */
  16. #ifndef KSPREAD_VALUEFORMATTER
  17. #define KSPREAD_VALUEFORMATTER
  18. #include "kspread_format.h"
  19. #include <tqdatetime.h>
  20. namespace KSpread
  21. {
  22. class Cell;
  23. class Value;
  24. class ValueConverter;
  25. /**
  26. The ValueFormatter class generates a textual representation of
  27. data stored in a Value, with a given formatting.
  28. */
  29. class ValueFormatter {
  30. public:
  31. /** copnstructor */
  32. ValueFormatter (ValueConverter *converter);
  33. /** create a text representation of data in this cell */
  34. TQString formatText (Cell *cell, FormatType fmtType);
  35. /** create a text representation of data in this Value */
  36. TQString formatText (const Value &value,
  37. FormatType fmtType, int precision = -1,
  38. Format::FloatFormat floatFormat = Format::OnlyNegSigned,
  39. const TQString &prefix = TQString(),
  40. const TQString &postfix = TQString(),
  41. const TQString &currencySymbol = TQString());
  42. /** create a date format */
  43. TQString dateFormat (const TQDate &_date, FormatType fmtType);
  44. /** create a time format */
  45. TQString timeFormat (const TQDateTime &_time, FormatType fmtType);
  46. protected:
  47. ValueConverter* converter;
  48. /** determine the formatting type that should be used to format this value
  49. in a cell with a given format type */
  50. FormatType determineFormatting (const Value &value,
  51. FormatType fmtType);
  52. /** create a number format */
  53. TQString createNumberFormat (double value, int precision, FormatType fmt,
  54. bool alwaysSigned, const TQString& currencySymbol);
  55. /** create a fraction format */
  56. TQString fractionFormat (double value, FormatType fmtType);
  57. TQString errorFormat (Cell *cell);
  58. /** Remove trailing zeros and the decimal point if necessary
  59. unless the number has no decimal point */
  60. void removeTrailingZeros (TQString &str, TQChar decimal_point);
  61. };
  62. } //namespace KSpread
  63. #endif //KSPREAD_VALUEFORMATTER