OpenXLSX 1.12.1
Modern C++ Excel Library (Fork of OpenXLSX by Kenneth Troldal Balslev)
Loading...
Searching...
No Matches
XLThreadedComments.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_XLTHREADEDCOMMENTS_HPP
12#define OPENXLSX_XLTHREADEDCOMMENTS_HPP
13
14#include <string>
15#include <vector>
16#include <gsl/pointers>
17#include "OpenXLSX-Exports.hpp"
18#include "XLXmlFile.hpp"
19
20namespace OpenXLSX
21{
22 class XLWorksheet;
26 class OPENXLSX_EXPORT XLThreadedComment
27 {
28 public:
29 XLThreadedComment() = default;
30 explicit XLThreadedComment(XMLNode node, XLWorksheet* wks = nullptr);
31 ~XLThreadedComment() = default;
32 XLThreadedComment(const XLThreadedComment& other) = default;
36
37 bool valid() const;
38
39 std::string ref() const;
40 std::string id() const;
41 std::string parentId() const;
42 std::string personId() const;
43 std::string text() const;
44
45 bool isResolved() const;
46 void setResolved(bool resolved);
47
51 XLThreadedComment& addReply(const std::string& text, const std::string& author = "");
52
53 void setWorksheet(XLWorksheet* wks) { m_wks = wks; }
54
55 private:
56 XMLNode m_node;
57 XLWorksheet* m_wks{nullptr};
58 };
59
60 class XLWorksheet;
61
65 class OPENXLSX_EXPORT XLThreadedComments : public XLXmlFile
66 {
67 public:
69 explicit XLThreadedComments(gsl::not_null<XLXmlData*> xmlData) : XLXmlFile(xmlData) {}
71 XLThreadedComments(const XLThreadedComments& other) = default;
75
79 XLThreadedComment comment(const std::string& ref) const;
80
84 std::vector<XLThreadedComment> replies(const std::string& parentId) const;
85
89 XLThreadedComment addComment(std::string_view ref, std::string_view personId, std::string_view text);
90
94 XLThreadedComment addReply(const std::string& parentId, const std::string& personId, const std::string& text);
95
99 bool deleteComment(const std::string& ref);
100 };
101
105 class OPENXLSX_EXPORT XLPerson
106 {
107 public:
108 XLPerson() = default;
109 explicit XLPerson(XMLNode node);
110 ~XLPerson() = default;
111 XLPerson(const XLPerson& other) = default;
112 XLPerson(XLPerson&& other) = default;
113 XLPerson& operator=(const XLPerson& other) = default;
114 XLPerson& operator=(XLPerson&& other) = default;
115
116 bool valid() const;
117
118 std::string id() const;
119 std::string displayName() const;
120
121 private:
122 XMLNode m_node;
123 };
124
128 class OPENXLSX_EXPORT XLPersons : public XLXmlFile
129 {
130 public:
131 XLPersons() : XLXmlFile(nullptr) {}
132 explicit XLPersons(gsl::not_null<XLXmlData*> xmlData) : XLXmlFile(xmlData) {}
133 ~XLPersons() = default;
134 XLPersons(const XLPersons& other) = default;
135 XLPersons(XLPersons&& other) = default;
136 XLPersons& operator=(const XLPersons& other) = default;
137 XLPersons& operator=(XLPersons&& other) = default;
138
142 XLPerson person(const std::string& id) const;
143
148 std::string addPerson(const std::string& displayName);
149 };
150} // namespace OpenXLSX
151
152#endif // OPENXLSX_XLTHREADEDCOMMENTS_HPP
A proxy class encapsulating a single person (author) entity.
Definition XLThreadedComments.hpp:106
XLPerson & operator=(XLPerson &&other)=default
XLPerson & operator=(const XLPerson &other)=default
bool valid() const
Definition XLThreadedComments.cpp:234
XLPerson(XLPerson &&other)=default
std::string displayName() const
Definition XLThreadedComments.cpp:241
XLPerson(const XLPerson &other)=default
std::string id() const
Definition XLThreadedComments.cpp:236
XLPersons(const XLPersons &other)=default
XLPersons & operator=(const XLPersons &other)=default
XLPersons(XLPersons &&other)=default
XLPersons & operator=(XLPersons &&other)=default
XLPersons(gsl::not_null< XLXmlData * > xmlData)
Definition XLThreadedComments.hpp:132
XLPerson person(const std::string &id) const
Retrieve a person entity by their unique personId.
Definition XLThreadedComments.cpp:248
XLPersons()
Definition XLThreadedComments.hpp:131
std::string addPerson(const std::string &displayName)
Add a person by their display name, generating a new ID if it doesn't exist.
Definition XLThreadedComments.cpp:259
A proxy class encapsulating a single modern threaded comment.
Definition XLThreadedComments.hpp:27
XLThreadedComment & operator=(XLThreadedComment &&other)=default
std::string parentId() const
Definition XLThreadedComments.cpp:73
void setWorksheet(XLWorksheet *wks)
Definition XLThreadedComments.hpp:53
XLThreadedComment & operator=(const XLThreadedComment &other)=default
std::string personId() const
Definition XLThreadedComments.cpp:78
std::string ref() const
Definition XLThreadedComments.cpp:63
std::string id() const
Definition XLThreadedComments.cpp:68
void setResolved(bool resolved)
Definition XLThreadedComments.cpp:95
XLThreadedComment(const XLThreadedComment &other)=default
XLThreadedComment & addReply(const std::string &text, const std::string &author="")
Add a reply to this thread (only works if initialized with Worksheet context).
Definition XLThreadedComments.cpp:55
XLThreadedComment(XLThreadedComment &&other)=default
bool isResolved() const
Definition XLThreadedComments.cpp:90
std::string text() const
Definition XLThreadedComments.cpp:83
bool valid() const
Definition XLThreadedComments.cpp:53
bool deleteComment(const std::string &ref)
Removes a threaded comment and its replies.
Definition XLThreadedComments.cpp:200
XLThreadedComments()
Definition XLThreadedComments.hpp:68
XLThreadedComment addComment(std::string_view ref, std::string_view personId, std::string_view text)
Add a new top-level threaded comment.
Definition XLThreadedComments.cpp:134
XLThreadedComments(const XLThreadedComments &other)=default
XLThreadedComments(XLThreadedComments &&other)=default
XLThreadedComments & operator=(const XLThreadedComments &other)=default
XLThreadedComments(gsl::not_null< XLXmlData * > xmlData)
Definition XLThreadedComments.hpp:69
XLThreadedComment addReply(const std::string &parentId, const std::string &personId, const std::string &text)
Add a reply to an existing threaded comment.
Definition XLThreadedComments.cpp:154
XLThreadedComments & operator=(XLThreadedComments &&other)=default
XLThreadedComment comment(const std::string &ref) const
Get the top-level comment thread for a specific cell reference.
Definition XLThreadedComments.cpp:108
std::vector< XLThreadedComment > replies(const std::string &parentId) const
Get all replies in a specific comment thread by parent ID.
Definition XLThreadedComments.cpp:122
A class encapsulating an Excel worksheet. Access to XLWorksheet objects should be via the workbook ob...
Definition XLWorksheet.hpp:132
std::string xmlData(XLXmlSavingDeclaration savingDeclaration=XLXmlSavingDeclaration{}) const
Method for getting the XML data represented by the object.
Definition XLXmlFile.cpp:49
XLXmlFile()=default
Default constructor.
Definition IXLCellProvider.hpp:24
OpenXLSX_xml_node XMLNode
Definition XLXmlParser.hpp:64