PDA

View Full Version : Mapper from QList to QTable* display



rwo123gr
8th May 2008, 17:49
Is there a Mapper from a QList to the items of a QTable? I have a rapidly changing application and i'm finding myself resetting up 20-30 columns and headers. I could subclass it, but there are some instances where the list comes from a sql query instead of the object itself.

All i really need to do is view it and change order, and some of the options seem like overkill.

wysota
8th May 2008, 20:34
There is QStringListModel or QStandardItemModel.

rwo123gr
9th May 2008, 19:05
What I meant was that I want to actually bind the two (QList to QModel) for the ordering. Later operations are defined on a QList, not a Model class.

I have an approach that sends a signal to the underlying list to reorder (moveUp / moveDown), then recreates the whole model. This seems sort of clumsy.

Alternatively i could subclass the model, but again, It seems like I would need to do the same thing, or make the same switch twice in the model and the underlying list. Again any operation that reorders the list would need to repopulate the whole model.

Is there a clean way to bind the model to the list a single time?

wysota
9th May 2008, 20:18
The model should operate directly on the list. So your list should be "inside" the model or there should be no list at all - do everything using the model interface.

Remember that the model is not "something that lets me display my data in a table" but it's means to access some arbitrary data through a unified interface. Simply make your application aware of the model - let it help you instead of getting in your way.

Maybe this blog entry helps you understand things a bit more:
http://blog.wysota.eu.org/index.php/2007/12/17/itemviews-data-redundancy/