On Wed, Apr 26, 2006 at 09:49:01AM +0200, Abdelrazak Younes wrote: > Andre Poenitz a écrit : > >On Mon, Apr 17, 2006 at 07:54:04PM +0200, Abdelrazak Younes wrote: > >>+void TocModel::populate(toc::Toc const & toc_list) > >>+{ > >>+ clear(); > >>+ > >>+ if (toc_list.empty()) > >>+ return; > >>+ > >>+ int current_row; > >>+ QModelIndex top_level_item; > >>+ > >>+ toc::Toc::const_iterator iter = toc_list.begin(); > >>+ toc::Toc::const_iterator end = toc_list.end(); > >>+ > >>+ insertColumns(0, 1); > > > >Indentation. > > ?? This line is at the same indent level as the previous one.
Not in my vi. The previous lines uses a tab for indentation (as they should) and the 'insertColums' line uses four spaces. Believe it or not, that _is_ a difference. > >>+void TocModel::populate(toc::Toc::const_iterator & iter, > >>+ toc::Toc::const_iterator > >>const & end, > >>+ QModelIndex const & parent) > >>+{ > >>+ int curdepth = iter->depth + 1; > >>+ int current_row; > >>+ QModelIndex child_item; > >>+ > >>+ insertColumns(0, 1, parent); > > > >And here. > > Ditto. Ditto. > >>+ current_row = rowCount(parent); > >>+ insertRows(current_row, 1, parent); > >>+ child_item = QStandardItemModel::index(current_row, 0, > >>parent); > >>+ //setData(child_item, toqstr(iter->str)); > >>+ setData(child_item, toqstr(iter->str), Qt::DisplayRole); > >>+ item_map_.insert(make_pair(child_item, *iter)); > >>+ index_map_.insert(make_pair( > >>+ iter->str.substr(iter->str.find(' ') + 1), > >>child_item)); > > > >I'd find > > > >+ index_map_[iter->str.substr(iter->str.find(' ') + 1)] = > >child_item; > > > >more readable. > > Me too but I was worried that a section with the same text could get > replaced. The last version in svn do not take str anyway... but still > make use of make_pair. The two versions are semantically equivalent. In fact, operator[] is just syntactic sugar. But it helps... > I've change that in my local version, I'll commit when I have > something more substancial to add. Or feel free to change it if you > want. > > >Apart from that I never completely understood what invalidates a > >QModelIndex. All I know that it is very prudent not to rely on its > >stability, so maybe that's not the best approach. > > What is not the best approach? Storing QModelIndex over 'a long period of time'. Qt dcumentation is pretty vague in this area, and I had crashs which went away after chosing something more robust. If you are sure that your way is safe, fine. I just wanted to warn... Andre'