]> git.lyx.org Git - features.git/commitdiff
Cleanup a bit the pargraph ids generation in order to (trying to) fix
authorAbdelrazak Younes <younes@lyx.org>
Tue, 5 Jan 2010 13:16:55 +0000 (13:16 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Tue, 5 Jan 2010 13:16:55 +0000 (13:16 +0000)
#6415
Enrico please verify that reverse dvi is fixed.

* Text and InsetText: create two private constructors and transfer some
initialisation code from InsetText.

* Paragraph: id generation is transfered to Text. May be transfered to
Buffer in the future, we'll see.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@32766 a592a061-630c-0410-9148-cb99ea01b6c8

src/Buffer.cpp
src/Paragraph.cpp
src/Paragraph.h
src/Text.cpp
src/Text.h
src/insets/InsetText.cpp
src/insets/InsetText.h

index bd7305701785929e0afe9bc9cb65aa89cb375e28..efc83fa4910a70fd0275945efb102bd739bc3ada 100644 (file)
@@ -315,9 +315,15 @@ Buffer::Buffer(string const & file, bool readonly, Buffer const * cloned_buffer)
 {
        LYXERR(Debug::INFO, "Buffer::Buffer()");
        if (cloned_buffer) {
-               d->inset = static_cast<InsetText *>(cloned_buffer->d->inset->clone());
+               d->inset = new InsetText(*cloned_buffer->d->inset);
                d->inset->setBuffer(*this);
-       } else 
+               // FIXME 1: optimize this loop somewhat, maybe by creatinga new
+               // greneral recursive Inset::setId().
+               DocIterator it = doc_iterator_begin(this);
+               DocIterator cloned_it = doc_iterator_begin(cloned_buffer);
+               for (; !it.atEnd(); it.forwardPar(), cloned_it.forwardPar())
+                       it.paragraph().setId(cloned_it.paragraph().id());
+       } else
                d->inset = new InsetText(this);
        d->inset->setAutoBreakRows(true);
        d->inset->getText(0)->setMacrocontextPosition(par_iterator_begin());
index 0711d2492bcd2aba51bdb20024d189624846a5ce..bfaec69d14f825f5c269d3fbcede6cf3049a7060 100644 (file)
@@ -189,9 +189,8 @@ public:
        FontList fontlist_;
 
        ///
-       unsigned int id_;
-       ///
-       static unsigned int paragraph_id;
+       int id_;
+
        ///
        ParagraphParameters params_;
 
@@ -216,9 +215,6 @@ public:
 };
 
 
-// Initialization of the counter for the paragraph id's,
-unsigned int Paragraph::Private::paragraph_id = 0;
-
 namespace {
 
 struct special_phrase {
@@ -240,20 +236,18 @@ size_t const phrases_nr = sizeof(special_phrases)/sizeof(special_phrase);
 
 
 Paragraph::Private::Private(Paragraph * owner, Layout const & layout)
-       : owner_(owner), inset_owner_(0), begin_of_body_(0), layout_(&layout)
+       : owner_(owner), inset_owner_(0), id_(-1), begin_of_body_(0), layout_(&layout)
 {
-       id_ = paragraph_id++;
        text_.reserve(100);
 }
 
 
 Paragraph::Private::Private(Private const & p, Paragraph * owner)
        : owner_(owner), inset_owner_(p.inset_owner_), fontlist_(p.fontlist_), 
-         params_(p.params_), changes_(p.changes_), insetlist_(p.insetlist_),
+         id_(p.id_), params_(p.params_), changes_(p.changes_), insetlist_(p.insetlist_),
          begin_of_body_(p.begin_of_body_), text_(p.text_), words_(p.words_),
          layout_(p.layout_)
 {
-       id_ = paragraph_id++;
 }
 
 
@@ -265,7 +259,6 @@ Paragraph::Private::Private(Private const & p, Paragraph * owner,
          begin_of_body_(p.begin_of_body_), words_(p.words_),
          layout_(p.layout_)
 {
-       id_ = paragraph_id++;
        if (beg >= pos_type(p.text_.size()))
                return;
        text_ = p.text_.substr(beg, end - beg);
@@ -2654,6 +2647,12 @@ int Paragraph::id() const
 }
 
 
+void Paragraph::setId(int id)
+{
+       d->id_ = id;
+}
+
+
 Layout const & Paragraph::layout() const
 {
        return *d->layout_;
index 485e239b6694dc8e04cea5f03e57db532d6296cf..761e6e9b5dbfe8b19e764372713eca0c89cc9426 100644 (file)
@@ -92,7 +92,7 @@ class Paragraph
 public:
        ///
        Paragraph();
-       ///
+       /// Copy constructor.
        Paragraph(Paragraph const &);
        /// Partial copy constructor.
        /// Copy the Paragraph contents from \p beg to \p end (without end).
@@ -103,6 +103,8 @@ public:
        ~Paragraph();
        ///
        int id() const;
+       ///
+       void setId(int id);
 
        ///
        void addChangesToToc(DocIterator const & cdit, Buffer const & buf) const;
index 5803c2d4ad07e1fca7be0574d645a9090801e26c..66c6090aa22c9abb40d8d9561fcdf82ddb7cbcb2 100644 (file)
@@ -170,6 +170,40 @@ void mergeParagraph(BufferParams const & bparams,
        pars.erase(boost::next(pars.begin(), par_offset + 1));
 }
 
+// Initialization of the counter for the paragraph id's,
+//
+// FIXME: There should be a more intelligent way to generate and use the
+// paragraph ids per buffer instead a global static counter for all InsetText
+// in the running program.
+static int paragraph_id = -1;
+
+Text::Text(InsetText * owner, bool use_default_layout)
+       : owner_(owner), autoBreakRows_(false), undo_counter_(0)
+{
+       pars_.push_back(Paragraph());
+       Paragraph & par = pars_.back();
+       par.setId(++paragraph_id);
+       par.setInsetOwner(owner);
+       DocumentClass const & dc = owner->buffer().params().documentClass();
+       if (use_default_layout)
+               par.setDefaultLayout(dc);
+       else
+               par.setPlainLayout(dc);
+}
+
+
+Text::Text(InsetText * owner, Text const & text)
+       : owner_(owner), autoBreakRows_(text.autoBreakRows_), undo_counter_(0)
+{
+       pars_ = text.pars_;
+       ParagraphList::iterator const end = pars_.end();
+       ParagraphList::iterator it = pars_.begin();
+       for (; it != end; ++it) {
+               it->setId(++paragraph_id);
+               it->setInsetOwner(owner);
+       }
+}
+
 
 pit_type Text::depthHook(pit_type pit, depth_type depth) const
 {
index c8073eec711150df87764b08b10a8573ef9d6642..98964e9b20bc4bb8faecab123cc681beb8a3d49e 100644 (file)
@@ -36,14 +36,17 @@ class Lexer;
 class PainterInfo;
 class Spacing;
 
-/// This class encapsulates the main text data and operations in LyX
+/// This class encapsulates the main text data and operations in LyX.
+/// This is more or less the private implementation of InsetText.
 class Text {
-public:
-       /// constructor
-       explicit Text(InsetText * owner)
-               : owner_(owner), autoBreakRows_(false), undo_counter_(0)
-       {}
+private:
+       /// Default constructor.
+       Text(InsetText * owner, bool use_default_layout);
 
+       /// Copy constructor.
+       Text(InsetText * owner, Text const & text);
+
+public:
        /// \return true if there's no content at all.
        /// \warning a non standard layout on an empty paragraph doesn't
        // count as empty.
index b7dc42bb72b02f0f23b02f37de2eff29bbc7f226..3c85bfd4702fb888470734d2e6423c5aa2ad198c 100644 (file)
@@ -75,20 +75,17 @@ using graphics::PreviewLoader;
 /////////////////////////////////////////////////////////////////////
 
 InsetText::InsetText(Buffer * buf, UsePlain type)
-       : Inset(buf), drawFrame_(false), frame_color_(Color_insetframe), text_(this)
+       : Inset(buf), drawFrame_(false), frame_color_(Color_insetframe),
+       text_(this, type == DefaultLayout)
 {
-       initParagraphs(type);
 }
 
 
 InsetText::InsetText(InsetText const & in)
-       : Inset(in), text_(this)
+       : Inset(in), text_(this, in.text_)
 {
-       text_.autoBreakRows_ = in.text_.autoBreakRows_;
        drawFrame_ = in.drawFrame_;
        frame_color_ = in.frame_color_;
-       text_.paragraphs() = in.text_.paragraphs();
-       setParagraphOwner();
 }
 
 
@@ -101,27 +98,6 @@ void InsetText::setBuffer(Buffer & buf)
 }
 
 
-void InsetText::initParagraphs(UsePlain type)
-{
-       LASSERT(paragraphs().empty(), /**/);
-       paragraphs().push_back(Paragraph());
-       Paragraph & ourpar = paragraphs().back();
-       ourpar.setInsetOwner(this);
-       DocumentClass const & dc = buffer_->params().documentClass();
-       if (type == DefaultLayout)
-               ourpar.setDefaultLayout(dc);
-       else
-               ourpar.setPlainLayout(dc);
-}
-
-
-void InsetText::setParagraphOwner()
-{
-       for_each(paragraphs().begin(), paragraphs().end(),
-                bind(&Paragraph::setInsetOwner, _1, this));
-}
-
-
 void InsetText::clear()
 {
        ParagraphList & pars = paragraphs();
index be3550513019cb28ff99cd614cc81ab9702b8e04..43ef3f717dd26cba86a7b23c247bbf57a7966263 100644 (file)
@@ -205,10 +205,6 @@ protected:
        ///
        docstring getCaptionHTML(OutputParams const &) const;
 private:
-       ///
-       void initParagraphs(UsePlain type);
-       ///
-       void setParagraphOwner();
        ///
        bool drawFrame_;
        ///