Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
simple-document.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
/*
5 * Authors: see git history
6 *
7 * Copyright (C) 2018 Authors
8 * Copyright 2005 MenTaLguY <mental@rydia.net>
9 *
10 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
11 */
12
13#include <glib.h> // g_assert()
14
15#include "xml/simple-document.h"
16#include "xml/event-fns.h"
17#include "xml/element-node.h"
18#include "xml/text-node.h"
19#include "xml/comment-node.h"
20#include "xml/pi-node.h"
21
22namespace Inkscape {
23
24namespace XML {
25
30
38
40 g_assert(_in_transaction);
41 _in_transaction = false;
43}
44
50
52 return new ElementNode(g_quark_from_string(name), this);
53}
54
55Node *SimpleDocument::createTextNode(char const *content) {
56 return new TextNode(Util::share_string(content), this);
57}
58
59Node *SimpleDocument::createTextNode(char const *content, bool const is_CData) {
60 return new TextNode(Util::share_string(content), this, is_CData);
61}
62
63Node *SimpleDocument::createComment(char const *content) {
64 return new CommentNode(Util::share_string(content), this);
65}
66
67Node *SimpleDocument::createPI(char const *target, char const *content) {
68 return new PINode(g_quark_from_string(target), Util::share_string(content), this);
69}
70
79
88
90 Node &child,
91 Node *old_prev,
92 Node *new_prev)
93{
94 if (_in_transaction) {
95 _log_builder.setChildOrder(parent, child, old_prev, new_prev);
96 }
97}
98
100 Util::ptr_shared old_content,
101 Util::ptr_shared new_content)
102{
103 if (_in_transaction) {
104 _log_builder.setContent(node, old_content, new_content);
105 }
106}
107
109 GQuark name,
110 Util::ptr_shared old_value,
111 Util::ptr_shared new_value)
112{
113 if (_in_transaction) {
114 _log_builder.setAttribute(node, name, old_value, new_value);
115 }
116}
117
119{
120 if (_in_transaction) {
121 _log_builder.setElementName(node, old_name, new_name);
122 }
123}
124
126{
127 auto *result = new SimpleDocument;
128 for (auto *child = firstChild(); child; child = child->next()) {
129 auto *new_child = child->duplicate(result);
130 result->appendChild(new_child);
131 GC::release(new_child);
132 }
133 return result;
134}
135
136} // end namespace XML
137} // end namespace Inkscape
138
139/*
140 Local Variables:
141 mode:c++
142 c-file-style:"stroustrup"
143 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
144 indent-tabs-mode:nil
145 fill-column:99
146 End:
147*/
148// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
Element node, e.g.
Enumeration of all XML event types.
Definition event.h:53
void removeChild(Node &node, Node &child, Node *prev)
void setContent(Node &node, Util::ptr_shared old_content, Util::ptr_shared new_content)
void addChild(Node &node, Node &child, Node *prev)
void setElementName(Node &node, GQuark old_name, GQuark new_name)
void setAttribute(Node &node, GQuark name, Util::ptr_shared old_value, Util::ptr_shared new_value)
void discard()
Clear the internal log.
Event * detach()
Get the internal event log.
void setChildOrder(Node &node, Node &child, Node *old_prev, Node *new_prev)
Interface for refcounted XML nodes.
Definition node.h:80
virtual Node * next()=0
Get the next sibling of this node.
virtual void appendChild(Node *child)=0
Append a node as the last child of this node.
void notifyChildOrderChanged(Node &parent, Node &child, Node *old_prev, Node *new_prev) override
Child order change callback.
void notifyContentChanged(Node &node, Util::ptr_shared old_content, Util::ptr_shared new_content) override
Content change callback.
Node * createComment(char const *content) override
Node * createElement(char const *name) override
void notifyChildRemoved(Node &parent, Node &child, Node *prev) override
Child removal callback.
void notifyElementNameChanged(Node &node, GQuark old_name, GQuark new_name) override
Element name change callback.
void rollback() override
Restore the state of the document prior to the transaction.
void beginTransaction() override
Begin a transaction and start recording changes.
Inkscape::XML::Event * commitUndoable() override
Commit a transaction and store the events for later use.
void notifyAttributeChanged(Node &node, GQuark name, Util::ptr_shared old_value, Util::ptr_shared new_value) override
Attribute change callback.
Node * createPI(char const *target, char const *content) override
void notifyChildAdded(Node &parent, Node &child, Node *prev) override
Child addition callback.
void commit() override
Commit a transaction and discard change data.
Document * duplicate(Document *) const override
Create a duplicate of this node.
Node * createTextNode(char const *content) override
Node * prev() override
Definition simple-node.h:58
Node * firstChild() override
Get the first child of this node.
Definition simple-node.h:61
Node * parent() override
Get the parent of this node.
Definition simple-node.h:53
char const * content() const override
Get the content of a text or comment node.
char const * name() const override
Get the name of the element node.
Comment node implementation.
Css & result
static char const *const parent
Definition dir-util.cpp:70
Element node implementation.
TODO: insert short description here.
void sp_repr_undo_log(Inkscape::XML::Event *log)
Definition event.cpp:137
void sp_repr_free_log(Inkscape::XML::Event *log)
Definition event.cpp:285
Inkscape::XML::Node * node
static R & release(R &r)
Decrements the reference count of a anchored object.
ptr_shared share_string(char const *string)
Definition share.cpp:20
Helper class to stream background task notifications as a series of messages.
Processing instruction node implementation.
Piecewise< SBasis > log(Interval in)
Definition pw-funcs.cpp:37
Ocnode * child[8]
Definition quantize.cpp:33
Inkscape::XML::SimpleDocument - generic XML document implementation.
guint32 GQuark
Comment node, e.g.
Interface for XML documents.
Definition document.h:43
Document * duplicate(Document *doc) const override=0
Create a duplicate of this node.
Processing instruction node, e.g.
Definition pi-node.h:24
Text node, e.g.
Definition text-node.h:24
Text node implementation.
Glib::ustring name
Definition toolbars.cpp:55