[Qt-interest] QAbstractProxyModel methods index, parent, rowCount, columnCount not implemented?
Andre Somers
andre at familiesomers.nl
Fri Jun 3 14:22:37 CEST 2011
Hi Stephen, anyone,
Op 18-5-2011 15:25, Andre Somers schreef:
> Op Wo, 18 mei, 2011 3:03 pm, schreef Stephen Kelly:
>> Andre Somers wrote:
>>>> 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.
>> I was referring to QModelIndexList members in the class. I only had a
>> quick
>> look and didn't think about it very hard, but if you also store
>> QPersistentModelIndexes you might be ok. I also didn't try to run it or
>> test it. I don't mean to offend.
> None taken.
> Actually, I think you are right that there is a possible issue with the
> way I deal with retreiving the selection now. I should re-think that. The
> base storing is probably OK, but there is an issue in the way I
> implemented the API for retrieving the lists of checked and unchecked
> items. These functions are meant to be called in close succession, but I
> think I should do this differently as there is no way to guarantee that
> they will be used in this way. Thanks for pointing that out.
The critique on this aspect was correct, I think. Therefore, I have
decided to re-design this part of the API, and came up with this solution:
Instead of the bunch of methods that all return a QModelIndexList, I
gave CheckableProxyModel now only one method checkedState() to access
this data. This method returns an instance of CheckableProxyModelState,
which is is not copyable or assignable and has a private constructor.
That is: the only way to get one, is through the checkedState() method.
This object has methods to retreive the different QModelIndexLists by
passing in a reference to one, and all of them return a reference to the
CheckableProxyModelState object again so you can chain calls to it. This
leads to code like this:
QModelIndexListselectedFiles;
QModelIndexList selectedDirectories;
QModelIndexList unselectedFiles;
QModelIndexList unselectedDirectories;
m_checkProxy->checkedState()
.checkedLeafIndexes(selectedFiles)
.checkedBranchIndexes(selectedDirectories)
.uncheckedLeafIndexes(unselectedFiles)
.uncheckedBranchIndexes(unselectedDirectories);
This way, there are no QModelIndexLists that are kept around in the
model any more, and you can still get the different lists in an
efficient way. The CheckableProxyModelState design should encourage
using it only in the designed way: as a result of
CheckableProxyModel::checkedState() to be discarded after the call.
The code is on gitorious: https://gitorious.org/checkableproxymodel
I do still need to address the other issues you mentioned, but I had the
impression that this was the most pressing one to fix. I'm looking
forwards to comments on this approach.
André
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110603/6dc3febf/attachment.html
More information about the Qt-interest-old
mailing list