OpenXLSX 1.12.1
Modern C++ Excel Library (Fork of OpenXLSX by Kenneth Troldal Balslev)
Loading...
Searching...
No Matches
XLStyles_Fills.hpp
Go to the documentation of this file.
1/*
2 * OpenXLSX-NX - Modern High-Performance C++ Excel Library
3 *
4 * Original work Copyright (c) 2018-2025, Kenneth Troldal Balslev and OpenXLSX contributors
5 * Modified work Copyright (c) 2026, Curry Tang and OpenXLSX-NX contributors
6 *
7 * Distributed under the BSD 3-Clause License.
8 * See LICENSE.md in the project root or https://opensource.org/licenses/BSD-3-Clause
9 */
10
11#ifndef OPENXLSX_XLSTYLES_FILLS_HPP
12#define OPENXLSX_XLSTYLES_FILLS_HPP
13
14#ifdef _MSC_VER
15# pragma warning(push)
16# pragma warning(disable : 4251)
17# pragma warning(disable : 4275)
18#endif
19
20#include "XLStyles_Common.hpp"
21#include "XLColor.hpp"
22#include "XLXmlParser.hpp"
23
24#include <memory>
25#include <string>
26#include <string_view>
27#include <unordered_map>
28#include <vector>
29
30
31namespace OpenXLSX
32{
33 class OPENXLSX_EXPORT XLDataBarColor
34 {
35 public:
40
45 explicit XLDataBarColor(const XMLNode& node);
46
51 XLDataBarColor(const XLDataBarColor& other);
52
57 XLDataBarColor(XLDataBarColor&& other) noexcept = default;
58
62 ~XLDataBarColor() = default;
63
70
76 XLDataBarColor& operator=(XLDataBarColor&& other) noexcept = default;
77
82 XLColor rgb() const;
83
88 double tint() const;
89
93 bool automatic() const; // <color auto="true" />
94 uint32_t indexed() const; // <color indexed="1" />
95 uint32_t theme() const; // <color theme="1" />
96
102 bool setRgb(XLColor newColor);
103 bool set(XLColor newColor) { return setRgb(newColor); } // alias for setRgb
104 bool setTint(double newTint);
105 bool setAutomatic(bool set = true);
106 bool setIndexed(uint32_t newIndex);
107 bool setTheme(uint32_t newTheme);
108
113 std::string summary() const;
114
115 private: // ---------- Private Member Variables ---------- //
116 std::unique_ptr<XMLNode> m_colorNode;
117 };
118
119 // XLFills Class
120
124 class OPENXLSX_EXPORT XLGradientStop
125 {
126 friend class XLGradientStops; // for access to m_stopNode in XLGradientStops::create
127 public: // ---------- Public Member Functions ----------- //
132
137 explicit XLGradientStop(const XMLNode& node);
138
143 XLGradientStop(const XLGradientStop& other);
144
149 XLGradientStop(XLGradientStop&& other) noexcept = default;
150
154 ~XLGradientStop() = default;
155
162
168 XLGradientStop& operator=(XLGradientStop&& other) noexcept = default;
169
174 XLDataBarColor color() const; // <stop><color /></stop>
175 double position() const; // <stop position="1.2" />
176
183 bool setPosition(double newPosition);
184
189 std::string summary() const;
190
191 private: // ---------- Private Member Variables ---------- //
192 std::unique_ptr<XMLNode> m_stopNode;
193 };
194
198 class OPENXLSX_EXPORT XLGradientStops
199 {
200 public: // ---------- Public Member Functions ---------- //
205
210 explicit XLGradientStops(const XMLNode& node);
211
216 XLGradientStops(const XLGradientStops& other);
217
223
228
235
241 XLGradientStops& operator=(XLGradientStops&& other) noexcept = default;
242
247 size_t count() const;
248
255
261 XLGradientStop operator[](XLStyleIndex index) const { return stopByIndex(index); }
262
269 XLStyleIndex create(XLGradientStop copyFrom = XLGradientStop{}, std::string_view styleEntriesPrefix = "");
270
271 std::string summary() const;
272
273 private:
274 std::unique_ptr<XMLNode> m_gradientNode;
275 std::vector<XLGradientStop> m_gradientStops;
276 };
277
281 class OPENXLSX_EXPORT XLFill
282 {
283 friend class XLFills; // for access to m_fillNode in XLFills::create
284 friend class XLStyles;
285 public: // ---------- Public Member Functions ---------- //
289 XLFill();
290
295 explicit XLFill(const XMLNode& node);
296
301 XLFill(const XLFill& other);
302
307 XLFill(XLFill&& other) noexcept = default;
308
313
319 XLFill& operator=(const XLFill& other);
320
326 XLFill& operator=(XLFill&& other) noexcept = default;
327
332 XLFillType fillType() const;
333
340 bool setFillType(XLFillType newFillType, bool force = false);
341
342 private: // ---------- Switch to private context for two Methods --------- //
348 void throwOnFillType(XLFillType typeToThrowOn, const char* functionName) const;
349
357 XMLNode getValidFillDescription(XLFillType fillTypeIfEmpty, const char* functionName);
358
359 public: // ---------- Switch back to public context ---------------------- //
364 XLGradientType gradientType(); // <gradientFill type="path" />
365 double degree();
366 double left();
367 double right();
368 double top();
369 double bottom();
371
377 XLColor color();
379
387 bool setGradientType(XLGradientType newType);
388 bool setDegree(double newDegree);
389 bool setLeft(double newLeft);
390 bool setRight(double newRight);
391 bool setTop(double newTop);
392 bool setBottom(double newBottom);
393
399 XLFill& setPatternType(XLPatternType newPatternType);
400 XLFill& setColor(XLColor newColor);
401 XLFill& setBackgroundColor(XLColor newBgColor);
402
407 std::string summary();
408
409 private: // ---------- Private Member Variables ---------- //
410 std::unique_ptr<XMLNode> m_fillNode;
411 };
412
416 class OPENXLSX_EXPORT XLFills
417 {
418 public: // ---------- Public Member Functions ---------- //
422 XLFills();
423
428 explicit XLFills(const XMLNode& node);
429
434 XLFills(const XLFills& other);
435
440 XLFills(XLFills&& other);
441
445 ~XLFills();
446
452 XLFills& operator=(const XLFills& other);
453
459 XLFills& operator=(XLFills&& other) noexcept = default;
460
465 size_t count() const;
466
472 XLFill fillByIndex(XLStyleIndex index) const;
473
479 XLFill operator[](XLStyleIndex index) const { return fillByIndex(index); }
480
487 XLStyleIndex create(XLFill copyFrom = XLFill{}, std::string_view styleEntriesPrefix = XLDefaultStyleEntriesPrefix);
488
493 XLStyleIndex findOrCreate(XLFill copyFrom, std::string_view styleEntriesPrefix = XLDefaultStyleEntriesPrefix);
494
495 private: // ---------- Private Member Variables ---------- //
496 std::unique_ptr<XMLNode> m_fillsNode;
497 std::vector<XLFill> m_fills;
498 mutable std::unordered_map<std::string, XLStyleIndex> m_fingerprintCache;
499 };
500
501} // namespace OpenXLSX
502
503#ifdef _MSC_VER
504# pragma warning(pop)
505#endif
506
507#endif // OPENXLSX_XLSTYLES_FILLS_HPP
Definition XLColor.hpp:32
Definition XLStyles_Fills.hpp:34
bool set(XLColor newColor)
Definition XLStyles_Fills.hpp:103
XLDataBarColor()
Definition XLStyles_Fills.cpp:81
uint32_t indexed() const
Definition XLStyles_Fills.cpp:96
uint32_t theme() const
Definition XLStyles_Fills.cpp:97
bool setRgb(XLColor newColor)
Setter functions for data bar color parameters.
Definition XLStyles_Fills.cpp:98
bool automatic() const
currently unsupported getter stubs
Definition XLStyles_Fills.cpp:95
XLDataBarColor & operator=(XLDataBarColor &&other) noexcept=default
Move assignment operator.
XLDataBarColor(XLDataBarColor &&other) noexcept=default
Move Constructor.
XLDataBarColor & operator=(const XLDataBarColor &other)
Copy assignment operator.
Definition XLStyles_Fills.cpp:87
double tint() const
Get the line color tint.
Definition XLStyles_Fills.cpp:94
XLColor rgb() const
Get the line color from the rgb attribute.
Definition XLStyles_Fills.cpp:93
An encapsulation of a fill item.
Definition XLStyles_Fills.hpp:282
bool setGradientType(XLGradientType newType)
Setter functions for gradientFill - will throwOnFillType(XLPatternFill, func).
Definition XLStyles_Fills.cpp:353
XLFill & setBackgroundColor(XLColor newBgColor)
Definition XLStyles_Fills.cpp:407
XLColor backgroundColor()
Definition XLStyles_Fills.cpp:345
XLGradientType gradientType()
Getter functions for gradientFill - will throwOnFillType(XLPatternFill, func).
Definition XLStyles_Fills.cpp:318
XLFill & setPatternType(XLPatternType newPatternType)
Setter functions for patternFill - will throwOnFillType(XLGradientFill, func).
Definition XLStyles_Fills.cpp:390
XLFill(XLFill &&other) noexcept=default
Move Constructor.
XLFill & setColor(XLColor newColor)
Definition XLStyles_Fills.cpp:397
XLPatternType patternType()
Getter functions for patternFill - will throwOnFillType(XLGradientFill, func).
Definition XLStyles_Fills.cpp:327
double degree()
Definition XLStyles_Fills.cpp:320
bool setTop(double newTop)
Definition XLStyles_Fills.cpp:379
XLFill & operator=(XLFill &&other) noexcept=default
Move assignment operator.
friend class XLStyles
Definition XLStyles_Fills.hpp:284
std::string summary()
Return a string summary of the fill properties.
Definition XLStyles_Fills.cpp:416
double bottom()
Definition XLStyles_Fills.cpp:324
bool setLeft(double newLeft)
Definition XLStyles_Fills.cpp:369
bool setBottom(double newBottom)
Definition XLStyles_Fills.cpp:384
double top()
Definition XLStyles_Fills.cpp:323
XLGradientStops stops()
Definition XLStyles_Fills.cpp:325
double right()
Definition XLStyles_Fills.cpp:322
XLFillType fillType() const
Get the name of the element describing a fill.
Definition XLStyles_Fills.cpp:269
bool setFillType(XLFillType newFillType, bool force=false)
Create & set the base XML element describing the fill.
Definition XLStyles_Fills.cpp:271
bool setRight(double newRight)
Definition XLStyles_Fills.cpp:374
XLFill & operator=(const XLFill &other)
Copy assignment operator.
Definition XLStyles_Fills.cpp:259
double left()
Definition XLStyles_Fills.cpp:321
friend class XLFills
Definition XLStyles_Fills.hpp:283
XLColor color()
Definition XLStyles_Fills.cpp:338
bool setDegree(double newDegree)
Definition XLStyles_Fills.cpp:358
XLFill()
Definition XLStyles_Fills.cpp:251
XLFill fillByIndex(XLStyleIndex index) const
Get the fill entry identified by index.
Definition XLStyles_Fills.cpp:482
size_t count() const
Get the count of fills.
Definition XLStyles_Fills.cpp:480
XLFills & operator=(const XLFills &other)
Copy assignment operator.
Definition XLStyles_Fills.cpp:470
XLFill operator[](XLStyleIndex index) const
Operator overload: allow [] as shortcut access to fillByIndex.
Definition XLStyles_Fills.hpp:479
XLFills()
Definition XLStyles_Fills.cpp:445
XLFills & operator=(XLFills &&other) noexcept=default
Move assignment operator.
An encapsulation of an fill::gradientFill::stop item.
Definition XLStyles_Fills.hpp:125
XLGradientStop()
Definition XLStyles_Fills.cpp:133
XLGradientStop & operator=(XLGradientStop &&other) noexcept=default
Move assignment operator.
double position() const
Definition XLStyles_Fills.cpp:151
friend class XLGradientStops
Definition XLStyles_Fills.hpp:126
XLGradientStop(XLGradientStop &&other) noexcept=default
Move Constructor.
std::string summary() const
Return a string summary of the stop properties.
Definition XLStyles_Fills.cpp:160
XLGradientStop & operator=(const XLGradientStop &other)
Copy assignment operator.
Definition XLStyles_Fills.cpp:139
bool setPosition(double newPosition)
Setter functions.
Definition XLStyles_Fills.cpp:157
XLDataBarColor color() const
Getter functions.
Definition XLStyles_Fills.cpp:145
An encapsulation of an array of fill::gradientFill::stop items.
Definition XLStyles_Fills.hpp:199
XLGradientStops & operator=(XLGradientStops &&other) noexcept=default
Move assignment operator.
XLGradientStops()
Definition XLStyles_Fills.cpp:165
size_t count() const
Get the count of gradient stops.
Definition XLStyles_Fills.cpp:203
XLGradientStops & operator=(const XLGradientStops &other)
Copy assignment operator.
Definition XLStyles_Fills.cpp:193
XLGradientStop stopByIndex(XLStyleIndex index) const
Get the gradient stop entry identified by index.
Definition XLStyles_Fills.cpp:205
XLGradientStop operator[](XLStyleIndex index) const
Operator overload: allow [] as shortcut access to stopByIndex.
Definition XLStyles_Fills.hpp:261
Definition IXLCellProvider.hpp:24
XLFillType
Definition XLStyles_Common.hpp:111
XLPatternType
Definition XLStyles_Common.hpp:119
XLGradientType
Definition XLStyles_Common.hpp:117
OpenXLSX_xml_node XMLNode
Definition XLXmlParser.hpp:64
size_t XLStyleIndex
Definition XLStyles_Common.hpp:36