Review Request 120119: KRecursiveFilterProxyModel: Fixed the model

David Faure faure at kde.org
Thu Jan 22 07:47:15 GMT 2015


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://git.reviewboard.kde.org/r/120119/#review74519
-----------------------------------------------------------


The commit log has the same tree twice. Was "D" supposed to be omitted from the second tree?

Overall I'm extremely surprised that this class didn't have a unittest yet.
I recently wrote many proxymodels for a customer, with full test coverage, so this hurts my eyes. I will expand this unittest once it's in.

If I understand correctly, the bug in refreshAscendantMapping is that basically the code was hoping to test the "old" state of the tree, while in fact acceptRow returns the new state already (so in this case, acceptRow returns true for every ascendant, so we don't know where to stop). A cache (remembering what we have inserted into the tree) would solve this, but managing the cache would be so much more work.
A more clever solution could be to store the state of things (in fact just "lastAscendant") in a slot connected to rowsAboutToBeInserted, and use that later in the slot connected to rowsInserted. What do you think of this approach?

(Personally I think we need more unittests before making any kind of change :-)


kdeui/itemviews/krecursivefilterproxymodel.cpp
<https://git.reviewboard.kde.org/r/120119/#comment51686>

    refreshAll isn't used anymore, the new code always "refreshes all ascendants"



kdeui/tests/krecursivefilterproxymodeltest.cpp
<https://git.reviewboard.kde.org/r/120119/#comment51677>

    const char *  (or const QString &)



kdeui/tests/krecursivefilterproxymodeltest.cpp
<https://git.reviewboard.kde.org/r/120119/#comment51678>

    Good, but don't keep that comment. In 2 years we won't know which fix this is about.



kdeui/tests/krecursivefilterproxymodeltest.cpp
<https://git.reviewboard.kde.org/r/120119/#comment51679>

    (this nested block isn't useful and even harms readability)



kdeui/tests/krecursivefilterproxymodeltest.cpp
<https://git.reviewboard.kde.org/r/120119/#comment51680>

    QCOMPARE(b, true) is always better written as QVERIFY(b), that's what QVERIFY is for.



kdeui/tests/krecursivefilterproxymodeltest.cpp
<https://git.reviewboard.kde.org/r/120119/#comment51682>

    Shouldn't rowsInserted even be emitted 3 times? Once for row1, once for child, once for subchild?



kdeui/tests/krecursivefilterproxymodeltest.cpp
<https://git.reviewboard.kde.org/r/120119/#comment51685>

    rename child2 to subchild then, it's the same setup as the previous method (-> could be factorized into a fillModel private method).
    
    This method's subchild would then become subsubchild ;)
    
    Maybe (with the next test being more complex) it would be easier to call the items
    1 (row), 1.1 (first child), 1.2 (second child), 1.1.1. (subchild), 1.1.1.1 (subsubchild).
    
    Anyway, this test makes me want to add more tests, I can do that later.



kdeui/tests/krecursivefilterproxymodeltest.cpp
<https://git.reviewboard.kde.org/r/120119/#comment51681>

    QVERIFY(!...)



kdeui/tests/krecursivefilterproxymodeltest.cpp
<https://git.reviewboard.kde.org/r/120119/#comment51683>

    also check that child and subchild etc. can be found?



kdeui/tests/krecursivefilterproxymodeltest.cpp
<https://git.reviewboard.kde.org/r/120119/#comment51684>

    I would also expect 3 signal emissions here....


- David Faure


On Sept. 10, 2014, 8:15 a.m., Christian Mollekopf wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://git.reviewboard.kde.org/r/120119/
> -----------------------------------------------------------
> 
> (Updated Sept. 10, 2014, 8:15 a.m.)
> 
> 
> Review request for kdelibs and Stephen Kelly.
> 
> 
> Bugs: 338950
>     http://bugs.kde.org/show_bug.cgi?id=338950
> 
> 
> Repository: kdelibs
> 
> 
> Description
> -------
> 
> (This problem probably applies to KF5 as well, and we'll need to forward port this patch.)
> 
> 
> KRecursiveFilterProxyModel: Fixed the model
> 
> The model was not working properly and didn't include all items under
> some circumstances.
> This patch fixes the following scenarios in particular:
> 
> * The change in sourceDataChanged is required to fix the shortcut condition.
> The idea is that if the parent is already part of the model (it must be if acceptRow returns true),
> we can directly invoke dataChanged on the parent, resulting in the changed index
> getting reevaluated. However, because the recursive filterAcceptsRow version was used
> the shortcut was also used when only the current index matches the filter and
> the parent index is in fact not yet in the model. In this case we failed to call
> dataChanged on the right index and thus the complete branch was never added to the model.
> 
> * The change in refreshAscendantMapping is required to include indexes that were
> included by descendants. The intended way how this was supposed to work is that we
> traverse the tree upwards and find the last index that is not yet part of the model.
> We would then call dataChanged on that index causing it and its descendants to get reevaluated.
> However, acceptRow does not reflect wether an index is already in the model or not.
> Consider the following model:
> 
> - A
>   - B
>     - C
>     - D
> 
> 
> If C is include in the model by default but D not and A & B only gets included due to C, we have the following model:
> - A
>   - B
>     - C
>     - D
> 
> If we then call refreshAscendantsMapping on D it will not consider B as already being part of the model.
> This results in the toplevel index A being considered lastAscendant, and a call to dataChanged on A results in
> a reevaluation of A only, which is already in the model. Thus D never gets added to the model.
> 
> Unfortunately there is no way to probe QSortFilterProxyModel for indexes that are
> already part of the model. Even the const mapFromSource internally creates a mapping when called,
> and thus instead of revealing indexes that are not yet part of the model, it silently
> creates a mapping (without issuing the relevant signals!).
> 
> As the only possible workaround we have to issues dataChanged for all ancestors
> which is ignored for indexes that are not yet mapped, and results in a rowsInserted
> signal for the correct indexes. It also results in superfluous dataChanged signals,
> since we don't know when to stop, but at least we have a properly behaving model
> this way.
> 
> 
> Diffs
> -----
> 
>   kdeui/itemviews/krecursivefilterproxymodel.cpp 6d6563166bcc9637d826f577925c47d5ecbef2cd 
>   kdeui/tests/CMakeLists.txt f661b9177a6e0e1de7f49bc3cb9fbb5e04f427c1 
>   kdeui/tests/krecursivefilterproxymodeltest.cpp PRE-CREATION 
> 
> Diff: https://git.reviewboard.kde.org/r/120119/diff/
> 
> 
> Testing
> -------
> 
> 
> Thanks,
> 
> Christian Mollekopf
> 
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20150122/2b3ec4a4/attachment.htm>


More information about the kde-core-devel mailing list