From 3f77f3542a6405fd832ababe48b950d1a65b00ed Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 30 Jun 2013 23:59:03 +0300 Subject: [PATCH] Refresh list items one at a time A blanket update doesn't work so well with items as widgets. --- source/list.cpp | 6 ++++-- source/list.h | 2 +- source/listdata.h | 18 ++++++++++++++++-- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/source/list.cpp b/source/list.cpp index ec3f994..fbb711e 100644 --- a/source/list.cpp +++ b/source/list.cpp @@ -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(); } diff --git a/source/list.h b/source/list.h index 1032db7..14d9eac 100644 --- a/source/list.h +++ b/source/list.h @@ -38,7 +38,7 @@ private: void item_added(unsigned); void item_removed(unsigned); void cleared(); - void refresh_strings(); + void refresh_item(unsigned); }; protected: diff --git a/source/listdata.h b/source/listdata.h index 094b287..4c02f44 100644 --- a/source/listdata.h +++ b/source/listdata.h @@ -1,6 +1,7 @@ #ifndef MSP_GLTK_LISTDATA_H_ #define MSP_GLTK_LISTDATA_H_ +#include #include #include #include @@ -15,7 +16,7 @@ public: sigc::signal signal_item_added; sigc::signal signal_item_removed; sigc::signal signal_cleared; - sigc::signal signal_refresh_strings; + sigc::signal 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 @@ -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()) -- 2.45.2