]> git.tdb.fi Git - libs/gltk.git/commitdiff
Refresh list items one at a time
authorMikko Rasa <tdb@tdb.fi>
Sun, 30 Jun 2013 20:59:03 +0000 (23:59 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 30 Jun 2013 20:59:03 +0000 (23:59 +0300)
A blanket update doesn't work so well with items as widgets.

source/list.cpp
source/list.h
source/listdata.h

index ec3f9942d458eece47a62f4eb2ee2b233c5d54b7..fbb711e146cab0d1fba0187dd8fdcf743896de60 100644 (file)
@@ -275,7 +275,7 @@ List::DataObserver::DataObserver(List &l):
        list.data->signal_item_added.connect(sigc::mem_fun(this, &DataObserver::item_added));
        list.data->signal_item_removed.connect(sigc::mem_fun(this, &DataObserver::item_removed));
        list.data->signal_cleared.connect(sigc::mem_fun(this, &DataObserver::cleared));
-       list.data->signal_refresh_strings.connect(sigc::mem_fun(this, &DataObserver::refresh_strings));
+       list.data->signal_refresh_item.connect(sigc::mem_fun(this, &DataObserver::refresh_item));
 }
 
 void List::DataObserver::item_added(unsigned i)
@@ -310,8 +310,10 @@ void List::DataObserver::cleared()
        list.items_changed();
 }
 
-void List::DataObserver::refresh_strings()
+void List::DataObserver::refresh_item(unsigned i)
 {
+       delete list.items[i];
+       list.items[i] = list.create_item(i);
        list.items_changed();
 }
 
index 1032db7e551229368ff57bc83ccb43e649cc9279..14d9eac291e3bb2b7daee7c9862a268108689182 100644 (file)
@@ -38,7 +38,7 @@ private:
                void item_added(unsigned);
                void item_removed(unsigned);
                void cleared();
-               void refresh_strings();
+               void refresh_item(unsigned);
        };
 
 protected:
index 094b287b703545c294f71a644b33b5be0032af00..4c02f44aed57a7f3d3ca3094c1924eb21a38c6e5 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef MSP_GLTK_LISTDATA_H_
 #define MSP_GLTK_LISTDATA_H_
 
+#include <stdexcept>
 #include <string>
 #include <vector>
 #include <sigc++/signal.h>
@@ -15,7 +16,7 @@ public:
        sigc::signal<void, unsigned> signal_item_added;
        sigc::signal<void, unsigned> signal_item_removed;
        sigc::signal<void> signal_cleared;
-       sigc::signal<void> signal_refresh_strings;
+       sigc::signal<void, unsigned> signal_refresh_item;
 
 protected:
        ListData() { }
@@ -24,7 +25,12 @@ public:
 
        virtual unsigned size() const = 0;
        virtual std::string get_string(unsigned) const = 0;
-       void refresh_strings() const { signal_refresh_strings.emit(); }
+       void refresh(unsigned i) const
+       {
+               if(i>=size())
+                       throw std::out_of_range("ListData::refresh");
+               signal_refresh_item.emit(i);
+       }
 };
 
 template<typename T>
@@ -63,6 +69,14 @@ public:
                return -1;
        }
 
+       using ListData::refresh;
+       void refresh(const T &v) const
+       {
+               int i = find(v);
+               if(i>=0)
+                       signal_refresh_item.emit(i);
+       }
+
        void remove(unsigned i)
        {
                if(i>=items.size())