[Qt-interest] Proxy models

Stephen Kelly steveire at gmail.com
Mon Aug 30 13:37:43 CEST 2010


Kishore wrote:

> I have been working with proxy models lately and am intrigued by their
> complexity.
> 
> In short, it seems that most implementations of proxies use a QMap that
> maps beween QPersistantModelIndex's of the source and the proxy. Somehow
> this seems very inefficient o me. Memory consumption would go very high
> when the number of indexes increase. It is not uncommon for say a mail
> application to have several thousands of indexes and maybe 2-3 proxies
> between the view and the actual data.

That's what we do in proxies used kmail, kaddressbook etc, execpt that we 
use two QHashes, not QMap. Additionally, you don't have to map every index, 
only the parent indexes, so it's not a huge problem given that in a mail 
application you'll probably have only a few hundred mail folders (which are 
the parents). We use far more than 4 or 5 proxies too, because you can have 
multiple tabs with different data and each tab has at least two proxies. 12 
at runtime is probably not uncommon. On mobile we don't have tabs but we 
have more proxies there for navigational reasons. A running kmail-mobile has 
about 18, though many are often empty or contain only a small amount of 
data, or do trivial fast mapping.

At any rate, they are not the cause of slowdown.

QSortFilterProxyModel doesn't use persistent indexes from the source model, 
which I thought was interesting and annoying because there's more work to do 
to keep them updated manually.

> 
> Is this design really the best way considering speed and memory? I have
> not really seen any other MVC classes for comparison...

Note that you can create mappings lazily. If you have a tree and the view 
has not expanded everything it won't ask for everything. You can create 
mappings in your rowCount or hasChildren implementation and only maintain 
them then. 

I also don't really know of any comparable MVC APIs, but I had a short look 
at gtkTreeView, but I don't think that has any proxying concept. I'm sure 
.NET has some MVC stuff now too, but I haven't looked at it. If you find any 
let us know.

All the best,

Steve.

> 
> I am getting more and more interested in this and am curious to see some
> other MVC architectures! :)





More information about the Qt-interest-old mailing list