Re: [Cxxgui-devel] Design / lists / MVC
Brought to you by:
davidturner
From: Daniel J. <dan...@em...> - 2004-03-10 19:58:47
|
On Tue, 2004-03-09 at 11:46, David Turner wrote: > The data ("Data") is stored in an unspecified container. > > The user must provide an adaptor class, called the Model. Canned models > for various STL container types will be provided. The model also supplies > metadata, such as column names. The Model derived from an ABC called > gui::data_model. > > The list widget itself is a view, called gui::data_view. The user > specifies the model to the view by passing it a pointer to a data_model. > The view automatically tracks the data. > > One problem I have with this design is the following: > > std::vector<std::string> my_data; > gui::linear_model<std::vector<std::string> > my_model; > gui::data_view view(my_model); > std::sort(my_data.begin(), my_data.end()); // view not updated > my_model.range_reordered(my_data.begin(), my_data.end()); // view updated > view.update(); // view updated > std::sort(my_model.begin(), my_model.end()); // view updated > > I dislike having to work explicitly through the model if the view is to be > updated. I don't think it's practical to use STL algorithms in this way. They mainly work by assignment, which doesn't map very well to gui operations. Also, it's hard to see how you would link items in the list view with items in the model, since iterators are easily invalidated. It will be very difficult to keep the model and view in sync. The interface for the supplied model will probably have to be limited to what works well with the data_view. Which probably means that the iterators would need to be const, and modifications would be done by member functions of the model. Having said that, you might be able to come with something clever that I haven't thought of. Daniel |