+TocItem const TocModels::currentItem(QString const & type,
+ QModelIndex const & index) const
+{
+ const_iterator it = models_.find(type);
+ if (it == models_.end() || !index.isValid()) {
+ LYXERR(Debug::GUI, "TocModels::currentItem(): QModelIndex is invalid!");
+ return TocItem();
+ }
+ LASSERT(index.model() == it.value()->model(), return TocItem());
+
+ return it.value()->tocItem(index);
+}
+
+
+void TocModels::updateBackend() const
+{
+ bv_->buffer().masterBuffer()->tocBackend().update();
+ bv_->buffer().structureChanged();
+}
+
+
+void TocModels::updateItem(QString const & type, DocIterator const & dit)
+{
+ models_[type]->updateItem(dit);
+}
+
+
+void TocModels::reset(BufferView const * bv)
+{
+ bv_ = bv;
+ clear();
+ if (!bv_) {
+ iterator end = models_.end();
+ for (iterator it = models_.begin(); it != end; ++it)
+ it.value()->reset();
+ names_->reset();
+ return;
+ }
+
+ names_->blockSignals(true);
+ names_->insertColumns(0, 1);
+ TocList const & tocs = bv_->buffer().masterBuffer()->tocBackend().tocs();
+ TocList::const_iterator it = tocs.begin();
+ TocList::const_iterator toc_end = tocs.end();
+ for (; it != toc_end; ++it) {
+ QString const type = toqstr(it->first);
+
+ // First, fill in the toc models.
+ iterator mod_it = models_.find(type);
+ if (mod_it == models_.end())
+ mod_it = models_.insert(type, new TocModel(this));
+ mod_it.value()->reset(it->second);
+
+ // Fill in the names_ model.
+ QString const gui_name = guiName(it->first, bv->buffer().params());
+ int const current_row = names_->rowCount();
+ names_->insertRows(current_row, 1);
+ QModelIndex const index = names_->index(current_row, 0);
+ names_->setData(index, gui_name, Qt::DisplayRole);
+ names_->setData(index, type, Qt::UserRole);
+ }
+ names_->blockSignals(false);
+ names_->reset();
+}
+
+
+bool TocModels::isSorted(QString const & type) const
+{
+ const_iterator it = models_.find(type);
+ if (it == models_.end()) {
+ LYXERR0("type not found: " << type);
+ return false;
+ }
+ return it.value()->isSorted();
+}
+
+
+void TocModels::sort(QString const & type, bool sort_it)