PDA

View Full Version : custom widget and model



asieriko
4th October 2008, 09:31
Hello,
I've (or better I'm creating) a new widget. It's like a calendar, and now I want to create a model to be able to populate easily that widget. I've been reading a lot of documentation about, but I don't get the solution. I'm thinking on a table model, maybe, and now I don't exactly know how to pass the data to the widget, I think that each day sould ask to the model what data does it have for that day, but I don't know how to do, al the references are about an index, and I don't know how to implement it.
I think It should be something like this:
Model:
20081001 data1
20081001 data2
20081002 data
20081003 data
And the view should ask "give me the data from 20081001" for example.

I hope you get my idea, and give me some solution.

Thank you in advance

zavulon
6th October 2008, 13:08
You have a model that provides a list or table of data from some data source:

<Date> <Record>

In order to filter only some records from that data, you can use a Proxy model:
QSortFilterProxyModel. Read the documentation about it.

However, it could become too complex architecture, if you have only 1 view and 2 models. In such a case, implement the filtering part inside your single model and provide only filtered data. The original full data will be still kept unchanged in the model source.

The proxy model is handy, when you need two views: one of the original full data, and the other - of filtered data. This is described in the QSortFilterProxyModel documentation.

wysota
6th October 2008, 14:11
I would suggest to create a two level model. First level stores dates, second level stores events under a particular date. Then it is easy to query the model for events on particular days.