From d2b70ea0e60a0bba695ccba4711b7d7e8774d5c4 Mon Sep 17 00:00:00 2001 From: John Levon Date: Fri, 14 Feb 2003 02:21:01 +0000 Subject: [PATCH] Replace ugly getParFromID() code with ParIterator-based stuff. I think we can do the same for getInsetFromID() but Juergen didn't answer my query. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6145 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 9 +++++++++ src/buffer.C | 19 +++++++++++-------- src/insets/ChangeLog | 11 +++++++++++ src/insets/inset.h | 8 ++------ src/insets/insetcollapsable.C | 7 ------- src/insets/insetcollapsable.h | 2 -- src/insets/insettabular.C | 13 ------------- src/insets/insettabular.h | 2 -- src/insets/insettext.C | 17 ----------------- src/insets/insettext.h | 2 -- src/paragraph.C | 6 ------ src/paragraph.h | 3 --- src/paragraph_pimpl.C | 13 ------------- src/paragraph_pimpl.h | 2 -- 14 files changed, 33 insertions(+), 81 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index c6495e0797..2dcf8199ff 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,12 @@ +2003-02-14 John Levon + + * buffer.C: use ParIterator for getParFromID() + + * paragraph.h: + * paragraph.C: + * paragraph_pimpl.h: + * paragraph_pimpl.C: remove unused getParFromID() + 2003-02-14 John Levon * buffer.C: remove some very old #if 0'd parse code diff --git a/src/buffer.C b/src/buffer.C index 8c7c7c5e41..04e3254105 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -3413,18 +3413,21 @@ Paragraph * Buffer::getParFromID(int id) const { if (id < 0) return 0; + + // why should we allow < 0 ?? + //lyx::Assert(id >= 0); + + ParConstIterator it(par_iterator_begin()); + ParConstIterator end(par_iterator_end()); - ParagraphList::iterator it = paragraphs.begin(); - ParagraphList::iterator end = paragraphs.end(); for (; it != end; ++it) { - if (it->id() == id) { - return &*it; - } - Paragraph * tmp = it->getParFromID(id); - if (tmp) { - return tmp; + // go on then, show me how to remove + // the cast + if ((*it)->id() == id) { + return const_cast(*it); } } + return 0; } diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 3aaefa26da..0352364794 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,14 @@ +2003-02-14 John Levon + + * inset.h: + * inset.C: + * insetcollapsable.h: + * insetcollapsable.C: + * insettabular.h: + * insettabular.C: + * insettext.h: + * insettext.C: remove unused getParFromID() + 2003-02-13 John Levon * insettext.h: diff --git a/src/insets/inset.h b/src/insets/inset.h index 5b297910cb..4957a395fb 100644 --- a/src/insets/inset.h +++ b/src/insets/inset.h @@ -201,7 +201,7 @@ public: virtual bool isTextInset() const { return false; } /// virtual bool doClearArea() const { return true; } - /// + /// return true if the inset should be removed automatically virtual bool autoDelete() const; /// returns true the inset can hold an inset of given type virtual bool insetAllowed(Inset::Code) const { return false; } @@ -288,11 +288,7 @@ public: return scx; return 0; } - /// try to get a paragraph pointer from it's id if we have a - /// paragraph to give back! - virtual Paragraph * getParFromID(int /* id */) const { - return 0; - } + /// try to get a inset pointer from it's id if we have /// an inset to give back! virtual Inset * getInsetFromID(int /* id */) const { diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index d646ce2295..5ae85084a0 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -608,13 +608,6 @@ int InsetCollapsable::scroll(bool recursive) const } -Paragraph * InsetCollapsable::getParFromID(int id) const -{ - lyxerr[Debug::INFO] << "Looking for paragraph " << id << endl; - return inset.getParFromID(id); -} - - Paragraph * InsetCollapsable::firstParagraph() const { return inset.firstParagraph(); diff --git a/src/insets/insetcollapsable.h b/src/insets/insetcollapsable.h index ad42fda8ad..f29428a3f7 100644 --- a/src/insets/insetcollapsable.h +++ b/src/insets/insetcollapsable.h @@ -150,8 +150,6 @@ public: UpdatableInset::scroll(bv, offset); } /// - Paragraph * getParFromID(int id) const; - /// Inset * getInsetFromID(int id) const; /// Paragraph * firstParagraph() const; diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index 23a31b653a..67d342a301 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -2664,19 +2664,6 @@ void InsetTabular::getSelection(int & srow, int & erow, } -Paragraph * InsetTabular::getParFromID(int id) const -{ - Paragraph * result; - for(int i = 0; i < tabular->rows(); ++i) { - for(int j = 0; j < tabular->columns(); ++j) { - if ((result = tabular->GetCellInset(i, j)->getParFromID(id))) - return result; - } - } - return 0; -} - - Paragraph * InsetTabular::firstParagraph() const { if (the_locking_inset) diff --git a/src/insets/insettabular.h b/src/insets/insettabular.h index d76d5d8656..11275a1298 100644 --- a/src/insets/insettabular.h +++ b/src/insets/insettabular.h @@ -196,8 +196,6 @@ public: UpdatableInset::scroll(bv, offset); } /// - Paragraph * getParFromID(int id) const; - /// Inset * getInsetFromID(int id) const; /// Paragraph * firstParagraph() const; diff --git a/src/insets/insettext.C b/src/insets/insettext.C index 3cc873c390..d445cff169 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -2515,23 +2515,6 @@ void InsetText::clearInset(BufferView * bv, int baseline, bool & cleared) const } -Paragraph * InsetText::getParFromID(int id) const -{ - ParagraphList::iterator it = paragraphs.begin(); - ParagraphList::iterator end = paragraphs.end(); - for (; it != end; ++it) { - if (it->id() == id) { - return &*(it); - } - Paragraph * tmp2 = it->getParFromID(id); - if (tmp2 != 0) { - return tmp2; - } - } - return 0; -} - - Paragraph * InsetText::firstParagraph() const { Paragraph * result; diff --git a/src/insets/insettext.h b/src/insets/insettext.h index 295e3c6177..710711b2af 100644 --- a/src/insets/insettext.h +++ b/src/insets/insettext.h @@ -203,8 +203,6 @@ public: /// void clearSelection(BufferView * bv); /// - Paragraph * getParFromID(int id) const; - /// Inset * getInsetFromID(int id) const; /// Paragraph * firstParagraph() const; diff --git a/src/paragraph.C b/src/paragraph.C index a38fe6e8c6..4e99c73185 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -1978,12 +1978,6 @@ ParagraphParameters const & Paragraph::params() const } -Paragraph * Paragraph::getParFromID(int id) const -{ - return pimpl_->getParFromID(id); -} - - bool Paragraph::isFreeSpacing() const { // for now we just need this, later should we need this in some diff --git a/src/paragraph.h b/src/paragraph.h index f6bdd55d98..7b749821c5 100644 --- a/src/paragraph.h +++ b/src/paragraph.h @@ -307,9 +307,6 @@ public: /// returns -1 if inset not found int getPositionOfInset(Inset const * inset) const; - /// some good comment here John? - Paragraph * getParFromID(int id) const; - /// int stripLeadingSpaces(); diff --git a/src/paragraph_pimpl.C b/src/paragraph_pimpl.C index bcc504112c..285a555f8d 100644 --- a/src/paragraph_pimpl.C +++ b/src/paragraph_pimpl.C @@ -849,19 +849,6 @@ void Paragraph::Pimpl::validate(LaTeXFeatures & features, } -Paragraph * Paragraph::Pimpl::getParFromID(int id) const -{ - InsetList::iterator cit = owner_->insetlist.begin(); - InsetList::iterator lend = owner_->insetlist.end(); - Paragraph * result; - for (; cit != lend; ++cit) { - if ((result = cit.getInset()->getParFromID(id))) - return result; - } - return 0; -} - - LyXFont const Paragraph::Pimpl::realizeFont(LyXFont const & font, BufferParams const & bparams) const { diff --git a/src/paragraph_pimpl.h b/src/paragraph_pimpl.h index 1304ee8ddf..5ecd70bcf2 100644 --- a/src/paragraph_pimpl.h +++ b/src/paragraph_pimpl.h @@ -171,8 +171,6 @@ struct Paragraph::Pimpl { void validate(LaTeXFeatures & features, LyXLayout const & layout) const; - /// - Paragraph * getParFromID(int id) const; /// unsigned int id_; /// -- 2.39.5