diff --git a/libs/canvas/canvas/group.h b/libs/canvas/canvas/group.h index 8dee5f2672..9a72d50873 100644 --- a/libs/canvas/canvas/group.h +++ b/libs/canvas/canvas/group.h @@ -40,6 +40,7 @@ public: void add (Item *); void remove (Item *); + void clear (bool with_delete = false); std::list const & items () const { return _items; } diff --git a/libs/canvas/group.cc b/libs/canvas/group.cc index 907282f9cd..fe783ad8b5 100644 --- a/libs/canvas/group.cc +++ b/libs/canvas/group.cc @@ -170,6 +170,8 @@ Group::compute_bounding_box () const void Group::add (Item* i) { + /* XXX should really notify canvas about this */ + _items.push_back (i); invalidate_lut (); _bounding_box_dirty = true; @@ -180,11 +182,40 @@ Group::add (Item* i) void Group::remove (Item* i) { + + if (i->parent() != this) { + return; + } + + begin_change (); + + i->unparent (); _items.remove (i); invalidate_lut (); _bounding_box_dirty = true; - DEBUG_TRACE (PBD::DEBUG::CanvasItemsDirtied, "canvas item dirty: group remove\n"); + end_change (); +} + +void +Group::clear (bool with_delete) +{ + begin_change (); + + for (list::iterator i = _items.begin(); i != _items.end(); ++i) { + if (with_delete) { + delete *i; + } else { + (*i)->unparent (); + } + } + + _items.clear (); + + invalidate_lut (); + _bounding_box_dirty = true; + + end_change (); } void