OpenXLSX 1.9.1
Loading...
Searching...
No Matches
XLComments.hpp
Go to the documentation of this file.
1#ifndef OPENXLSX_XLCOMMENTS_HPP
2#define OPENXLSX_XLCOMMENTS_HPP
3
4// ===== External Includes ===== //
5#include <cstdint> // uint8_t, uint16_t, uint32_t
6#include <ostream> // std::basic_ostream
7#include <unordered_map> // std::unordered_map
8
9// ===== OpenXLSX Includes ===== //
10#include "OpenXLSX-Exports.hpp"
11// #include "XLDocument.hpp"
12#include "XLDrawing.hpp" // XLVmlDrawing
13#include "XLException.hpp"
14#include "XLRichText.hpp"
15#include "XLXmlData.hpp"
16#include "XLXmlFile.hpp"
17
18namespace OpenXLSX
19{
23 class OPENXLSX_EXPORT XLComment
24 {
25 public:
26 XLComment() = delete; // do not allow default constructor (for now) - could still be constructed with an empty XMLNode
27
32 explicit XLComment(XMLNode node);
33
38 XLComment(const XLComment& other) = default;
39
44 XLComment(XLComment&& other) noexcept = default;
45 ~XLComment() = default;
46
52 XLComment& operator=(const XLComment& other) = default;
53
59 XLComment& operator=(XLComment&& other) noexcept = default;
60
65 bool valid() const;
66 std::string ref() const; // the cell reference of the comment
67 std::string text() const;
68 XLRichText richText() const;
69 uint16_t authorId() const;
70 XLComment& setText(const std::string& newText);
71 XLComment& setRichText(const XLRichText& richText);
72 XLComment& setAuthorId(uint16_t newAuthorId);
73
74 // /**
75 // * @brief Return a string summary of the comment properties
76 // * @return string with info about the comment object
77 // */
78 // std::string summary() const;
79
80 private:
81 mutable XMLNode m_commentNode;
82 };
83
87 class OPENXLSX_EXPORT XLComments : public XLXmlFile
88 {
89 friend class XLWorksheet; // for access to XLXmlFile::getXmlPath
90 public:
94 XLComments();
95
100 explicit XLComments(XLXmlData* xmlData);
101
106 XLComments(const XLComments& other) = default;
107
112 XLComments(XLComments&& other) noexcept = default;
113
118 ~XLComments() = default;
119
125 XLComments& operator=(XLComments&& other) noexcept = default;
126
131 XLComments& operator=(const XLComments& other) = default;
132
138 bool setVmlDrawing(const XLVmlDrawing& vmlDrawing);
139
140 private:
141 XMLNode authorNode(uint16_t index) const;
142 XMLNode commentNode(size_t index) const;
143 XMLNode commentNode(const std::string& cellRef) const;
144 void setupVmlShape(const std::string& cellRef,
145 uint32_t destRow,
146 uint16_t destCol,
147 bool newCommentCreated,
148 uint16_t widthCols = 4,
149 uint16_t heightRows = 6);
150
151 public:
152 uint16_t authorCount() const;
153
154 std::string author(uint16_t index) const;
155
156 bool deleteAuthor(uint16_t index);
157
158 uint16_t addAuthor(const std::string& authorName);
159
164 size_t count() const;
165
166 uint16_t authorId(const std::string& cellRef) const;
167
168 bool deleteComment(const std::string& cellRef);
169
175 XLComment get(size_t index) const;
176
182 std::string get(std::string const& cellRef) const;
183
193 bool set(std::string const& cellRef,
194 std::string const& comment,
195 uint16_t authorId_ = 0,
196 uint16_t widthCols = 4,
197 uint16_t heightRows = 6);
198
208 bool set(std::string const& cellRef,
209 std::string const& comment,
210 std::string const& authorName,
211 uint16_t widthCols = 4,
212 uint16_t heightRows = 6);
213
223 bool setRichText(std::string const& cellRef,
224 const XLRichText& richText,
225 uint16_t authorId_ = 0,
226 uint16_t widthCols = 4,
227 uint16_t heightRows = 6);
228
238 bool setRichText(std::string const& cellRef,
239 const XLRichText& richText,
240 std::string const& authorName,
241 uint16_t widthCols = 4,
242 uint16_t heightRows = 6);
243
247 XLShape shape(std::string const& cellRef);
248
255 bool setVisible(std::string const& cellRef, bool visible);
256
260 void print(std::basic_ostream<char>& ostr) const;
261
262 private:
263 XMLNode m_authors{};
264 XMLNode m_commentList{};
265 XLVmlDrawing m_vmlDrawing;
266 mutable std::unordered_map<std::string, XMLNode> m_commentMap{};
267 mutable XMLNode m_hintNode{}; // the last comment XML Node accessed by index is stored here, if any - will be reset when comments
268 // are inserted or deleted
269 mutable size_t m_hintIndex{0}; // this has the index at which m_hintNode was accessed, only valid if not m_hintNode.empty()
270 inline static const std::vector<std::string_view> m_nodeOrder = {// comments XML node required child sequence
271 "authors",
272 "commentList"};
273 };
274} // namespace OpenXLSX
275
276#endif // OPENXLSX_XLCOMMENTS_HPP
XLXmlData * xmlData
Definition XLDocument.cpp:1422
Definition XLXmlParser.hpp:84
An encapsulation of a comment element.
Definition XLComments.hpp:24
XLComment(XLComment &&other) noexcept=default
Move Constructor.
XLComment(const XLComment &other)=default
Copy Constructor.
XLComment & operator=(XLComment &&other) noexcept=default
Move assignment operator.
XLComment & operator=(const XLComment &other)=default
Copy assignment operator.
The XLComments class is the base class for worksheet comments.
Definition XLComments.hpp:88
XLComments & operator=(const XLComments &other)=default
Assignment operator.
XLComments & operator=(XLComments &&other) noexcept=default
~XLComments()=default
The destructor.
XLComments(XLComments &&other) noexcept=default
XLComments(const XLComments &other)=default
The copy constructor.
A class representing rich text in a cell.
Definition XLRichText.hpp:129
Definition XLDrawing.hpp:209
The XLVmlDrawing class is the base class for worksheet comments.
Definition XLDrawing.hpp:508
A class encapsulating an Excel worksheet. Access to XLWorksheet objects should be via the workbook ob...
Definition XLWorksheet.hpp:118
The XLXmlData class encapsulates the properties and behaviour of the .xml files in an ....
Definition XLXmlData.hpp:29
The XLXmlFile class provides an interface for derived classes to use. It functions as an ancestor to ...
Definition XLXmlFile.hpp:42
Definition IZipArchive.hpp:18
OpenXLSX_xml_node XMLNode
Definition XLXmlParser.hpp:63