Nux

Merge lp:~loic.molinari/nux/nux-sigc-trackable-base-class into lp:nux

Proposed by Loïc Molinari
Status: Merged
Merged at revision: 194
Proposed branch: lp:~loic.molinari/nux/nux-sigc-trackable-base-class
Merge into: lp:nux
Diff against target: 226 lines (+36/-16)
10 files modified
Nux/Area.cpp (+0/-1)
Nux/Area.h (+1/-7)
Nux/InputArea.h (+1/-1)
Nux/RadioButtonGroup.h (+1/-1)
Nux/View.h (+1/-1)
NuxCore/Object.cpp (+1/-1)
NuxCore/Object.h (+7/-1)
NuxCore/nux-core.pc.in (+1/-1)
configure.ac (+4/-1)
tests/test-object.cpp (+19/-1)
To merge this branch: bzr merge lp:~loic.molinari/nux/nux-sigc-trackable-base-class
Reviewer Review Type Date Requested Status
Jay Taoko (community) Approve
Review via email: mp+47779@code.launchpad.net

Description of the change

This branch makes nux::Trackable inherit from sigc::trackable which allows users to easily define new signal all along the class hierarchy. Based on that, it adds a new OnDestroyed signal in the nux::Trackable class that's implemented by nux::Object.

Fixes lp:703054 and invalidates lp:706891.

To post a comment you must log in.
Revision history for this message
Jay Taoko (jaytaoko) wrote :

Approved

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Nux/Area.cpp'
2--- Nux/Area.cpp 2011-01-16 23:25:28 +0000
3+++ Nux/Area.cpp 2011-01-28 10:08:16 +0000
4@@ -47,7 +47,6 @@
5
6 Area::~Area()
7 {
8- OnDelete.emit (this);
9 }
10
11 const NString &Area::GetBaseString() const
12
13=== modified file 'Nux/Area.h'
14--- Nux/Area.h 2011-01-19 04:39:26 +0000
15+++ Nux/Area.h 2011-01-28 10:08:16 +0000
16@@ -23,11 +23,6 @@
17 #ifndef BASEOBJECT_H
18 #define BASEOBJECT_H
19
20-#include <sigc++/trackable.h>
21-#include <sigc++/signal.h>
22-#include <sigc++/functors/ptr_fun.h>
23-#include <sigc++/functors/mem_fun.h>
24-
25 #include "NuxCore/InitiallyUnownedObject.h"
26
27 #include "Utils.h"
28@@ -125,7 +120,7 @@
29 class Area;
30
31
32- class Area: public InitiallyUnownedObject, public sigc::trackable
33+ class Area: public InitiallyUnownedObject
34 {
35 public:
36 NUX_DECLARE_OBJECT_TYPE (Area, InitiallyUnownedObject);
37@@ -374,7 +369,6 @@
38 outofbound = b;
39 }
40
41- sigc::signal<void, Area*> OnDelete; //!< Signal emitted when an area is destroyed.
42 sigc::signal<void, int, int, int, int> OnResize; //!< Signal emitted when an area is resized.
43
44 unsigned int m_stretchfactor;
45
46=== modified file 'Nux/InputArea.h'
47--- Nux/InputArea.h 2011-01-26 06:08:18 +0000
48+++ Nux/InputArea.h 2011-01-28 10:08:16 +0000
49@@ -45,7 +45,7 @@
50 class InputArea;
51 typedef InputArea CoreArea;
52
53- class InputArea : public Area //public sigc::trackable
54+ class InputArea : public Area
55 {
56 public:
57 NUX_DECLARE_OBJECT_TYPE (InputArea, Area);
58
59=== modified file 'Nux/RadioButtonGroup.h'
60--- Nux/RadioButtonGroup.h 2010-12-06 06:09:44 +0000
61+++ Nux/RadioButtonGroup.h 2011-01-28 10:08:16 +0000
62@@ -32,7 +32,7 @@
63 /*!
64 RadioButtonGroup does not hold reference on radio buttons.
65 */
66- class RadioButtonGroup: public Object, public sigc::trackable
67+ class RadioButtonGroup: public Object
68 {
69 public:
70 RadioButtonGroup (NUX_FILE_LINE_PROTO);
71
72=== modified file 'Nux/View.h'
73--- Nux/View.h 2011-01-19 04:39:26 +0000
74+++ Nux/View.h 2011-01-28 10:08:16 +0000
75@@ -38,7 +38,7 @@
76 ePopupBox
77 };
78
79- class View: public InputArea //Area //public sigc::trackable
80+ class View: public InputArea //Area
81 {
82 NUX_DECLARE_OBJECT_TYPE (View, InputArea);
83 public:
84
85=== modified file 'NuxCore/Object.cpp'
86--- NuxCore/Object.cpp 2011-01-06 06:43:42 +0000
87+++ NuxCore/Object.cpp 2011-01-28 10:08:16 +0000
88@@ -80,7 +80,6 @@
89
90 Trackable::~Trackable()
91 {
92-
93 }
94
95 bool Trackable::Reference()
96@@ -420,6 +419,7 @@
97 //nuxDebugMsg (TEXT("[Object::Destroy] There are weak references pending on this object. This is OK!"));
98 }
99
100+ OnDestroyed.emit ();
101 delete this;
102 }
103
104
105=== modified file 'NuxCore/Object.h'
106--- NuxCore/Object.h 2010-12-12 20:46:29 +0000
107+++ NuxCore/Object.h 2011-01-28 10:08:16 +0000
108@@ -23,6 +23,9 @@
109 #ifndef NUXOBJECT_H
110 #define NUXOBJECT_H
111
112+#include <sigc++/trackable.h>
113+#include <sigc++/signal.h>
114+
115 namespace nux
116 {
117
118@@ -66,7 +69,7 @@
119 Trackable does not implement reference counting. It only defines the API. It is up
120 to the class that inherit from Trackable to implement the reference counting.
121 */
122- class Trackable
123+ class Trackable : public sigc::trackable
124 {
125 public:
126 NUX_DECLARE_ROOT_OBJECT_TYPE (Trackable);
127@@ -88,6 +91,9 @@
128 */
129 bool IsDynamic() const;
130
131+ //! Signal emitted immediately before the object is destroyed.
132+ sigc::signal<void> OnDestroyed;
133+
134 //! Increase the reference count.
135 /*
136 Widget are typically created and added to containers. It is decided that when widgets are created, they should have a floating reference
137
138=== modified file 'NuxCore/nux-core.pc.in'
139--- NuxCore/nux-core.pc.in 2010-09-01 19:40:43 +0000
140+++ NuxCore/nux-core.pc.in 2011-01-28 10:08:16 +0000
141@@ -8,4 +8,4 @@
142 Version: @VERSION@
143 Libs: -L${libdir} -lnux-core-@NUX_API_VERSION@
144 Cflags: -I${includedir}/Nux-@NUX_API_VERSION@
145-Requires: glib-2.0
146+Requires: glib-2.0 sigc++-2.0
147
148=== modified file 'configure.ac'
149--- configure.ac 2011-01-27 11:44:31 +0000
150+++ configure.ac 2011-01-28 10:08:16 +0000
151@@ -109,7 +109,7 @@
152
153 dnl ===========================================================================
154
155-PKG_CHECK_MODULES(NUX_CORE, glib-2.0 >= 2.25.14 gthread-2.0)
156+PKG_CHECK_MODULES(NUX_CORE, glib-2.0 >= 2.25.14 gthread-2.0 sigc++-2.0)
157 AC_SUBST(NUX_CORE_CFLAGS)
158 AC_SUBST(NUX_CORE_LIBS)
159
160@@ -118,6 +118,7 @@
161 gdk-pixbuf-2.0
162 cairo >= 1.9.14
163 libpng >= 1.2.44
164+ sigc++-2.0
165 )
166 AC_SUBST(NUX_IMAGE_CFLAGS)
167 AC_SUBST(NUX_IMAGE_LIBS)
168@@ -127,6 +128,7 @@
169 gdk-pixbuf-2.0
170 glew
171 glewmx
172+ sigc++-2.0
173 )
174 AC_SUBST(NUX_MESH_CFLAGS)
175 AC_SUBST(NUX_MESH_LIBS)
176@@ -138,6 +140,7 @@
177 glew
178 glewmx
179 xxf86vm
180+ sigc++-2.0
181 )
182 AC_SUBST(NUX_GRAPHICS_CFLAGS)
183 AC_SUBST(NUX_GRAPHICS_LIBS)
184
185=== modified file 'tests/test-object.cpp'
186--- tests/test-object.cpp 2010-12-19 02:57:54 +0000
187+++ tests/test-object.cpp 2011-01-28 10:08:16 +0000
188@@ -28,6 +28,7 @@
189 static void TestObjectPtr (void);
190 static void TestObjectPtr1 (void);
191 static void TestObjectPtr2 (void);
192+static void TestObjectSignal (void);
193
194 void
195 TestObjectSuite (void)
196@@ -39,6 +40,7 @@
197 g_test_add_func (TESTDOMAIN"/TestObjectPtr", TestObjectPtr);
198 g_test_add_func (TESTDOMAIN"/TestObjectPtr1", TestObjectPtr1);
199 g_test_add_func (TESTDOMAIN"/TestObjectPtr2", TestObjectPtr2);
200+ g_test_add_func (TESTDOMAIN"/TestObjectSignal", TestObjectSignal);
201 }
202
203 static const int ARRAY_SIZE = 1000;
204@@ -224,4 +226,20 @@
205
206 g_assert (object_ptr2.GetWeakReferenceCount () == 1);
207 g_assert (object_ptr2.Release () == true);
208-}
209\ No newline at end of file
210+}
211+
212+static bool g_signal_called = false;
213+
214+static void on_destroyed_cb () {
215+ g_signal_called = true;
216+}
217+
218+static void
219+TestObjectSignal (void)
220+{
221+ nux::Object *obj = new nux::Object ();
222+ obj->OnDestroyed.connect (sigc::ptr_fun (on_destroyed_cb));
223+ g_assert (g_signal_called == false);
224+ obj->UnReference ();
225+ g_assert (g_signal_called == true);
226+}

Subscribers

People subscribed via source and target branches