[Qt-interest] QAbstractProxyModel methods index, parent, rowCount, columnCount not implemented?

Andre Somers andre at familiesomers.nl
Wed May 18 14:25:59 CEST 2011


>>> Great, I will port my CheckableProxyModel to use it as soon as Qt 4.8
>>> is out.
>
> I had a quick look at your CheckableProxyModel, and it does a bunch of
> things wrong, such as storing QModelIndexes instead of
> QPersistentModelIndexes,
No, it does not do that. A QHash<QPersistentModelIndex, NodeState> is used
for storing the states. I don't know where you get that I store
QModelIndex directly? I don't claim there are no mistakes in the code, but
this is not one of them.

> and not listening to the source model for changes
> and keeping up to date.
The persistent model indexes are checked for validity before they are
used, but you are right that tests are needed there. It does work just
fine for lazily populated models (such as the QFileSystemModel) though.

> QItemSelectionModel does both of those things, which
> is what I use in KCheckableProxyModel.
I did use that class in an earlier version too, but it does not give me
enough freedom in what I store for each node. I need to store more than
just a boolean per node, otherwise it becomes *very* inefficient for large
trees.

> You should probably write some
> tests with a changing source model and see what happens.
That I should do indeed. Do you happen to have unit tests that you use for
your KCheckableProxyModel that I could use as a starting point?

> If you store data in a proxy, beware of reset()s of the source and the
> proxy. QIdentityProxyModel does not give you any API to handle them
> properly
> because the trolls don't want the fix in QAIM. That means everyone has to
> figure out the fix and apply it to each concrete proxy model. The fix is
> also not documented, so good look finding it :). It's described in a unit
> test in one of my old merge requests though.
Nice. A treasure hunt based on a couple of vague hints. I know that you
are an expert in Qt model-view programming, and you have contributed many
useful classes dealing with proxymodels and their impact on selection
behaviour, but this comment is not all that helpful. Could you be a bit
more specific please?

André





More information about the Qt-interest-old mailing list