diff --git a/src/TocBackend.cpp b/src/TocBackend.cpp index 7f748e7fbd..984eb1ab65 100644 --- a/src/TocBackend.cpp +++ b/src/TocBackend.cpp @@ -22,6 +22,7 @@ #include "Layout.h" #include "LyXAction.h" #include "Paragraph.h" +#include "ParIterator.h" #include "TextClass.h" #include "insets/InsetOptArg.h" @@ -43,15 +44,15 @@ namespace lyx { // /////////////////////////////////////////////////////////////////////////// -TocItem::TocItem(ParConstIterator const & par_it, int d, docstring const & s) - : par_it_(par_it), depth_(d), str_(s) +TocItem::TocItem(DocIterator const & dit, int d, docstring const & s) + : dit_(dit), depth_(d), str_(s) { } int TocItem::id() const { - return par_it_->id(); + return dit_.paragraph().id(); } @@ -101,7 +102,7 @@ Toc & TocBackend::toc(string const & type) } -void TocBackend::updateItem(ParConstIterator const & par_it) +void TocBackend::updateItem(DocIterator const & dit) { if (toc("tableofcontents").empty()) { // FIXME: should not happen, @@ -113,32 +114,33 @@ void TocBackend::updateItem(ParConstIterator const & par_it) BufferParams const & bufparams = buffer_->params(); const int min_toclevel = bufparams.documentClass().min_toclevel(); - TocIterator toc_item = item("tableofcontents", par_it); + TocIterator toc_item = item("tableofcontents", dit); docstring tocstring; // For each paragraph, traverse its insets and let them add // their toc items - InsetList::const_iterator it = toc_item->par_it_->insetList().begin(); - InsetList::const_iterator end = toc_item->par_it_->insetList().end(); + Paragraph & par = toc_item->dit_.paragraph(); + InsetList::const_iterator it = par.insetList().begin(); + InsetList::const_iterator end = par.insetList().end(); for (; it != end; ++it) { Inset & inset = *it->inset; if (inset.lyxCode() == OPTARG_CODE) { if (!tocstring.empty()) break; - Paragraph const & par = + Paragraph const & inset_par = *static_cast(inset).paragraphs().begin(); - if (!toc_item->par_it_->labelString().empty()) - tocstring = toc_item->par_it_->labelString() + ' '; - tocstring += par.asString(false); + if (!par.labelString().empty()) + tocstring = par.labelString() + ' '; + tocstring += inset_par.asString(false); break; } } - int const toclevel = toc_item->par_it_->layout().toclevel; + int const toclevel = par.layout().toclevel; if (toclevel != Layout::NOT_IN_TOC && toclevel >= min_toclevel && tocstring.empty()) - tocstring = toc_item->par_it_->asString(true); + tocstring = par.asString(true); const_cast(*toc_item).str_ = tocstring; } @@ -165,6 +167,7 @@ void TocBackend::update() InsetList::const_iterator end = pit->insetList().end(); for (; it != end; ++it) { Inset & inset = *it->inset; + pit.pos() = it->pos; //lyxerr << (void*)&inset << " code: " << inset.lyxCode() << std::endl; inset.addToToc(pit); switch (inset.lyxCode()) { @@ -198,7 +201,7 @@ void TocBackend::update() TocIterator TocBackend::item(string const & type, - ParConstIterator const & par_it) const + DocIterator const & dit) const { TocList::const_iterator toclist_it = tocs_.find(type); // Is the type supported? @@ -212,7 +215,7 @@ TocIterator TocBackend::item(string const & type, --it; - ParConstIterator par_it_text = par_it; + ParConstIterator par_it_text(dit); if (par_it_text.inMathed()) { // We are only interested in text so remove the math CursorSlice. while (par_it_text.inMathed()) @@ -223,9 +226,9 @@ TocIterator TocBackend::item(string const & type, // We verify that we don't compare contents of two // different document. This happens when you // have parent and child documents. - if (&it->par_it_[0].inset() != &par_it_text[0].inset()) + if (&it->dit_[0].inset() != &par_it_text[0].inset()) continue; - if (it->par_it_ <= par_it_text) + if (it->dit_ <= par_it_text) return it; } diff --git a/src/TocBackend.h b/src/TocBackend.h index 9704352922..f9e700e379 100644 --- a/src/TocBackend.h +++ b/src/TocBackend.h @@ -14,7 +14,7 @@ #ifndef TOC_BACKEND_H #define TOC_BACKEND_H -#include "ParIterator.h" +#include "DocIterator.h" #include "support/strfwd.h" @@ -39,7 +39,7 @@ public: /// Default constructor for STL containers. TocItem() {} /// - TocItem(ParConstIterator const & par_it, + TocItem(DocIterator const & dit, int depth, docstring const & s ); @@ -59,7 +59,7 @@ public: protected: /// Current position of item. - ParConstIterator par_it_; + DocIterator dit_; /// nesting depth int depth_; @@ -92,7 +92,7 @@ public: /// void update(); /// - void updateItem(ParConstIterator const & pit); + void updateItem(DocIterator const & pit); /// TocList const & tocs() const { return tocs_; } @@ -105,7 +105,7 @@ public: /// Return the first Toc Item before the cursor TocIterator item( std::string const & type, ///< Type of Toc. - ParConstIterator const & ///< The cursor location in the document. + DocIterator const & dit ///< The cursor location in the document. ) const; /// diff --git a/src/frontends/qt4/Menus.cpp b/src/frontends/qt4/Menus.cpp index 51ef148db9..ee1a5b69c3 100644 --- a/src/frontends/qt4/Menus.cpp +++ b/src/frontends/qt4/Menus.cpp @@ -42,6 +42,7 @@ #include "LyX.h" // for lastfiles #include "LyXFunc.h" #include "Paragraph.h" +#include "ParIterator.h" #include "Session.h" #include "TextClass.h" #include "TocBackend.h" diff --git a/src/insets/Inset.h b/src/insets/Inset.h index be04893b45..620fc428e0 100644 --- a/src/insets/Inset.h +++ b/src/insets/Inset.h @@ -436,7 +436,7 @@ public: virtual void addPreview(graphics::PreviewLoader &) const {} /// Add an entry to the TocList /// pit is the ParConstIterator of the paragraph containing the inset - virtual void addToToc(ParConstIterator const &) const {} + virtual void addToToc(DocIterator const &) {} /// Fill keys with BibTeX information virtual void fillWithBibKeys(BiblioInfo &, InsetIterator const &) const {} /// Update the counters of this inset and of its contents diff --git a/src/insets/InsetCaption.cpp b/src/insets/InsetCaption.cpp index 5697e53397..dafaddef13 100644 --- a/src/insets/InsetCaption.cpp +++ b/src/insets/InsetCaption.cpp @@ -102,16 +102,16 @@ void InsetCaption::setCustomLabel(docstring const & label) } -void InsetCaption::addToToc(ParConstIterator const & cpit) const +void InsetCaption::addToToc(DocIterator const & cpit) { if (type_.empty()) return; - ParConstIterator pit = cpit; - pit.push_back(*this); + DocIterator pit = cpit; + pit.push_back(CursorSlice(*this)); Toc & toc = buffer().tocBackend().toc(type_); - docstring const str = full_label_ + ". " + pit->asString(false); + docstring const str = full_label_ + ". " + text_.getPar(0).asString(false); toc.push_back(TocItem(pit, 0, str)); } diff --git a/src/insets/InsetCaption.h b/src/insets/InsetCaption.h index 4f7aa9a981..f5b4bba0f2 100644 --- a/src/insets/InsetCaption.h +++ b/src/insets/InsetCaption.h @@ -71,7 +71,7 @@ private: /// void setCustomLabel(docstring const & label); /// - void addToToc(ParConstIterator const &) const; + void addToToc(DocIterator const &); /// virtual bool forceEmptyLayout(idx_type = 0) const { return true; } /// Captions don't accept alignment, spacing, etc. diff --git a/src/insets/InsetCitation.cpp b/src/insets/InsetCitation.cpp index c41cd370ef..ea5700e559 100644 --- a/src/insets/InsetCitation.cpp +++ b/src/insets/InsetCitation.cpp @@ -427,7 +427,7 @@ void InsetCitation::updateLabels(ParIterator const &) } -void InsetCitation::addToToc(ParConstIterator const & cpit) const +void InsetCitation::addToToc(DocIterator const & cpit) { Toc & toc = buffer().tocBackend().toc("citation"); toc.push_back(TocItem(cpit, 0, cache.screen_label)); diff --git a/src/insets/InsetCitation.h b/src/insets/InsetCitation.h index a7c2ce02cc..b0399d0898 100644 --- a/src/insets/InsetCitation.h +++ b/src/insets/InsetCitation.h @@ -54,7 +54,7 @@ public: /// void updateLabels(ParIterator const & it); /// - void addToToc(ParConstIterator const &) const; + void addToToc(DocIterator const &); /// static ParamInfo const & findInfo(std::string const &); diff --git a/src/insets/InsetFoot.cpp b/src/insets/InsetFoot.cpp index 2785c51a68..9b5e1f65a8 100644 --- a/src/insets/InsetFoot.cpp +++ b/src/insets/InsetFoot.cpp @@ -64,13 +64,12 @@ void InsetFoot::updateLabels(ParIterator const & it) } -void InsetFoot::addToToc(ParConstIterator const & cpit) const +void InsetFoot::addToToc(DocIterator const & cpit) { - ParConstIterator pit = cpit; - pit.push_back(*this); + DocIterator pit = cpit; + pit.push_back(CursorSlice(*this)); Toc & toc = buffer().tocBackend().toc("footnote"); - // FIXME: we probably want the footnote number too. docstring str; str = custom_label_ + ": " + getNewLabel(str); toc.push_back(TocItem(pit, 0, str)); diff --git a/src/insets/InsetFoot.h b/src/insets/InsetFoot.h index 8e2e3989fb..64e6249711 100644 --- a/src/insets/InsetFoot.h +++ b/src/insets/InsetFoot.h @@ -42,7 +42,7 @@ private: /// Update the counters of this inset and of its contents void updateLabels(ParIterator const &); /// - void addToToc(ParConstIterator const &) const; + void addToToc(DocIterator const &); /// docstring toolTip(BufferView const & bv, int x, int y) const; /// diff --git a/src/insets/InsetGraphics.cpp b/src/insets/InsetGraphics.cpp index 62edf121f1..d2ac809aa5 100644 --- a/src/insets/InsetGraphics.cpp +++ b/src/insets/InsetGraphics.cpp @@ -907,7 +907,7 @@ void InsetGraphics::editGraphics(InsetGraphicsParams const & p, } -void InsetGraphics::addToToc(ParConstIterator const & cpit) const +void InsetGraphics::addToToc(DocIterator const & cpit) { TocBackend & backend = buffer().tocBackend(); diff --git a/src/insets/InsetGraphics.h b/src/insets/InsetGraphics.h index cca885784f..bfb4784aed 100644 --- a/src/insets/InsetGraphics.h +++ b/src/insets/InsetGraphics.h @@ -105,7 +105,7 @@ private: /// bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const; /// - void addToToc(ParConstIterator const &) const; + void addToToc(DocIterator const &); /// docstring contextMenu(BufferView const & bv, int x, int y) const; /// Force inset into LTR environment if surroundings are RTL? diff --git a/src/insets/InsetInclude.cpp b/src/insets/InsetInclude.cpp index f80913722f..f04f170b05 100644 --- a/src/insets/InsetInclude.cpp +++ b/src/insets/InsetInclude.cpp @@ -880,7 +880,7 @@ void InsetInclude::addPreview(graphics::PreviewLoader & ploader) const } -void InsetInclude::addToToc(ParConstIterator const & cpit) const +void InsetInclude::addToToc(DocIterator const & cpit) { TocBackend & backend = buffer().tocBackend(); @@ -895,8 +895,8 @@ void InsetInclude::addToToc(ParConstIterator const & cpit) const Toc & toc = backend.toc("listing"); docstring str = convert(toc.size() + 1) + ". " + from_utf8(caption); - ParConstIterator pit = cpit; - pit.push_back(*this); + DocIterator pit = cpit; + pit.push_back(CursorSlice(*this)); toc.push_back(TocItem(pit, 0, str)); return; } diff --git a/src/insets/InsetInclude.h b/src/insets/InsetInclude.h index d06815100f..e2c3a8a268 100644 --- a/src/insets/InsetInclude.h +++ b/src/insets/InsetInclude.h @@ -84,7 +84,7 @@ public: /// void addPreview(graphics::PreviewLoader &) const; /// - void addToToc(ParConstIterator const &) const; + void addToToc(DocIterator const &); /// void updateLabels(ParIterator const &); /// diff --git a/src/insets/InsetIndex.cpp b/src/insets/InsetIndex.cpp index c6a008c5f1..9733467679 100644 --- a/src/insets/InsetIndex.cpp +++ b/src/insets/InsetIndex.cpp @@ -93,10 +93,10 @@ void InsetIndex::write(ostream & os) const } -void InsetIndex::addToToc(ParConstIterator const & cpit) const +void InsetIndex::addToToc(DocIterator const & cpit) { - ParConstIterator pit = cpit; - pit.push_back(*this); + DocIterator pit = cpit; + pit.push_back(CursorSlice(*this)); Toc & toc = buffer().tocBackend().toc("index"); docstring str; diff --git a/src/insets/InsetIndex.h b/src/insets/InsetIndex.h index 513a0eb2d1..092311c64c 100644 --- a/src/insets/InsetIndex.h +++ b/src/insets/InsetIndex.h @@ -41,7 +41,7 @@ private: /// should paragraph indendation be omitted in any case? bool neverIndent() const { return true; } /// - void addToToc(ParConstIterator const &) const; + void addToToc(DocIterator const &); /// Inset * clone() const { return new InsetIndex(*this); } }; diff --git a/src/insets/InsetLabel.cpp b/src/insets/InsetLabel.cpp index 65247a2971..55ab479fa2 100644 --- a/src/insets/InsetLabel.cpp +++ b/src/insets/InsetLabel.cpp @@ -111,7 +111,7 @@ void InsetLabel::updateLabels(ParIterator const &) } -void InsetLabel::addToToc(ParConstIterator const & cpit) const +void InsetLabel::addToToc(DocIterator const & cpit) { docstring const & label = getParam("name"); Toc & toc = buffer().tocBackend().toc("label"); @@ -124,7 +124,7 @@ void InsetLabel::addToToc(ParConstIterator const & cpit) const Buffer::References::const_iterator it = refs.begin(); Buffer::References::const_iterator end = refs.end(); for (; it != end; ++it) { - ParConstIterator const ref_pit(it->second); + DocIterator const ref_pit(it->second); toc.push_back(TocItem(ref_pit, 1, it->first->screenLabel())); } } diff --git a/src/insets/InsetLabel.h b/src/insets/InsetLabel.h index d7daae3461..33ba32ebc2 100644 --- a/src/insets/InsetLabel.h +++ b/src/insets/InsetLabel.h @@ -53,7 +53,7 @@ public: /// void updateLabels(ParIterator const & it); /// - void addToToc(ParConstIterator const &) const; + void addToToc(DocIterator const &); /// void updateCommand(docstring const & new_label, bool updaterefs = true); protected: diff --git a/src/insets/InsetMarginal.cpp b/src/insets/InsetMarginal.cpp index 46485e4394..d9deba880a 100644 --- a/src/insets/InsetMarginal.cpp +++ b/src/insets/InsetMarginal.cpp @@ -66,10 +66,10 @@ int InsetMarginal::docbook(odocstream & os, } -void InsetMarginal::addToToc(ParConstIterator const & cpit) const +void InsetMarginal::addToToc(DocIterator const & cpit) { - ParConstIterator pit = cpit; - pit.push_back(*this); + DocIterator pit = cpit; + pit.push_back(CursorSlice(*this)); Toc & toc = buffer().tocBackend().toc("marginalnote"); docstring str; diff --git a/src/insets/InsetMarginal.h b/src/insets/InsetMarginal.h index 1899cf8d72..69b3bdec18 100644 --- a/src/insets/InsetMarginal.h +++ b/src/insets/InsetMarginal.h @@ -39,7 +39,7 @@ public: /// docstring editMessage() const; /// - void addToToc(ParConstIterator const &) const; + void addToToc(DocIterator const &); private: /// Inset * clone() const { return new InsetMarginal(*this); } diff --git a/src/insets/InsetNote.cpp b/src/insets/InsetNote.cpp index 133f14d478..c8dededc59 100644 --- a/src/insets/InsetNote.cpp +++ b/src/insets/InsetNote.cpp @@ -221,10 +221,10 @@ bool InsetNote::getStatus(Cursor & cur, FuncRequest const & cmd, } -void InsetNote::addToToc(ParConstIterator const & cpit) const +void InsetNote::addToToc(DocIterator const & cpit) { - ParConstIterator pit = cpit; - pit.push_back(*this); + DocIterator pit = cpit; + pit.push_back(CursorSlice(*this)); Toc & toc = buffer().tocBackend().toc("note"); docstring str; diff --git a/src/insets/InsetNote.h b/src/insets/InsetNote.h index bf5ca70a3f..d588f011aa 100644 --- a/src/insets/InsetNote.h +++ b/src/insets/InsetNote.h @@ -95,7 +95,7 @@ private: /// bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const; /// - void addToToc(ParConstIterator const &) const; + void addToToc(DocIterator const &); /// void doDispatch(Cursor & cur, FuncRequest & cmd); /// diff --git a/src/insets/InsetRef.cpp b/src/insets/InsetRef.cpp index b62839c162..f0c45db39c 100644 --- a/src/insets/InsetRef.cpp +++ b/src/insets/InsetRef.cpp @@ -142,7 +142,7 @@ void InsetRef::updateLabels(ParIterator const & it) } -void InsetRef::addToToc(ParConstIterator const & cpit) const +void InsetRef::addToToc(DocIterator const & cpit) { docstring const & label = getParam("reference"); if (buffer().insetLabel(label)) diff --git a/src/insets/InsetRef.h b/src/insets/InsetRef.h index 1af31fa3f8..78ddbbdbeb 100644 --- a/src/insets/InsetRef.h +++ b/src/insets/InsetRef.h @@ -67,7 +67,7 @@ public: /// void updateLabels(ParIterator const & it); /// - void addToToc(ParConstIterator const &) const; + void addToToc(DocIterator const &); protected: /// InsetRef(InsetRef const &); diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp index 208f10f04d..8231d2cb38 100644 --- a/src/insets/InsetText.cpp +++ b/src/insets/InsetText.cpp @@ -423,7 +423,7 @@ ParagraphList & InsetText::paragraphs() } -//void InsetInclude::addToToc(ParConstIterator const & cpit) const +//void InsetInclude::addToToc(DocIterator const & cpit) //{ //} diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp index dcb9e9a7a7..c9e540bed6 100644 --- a/src/mathed/InsetMathHull.cpp +++ b/src/mathed/InsetMathHull.cpp @@ -236,7 +236,7 @@ void InsetMathHull::updateLabels(ParIterator const & it) } -void InsetMathHull::addToToc(ParConstIterator const & pit) const +void InsetMathHull::addToToc(DocIterator const & pit) { if (!buffer_) { //FIXME: buffer_ should be set at creation for this inset! Problem is @@ -245,10 +245,6 @@ void InsetMathHull::addToToc(ParConstIterator const & pit) const return; } - // FIXME: it would be way better to directly use InsetLabel instead of this - // label list. But it should be possible to copy&paste the code in - // InsetLabel::addToToc() anyway. - Toc & toc = buffer().tocBackend().toc("equation"); for (row_type row = 0; row != nrows(); ++row) { diff --git a/src/mathed/InsetMathHull.h b/src/mathed/InsetMathHull.h index 927ef15db2..f441687b5f 100644 --- a/src/mathed/InsetMathHull.h +++ b/src/mathed/InsetMathHull.h @@ -38,7 +38,7 @@ public: /// void updateLabels(ParIterator const &); /// - void addToToc(ParConstIterator const &) const; + void addToToc(DocIterator const &); /// InsetMathHull & operator=(InsetMathHull const &); ///