This is a question about programming practice. I am looking for opinions.
Not infrequently I write applications where users interact with data through a list or tree widget of some sort. I've sort of stumbled upon two approaches to this:
(1) I respond to events in the tree|list widget by figuring out the index of the widget item, and then modify the data structure (e.g. a QList) based on that widget.
(2) I subclass QTreeWidgetItem (or QListWidgetItem), and include a pointer to the appropriate data structure in the new class. Then when an event occurs, I cast the pointer to QTreeWidgetItem to the subclass, and modify the data structure that way.
At this point in my thinking, option #2 seems more elegant. I am open to suggestions.
I should mention that while I'm aware of model/view programming, I've always had fairly simple applications, and whenever I've looked closely it looked like more trouble than it was worth (for my particular applications). If you think that model/view is definitely the way to go in any circumstance, I'd be interested to hear that.
Thanks for your thoughts,
Adam
Bookmarks