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.

151 lines
4.2KB

  1. /* This file is part of the KDE project
  2. Copyright 1998, 1999 Torben Weis <weis@kde.org>
  3. Copyright 1999- 2006 The KSpread Team
  4. www.koffice.org/kspread
  5. This library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Library General Public
  7. License as published by the Free Software Foundation; either
  8. version 2 of the License, or (at your option) any later version.
  9. This library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Library General Public License for more details.
  13. You should have received a copy of the GNU Library General Public License
  14. along with this library; see the file COPYING.LIB. If not, write to
  15. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  16. * Boston, MA 02110-1301, USA.
  17. */
  18. #ifndef __kspread_condition_h__
  19. #define __kspread_condition_h__
  20. #include <tqdom.h>
  21. #include <tqvaluelist.h>
  22. #include <koffice_export.h>
  23. #include "kspread_global.h"
  24. class TQColor;
  25. class TQFont;
  26. class TQString;
  27. class KoGenStyle;
  28. namespace KSpread
  29. {
  30. class Cell;
  31. class Style;
  32. /**
  33. * Structure to indicate the condition we're testing on a cell and the special
  34. * font and color that will be applied if it's true
  35. */
  36. class KSPREAD_EXPORT Conditional
  37. {
  38. public:
  39. enum Type { None, Equal, Superior, Inferior, SuperiorEqual,
  40. InferiorEqual, Between, Different, DifferentTo };
  41. double val1;
  42. double val2;
  43. TQString * strVal1;
  44. TQString * strVal2;
  45. TQColor * colorcond;
  46. TQFont * fontcond;
  47. TQString * styleName;
  48. Style * style;
  49. Type cond;
  50. Conditional();
  51. ~Conditional();
  52. Conditional( const Conditional& );
  53. Conditional& operator=( const Conditional& );
  54. bool operator==(const Conditional& other) const;
  55. inline bool operator!=( const Conditional& other ) const { return !operator==( other ); }
  56. };
  57. /**
  58. * Manages a set of conditions for a cell
  59. */
  60. class Conditions
  61. {
  62. public:
  63. /**
  64. * Constructor. There is no default constructor - you must use this one
  65. * with the owner cell as a parameter
  66. */
  67. Conditions( const Cell * ownerCell );
  68. virtual ~Conditions();
  69. /**
  70. * Use this function to see what conditions actually apply currently
  71. *
  72. * @param condition a reference to a condition that will be set to the
  73. * matching condition. If none of the conditions are true
  74. * then this parameter is undefined on exit (check the
  75. * return value).
  76. *
  77. * @return true if one of the conditions is true, false if not.
  78. */
  79. bool currentCondition( Conditional & condition );
  80. /**
  81. * Retrieve the current list of conditions we're checking
  82. */
  83. TQValueList<Conditional> conditionList() const;
  84. /**
  85. * Replace the current list of conditions with this new one
  86. */
  87. void setConditionList( const TQValueList<Conditional> & list );
  88. /**
  89. * Saves the conditions to a DOM tree structure.
  90. * @return the DOM element for the conditions.
  91. */
  92. TQDomElement saveConditions( TQDomDocument & doc ) const;
  93. /**
  94. * Takes a parsed DOM element and recreates the conditions structure out of
  95. * it
  96. */
  97. void loadConditions( const TQDomElement & element );
  98. void loadOasisConditions( const TQDomElement & element );
  99. void saveOasisConditions( KoGenStyle &currentCellStyle );
  100. /**
  101. * returns the style that matches first (or NULL if no condition matches)
  102. */
  103. Style * matchedStyle() const { return m_matchedStyle; }
  104. void checkMatches();
  105. bool operator==( const Conditions& other ) const;
  106. inline bool operator!=( const Conditions& other ) const { return !operator==( other ); }
  107. private:
  108. Conditions() {}
  109. TQString saveOasisConditionValue(Conditional &cond);
  110. void loadOasisConditionValue( const TQString &styleCondition, Conditional &newCondition );
  111. void loadOasisValidationValue( const TQStringList &listVal, Conditional &newCondition );
  112. void loadOasisCondition( TQString &valExpression, Conditional &newCondition );
  113. const Cell * m_cell;
  114. TQValueList<Conditional> m_condList;
  115. Style * m_matchedStyle;
  116. };
  117. } // namespace KSpread
  118. #endif /*defined __kspread_condition_h__ */