PDA

View Full Version : QDirModel subclassing and private data member



jej
26th May 2009, 11:24
Hi, I would appreciate some help on the following:

I have a class named ThumbnailDirModel (subclass of QDirModel) with an additional role (ThumbnailRole). A custom delegate (ThumbnailItemDelegate) can call the data() member function of the ThumbnailDirModel to get a QPixmap and render it in a View.
(the pixmap is the actual content of the image file to be rendered).
Everything works fine until I tried to implement a container of Pixmap for the purpose of avoiding recreating a pixmap from a file everytime it is needed.
I tought the logical place for the container would be a private data member in ThumbnailDirModel as the model is responsible for providing all the data.
So when a request for a thumbnail is made via data() the model checks if it is present in the container, if not the container loads it from the file...
And there it is ! data() is const and does not allow the container expansion (non const)
In a general sense: how a model internal data can update itself when a request for data is made to the model ?
And/Or in a pratical sense: what is wrong with my design ?

Thanks

jpn
26th May 2009, 11:40
You can mark the member variable as 'mutable' or const_cast<ThumbnailDirModel*>(this).

jej
26th May 2009, 15:04
Whoua, I missed the basics i guess.
Thanks a lot....