Re: [Cxxgui-devel] Design / lists / MVC
Brought to you by:
davidturner
From: Matt T. <mat...@ho...> - 2004-03-11 14:01:41
|
Heya David, > This is my preliminary design for the list widget. I'm concerned that > it might be too complicated. Let me know what you think. I'm concerned it may be too complicated too! :O > 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. What would be the purpose of the metadata? > 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. Or a reference preferably... :) > The view automatically tracks the data. I'm not convinced automatic tracking is ideal. We used to use it in our framework at work but found that often only the manipulator of the data/model knows best when to trigger an update. For example, typically what happens is that a number of changes occur to the data. With automatic tracking this means that every change causes an update which is unnecessary. Manual tracking would allow you to change the data willy-nilly and then signal the model to call an update to the view (if required) at the end. Perhaps manual/auto should be a policy? > 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 How would the model know to update the view here? > I dislike having to work explicitly through the model if the view is to > be updated. I agree. It's a bit clumsy because the model can never know if the data has changed. But a better solution? Not sure yet. I'm going to sleep on it... :) Will speak soon! Cheers, Matt |