aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-06-07 02:44:16 +0000
committerDavid Robillard <d@drobilla.net>2011-06-07 02:44:16 +0000
commitd4785081aea2092ac7a98e1ef3ec6031574286e8 (patch)
treee208c48f3a508aa953a92d7409b00de2a3679f19
parent0bfaff9535291d6074d1541af2f7f83c61605d7f (diff)
downloadmachina-d4785081aea2092ac7a98e1ef3ec6031574286e8.tar.gz
machina-d4785081aea2092ac7a98e1ef3ec6031574286e8.tar.bz2
machina-d4785081aea2092ac7a98e1ef3ec6031574286e8.zip
Remove use of smart pointers in FlowCanvas entirely.
Since FlowCanvas's containers own their children, there is no real benefit to using smart pointers for objects, though there is overhead. There are no longer any add or remove methods for containers, simply create (new) and destroy (delete) objects and things should work as expected. git-svn-id: http://svn.drobilla.net/lad/trunk/machina@3366 a436a847-0d15-0410-975c-d299462d15a1
-rw-r--r--src/gui/EdgeView.cpp4
-rw-r--r--src/gui/MachinaCanvas.cpp17
-rw-r--r--src/gui/MachinaGUI.cpp11
3 files changed, 15 insertions, 17 deletions
diff --git a/src/gui/EdgeView.cpp b/src/gui/EdgeView.cpp
index b422e5e..0767ace 100644
--- a/src/gui/EdgeView.cpp
+++ b/src/gui/EdgeView.cpp
@@ -66,7 +66,7 @@ EdgeView::EdgeView(Canvas& canvas,
SharedPtr<NodeView> src,
SharedPtr<NodeView> dst,
SharedPtr<Machina::Client::ClientObject> edge)
- : FlowCanvas::Connection(canvas, src, dst, 0x9FA0A0F4, true)
+ : FlowCanvas::Connection(canvas, src.get(), dst.get(), 0x9FA0A0F4, true)
, _edge(edge)
{
set_color(edge_color(probability()));
@@ -85,7 +85,7 @@ EdgeView::probability() const
double
EdgeView::length_hint() const
{
- SharedPtr<NodeView> tail = PtrCast<NodeView>(source().lock());
+ NodeView* tail = dynamic_cast<NodeView*>(source());
return tail->node()->get(URIs::instance().machina_duration).get_float() * 10.0;
}
diff --git a/src/gui/MachinaCanvas.cpp b/src/gui/MachinaCanvas.cpp
index efb677f..2869c22 100644
--- a/src/gui/MachinaCanvas.cpp
+++ b/src/gui/MachinaCanvas.cpp
@@ -62,7 +62,7 @@ MachinaCanvas::node_clicked(WeakPtr<NodeView> item, GdkEventButton* event)
if (last) {
if (node != last) {
- if (get_connection(last, node))
+ if (get_connection(last.get(), node.get()))
action_disconnect(last, node);
else
action_connect(last, node);
@@ -112,7 +112,7 @@ MachinaCanvas::on_new_object(SharedPtr<Client::ClientObject> object)
WeakPtr<NodeView>(view)));
object->set_view(view);
- add_item(view);
+ add_item(view.get());
} else if (type == "machina:Edge") {
SharedPtr<Machina::Client::ClientObject> tail = _app->client_model()->find(
@@ -126,11 +126,11 @@ MachinaCanvas::on_new_object(SharedPtr<Client::ClientObject> object)
SharedPtr<EdgeView> view(
new EdgeView(*this, tail_view, head_view, object));
- tail_view->add_connection(view);
- head_view->add_connection(view);
+ tail_view->add_connection(view.get());
+ head_view->add_connection(view.get());
object->set_view(view);
- add_connection(view);
+ add_connection(view.get());
} else {
Raul::error << "Unknown object type " << type << std::endl;
@@ -142,14 +142,11 @@ MachinaCanvas::on_erase_object(SharedPtr<Client::ClientObject> object)
{
const Raul::Atom& type = object->get(URIs::instance().rdf_type);
if (type == "machina:Node") {
- SharedPtr<NodeView> view = PtrCast<NodeView>(object->view());
- if (view) {
- remove_item(view);
- }
+ // Destruction of the view will remove from the canvas
} else if (type == "machina:Edge") {
SharedPtr<EdgeView> view = PtrCast<EdgeView>(object->view());
if (view) {
- remove_connection(view->source().lock(), view->dest().lock());
+ remove_connection(view->source(), view->dest());
}
} else {
Raul::error << "Unknown object type " << type << std::endl;
diff --git a/src/gui/MachinaGUI.cpp b/src/gui/MachinaGUI.cpp
index 3e9424a..6763ec0 100644
--- a/src/gui/MachinaGUI.cpp
+++ b/src/gui/MachinaGUI.cpp
@@ -235,7 +235,7 @@ MachinaGUI::scrolled_window_event(GdkEvent* event)
_canvas->clear_selection();
for (Canvas::Items::iterator i = selection.begin(); i != selection.end(); ++i) {
- SharedPtr<NodeView> view = PtrCast<NodeView>(*i);
+ NodeView* const view = dynamic_cast<NodeView*>(*i);
if (view) {
_controller->erase(view->node()->id());
//_engine->machine()->remove_node(view->node());
@@ -599,15 +599,16 @@ MachinaGUI::show_labels_toggled()
{
const bool show = _menu_view_labels->get_active();
- for (Canvas::Items::iterator i = _canvas->items().begin(); i != _canvas->items().end(); ++i) {
- const SharedPtr<NodeView> nv = PtrCast<NodeView>(*i);
+ for (Canvas::Items::iterator i = _canvas->items().begin();
+ i != _canvas->items().end(); ++i) {
+ NodeView* const nv = dynamic_cast<NodeView*>(*i);
if (nv)
nv->show_label(show);
}
- for (ConnectionList::iterator c = _canvas->connections().begin();
+ for (Canvas::Connections::iterator c = _canvas->connections().begin();
c != _canvas->connections().end(); ++c) {
- const SharedPtr<EdgeView> ev = PtrCast<EdgeView>(*c);
+ EdgeView* const ev = dynamic_cast<EdgeView*>(*c);
if (ev)
ev->show_label(show);
}