Cleanup a bit the pargraph ids generation in order to (trying to) fix

#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
This commit is contained in:
Abdelrazak Younes 2010-01-05 13:16:55 +00:00
parent 42f455cacb
commit 744ee152fa
7 changed files with 67 additions and 51 deletions

View 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());

View 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_;

View 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;

View 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
{

View 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.

View 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();

View File

@ -205,10 +205,6 @@ protected:
///
docstring getCaptionHTML(OutputParams const &) const;
private:
///
void initParagraphs(UsePlain type);
///
void setParagraphOwner();
///
bool drawFrame_;
///