PDA

View Full Version : Model Choices review/questions



ucntcme
16th September 2007, 22:45
I think I've narrowed down the architecture I need, but would like some input on it. I've not needed Views and models much as most of my Qt4 has been in non-GUI apps.

First, the app overview:
1) Retrieves an XML doc from a webserver.
2) Parses the file
3) Displays the data in a QTreeWidget (I need columns, but have no hierarchy)
4) If a row is selected and marked "archive", a web request is sent via POST to archive that entry. Each entry has a unique ID to facilitate this.
5) Periodically, or upon refresh new data is retrieved and the display updated

Now, some niggly bits. The updated list may contain none of the previous items, and will contain more items usually. I will actually want to display two treewidgets - one will display items with a given attribute the other will display the rest.

I've implemented 1-3 in a prototype fashion. I can retrieve, parse and then stuff into a QTreeWidget directly. I also have the QTimer working to periodically update.

However...

I'd like to not clear and repopulate the items on data refresh - I'd like for a selected item to remain selected if still present. But if this turns out to be the much easier route, I'll take it.

Looking at the Item/View classes it seems I need a TreeView and a data model. This is where my understanding falters. I would like to avoid subclassing any of the Abstracts as I don't think I need them and would prefer to avoid implementing all the virtuals. ;)

Essentially my data is a list of QStringLists. Does this fit with the List Model, or will I need to implement a custom model for this? A Table would be functionally accurate but user interaction-wise not appropriate. Particularly since there is no editing going on.

For the two views it looks like a pair of filter proxy models is what I need to do - one for each condition. Is this accurate? Right now I have a conditional when parsing to add to each QTreeWidget as necessary. Seems to me that could be simplified by the filter model.

I've looked at the Tree examples I can find, but it seems all the model examples just use QDirModel, which is not terribly useful to this data model - though great for hierarchical directory views. ;)

Some assistance on the model aspect would be much appreciated, as well as advice about which models/view would be best here, or even if it just makes more sense to stick with the "old fashioned way" I used in the proto.

Thanks

wysota
16th September 2007, 22:57
Go either for a QStringListModel or a QStandardItemModel depending on your needs.