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.

115 lines
3.4KB

  1. /* This file is part of the KDE project
  2. Copyright (C) 2006 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.
  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_MANIPULATOR_DATA
  17. #define KSPREAD_MANIPULATOR_DATA
  18. #include "manipulator.h"
  19. #include "kspread_global.h"
  20. #include "kspread_value.h"
  21. namespace KSpread {
  22. /**
  23. * AbstractDataManipulator - provides storage of old cell data (for undo)
  24. * and has an abstract method for the actual setting of new values
  25. */
  26. struct ADMStorage {
  27. Value val;
  28. TQString text;
  29. FormatType format;
  30. };
  31. class AbstractDataManipulator : public Manipulator {
  32. public:
  33. AbstractDataManipulator ();
  34. virtual ~AbstractDataManipulator ();
  35. virtual bool process (Element* element);
  36. /** this abstract method should return a value that will be set
  37. for a given cell */
  38. protected:
  39. /** Return new value. row/col are relative to sheet, not element.
  40. If the function sets *parse to true, the value will be treated as an
  41. user-entered string and parsed by Cell. */
  42. virtual Value newValue (Element *element, int col, int row,
  43. bool *parse, FormatType *fmtType) = 0;
  44. /** preProcessing will store the old cell's data */
  45. virtual bool preProcessing ();
  46. TQMap<int, TQMap<int, ADMStorage> > oldData;
  47. };
  48. /**
  49. * DataManipulator - allows setting values on one range.
  50. * If multiple ranges are selected, they all get set to the same values
  51. */
  52. class DataManipulator : public AbstractDataManipulator {
  53. public:
  54. DataManipulator ();
  55. virtual ~DataManipulator ();
  56. void setParsing (bool val) { m_parsing = val; };
  57. /** set the values for the range. Can be either a single value, or
  58. a value array */
  59. void setValue (Value val) { data = val; };
  60. /** If set, all cells shall be switched to this format. Will do
  61. nothing if parsing is true. */
  62. void setFormat (FormatType fmtType) { m_format = fmtType; };
  63. protected:
  64. virtual Value newValue (Element *element, int col, int row, bool *,
  65. FormatType *);
  66. Value data;
  67. FormatType m_format;
  68. bool m_parsing : 1;
  69. };
  70. class ArrayFormulaManipulator : public AbstractDataManipulator {
  71. public:
  72. ArrayFormulaManipulator ();
  73. virtual ~ArrayFormulaManipulator ();
  74. void setText (const TQString text) { m_text = text; };
  75. protected:
  76. virtual Value newValue (Element *element, int col, int row, bool *,
  77. FormatType *);
  78. TQString cellRef, m_text;
  79. };
  80. /** class ProtectedCheck can be used to check, whether a particular
  81. range is protected or not */
  82. class ProtectedCheck : public Region {
  83. public:
  84. ProtectedCheck ();
  85. virtual ~ProtectedCheck ();
  86. void setSheet (Sheet *sheet) { m_sheet = sheet; };
  87. bool check ();
  88. protected:
  89. Sheet *m_sheet;
  90. };
  91. } // namespace KSpread
  92. #endif // KSPREAD_MANIPULATOR_DATA