Inkscape
Vector Graphics Editor
|
#include <simple-document.h>
Public Member Functions | |
SimpleDocument () | |
NodeType | type () const override |
Get the type of the node. | |
bool | inTransaction () override |
Checks whether there is an active transaction for this document. | |
void | beginTransaction () override |
Begin a transaction and start recording changes. | |
void | rollback () override |
Restore the state of the document prior to the transaction. | |
void | commit () override |
Commit a transaction and discard change data. | |
Inkscape::XML::Event * | commitUndoable () override |
Commit a transaction and store the events for later use. | |
Node * | createElement (char const *name) override |
Node * | createTextNode (char const *content) override |
Node * | createTextNode (char const *content, bool const is_CData) override |
Node * | createComment (char const *content) override |
Node * | createPI (char const *target, char const *content) override |
Document * | duplicate (Document *) const override |
Create a duplicate of this node. | |
void | notifyChildAdded (Node &parent, Node &child, Node *prev) override |
Child addition callback. | |
void | notifyChildRemoved (Node &parent, Node &child, Node *prev) override |
Child removal callback. | |
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. | |
void | notifyAttributeChanged (Node &node, GQuark name, Util::ptr_shared old_value, Util::ptr_shared new_value) override |
Attribute change callback. | |
void | notifyElementNameChanged (Node &node, GQuark old_name, GQuark new_name) override |
Element name change callback. | |
![]() | |
char const * | name () const override |
Get the name of the element node. | |
int | code () const override |
Get the integer code corresponding to the node's name. | |
void | setCodeUnsafe (int code) override |
Set the integer GQuark code for the name of the node. | |
Document * | document () override |
Get the node's associated document. | |
Document const * | document () const override |
Node * | root () override |
Get the root node of this node's document. | |
Node const * | root () const override |
Node * | parent () override |
Get the parent of this node. | |
Node const * | parent () const override |
Node * | next () override |
Get the next sibling of this node. | |
Node const * | next () const override |
Node * | prev () override |
Node const * | prev () const override |
Node * | firstChild () override |
Get the first child of this node. | |
Node const * | firstChild () const override |
Node * | lastChild () override |
Get the last child of this node. | |
Node const * | lastChild () const override |
unsigned | childCount () const override |
Get the number of children of this node. | |
Node * | nthChild (unsigned index) override |
Get the child of this node with a given index. | |
Node const * | nthChild (unsigned index) const override |
void | addChild (Node *child, Node *ref) override |
Insert another node as a child of this node. | |
void | appendChild (Node *child) override |
Append a node as the last child of this node. | |
void | removeChild (Node *child) override |
Remove a child of this node. | |
void | changeOrder (Node *child, Node *ref) override |
Move a given node in this node's child order. | |
unsigned | position () const override |
Get the index of this node in parent's child order. | |
void | setPosition (int pos) override |
Set the position of this node in parent's child order. | |
char const * | attribute (char const *key) const override |
Get the string representation of a node's attribute. | |
bool | matchAttributeName (char const *partial_name) const override |
Check whether this node has any attribute that matches a string. | |
char const * | content () const override |
Get the content of a text or comment node. | |
void | setContent (char const *value) override |
Set the content of a text or comment node. | |
void | cleanOriginal (Node *src, gchar const *key) override |
bool | equal (Node const *other, bool recursive, bool skip_ids=false) override |
Compare 2 nodes equality. | |
void | mergeFrom (Node const *src, char const *key, bool extension=false, bool clean=false) override |
Merge all children of another node with the current. | |
const AttributeVector & | attributeList () const override |
Get a list of the node's attributes. | |
void | synthesizeEvents (NodeObserver &observer) override |
Generate a sequence of events corresponding to the state of this node. | |
void | addObserver (NodeObserver &observer) override |
Add an object that will be notified of the changes to this node. | |
void | removeObserver (NodeObserver &observer) override |
Remove an object from the list of observers. | |
void | addSubtreeObserver (NodeObserver &observer) override |
Add an object that will be notified of the changes to this node and its descendants. | |
void | removeSubtreeObserver (NodeObserver &observer) override |
Remove an object from the subtree observers list. | |
void | recursivePrintTree (unsigned level=0) override |
![]() | |
Node ()=default | |
~Node () override=default | |
void | setAttribute (Util::const_char_ptr key, Util::const_char_ptr value) |
Change an attribute of this node. | |
bool | copyAttribute (Util::const_char_ptr key, Node const *source_node, bool remove_if_empty=false) |
Copy attribute value from another node to this node. | |
bool | getAttributeBoolean (Util::const_char_ptr key, bool default_value=false) const |
Parses the boolean value of an attribute "key" in repr and sets val accordingly, or to false if the attr is not set. | |
int | getAttributeInt (Util::const_char_ptr key, int default_value=0) const |
double | getAttributeDouble (Util::const_char_ptr key, double default_value=0.0) const |
bool | setAttributeBoolean (Util::const_char_ptr key, bool val) |
bool | setAttributeInt (Util::const_char_ptr key, int val) |
bool | setAttributeCssDouble (Util::const_char_ptr key, double val) |
Set a property attribute to val [slightly rounded], in the format required for CSS properties: in particular, it never uses exponent notation. | |
bool | setAttributeSvgDouble (Util::const_char_ptr key, double val) |
For attributes where an exponent is allowed. | |
bool | setAttributeSvgNonDefaultDouble (Util::const_char_ptr key, double val, double default_value) |
bool | setAttributeSvgLength (Util::const_char_ptr key, SVGLength const &val) |
bool | setAttributePoint (Util::const_char_ptr key, Geom::Point const &val) |
Geom::Point | getAttributePoint (Util::const_char_ptr key, Geom::Point default_value={}) const |
void | setAttributeOrRemoveIfEmpty (Inkscape::Util::const_char_ptr key, Inkscape::Util::const_char_ptr value) |
Change an attribute of this node. | |
void | removeAttribute (Inkscape::Util::const_char_ptr key) |
Remove an attribute of this node. | |
void | addChildAtPos (Node *child, unsigned pos) |
Insert another node as a child of this node. | |
virtual void | cleanOriginal (Node *src, char const *key)=0 |
Remove all elements that not in src node. | |
iterator | begin () |
Iterator over children. | |
iterator | end () |
Helper to use the standard lib container functions. | |
bool | operator== (const std::string &name) const |
Compare a node by looking at its name to a string. | |
template<typename T > | |
Node * | findChildPath (T list) |
depth first search to find a node | |
template<typename iterT > | |
Node * | findChildPath (iterT itr, iterT end) |
template reshuffling to make the more useful findChildPath cleaner | |
![]() | |
void | anchor () const |
void | release () const |
unsigned | _anchored_refcount () const |
Anchored (Anchored const &)=delete | |
void | operator= (Anchored const &)=delete |
![]() | |
void * | operator new (std::size_t size, ScanPolicy scan=default_scan, CollectionPolicy collect=default_collect) |
void * | operator new[] (std::size_t size, ScanPolicy scan=default_scan, CollectionPolicy collect=default_collect) |
void | operator delete (void *p) |
Document transactions | |
Create new nodes | |
![]() | |
virtual | ~NodeObserver ()=default |
Protected Member Functions | |
SimpleDocument (SimpleDocument const &doc) | |
NodeObserver * | logger () override |
Get the event logger for this document. | |
![]() | |
SimpleNode (int code, Document *document) | |
SimpleNode (SimpleNode const &repr, Document *document) | |
void | setAttributeImpl (char const *key, char const *value) override |
![]() | |
Node (Node const &) | |
![]() | |
Anchored () | |
virtual | ~Anchored ()=default |
![]() | |
NodeObserver ()=default | |
Private Attributes | |
bool | _in_transaction = false |
LogBuilder | _log_builder |
Additional Inherited Members | |
![]() | |
using | iterator = Inkscape::XML::NodeSiblingIterator |
![]() | |
Node * | next_node (Node *node) |
Get the next node in sibling order. | |
Node * | previous_node (Node *node) |
Get the previous node in sibling order. | |
Node * | parent_node (Node *node) |
Get the node's parent. | |
Inkscape::XML::Node * | sp_repr_lookup_child (Inkscape::XML::Node *repr, gchar const *key, gchar const *value) |
Find an element node using an unique attribute. | |
Inkscape::XML::Node * | sp_repr_lookup_name (Inkscape::XML::Node *repr, char const *name, int maxdepth=-1) |
Find an element node with the given name. | |
template<typename Visitor > | |
void | sp_repr_visit_descendants (Inkscape::XML::Node *node, Visitor visitor) |
Visit all descendants recursively. | |
template<typename Visitor > | |
void | sp_repr_visit_descendants (Inkscape::XML::Node *a, Inkscape::XML::Node *b, Visitor visitor) |
Visit descendants of 2 nodes in parallel. | |
Definition at line 25 of file simple-document.h.
|
inlineexplicit |
Definition at line 30 of file simple-document.h.
Referenced by duplicate().
|
inlineprotected |
Definition at line 69 of file simple-document.h.
|
overridevirtual |
Begin a transaction and start recording changes.
By calling this method you effectively establish a resotre point. You can undo all changes made to the document after this call using rollback().
Implements Inkscape::XML::Document.
Definition at line 26 of file simple-document.cpp.
References _in_transaction.
|
overridevirtual |
Commit a transaction and discard change data.
This method finishes the active transaction and discards the recorded changes.
Implements Inkscape::XML::Document.
Definition at line 39 of file simple-document.cpp.
References _in_transaction, _log_builder, and Inkscape::XML::LogBuilder::discard().
|
overridevirtual |
Commit a transaction and store the events for later use.
This method finishes a transaction and returns an event chain that describes the changes made to the document. This method may return NULL, which means that the document implementation doesn't support event logging, or that no changes were made.
Implements Inkscape::XML::Document.
Definition at line 45 of file simple-document.cpp.
References _in_transaction, _log_builder, and Inkscape::XML::LogBuilder::detach().
|
overridevirtual |
Implements Inkscape::XML::Document.
Definition at line 63 of file simple-document.cpp.
References Inkscape::XML::SimpleNode::content(), and Inkscape::Util::share_string().
|
overridevirtual |
Implements Inkscape::XML::Document.
Definition at line 51 of file simple-document.cpp.
References Inkscape::XML::SimpleNode::name().
Referenced by SPStyle::readFromPrefs().
|
overridevirtual |
Implements Inkscape::XML::Document.
Definition at line 67 of file simple-document.cpp.
References Inkscape::XML::SimpleNode::content(), and Inkscape::Util::share_string().
|
overridevirtual |
Implements Inkscape::XML::Document.
Definition at line 55 of file simple-document.cpp.
References Inkscape::XML::SimpleNode::content(), and Inkscape::Util::share_string().
|
overridevirtual |
Implements Inkscape::XML::Document.
Definition at line 59 of file simple-document.cpp.
References Inkscape::XML::SimpleNode::content(), and Inkscape::Util::share_string().
Create a duplicate of this node.
The newly created node has no parent, and a refcount equal 1. You need to manually insert it into the document, using e.g. appendChild(). Afterwards, call Inkscape::GC::release on it, so that it will be automatically collected when the parent is collected.
doc | The document in which the duplicate should be created |
Implements Inkscape::XML::Node.
Definition at line 125 of file simple-document.cpp.
References Inkscape::XML::Node::appendChild(), child, Inkscape::XML::Document::duplicate(), Inkscape::XML::SimpleNode::firstChild(), Inkscape::XML::Node::next(), Inkscape::GC::release(), result, and SimpleDocument().
|
inlineoverridevirtual |
Checks whether there is an active transaction for this document.
Implements Inkscape::XML::Document.
Definition at line 36 of file simple-document.h.
References _in_transaction.
|
inlineoverrideprotectedvirtual |
Get the event logger for this document.
This is an implementation detail that should not be used outside of node implementations. It should be made non-public in the future.
Implements Inkscape::XML::Document.
Definition at line 73 of file simple-document.h.
|
overridevirtual |
Attribute change callback.
This method is called whenever one of a node's attributes is changed.
node | The changed XML node |
name | GQuark corresponding to the attribute's name |
old_value | Old value of the modified attribute. Is a nullptr when the attribute is added. |
new_value | New value of the modified attribute. Is a nullptr when the attribute is removed. |
Reimplemented from Inkscape::XML::NodeObserver.
Definition at line 108 of file simple-document.cpp.
References _in_transaction, _log_builder, Inkscape::XML::SimpleNode::name(), node, and Inkscape::XML::LogBuilder::setAttribute().
|
overridevirtual |
Child addition callback.
This method is called whenever a child is added to the observed node. The prev
parameter is NULL when the newly added child is first in the sibling order.
node | The changed XML node |
child | The newly added child node |
prev | The node after which the new child was inserted into the sibling order, or NULL |
Reimplemented from Inkscape::XML::NodeObserver.
Definition at line 71 of file simple-document.cpp.
References _in_transaction, _log_builder, Inkscape::XML::LogBuilder::addChild(), child, Inkscape::XML::SimpleNode::parent(), and Inkscape::XML::SimpleNode::prev().
|
overridevirtual |
Child order change callback.
This method is called whenever the order of a node's children is changed using Node::changeOrder(). The old_prev
parameter is NULL if the relocated node was first in the sibling order before the order change, and new_prev
is NULL if it was moved to the first position by this operation.
node | The changed XML node |
child | The child node that was relocated in the sibling order |
old_prev | The node that was before child prior to the order change |
new_prev | The node that is before child after the order change |
Reimplemented from Inkscape::XML::NodeObserver.
Definition at line 89 of file simple-document.cpp.
References _in_transaction, _log_builder, child, Inkscape::XML::SimpleNode::parent(), and Inkscape::XML::LogBuilder::setChildOrder().
|
overridevirtual |
Child removal callback.
This method is called whenever a child is removed from the observed node. The prev
parameter is NULL when the removed child was first in the sibling order.
node | The changed XML node |
child | The removed child node |
prev | The node that was before the removed node in sibling order, or NULL |
Reimplemented from Inkscape::XML::NodeObserver.
Definition at line 80 of file simple-document.cpp.
References _in_transaction, _log_builder, child, Inkscape::XML::SimpleNode::parent(), Inkscape::XML::SimpleNode::prev(), and Inkscape::XML::LogBuilder::removeChild().
|
overridevirtual |
Content change callback.
This method is called whenever a node's content is changed using Node::setContent(), e.g. for text or comment nodes.
node | The changed XML node |
old_content | Old content of node |
new_content | New content of node |
Reimplemented from Inkscape::XML::NodeObserver.
Definition at line 99 of file simple-document.cpp.
References _in_transaction, _log_builder, node, and Inkscape::XML::LogBuilder::setContent().
|
overridevirtual |
Element name change callback.
This method is called whenever an element node's name is changed.
node | The changed XML node. |
old_name | GQuark corresponding to the old element name. |
new_name | GQuark corresponding to the new element name. |
Reimplemented from Inkscape::XML::NodeObserver.
Definition at line 118 of file simple-document.cpp.
References _in_transaction, _log_builder, node, and Inkscape::XML::LogBuilder::setElementName().
|
overridevirtual |
Restore the state of the document prior to the transaction.
This method applies the inverses of all recorded changes in reverse order, restoring the document state from before the transaction. For some implementations, this function may do nothing.
Implements Inkscape::XML::Document.
Definition at line 31 of file simple-document.cpp.
References _in_transaction, _log_builder, Inkscape::XML::LogBuilder::detach(), log(), sp_repr_free_log(), and sp_repr_undo_log().
|
inlineoverridevirtual |
Get the type of the node.
Implements Inkscape::XML::Node.
Definition at line 34 of file simple-document.h.
References Inkscape::XML::DOCUMENT_NODE.
|
private |
Definition at line 76 of file simple-document.h.
Referenced by beginTransaction(), commit(), commitUndoable(), inTransaction(), notifyAttributeChanged(), notifyChildAdded(), notifyChildOrderChanged(), notifyChildRemoved(), notifyContentChanged(), notifyElementNameChanged(), and rollback().
|
private |
Definition at line 77 of file simple-document.h.
Referenced by commit(), commitUndoable(), notifyAttributeChanged(), notifyChildAdded(), notifyChildOrderChanged(), notifyChildRemoved(), notifyContentChanged(), notifyElementNameChanged(), and rollback().