[Qt-interest] dataChanged() SIGNAL in proxy models

Stephen Kelly steveire at gmail.com
Thu Jul 1 15:05:30 CEST 2010


Mandeep Sandhu wrote:

>>> I have a QStringListModel on which I have applied my proxy model to
>>> return the data in a tabular manner (rows/cols).
>>
>> I would say it's a better idea to write your own table model instead of
>> trying to turn a list into a table. Adding extra columns by using a proxy
>> model is a bad idea and will likely cause QPersistentModelIndexes to
>> become corrupted.
> 
> I'm actually not adding extra columns to the list model. It's rows in
> the list which get transformed into columns in the table model.
> 
> eg: if list model has 5 rows (and 1 column) and the table dimension is
> set to 3X3, then I will proxy the data such that the table proxy
> returns 2 rows as rowcount and 3 columns column count.
> 
> List = 1,2,3,4,5
> 
> Table:
> 1,2,3
> 4,5

You might have seen these, but I'll draw your attention to them anyway:

http://doc.trolltech.com/latest/qlistview.html#LayoutMode-enum
http://doc.trolltech.com/latest/qlistview.html#batchSize-prop

It doesn't really make the data tabular, but it will lay it out in rows.

> 
> The reason I'm doing this is because the source of the data is
> returning a list but the display has to be tabular (I could still
> extract the list data and populate a table model, but I though this
> might turn out to be easier).

If the choice really is between a proxy to turn the stuff into a table or 
implement your own model to structure the data in a tabular way in the first 
place, I still recommend the table model, not the proxy.

> 
> I agree that QPersistentModelIndexes might get corrupted, but there's
> no requirement to hold/store the model indexes persistently. (the data
> from the source is pretty dynamic).

QPersistentModelIndexes are created when a selection is made, among other 
things.

> 
>>
>>>
>> const QModelIndex proxyBottom = mapFromSource(sourceBottomRight);
>> const QModelIndex proxyBotttomRight =
>> proxyBottom.sibling(proxyBottom.row(), proxyBottom.column() +
>> number_of_extra_columns);
> 
> I don't understand, why is this needed?

Because I thought you had a list and were adding extra columns. If you're 
not, it is not needed.

All the best,

Steve.

> 
> Thanks,
> -mandeep
> 
>>
>> emit dataChanged(proxyTopLeft, proxyBottomRight);
>> }





More information about the Qt-interest-old mailing list