Review Request 110236: Remove pointless call to model index parent to count top level items

David Edmundson david at davidedmundson.co.uk
Mon Apr 29 12:11:32 UTC 2013



> On April 29, 2013, 6:57 a.m., Daniele E. Domenichelli wrote:
> > global-presence-chooser.cpp, line 95
> > <http://git.reviewboard.kde.org/r/110236/diff/1/?file=141318#file141318line95>
> >
> >     Isn't QModelIndex() and invalid index?
> 
> David Edmundson wrote:
>     Yes. And the parent of a top level item is an invalid index.
>     
>     If we look at rowCount we do:
>     if (parent.isValid) {return 0;}
>     
>     we want to pass an invalid index to get the list row count.
> 
> Daniele E. Domenichelli wrote:
>     I still don't get this, sorry...
>     If "rowCount(QModelIndex())" returns 0, "rowCount(QModelIndex())-1" is always "-1", or am I missing something?
>
> 
> Martin Klapetek wrote:
>     I don't think the rowCount part from David is correct. If you pass invalid index to rowCount(), it counts the top-level items, which in this case they are all top-level, so it does not return 0, but the correct list size.

My code snippet is correct, but missing some stuff. Let me explain again.

our rowCount code says 

if (parent.isValid()) {
  return 0; //it must be a child item so we return 0 to show it's not a tree
} else {
  return m_list.size(); //top level items
}

we want to get into the else statement, which means we need to pass an invalid index.


- David


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
http://git.reviewboard.kde.org/r/110236/#review31725
-----------------------------------------------------------


On April 29, 2013, 11:58 a.m., David Edmundson wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> http://git.reviewboard.kde.org/r/110236/
> -----------------------------------------------------------
> 
> (Updated April 29, 2013, 11:58 a.m.)
> 
> 
> Review request for Telepathy.
> 
> 
> Description
> -------
> 
> Remove pointless call to model index parent to count top level items
> 
> BUG: 304085
> 
> 
> Diffs
> -----
> 
>   global-presence-chooser.cpp f5d59399a904195121ebac7266bef4176ac82bfb 
> 
> Diff: http://git.reviewboard.kde.org/r/110236/diff/
> 
> 
> Testing
> -------
> 
> 
> Thanks,
> 
> David Edmundson
> 
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-telepathy/attachments/20130429/8067b231/attachment.html>


More information about the KDE-Telepathy mailing list