Re: [Development] Role names and Proxy Models
On Tuesday, January 17, 2012 08:48:29 you wrote: Wouldn't that force the model to reset twice? That is, would I not have to add beginResetModel / endResetModel around the call to setRoleNames? Yes, true. Also not an unsolvable problem. In Qt5 it's not so relevant anyway because roleNames is virtual. My impression is that this did not work correctly with 4.8, but all I really confirmed was that I got questions for the wrong role numbers. The core reason for this, is that Qt 4.8 forces the wrong role names onto the proxy models. How does it force the wrong role names onto proxy models? Force is a strong word, it implies that proxy models need to use the role names of the model being proxies, which might be the case for the sort filter proxy model, but, imho, not for the identity proxy model. A virtual method looks handy, makes it possible to do what I want to. However, the default role name setting in QAbstractProxyModel::setSourceModel is still present in Qt 5.0. Does it make more sense now? :-) I'm afraid I don't see why the above setSourceModel implementation wouldn't work. I suppose that it can be made to work, but with a change in the policy of handling roles combined with a minimal code change, it can be made to work better, imho. I think you'd need to show some kind of minimal maybe incomplete patch and some example code showing why it's needed. Preferably using the current Qt5 API (virtual roleNames()). Thanks, -- Stephen Kelly stephen.ke...@kdab.com | 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 Development@qt-project.org http://lists.qt-project.org/mailman/listinfo/development
Re: [Development] Role names and Proxy Models
Hi Johan, Please reply to the list. On Monday, January 16, 2012 08:22:48 you wrote: 2012/1/16 Stephen Kelly stephen.ke...@kdab.com: I'm not sure what your actual proposal is? My issue is that the role names of a proxy model are taken directly from the model being proxied, i.e. the following lines from qabstractproxymodel.cpp (around line 135, in QAbstractProxyModel::setSourceModel, Qt 4.8): ... } d-roleNames = d-model-roleNames(); } ... This overrides any attempts to use setRoleNames in a proxymodel, to do, for instance, role-name.transformations. How so? This works: MyProxyModel::setSourceModel(...) { // ... BaseProxy::setSourceModel(...); // ... setRoleNames(...); } My impression is that this did not work correctly with 4.8, but all I really confirmed was that I got questions for the wrong role numbers. The core reason for this, is that Qt 4.8 forces the wrong role names onto the proxy models. How does it force the wrong role names onto proxy models? A virtual method looks handy, makes it possible to do what I want to. However, the default role name setting in QAbstractProxyModel::setSourceModel is still present in Qt 5.0. Does it make more sense now? :-) I'm afraid I don't see why the above setSourceModel implementation wouldn't work. Thanks, -- Stephen Kelly stephen.ke...@kdab.com | 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 Development@qt-project.org http://lists.qt-project.org/mailman/listinfo/development
Re: [Development] Role names and Proxy Models
On Monday 16 January 2012 02:13:44 Stephen Kelly wrote: [...] 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). I don't recall all the details either, but if I remember correctly, your patch was doing things that were not allowed. The role name feature is a bit broken as you can't really modify them. (As usual with features that are added to Qt in a rush by the decarative team for their own use cases, without much thinking ahead) The documentation say: This function allows mapping of role identifiers to role property names in Declarative UI. This function must be called before the model is used. Modifying the role names after the model has been set may result in undefined behaviour. And you were calling it while the model was already in use, and I think it was the reason why I rejected. 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'. I think Qt 5 still do not implement ways to notify that the role name change. ___ Development mailing list Development@qt-project.org http://lists.qt-project.org/mailman/listinfo/development
Re: [Development] Role names and Proxy Models
On 16 January 2012 12:21, Olivier Goffart oliv...@woboq.com wrote: I think Qt 5 still do not implement ways to notify that the role name change. Proper signals to handle that (along the lines of all other QAIM signals) can always be added after 5.0, right? -- Giuseppe D'Angelo ___ Development mailing list Development@qt-project.org http://lists.qt-project.org/mailman/listinfo/development
Re: [Development] Role names and Proxy Models
On Monday, January 16, 2012 13:21:19 you wrote: On Monday 16 January 2012 02:13:44 Stephen Kelly wrote: [...] 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). I don't recall all the details either, but if I remember correctly, your patch was doing things that were not allowed. The role name feature is a bit broken as you can't really modify them. (As usual with features that are added to Qt in a rush by the decarative team for their own use cases, without much thinking ahead) The documentation say: This function allows mapping of role identifiers to role property names in Declarative UI. This function must be called before the model is used. Modifying the role names after the model has been set may result in undefined behaviour. And you were calling it while the model was already in use, and I think it was the reason why I rejected. Yes, I think that was it. Bad documentation IMO. Resetting the model means you have to read everything from it from scratch. It is very much well enough defined IMO that resetting the model might mean that it has different role names. 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'. I think Qt 5 still do not implement ways to notify that the role name change. Resetting the model means 'everything just changed'. The rolenames are part of 'everything'. I think all it takes is fixing the documentation for Qt 5 to make that clearer for you. Thanks, -- Stephen Kelly stephen.ke...@kdab.com | 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 Development@qt-project.org http://lists.qt-project.org/mailman/listinfo/development
Re: [Development] Role names and Proxy Models
On Monday 16 January 2012 13:48:33 Stephen Kelly wrote: On Monday, January 16, 2012 13:21:19 you wrote: On Monday 16 January 2012 02:13:44 Stephen Kelly wrote: [...] 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). I don't recall all the details either, but if I remember correctly, your patch was doing things that were not allowed. The role name feature is a bit broken as you can't really modify them. (As usual with features that are added to Qt in a rush by the decarative team for their own use cases, without much thinking ahead) The documentation say: This function allows mapping of role identifiers to role property names in Declarative UI. This function must be called before the model is used. Modifying the role names after the model has been set may result in undefined behaviour. And you were calling it while the model was already in use, and I think it was the reason why I rejected. Yes, I think that was it. Bad documentation IMO. Resetting the model means you have to read everything from it from scratch. It is very much well enough defined IMO that resetting the model might mean that it has different role names. 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'. I think Qt 5 still do not implement ways to notify that the role name change. Resetting the model means 'everything just changed'. The rolenames are part of 'everything'. I think all it takes is fixing the documentation for Qt 5 to make that clearer for you. Yes, a change in the documentatin would be enough for the qtbase part. (ok, maybe some tsts welcome as well) But declarative also need to be fixed to the fact that roles name can change. ___ Development mailing list Development@qt-project.org http://lists.qt-project.org/mailman/listinfo/development
Re: [Development] Role names and Proxy Models
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 stephen.ke...@kdab.com | 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 Development@qt-project.org http://lists.qt-project.org/mailman/listinfo/development