+void TocModel::reset()
+{
+ model_->reset();
+}
+
+
+void TocModel::updateItem(DocIterator const & dit)
+{
+ QModelIndex index = modelIndex(dit);
+ TocItem const & toc_item = tocItem(index);
+ model_->setData(index, toqstr(toc_item.str()), Qt::DisplayRole);
+}
+
+
+void TocModel::reset(Toc const & toc)
+{
+ toc_ = &toc;
+ if (toc_->empty()) {
+ maxdepth_ = 0;
+ mindepth_ = 0;
+ reset();
+ return;
+ }
+
+ model_->blockSignals(true);
+ model_->insertColumns(0, 1);
+ maxdepth_ = 0;
+ mindepth_ = INT_MAX;
+
+ size_t end = toc_->size();
+ for (unsigned int index = 0; index != end; ++index) {
+ TocItem const & item = (*toc_)[index];
+ maxdepth_ = max(maxdepth_, item.depth());
+ mindepth_ = min(mindepth_, item.depth());
+ int current_row = model_->rowCount();
+ model_->insertRows(current_row, 1);
+ QModelIndex top_level_item = model_->index(current_row, 0);
+ model_->setData(top_level_item, toqstr(item.str()), Qt::DisplayRole);
+ model_->setData(top_level_item, index, Qt::UserRole);
+
+ LYXERR(Debug::GUI, "Toc: at depth " << item.depth()
+ << ", added item " << item.str());
+
+ populate(index, top_level_item);
+ if (index >= end)
+ break;