Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
helper-observer.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 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
9 */
10
11#include "helper-observer.h"
12
13#include "object/sp-object.h"
14
15namespace Inkscape {
16namespace XML {
17
18// Very simple observer that just emits a signal if anything happens to a node
20 : _oldsel(nullptr)
21{}
22
24{
25 set(nullptr); // if _oldsel!=nullptr, remove observer and decrease refcount
26}
27
28// Add this observer to the SPObject and remove it from any previous object
30{
31 // XML Tree being used directly in this function in the following code
32 // while it shouldn't be
33 // Pointer to object is stored, so refcounting should be increased/decreased
34 if(_oldsel) {
35 if (_oldsel->getRepr()) {
37 }
39 _oldsel = nullptr;
40 }
41 if(o) {
42 if (o->getRepr()) {
43 o->getRepr()->addObserver(*this);
45 _oldsel = o;
46 }
47 }
48}
49
52
55
58
61
64
69
70sigc::signal<void ()>& SignalObserver::signal_changed()
71{
72 return _signal_changed;
73}
74
75} //namespace XML
76} //namespace Inkscape
77
Interface for refcounted XML nodes.
Definition node.h:80
virtual void addObserver(NodeObserver &observer)=0
Add an object that will be notified of the changes to this node.
virtual void removeObserver(NodeObserver &observer)=0
Remove an object from the list of observers.
void notifyAttributeChanged(Node &, GQuark, Util::ptr_shared, Util::ptr_shared) override
Attribute change callback.
void notifyElementNameChanged(Node &, GQuark, GQuark) override
Element name change callback.
void notifyChildOrderChanged(Node &, Node &, Node *, Node *) override
Child order change callback.
void notifyChildRemoved(Node &, Node &, Node *) override
Child removal callback.
void notifyContentChanged(Node &, Util::ptr_shared, Util::ptr_shared) override
Content change callback.
sigc::signal< void()> & signal_changed()
void notifyChildAdded(Node &, Node &, Node *) override
Child addition callback.
sigc::signal< void()> _signal_changed
SPObject is an abstract base class of all of the document nodes at the SVG document level.
Definition sp-object.h:160
Inkscape::XML::Node * getRepr()
Returns the XML representation of tree.
TODO: insert short description here.
Helper class to stream background task notifications as a series of messages.
guint32 GQuark
SPObject * sp_object_unref(SPObject *object, SPObject *owner)
Decrease reference count of object, with possible debugging and finalization.
SPObject * sp_object_ref(SPObject *object, SPObject *owner)
Increase reference count of object, with possible debugging.