From f83a38b3defc997f808539d0dfd618f5ba71e13c Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Sat, 13 Sep 2008 17:01:54 +0000 Subject: [PATCH] Paragraph::inInset() shall not be used if the owner inset was not initialized. Make this rule clear and unavoidable. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@26385 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/CutAndPaste.cpp | 1 + src/Paragraph.cpp | 24 ++++++++---------------- src/Paragraph.h | 4 ++-- src/frontends/qt4/GuiToolbar.cpp | 2 +- src/insets/InsetText.cpp | 2 +- src/paragraph_funcs.cpp | 7 +++---- 6 files changed, 16 insertions(+), 24 deletions(-) diff --git a/src/CutAndPaste.cpp b/src/CutAndPaste.cpp index 87e0803b78..901b7d7f4a 100644 --- a/src/CutAndPaste.cpp +++ b/src/CutAndPaste.cpp @@ -122,6 +122,7 @@ pasteSelectionHelper(Cursor & cur, ParagraphList const & parlist, if (insertion[i].isNewline(j)) { // do not track deletion of newline insertion[i].eraseChar(j, false); + insertion[i].setInsetOwner(target_inset); breakParagraphConservative( buffer.params(), insertion, i, j); diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp index 98cd13d811..5ab65b49a4 100644 --- a/src/Paragraph.cpp +++ b/src/Paragraph.cpp @@ -175,7 +175,7 @@ public: Paragraph * owner_; /// In which Inset? - Inset * inset_owner_; + Inset const * inset_owner_; /// FontList fontlist_; @@ -1656,28 +1656,19 @@ void Paragraph::setBeginOfBody() bool Paragraph::forcePlainLayout() const { - Inset const * const inset = inInset(); - if (!inset) - return true; - return inset->forcePlainLayout(); + return inInset().forcePlainLayout(); } bool Paragraph::allowParagraphCustomization() const { - Inset const * const inset = inInset(); - if (!inset) - return true; - return inset->allowParagraphCustomization(); + return inInset().allowParagraphCustomization(); } bool Paragraph::usePlainLayout() const { - Inset const * const inset = inInset(); - if (!inset) - return false; - return inset->usePlainLayout(); + return inInset().usePlainLayout(); } @@ -2390,7 +2381,7 @@ docstring Paragraph::asString(pos_type beg, pos_type end, int options) const } -void Paragraph::setInsetOwner(Inset * inset) +void Paragraph::setInsetOwner(Inset const * inset) { d->inset_owner_ = inset; } @@ -2423,9 +2414,10 @@ void Paragraph::setPlainOrDefaultLayout(DocumentClass const & tclass) } -Inset * Paragraph::inInset() const +Inset const & Paragraph::inInset() const { - return d->inset_owner_; + LASSERT(d->inset_owner_, exit(10)); + return *d->inset_owner_; } diff --git a/src/Paragraph.h b/src/Paragraph.h index c5bf500043..6fdb270177 100644 --- a/src/Paragraph.h +++ b/src/Paragraph.h @@ -153,9 +153,9 @@ public: void makeSameLayout(Paragraph const & par); /// - void setInsetOwner(Inset * inset); + void setInsetOwner(Inset const * inset); /// - Inset * inInset() const; + Inset const & inInset() const; /// InsetCode ownerCode() const; /// diff --git a/src/frontends/qt4/GuiToolbar.cpp b/src/frontends/qt4/GuiToolbar.cpp index 632f7b4979..aead589113 100644 --- a/src/frontends/qt4/GuiToolbar.cpp +++ b/src/frontends/qt4/GuiToolbar.cpp @@ -602,7 +602,7 @@ void GuiLayoutBox::updateContents(bool reset) // or we've moved from one inset to another DocumentClass const * text_class = &buffer->params().documentClass(); Inset const * inset = - owner_.view()->cursor().innerParagraph().inInset(); + &(owner_.view()->cursor().innerParagraph().inInset()); if (!reset && text_class_ == text_class && inset_ == inset) { set(owner_.view()->cursor().innerParagraph().layout().name()); return; diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp index cf34fc9ed0..56e9d8f031 100644 --- a/src/insets/InsetText.cpp +++ b/src/insets/InsetText.cpp @@ -103,8 +103,8 @@ void InsetText::initParagraphs(BufferParams const & bparams) LASSERT(paragraphs().empty(), /**/); paragraphs().push_back(Paragraph()); Paragraph & ourpar = paragraphs().back(); - ourpar.setPlainOrDefaultLayout(bparams.documentClass()); ourpar.setInsetOwner(this); + ourpar.setPlainOrDefaultLayout(bparams.documentClass()); } diff --git a/src/paragraph_funcs.cpp b/src/paragraph_funcs.cpp index dc32425ea2..600d361bd7 100644 --- a/src/paragraph_funcs.cpp +++ b/src/paragraph_funcs.cpp @@ -47,8 +47,7 @@ static bool moveItem(Paragraph & fromPar, pos_type fromPos, tmpInset = fromPar.releaseInset(fromPos); } - Inset * inset = toPar.inInset(); - if (inset && !inset->insetAllowed(tmpInset->lyxCode())) { + if (!toPar.inInset().insetAllowed(tmpInset->lyxCode())) { delete tmpInset; return false; } @@ -75,7 +74,7 @@ void breakParagraph(BufferParams const & bparams, Paragraph & par = pars[par_offset]; // remember to set the inset_owner - tmp->setInsetOwner(par.inInset()); + tmp->setInsetOwner(&par.inInset()); // without doing that we get a crash when typing at the // end of a paragraph tmp->setPlainOrDefaultLayout(bparams.documentClass()); @@ -163,8 +162,8 @@ void breakParagraphConservative(BufferParams const & bparams, Paragraph()); Paragraph & par = pars[par_offset]; + tmp.setInsetOwner(&par.inInset()); tmp.makeSameLayout(par); - tmp.setInsetOwner(par.inInset()); LASSERT(pos <= par.size(), /**/); -- 2.39.2