]> git.mxchange.org Git - simgear.git/commitdiff
canvas::Layout: add clear method to remove all items.
authorThomas Geymayer <tomgey@gmail.com>
Sat, 14 Jun 2014 11:19:00 +0000 (13:19 +0200)
committerThomas Geymayer <tomgey@gmail.com>
Sat, 14 Jun 2014 11:19:00 +0000 (13:19 +0200)
simgear/canvas/layout/BoxLayout.cxx
simgear/canvas/layout/BoxLayout.hxx
simgear/canvas/layout/Layout.cxx
simgear/canvas/layout/Layout.hxx
simgear/canvas/layout/canvas_layout_test.cxx

index a981db99c726020325b9add8a3e0837eca1aa06b..c7140467efc7a02b627596ab644981d4ff6ed6ca 100644 (file)
@@ -121,6 +121,13 @@ namespace canvas
     return item;
   }
 
+  //----------------------------------------------------------------------------
+  void BoxLayout::clear()
+  {
+    _layout_items.clear();
+    invalidate();
+  }
+
   //----------------------------------------------------------------------------
   void BoxLayout::setStretch(size_t index, int stretch)
   {
index 4ee16c3cd6e581419480f09e3fbba1ec0eaba7a0..fc3b4a25efa7c5e5226b7049252486f3f400285a 100644 (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.
index b7e29c361c43c52d11c919513ca0df5918ad6308..ff6994d181bbdea00c85cb75818a175807c1639c 100644 (file)
@@ -67,6 +67,13 @@ namespace canvas
     }
   }
 
+  //----------------------------------------------------------------------------
+  void Layout::clear()
+  {
+    while( itemAt(0) )
+      takeAt(0);
+  }
+
   //----------------------------------------------------------------------------
   void Layout::ItemData::reset()
   {
index 37ab1424fac600dfbd82a239caeb8644095e55f4..6a7fe3a1d87e4c483cefc32bef8bd69efaade946 100644 (file)
@@ -66,6 +66,11 @@ namespace canvas
        */
       void removeItem(const LayoutItemRef& item);
 
+      /**
+       * Remove all items.
+       */
+      virtual void clear();
+
     protected:
       enum LayoutFlags
       {
index 42524e85204febc06e20e06b3e525deecf66e8ad..fc693e446089cc1568475b6249e354680eed8431 100644 (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);
 }
 
 //------------------------------------------------------------------------------