]> git.tdb.fi Git - libs/gltk.git/commitdiff
Recreate list items when setting data
authorMikko Rasa <tdb@tdb.fi>
Sun, 30 Jun 2013 20:41:19 +0000 (23:41 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 30 Jun 2013 20:41:19 +0000 (23:41 +0300)
source/list.cpp

index 2c13ccca8e2d403a8911c8061e0f502a60a60901..ec3f9942d458eece47a62f4eb2ee2b233c5d54b7 100644 (file)
@@ -82,6 +82,17 @@ void List::set_data(ListData &d)
        own_data = false;
        observer = new DataObserver(*this);
 
+       for(vector<Item *>::iterator i=items.begin(); i!=items.end(); ++i)
+               delete *i;
+       items.clear();
+       unsigned n_items = data->size();
+       for(unsigned i=0; i<n_items; ++i)
+       {
+               Item *item = create_item(i);
+               add(*item);
+               items.push_back(item);
+       }
+
        items_changed();
 }