[Qt-interest] MVC Questions and Syncing QTreeView and QTableView

lbutler3 at comcast.net lbutler3 at comcast.net
Tue Jan 11 17:19:48 CET 2011


I've got some questions about how to keep multiple views of the same data in sync. 

I'm building an application to organize 3D models and manipulate meta-data. Think about grouping objects together into collections (and collections of collections) as well as setting attributes (like color) of the leaf items. 

The heirarchy is displayed and edited using a QTreeView which has a data model class derived from QAbstractItemModel to give it access to data to display. I need to display a table of "parts" (the leaves of the heirarcy) and their associated properties (eg. color) for users to edit. I can create a table model derived from QAbstractItemModel. 

The question is how to keep these two data models in sync. They both have selection models that need to be kept in sync. Contrary to the tutorials and examples I've seen, neither datamodel seems appropriate to "own" the underlying data. They just provide an interface for the Q*Views. For example, the rendering pipeline needs access to the application-native representation of the data for drawing the 3D display. So how do we map QModelIndex items from one view to another? How do we keep selection models in sync? And most crucially: Where does this processing take place? I accept that the classes derived from QAbstractItemModel are a part of the "data model" (M from Model-View-Controller). Does the controller take the responsibility of reaching down into both models to manipulate their selections? I guess I can see this when doing operations like cut-paste, but for selection I was hoping there might be a cleaner way. 

Your counsel would be greatly appreciated. 

Lee 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110111/7765c4fc/attachment.html 


More information about the Qt-interest-old mailing list