On Friday, January 13, 2012 22:37:16 Johan Thelin wrote: > Hi all, > > I've been constructing a proxy model that hides multiple underlying > models. In this process, I have to translate the custom roles for each > model. E.g. the custom role enumeration for the duration of a music > track is not the same as for an album, but when accessed through my > proxy model, it should be. This is where I encountered an issue with > the current proxy models (in Qt 4.8). > > The role names for the model being proxied is copied each time > setModel is called. This means that the role names might change while > the model lives - something that does not work well with QML (as is > pointed out by the documentaiton). It also means that any calls to > setRoleNames in the c'tor of the proxy model are futile - the roles > are replaced when a model is set. > > In my opinion, this behavior should not be enforced at the current > level, i.e. in QAbstractProxyModel, but rather, in each specific > implementation, e.g. in QAbstractSortfFilterProxyModel, but not in > QIdentityProxyModel, so that a role-tranforming-proxy, like the one I > created, can be implemented. > > Introducing this in the 4.x tree might be considered to break the API, > but this is definitely something that I would like to see in Qt 5. > Does anyone object to this? Or is it time to submit a small patch? >
I'm not sure what your actual proposal is? If a model changes its rolenames then it should emit signals about being reset. If it emits signals about being reset, then QML should re-read the rolenames (note that proxies are not relevant in those sentences - the relevant API is QAbstractItemModel). If QML doesn't re-read the rolenames when the model is reset, then there's a patch to be made in QtDeclarative. (QAbstractProxyModel doesn't re-read them on reset either. Ogoffart rejected my patch to make it do that for reasons which never made sense to me and which I now forget and can't find on the internet). Anyway the Qt 5.0 way to set rolenames is to implement a virtual method. Please see if that addresses your concern, and if it doesn't, then please write an example which doesn't require a proxy which hides 'multiple underlying models'. That might not work anyway for various reasons (if you are using QAbstractProxyModel). Use an example such as 'a proxy model which returns a string filename for an image instead of a QImage for the decoration role'. Thanks, -- Stephen Kelly <[email protected]> | Software Engineer KDAB (Deutschland) GmbH & Co.KG, a KDAB Group Company www.kdab.com || Germany +49-30-521325470 || Sweden (HQ) +46-563-540090 KDAB - Qt Experts - Platform-Independent Software Solutions
signature.asc
Description: This is a digitally signed message part.
_______________________________________________ Development mailing list [email protected] http://lists.qt-project.org/mailman/listinfo/development
