- maxdepth_ = max(maxdepth_, iter->depth());
- mindepth_ = min(mindepth_, iter->depth());
- 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);
-
- // This looks like a gcc bug, in principle this should work:
- //toc_map_[child_item] = iter;
- // but it crashes with gcc-4.1 and 4.0.2
- toc_map_.insert( TocPair(child_item, iter) );
- model_map_[iter] = child_item;
- populate(iter, end, child_item);
+void TocModels::clear()
+{
+ names_->blockSignals(true);
+ names_->clear();
+ names_->blockSignals(false);
+ iterator end = models_.end();
+ for (iterator it = models_.begin(); it != end; ++it)
+ it.value()->clear();
+}
+
+
+int TocModels::depth(QString const & type)
+{
+ const_iterator it = models_.find(type);
+ if (!bv_ || it == models_.end())
+ return 0;
+ return it.value()->modelDepth();
+}
+
+
+QAbstractItemModel * TocModels::model(QString const & type)
+{
+ if (!bv_)
+ return 0;
+ iterator it = models_.find(type);
+ if (it != models_.end())
+ return it.value()->model();
+ LYXERR0("type not found: " << type);
+ return 0;
+}
+
+
+QAbstractItemModel * TocModels::nameModel()
+{
+ return names_sorted_;
+}
+
+
+QModelIndex TocModels::currentIndex(QString const & type) const
+{
+ const_iterator it = models_.find(type);
+ if (!bv_ || it == models_.end())
+ return QModelIndex();
+ return it.value()->modelIndex(bv_->cursor());
+}
+
+
+void TocModels::goTo(QString const & type, QModelIndex const & index) const
+{
+ const_iterator it = models_.find(type);
+ if (it == models_.end() || !index.isValid()) {
+ LYXERR(Debug::GUI, "TocModels::goTo(): QModelIndex is invalid!");
+ return;
+ }
+ LASSERT(index.model() == it.value()->model(), return);
+ TocItem const item = it.value()->tocItem(index);
+ LYXERR(Debug::GUI, "TocModels::goTo " << item.str());
+ dispatch(item.action());
+}
+
+
+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;