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.
+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.
+ 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. 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? I can assure you that I have tried
multiple combinations before ending up on my current logic. And the
TocModel is reconstructed each time there's a single change in the Toc.
It works well, try it :-)
Abdel.