-
- BufferParams const & bufparams = buffer_->params();
- const int min_toclevel = bufparams.textClass().min_toclevel();
-
- Toc & toc = tocs_["tableofcontents"];
- ParConstIterator pit = buffer_->par_iterator_begin();
- ParConstIterator end = buffer_->par_iterator_end();
- for (; pit != end; ++pit) {
-
- // the string that goes to the toc (could be the optarg)
- docstring tocstring;
-
- // For each paragraph, traverse its insets and let them add
- // their toc items
- InsetList::const_iterator it = pit->insetList().begin();
- InsetList::const_iterator end = pit->insetList().end();
- for (; it != end; ++it) {
- Inset & inset = *it->inset;
- inset.addToToc(*buffer_, pit);
- switch (inset.lyxCode()) {
- case OPTARG_CODE: {
- if (!tocstring.empty())
- break;
- Paragraph const & par =
- *static_cast<InsetOptArg&>(inset).paragraphs().begin();
- if (!pit->getLabelstring().empty())
- tocstring = pit->getLabelstring() + ' ';
- tocstring += par.asString(*buffer_, false);
- break;
- }
- default:
- break;
- }
- }
-
- /// now the toc entry for the paragraph
- int const toclevel = pit->layout()->toclevel;
- if (toclevel != Layout::NOT_IN_TOC
- && toclevel >= min_toclevel) {
- // insert this into the table of contents
- if (tocstring.empty())
- tocstring = pit->asString(*buffer_, true);
- toc.push_back(TocItem(pit, toclevel - min_toclevel,
- tocstring));
- }