conditional_format.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. // Copyright (c) 2014-2021 Thomas Fussell
  2. // Copyright (c) 2010-2015 openpyxl
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE
  21. //
  22. // @license: http://www.opensource.org/licenses/mit-license.php
  23. // @author: see AUTHORS file
  24. #include <xlnt/styles/border.hpp>
  25. #include <xlnt/styles/conditional_format.hpp>
  26. #include <xlnt/styles/fill.hpp>
  27. #include <xlnt/styles/font.hpp>
  28. #include <detail/implementations/conditional_format_impl.hpp>
  29. #include <detail/implementations/stylesheet.hpp>
  30. namespace xlnt {
  31. condition condition::text_starts_with(const std::string &text)
  32. {
  33. condition c;
  34. c.type_ = type::contains_text;
  35. c.operator_ = condition_operator::starts_with;
  36. c.text_comparand_ = text;
  37. return c;
  38. }
  39. condition condition::text_ends_with(const std::string &text)
  40. {
  41. condition c;
  42. c.type_ = type::contains_text;
  43. c.operator_ = condition_operator::ends_with;
  44. c.text_comparand_ = text;
  45. return c;
  46. }
  47. condition condition::text_contains(const std::string &text)
  48. {
  49. condition c;
  50. c.type_ = type::contains_text;
  51. c.operator_ = condition_operator::contains;
  52. c.text_comparand_ = text;
  53. return c;
  54. }
  55. condition condition::text_does_not_contain(const std::string &text)
  56. {
  57. condition c;
  58. c.type_ = type::contains_text;
  59. c.operator_ = condition_operator::does_not_contain;
  60. c.text_comparand_ = text;
  61. return c;
  62. }
  63. conditional_format::conditional_format(detail::conditional_format_impl *d)
  64. : d_(d)
  65. {
  66. }
  67. bool conditional_format::operator==(const conditional_format &other) const
  68. {
  69. return d_ == other.d_;
  70. }
  71. bool conditional_format::operator!=(const conditional_format &other) const
  72. {
  73. return !(*this == other);
  74. }
  75. bool conditional_format::has_border() const
  76. {
  77. return d_->border_id.is_set();
  78. }
  79. xlnt::border conditional_format::border() const
  80. {
  81. return d_->parent->borders.at(d_->border_id.get());
  82. }
  83. conditional_format conditional_format::border(const xlnt::border &new_border)
  84. {
  85. d_->border_id = d_->parent->find_or_add(d_->parent->borders, new_border);
  86. return *this;
  87. }
  88. bool conditional_format::has_fill() const
  89. {
  90. return d_->fill_id.is_set();
  91. }
  92. xlnt::fill conditional_format::fill() const
  93. {
  94. return d_->parent->fills.at(d_->fill_id.get());
  95. }
  96. conditional_format conditional_format::fill(const xlnt::fill &new_fill)
  97. {
  98. d_->fill_id = d_->parent->find_or_add(d_->parent->fills, new_fill);
  99. return *this;
  100. }
  101. bool conditional_format::has_font() const
  102. {
  103. return d_->font_id.is_set();
  104. }
  105. xlnt::font conditional_format::font() const
  106. {
  107. return d_->parent->fonts.at(d_->font_id.get());
  108. }
  109. conditional_format conditional_format::font(const xlnt::font &new_font)
  110. {
  111. d_->font_id = d_->parent->find_or_add(d_->parent->fonts, new_font);
  112. return *this;
  113. }
  114. } // namespace xlnt