Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
Inkscape::XML::SimpleDocument Class Reference

#include <simple-document.h>

Inheritance diagram for Inkscape::XML::SimpleDocument:
Inkscape::XML::SimpleNode Inkscape::XML::Document Inkscape::XML::NodeObserver Inkscape::XML::Node Inkscape::GC::Managed< default_scan, default_collect > Inkscape::XML::Node Inkscape::GC::Anchored Inkscape::GC::Anchored

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::EventcommitUndoable () override
 Commit a transaction and store the events for later use.
 
NodecreateElement (char const *name) override
 
NodecreateTextNode (char const *content) override
 
NodecreateTextNode (char const *content, bool const is_CData) override
 
NodecreateComment (char const *content) override
 
NodecreatePI (char const *target, char const *content) override
 
Documentduplicate (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.
 
- Public Member Functions inherited from Inkscape::XML::SimpleNode
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.
 
Documentdocument () override
 Get the node's associated document.
 
Document const * document () const override
 
Noderoot () override
 Get the root node of this node's document.
 
Node const * root () const override
 
Nodeparent () override
 Get the parent of this node.
 
Node const * parent () const override
 
Nodenext () override
 Get the next sibling of this node.
 
Node const * next () const override
 
Nodeprev () override
 
Node const * prev () const override
 
NodefirstChild () override
 Get the first child of this node.
 
Node const * firstChild () const override
 
NodelastChild () 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.
 
NodenthChild (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 AttributeVectorattributeList () 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
 
- Public Member Functions inherited from Inkscape::XML::Node
 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 >
NodefindChildPath (T list)
 depth first search to find a node
 
template<typename iterT >
NodefindChildPath (iterT itr, iterT end)
 template reshuffling to make the more useful findChildPath cleaner
 
- Public Member Functions inherited from Inkscape::GC::Anchored
void anchor () const
 
void release () const
 
unsigned _anchored_refcount () const
 
 Anchored (Anchored const &)=delete
 
void operator= (Anchored const &)=delete
 
- Public Member Functions inherited from Inkscape::GC::Managed< default_scan, default_collect >
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
- Public Member Functions inherited from Inkscape::XML::NodeObserver
virtual ~NodeObserver ()=default
 

Protected Member Functions

 SimpleDocument (SimpleDocument const &doc)
 
NodeObserverlogger () override
 Get the event logger for this document.
 
- Protected Member Functions inherited from Inkscape::XML::SimpleNode
 SimpleNode (int code, Document *document)
 
 SimpleNode (SimpleNode const &repr, Document *document)
 
void setAttributeImpl (char const *key, char const *value) override
 
- Protected Member Functions inherited from Inkscape::XML::Node
 Node (Node const &)
 
- Protected Member Functions inherited from Inkscape::GC::Anchored
 Anchored ()
 
virtual ~Anchored ()=default
 
- Protected Member Functions inherited from Inkscape::XML::NodeObserver
 NodeObserver ()=default
 

Private Attributes

bool _in_transaction = false
 
LogBuilder _log_builder
 

Additional Inherited Members

- Public Types inherited from Inkscape::XML::Node
using iterator = Inkscape::XML::NodeSiblingIterator
 

Detailed Description

Definition at line 25 of file simple-document.h.

Constructor & Destructor Documentation

◆ SimpleDocument() [1/2]

Inkscape::XML::SimpleDocument::SimpleDocument ( )
inlineexplicit

Definition at line 30 of file simple-document.h.

Referenced by duplicate().

◆ SimpleDocument() [2/2]

Inkscape::XML::SimpleDocument::SimpleDocument ( SimpleDocument const &  doc)
inlineprotected

Definition at line 69 of file simple-document.h.

Member Function Documentation

◆ beginTransaction()

void Inkscape::XML::SimpleDocument::beginTransaction ( )
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.

◆ commit()

void Inkscape::XML::SimpleDocument::commit ( )
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().

◆ commitUndoable()

Inkscape::XML::Event * Inkscape::XML::SimpleDocument::commitUndoable ( )
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.

Returns
Event chain describing the changes, or NULL

Implements Inkscape::XML::Document.

Definition at line 45 of file simple-document.cpp.

References _in_transaction, _log_builder, and Inkscape::XML::LogBuilder::detach().

◆ createComment()

Node * Inkscape::XML::SimpleDocument::createComment ( char const *  content)
overridevirtual

◆ createElement()

Node * Inkscape::XML::SimpleDocument::createElement ( char const *  name)
overridevirtual

Implements Inkscape::XML::Document.

Definition at line 51 of file simple-document.cpp.

References Inkscape::XML::SimpleNode::name().

Referenced by SPStyle::readFromPrefs().

◆ createPI()

Node * Inkscape::XML::SimpleDocument::createPI ( char const *  target,
char const *  content 
)
overridevirtual

◆ createTextNode() [1/2]

Node * Inkscape::XML::SimpleDocument::createTextNode ( char const *  content)
overridevirtual

◆ createTextNode() [2/2]

Node * Inkscape::XML::SimpleDocument::createTextNode ( char const *  content,
bool const  is_CData 
)
overridevirtual

◆ duplicate()

Document * Inkscape::XML::SimpleDocument::duplicate ( Document doc) const
overridevirtual

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.

Parameters
docThe document in which the duplicate should be created
Returns
A pointer to the duplicated node

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().

◆ inTransaction()

bool Inkscape::XML::SimpleDocument::inTransaction ( )
inlineoverridevirtual

Checks whether there is an active transaction for this document.

Returns
true if there's an established transaction for this document, false otherwise

Implements Inkscape::XML::Document.

Definition at line 36 of file simple-document.h.

References _in_transaction.

◆ logger()

NodeObserver * Inkscape::XML::SimpleDocument::logger ( )
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.

◆ notifyAttributeChanged()

void Inkscape::XML::SimpleDocument::notifyAttributeChanged ( Node node,
GQuark  name,
Util::ptr_shared  old_value,
Util::ptr_shared  new_value 
)
overridevirtual

Attribute change callback.

This method is called whenever one of a node's attributes is changed.

Parameters
nodeThe changed XML node
nameGQuark corresponding to the attribute's name
old_valueOld value of the modified attribute. Is a nullptr when the attribute is added.
new_valueNew 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().

◆ notifyChildAdded()

void Inkscape::XML::SimpleDocument::notifyChildAdded ( Node node,
Node child,
Node prev 
)
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.

Parameters
nodeThe changed XML node
childThe newly added child node
prevThe 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().

◆ notifyChildOrderChanged()

void Inkscape::XML::SimpleDocument::notifyChildOrderChanged ( Node node,
Node child,
Node old_prev,
Node new_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.

Parameters
nodeThe changed XML node
childThe child node that was relocated in the sibling order
old_prevThe node that was before child prior to the order change
new_prevThe 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().

◆ notifyChildRemoved()

void Inkscape::XML::SimpleDocument::notifyChildRemoved ( Node node,
Node child,
Node prev 
)
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.

Parameters
nodeThe changed XML node
childThe removed child node
prevThe 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().

◆ notifyContentChanged()

void Inkscape::XML::SimpleDocument::notifyContentChanged ( Node node,
Util::ptr_shared  old_content,
Util::ptr_shared  new_content 
)
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.

Parameters
nodeThe changed XML node
old_contentOld content of node
new_contentNew 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().

◆ notifyElementNameChanged()

void Inkscape::XML::SimpleDocument::notifyElementNameChanged ( Node node,
GQuark  old_name,
GQuark  new_name 
)
overridevirtual

Element name change callback.

This method is called whenever an element node's name is changed.

Parameters
nodeThe changed XML node.
old_nameGQuark corresponding to the old element name.
new_nameGQuark 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().

◆ rollback()

void Inkscape::XML::SimpleDocument::rollback ( )
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().

◆ type()

NodeType Inkscape::XML::SimpleDocument::type ( ) const
inlineoverridevirtual

Get the type of the node.

Returns
NodeType enumeration member corresponding to the type of the node.

Implements Inkscape::XML::Node.

Definition at line 34 of file simple-document.h.

References Inkscape::XML::DOCUMENT_NODE.

Member Data Documentation

◆ _in_transaction

◆ _log_builder


The documentation for this class was generated from the following files: