canvas::Layout: add clear method to remove all items.

This commit is contained in:
Thomas Geymayer
2014-06-14 13:19:00 +02:00
parent 9bef80fbef
commit b58bf443ff
5 changed files with 26 additions and 0 deletions

View File

@@ -121,6 +121,13 @@ namespace canvas
return item;
}
//----------------------------------------------------------------------------
void BoxLayout::clear()
{
_layout_items.clear();
invalidate();
}
//----------------------------------------------------------------------------
void BoxLayout::setStretch(size_t index, int stretch)
{

View File

@@ -58,6 +58,7 @@ namespace canvas
virtual size_t count() const;
virtual LayoutItemRef itemAt(size_t index);
virtual LayoutItemRef takeAt(size_t index);
virtual void clear();
/**
* Set the stretch factor of the item at position @a index to @a stretch.

View File

@@ -67,6 +67,13 @@ namespace canvas
}
}
//----------------------------------------------------------------------------
void Layout::clear()
{
while( itemAt(0) )
takeAt(0);
}
//----------------------------------------------------------------------------
void Layout::ItemData::reset()
{

View File

@@ -66,6 +66,11 @@ namespace canvas
*/
void removeItem(const LayoutItemRef& item);
/**
* Remove all items.
*/
virtual void clear();
protected:
enum LayoutFlags
{

View File

@@ -309,6 +309,12 @@ BOOST_AUTO_TEST_CASE( boxlayout_insert_remove )
hbox.removeItem(w2);
BOOST_CHECK_EQUAL(hbox.count(), 1);
BOOST_CHECK_EQUAL(hbox.itemAt(0), w1);
hbox.addItem(w2);
BOOST_CHECK_EQUAL(hbox.count(), 2);
hbox.clear();
BOOST_CHECK_EQUAL(hbox.count(), 0);
}
//------------------------------------------------------------------------------