[Development] Role names and Proxy Models

Johan Thelin e8johan at gmail.com
Tue Jan 17 08:48:29 CET 2012


On Mon, Jan 16, 2012 at 09:58, Stephen Kelly <stephen.kelly at kdab.com> wrote:
> Please reply to the list.

Sorry, forgot the "reply to all", not on purpose.

> On Monday, January 16, 2012 08:22:48 you wrote:
>> 2012/1/16 Stephen Kelly <stephen.kelly at 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(...);
> }
>

Wouldn't that force the model to reset twice? That is, would I not
have to add beginResetModel / endResetModel around the call to
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?

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.

Kind regards,

Johan

> Thanks,
>
> --
> Stephen Kelly <stephen.kelly at 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



More information about the Development mailing list