mostly s/Paragraph::layout(...)/Paragraph::setLayout(...)/

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23159 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2008-02-23 16:45:38 +00:00
parent 4a7b0625b3
commit 0fb8f3fba1
21 changed files with 108 additions and 124 deletions

View File

@ -127,11 +127,11 @@ pasteSelectionHelper(Cursor & cur, ParagraphList const & parlist,
// Convert newline to paragraph break in ERT inset.
// This should not be here!
if (pars[pit].inInset() &&
(pars[pit].inInset()->lyxCode() == ERT_CODE ||
pars[pit].inInset()->lyxCode() == LISTINGS_CODE)) {
for (ParagraphList::size_type i = 0; i < insertion.size(); ++i) {
for (pos_type j = 0; j < insertion[i].size(); ++j) {
Inset * inset = pars[pit].inInset();
if (inset && (inset->lyxCode() == ERT_CODE ||
inset->lyxCode() == LISTINGS_CODE)) {
for (size_t i = 0; i != insertion.size(); ++i) {
for (pos_type j = 0; j != insertion[i].size(); ++j) {
if (insertion[i].isNewline(j)) {
// do not track deletion of newline
insertion[i].eraseChar(j, false);
@ -152,7 +152,7 @@ pasteSelectionHelper(Cursor & cur, ParagraphList const & parlist,
ParagraphList::iterator const end = insertion.end();
for (ParagraphList::iterator par = insertion.begin();
par != end; ++par)
par->layout(layout);
par->setLayout(layout);
}
// Make sure there is no class difference.
@ -421,9 +421,9 @@ void switchBetweenClasses(TextClassIndex const & oldtcindex,
bool hasLayout = newtc.hasLayout(name);
if (hasLayout)
it->layout(newtc[name]);
it->setLayout(newtc[name]);
else
it->layout(newtc.defaultLayout());
it->setLayout(newtc.defaultLayout());
if (!hasLayout && name != oldtc.defaultLayoutName()) {
docstring const s = bformat(
@ -621,7 +621,7 @@ void copySelectionToStack(Cursor & cur, CutStack & cutstack)
ParagraphList pars;
Paragraph par;
BufferParams const & bp = cur.buffer().params();
par.layout(bp.textClass().defaultLayout());
par.setLayout(bp.textClass().defaultLayout());
par.insert(0, grabSelection(cur), Font(), Change(Change::UNCHANGED));
pars.push_back(par);
cutstack.push(make_pair(pars, bp.textClassIndex()));
@ -648,7 +648,7 @@ void copySelection(Cursor & cur, docstring const & plaintext)
ParagraphList pars;
Paragraph par;
BufferParams const & bp = cur.buffer().params();
par.layout(bp.textClass().defaultLayout());
par.setLayout(bp.textClass().defaultLayout());
par.insert(0, plaintext, Font(), Change(Change::UNCHANGED));
pars.push_back(par);
theCuts.push(make_pair(pars, bp.textClassIndex()));

View File

@ -223,14 +223,9 @@ bool Layout::read(Lexer & lexrc, TextClass const & tclass)
<< to_utf8(style) << "'\n"
<< "All layouts so far:"
<< endl;
TextClass::const_iterator it =
tclass.begin();
TextClass::const_iterator end =
tclass.end();
for (; it != end; ++it) {
lyxerr << to_utf8((*it)->name())
for (size_t i = 0; i != tclass.layoutCount(); ++i)
lyxerr << to_utf8(tclass.layout(i)->name())
<< endl;
}
//lexrc.printError("Cannot copy known "
// "style `$$Token'");

View File

@ -640,10 +640,10 @@ void expandFlexInsert(Menu & tomenu, Buffer const * buf, string s)
FuncRequest(LFUN_NOACTION)));
return;
}
InsetLayouts const & insetlayouts =
buf->params().textClass().insetlayouts();
InsetLayouts::const_iterator cit = insetlayouts.begin();
InsetLayouts::const_iterator end = insetlayouts.end();
InsetLayouts const & insetLayouts =
buf->params().textClass().insetLayouts();
InsetLayouts::const_iterator cit = insetLayouts.begin();
InsetLayouts::const_iterator end = insetLayouts.end();
for (; cit != end; ++cit) {
docstring const label = cit->first;
if (cit->second.lyxtype() == s)

View File

@ -1473,7 +1473,7 @@ char Paragraph::getAlign() const
}
docstring const & Paragraph::getLabelstring() const
docstring const & Paragraph::labelString() const
{
return d->params_.labelString();
}
@ -2334,9 +2334,18 @@ LayoutPtr const & Paragraph::layout() const
}
void Paragraph::layout(LayoutPtr const & new_layout)
void Paragraph::setLayout(LayoutPtr const & layout)
{
d->layout_ = new_layout;
d->layout_ = layout;
}
void Paragraph::setEmptyOrDefaultLayout(TextClass const & tclass)
{
if (useEmptyLayout())
setLayout(tclass.emptyLayout());
else
setLayout(tclass.defaultLayout());
}

View File

@ -43,6 +43,7 @@ class MetricsInfo;
class OutputParams;
class PainterInfo;
class ParagraphParameters;
class TextClass;
class TexRow;
@ -158,7 +159,9 @@ public:
///
LayoutPtr const & layout() const;
///
void layout(LayoutPtr const & new_layout);
void setLayout(LayoutPtr const & layout);
///
void setEmptyOrDefaultLayout(TextClass const & tc);
/// This is the item depth, only used by enumerate and itemize
signed char itemdepth;
@ -201,7 +204,7 @@ public:
void setBeginOfBody();
///
docstring const & getLabelstring() const;
docstring const & labelString() const;
/// the next two functions are for the manual labels
docstring const getLabelWidthString() const;

View File

@ -125,12 +125,12 @@ void readParToken(Buffer const & buf, Paragraph & par, Lexer & lex,
tclass.defaultLayoutName();
}
par.layout(bp.textClass()[layoutname]);
par.setLayout(bp.textClass()[layoutname]);
// Test whether the layout is obsolete.
LayoutPtr const & layout = par.layout();
if (!layout->obsoleted_by().empty())
par.layout(bp.textClass()[layout->obsoleted_by()]);
par.setLayout(bp.textClass()[layout->obsoleted_by()]);
par.params().read(lex);
@ -340,8 +340,7 @@ bool Text::empty() const
}
double Text::spacing(Buffer const & buffer,
Paragraph const & par) const
double Text::spacing(Buffer const & buffer, Paragraph const & par) const
{
if (par.params().spacing().isDefault())
return buffer.params().spacing().getValue();
@ -929,9 +928,9 @@ bool Text::handleBibitems(Cursor & cur)
// otherwise reset to default
if (par.useEmptyLayout())
cur.paragraph().layout(bufparams.textClass().emptyLayout());
cur.paragraph().setLayout(bufparams.textClass().emptyLayout());
else
cur.paragraph().layout(bufparams.textClass().defaultLayout());
cur.paragraph().setLayout(bufparams.textClass().defaultLayout());
return true;
}

View File

@ -219,10 +219,8 @@ static bool doInsertInset(Cursor & cur, Text * text,
InsetText * insetText = dynamic_cast<InsetText *>(inset);
if (insetText && !insetText->allowMultiPar() || cur.lastpit() == 0) {
// reset first par to default
LayoutPtr const layout = insetText->useEmptyLayout()
? bparams.textClass().emptyLayout()
: bparams.textClass().defaultLayout();
cur.text()->paragraphs().begin()->layout(layout);
cur.text()->paragraphs().begin()
->setEmptyOrDefaultLayout(bparams.textClass());
cur.pos() = 0;
cur.pit() = 0;
// Merge multiple paragraphs -- hack
@ -268,8 +266,7 @@ static void outline(OutlineOp mode, Cursor & cur)
ParagraphList::iterator finish = start;
ParagraphList::iterator end = pars.end();
TextClass::const_iterator lit = buf.params().textClass().begin();
TextClass::const_iterator const lend = buf.params().textClass().end();
TextClass const & tc = buf.params().textClass();
int const thistoclevel = start->layout()->toclevel;
int toclevel;
@ -344,20 +341,22 @@ static void outline(OutlineOp mode, Cursor & cur)
}
case OutlineIn:
buf.undo().recordUndo(cur);
for (; lit != lend; ++lit) {
if ((*lit)->toclevel == thistoclevel + 1 &&
start->layout()->labeltype == (*lit)->labeltype) {
start->layout((*lit));
for (size_t i = 0; i != tc.layoutCount(); ++i) {
LayoutPtr const & lt = tc.layout(i);
if (lt->toclevel == thistoclevel + 1 &&
start->layout()->labeltype == lt->labeltype) {
start->setLayout(lt);
break;
}
}
break;
case OutlineOut:
buf.undo().recordUndo(cur);
for (; lit != lend; ++lit) {
if ((*lit)->toclevel == thistoclevel - 1 &&
start->layout()->labeltype == (*lit)->labeltype) {
start->layout((*lit));
for (size_t i = 0; i != tc.layoutCount(); ++i) {
LayoutPtr const & lt = tc.layout(i);
if (lt->toclevel == thistoclevel - 1 &&
start->layout()->labeltype == lt->labeltype) {
start->setLayout(lt);
break;
}
}
@ -1390,11 +1389,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
// add a separate paragraph for the caption inset
pars.push_back(Paragraph());
pars.back().setInsetOwner(pars[0].inInset());
if (pars.back().useEmptyLayout())
pars.back().layout(tclass.emptyLayout());
else
pars.back().layout(tclass.defaultLayout());
pars.back().setEmptyOrDefaultLayout(tclass);
int cap_pit = pars.size() - 1;
// if an empty inset was created, we create an additional empty
@ -1403,10 +1398,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
if (!content) {
pars.push_back(Paragraph());
pars.back().setInsetOwner(pars[0].inInset());
if (pars.back().useEmptyLayout())
pars.back().layout(tclass.emptyLayout());
else
pars.back().layout(tclass.defaultLayout());
pars.back().setEmptyOrDefaultLayout(tclass);
}
// reposition the cursor to the caption
@ -1954,7 +1946,7 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
case LFUN_FLEX_INSERT: {
code = FLEX_CODE;
string s = cmd.getArg(0);
InsetLayout il = cur.buffer().params().textClass().insetlayout(from_utf8(s));
InsetLayout il = cur.buffer().params().textClass().insetLayout(from_utf8(s));
if (il.lyxtype() != "charstyle" &&
il.lyxtype() != "custom" &&
il.lyxtype() != "element" &&

View File

@ -539,18 +539,14 @@ bool TextClass::read(FileName const & filename, ReadType rt)
min_toclevel_ = Layout::NOT_IN_TOC;
max_toclevel_ = Layout::NOT_IN_TOC;
const_iterator cit = begin();
const_iterator the_end = end();
for ( ; cit != the_end ; ++cit) {
int const toclevel = (*cit)->toclevel;
for (size_t i = 0; i != layoutCount(); ++i) {
int const toclevel = layout(i)->toclevel;
if (toclevel != Layout::NOT_IN_TOC) {
if (min_toclevel_ == Layout::NOT_IN_TOC)
min_toclevel_ = toclevel;
else
min_toclevel_ = min(min_toclevel_,
toclevel);
max_toclevel_ = max(max_toclevel_,
toclevel);
min_toclevel_ = min(min_toclevel_, toclevel);
max_toclevel_ = max(max_toclevel_, toclevel);
}
}
LYXERR(Debug::TCLASS, "Minimum TocLevel is " << min_toclevel_
@ -978,13 +974,13 @@ Counters & TextClass::counters() const
// will invoke the layout object defined by name = 'CharStyle'.
// If that doesn't work either, an empty object returns (shouldn't
// happen). -- Idea JMarc, comment MV
InsetLayout const & TextClass::insetlayout(docstring const & name) const
InsetLayout const & TextClass::insetLayout(docstring const & name) const
{
docstring n = name;
while (!n.empty()) {
if (insetlayoutlist_.count(n) > 0)
return insetlayoutlist_[n];
docstring::size_type i = n.find(':');
size_t i = n.find(':');
if (i == string::npos)
break;
n = n.substr(0,i);

View File

@ -58,8 +58,6 @@ class TextClass {
public:
/// The individual styles comprising the document class
typedef std::vector<LayoutPtr> LayoutList;
/// Enumerate the paragraph styles.
typedef LayoutList::const_iterator const_iterator;
/// Construct a layout with default values. Actual values loaded later.
explicit
TextClass(std::string const & = std::string(),
@ -70,12 +68,12 @@ public:
/// check whether the TeX class is available
bool isTeXClassAvailable() const;
/// paragraph styles begin iterator.
const_iterator begin() const { return layoutlist_.begin(); }
/// paragraph styles end iterator
const_iterator end() const { return layoutlist_.end(); }
/// Enumerate the paragraph styles.
size_t layoutCount() const { return layoutlist_.size(); }
/// Access the paragraph styles.
LayoutPtr const & layout(size_t index) const { return layoutlist_[index]; }
///Enum used with TextClass::read
/// Enum used with TextClass::read
enum ReadType {
BASECLASS, //>This is a base class, i.e., top-level layout file
MERGE, //>This is a file included in a layout file
@ -116,9 +114,9 @@ public:
/// The Counters present in this document class.
Counters & counters() const;
/// Inset layouts of this doc class
InsetLayouts & insetlayouts() const { return insetlayoutlist_; };
InsetLayouts & insetLayouts() const { return insetlayoutlist_; };
///
InsetLayout const & insetlayout(docstring const & name) const;
InsetLayout const & insetLayout(docstring const & name) const;
///
docstring const & defaultLayoutName() const;
///

View File

@ -998,7 +998,7 @@ Dimension TextMetrics::rowHeight(pit_type const pit, pos_type const first,
|| layout->labeltype == LABEL_BIBLIO
|| layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)
&& isFirstInSequence(pit, pars)
&& !par.getLabelstring().empty())
&& !par.labelString().empty())
{
labeladdon = int(
labelfont_metrics.maxHeight()
@ -1810,9 +1810,9 @@ int TextMetrics::leftMargin(int max_width,
l_margin += theFontMetrics(buffer.params().getFont()).signedWidth(
layout->leftmargin);
}
if (!par.getLabelstring().empty()) {
if (!par.labelString().empty()) {
l_margin += labelfont_metrics.signedWidth(layout->labelindent);
l_margin += labelfont_metrics.width(par.getLabelstring());
l_margin += labelfont_metrics.width(par.labelString());
l_margin += labelfont_metrics.width(layout->labelsep);
}
break;
@ -1856,7 +1856,7 @@ int TextMetrics::leftMargin(int max_width,
LABEL_CENTERED_TOP_ENVIRONMENT) {
l_margin += labelfont_metrics.signedWidth(layout->labelindent);
l_margin += labelfont_metrics.width(layout->labelsep);
l_margin += labelfont_metrics.width(par.getLabelstring());
l_margin += labelfont_metrics.width(par.labelString());
}
break;

View File

@ -125,8 +125,8 @@ void TocBackend::updateItem(ParConstIterator const & par_it)
break;
Paragraph const & par =
*static_cast<InsetOptArg&>(inset).paragraphs().begin();
if (!toc_item->par_it_->getLabelstring().empty())
tocstring = toc_item->par_it_->getLabelstring() + ' ';
if (!toc_item->par_it_->labelString().empty())
tocstring = toc_item->par_it_->labelString() + ' ';
tocstring += par.asString(*buffer_, false);
break;
}
@ -169,8 +169,8 @@ void TocBackend::update()
break;
Paragraph const & par =
*static_cast<InsetOptArg&>(inset).paragraphs().begin();
if (!pit->getLabelstring().empty())
tocstring = pit->getLabelstring() + ' ';
if (!pit->labelString().empty())
tocstring = pit->labelString() + ' ';
tocstring += par.asString(*buffer_, false);
break;
}

View File

@ -518,7 +518,7 @@ GuiDocument::GuiDocument(GuiView & lv)
this, SLOT(change_adaptor()));
connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
this, SLOT(setLSpacing(int)));
connect(textLayoutModule->lspacingLE, SIGNAL(textChanged(const QString&)),
connect(textLayoutModule->lspacingLE, SIGNAL(textChanged(const QString &)),
this, SLOT(change_adaptor()));
connect(textLayoutModule->skipRB, SIGNAL(clicked()),
this, SLOT(change_adaptor()));
@ -1363,15 +1363,13 @@ void GuiDocument::updateNumbering()
int const toc = numberingModule->tocSL->value();
QString const no = qt_("No");
QString const yes = qt_("Yes");
TextClass::const_iterator end = tclass.end();
TextClass::const_iterator cit = tclass.begin();
QTreeWidgetItem * item = 0;
for ( ; cit != end ; ++cit) {
int const toclevel = (*cit)->toclevel;
if (toclevel != Layout::NOT_IN_TOC
&& (*cit)->labeltype == LABEL_COUNTER) {
for (size_t i = 0; i != tclass.layoutCount(); ++i) {
Layout const & lt = *tclass.layout(i);
int const toclevel = lt.toclevel;
if (toclevel != Layout::NOT_IN_TOC && lt.labeltype == LABEL_COUNTER) {
item = new QTreeWidgetItem(numberingModule->tocTW);
item->setText(0, toqstr(translateIfPossible((*cit)->name())));
item->setText(0, toqstr(translateIfPossible(lt.name())));
item->setText(1, (toclevel <= depth) ? yes : no);
item->setText(2, (toclevel <= toc) ? yes : no);
}

View File

@ -323,11 +323,10 @@ void GuiLayoutBox::updateContents(bool reset)
text_class_ = text_class;
clear();
TextClass::const_iterator it = text_class_->begin();
TextClass::const_iterator const end = text_class_->end();
for (; it != end; ++it) {
docstring const & name = (*it)->name();
for (size_t i = 0; i != text_class_->layoutCount(); ++i) {
Layout const & lt = *text_class_->layout(i);
docstring const & name = lt.name();
// if this inset requires the empty layout, we skip the default
// layout
if (name == text_class_->defaultLayoutName() && inset &&
@ -359,14 +358,12 @@ void GuiLayoutBox::selected(const QString & str)
return;
docstring const name = qstring_to_ucs4(str);
TextClass::const_iterator it = text_class_->begin();
TextClass::const_iterator const end = text_class_->end();
for (; it != end; ++it) {
docstring const & itname = (*it)->name();
//FIXME Comparing translated strings is not ideal.
//This should be done the way module names are handled
//in GuiDocument: viz, the untranslated name should be
//associated with the item via QComboBox::setItemData().
for (size_t i = 0; i != text_class_->layoutCount(); ++i) {
docstring const & itname = text_class_->layout(i)->name();
// FIXME: Comparing translated strings is not ideal.
// This should be done the way module names are handled
// in GuiDocument: viz, the untranslated name should be
// associated with the item via QComboBox::setItemData().
if (translateIfPossible(itname) == name) {
FuncRequest const func(LFUN_LAYOUT, itname,
FuncRequest::TOOLBAR);

View File

@ -361,7 +361,7 @@ bool Inset::covers(BufferView const & bv, int x, int y) const
InsetLayout const & Inset::getLayout(BufferParams const & bp) const
{
return bp.textClass().insetlayout(name());
return bp.textClass().insetLayout(name());
}

View File

@ -89,7 +89,7 @@ InsetBox::InsetBox(BufferParams const & bp, string const & label)
: InsetCollapsable(bp), params_(label)
{
if (forceEmptyLayout())
paragraphs().back().layout(bp.textClass().emptyLayout());
paragraphs().back().setLayout(bp.textClass().emptyLayout());
}

View File

@ -64,7 +64,7 @@ InsetCaption::InsetCaption(BufferParams const & bp)
setFrameColor(Color_captionframe);
//FIXME Do we need to set all paragraphs here? or will there
//always only be one?
paragraphs().back().layout(bp.textClass().emptyLayout());
paragraphs().back().setLayout(bp.textClass().emptyLayout());
}

View File

@ -87,7 +87,7 @@ InsetCollapsable::InsetCollapsable(BufferParams const & bp,
setAutoBreakRows(true);
setDrawFrame(true);
setFrameColor(Color_collapsableframe);
paragraphs().back().layout(bp.textClass().emptyLayout());
paragraphs().back().setLayout(bp.textClass().emptyLayout());
}
@ -134,7 +134,7 @@ void InsetCollapsable::setLayout(TextClassIndex tcindex)
{
textClass_ = tcindex;
if (tcindex != TextClassIndex(-1)) {
layout_ = &textclasslist[tcindex].insetlayout(name());
layout_ = &textclasslist[tcindex].insetLayout(name());
labelstring_ = layout_->labelstring();
} else {
layout_ = &TextClass::emptyInsetLayout();

View File

@ -486,7 +486,7 @@ Tabular::cellstruct::cellstruct(BufferParams const & bp)
rotate(false),
inset(new InsetText(bp))
{
inset->paragraphs().back().layout(bp.textClass().emptyLayout());
inset->paragraphs().back().setLayout(bp.textClass().emptyLayout());
}

View File

@ -100,10 +100,7 @@ InsetText::InsetText(BufferParams const & bp)
{
paragraphs().push_back(Paragraph());
Paragraph & ourpar = paragraphs().back();
if (useEmptyLayout())
ourpar.layout(bp.textClass().emptyLayout());
else
ourpar.layout(bp.textClass().defaultLayout());
ourpar.setEmptyOrDefaultLayout(bp.textClass());
ourpar.setInsetOwner(this);
}
@ -140,7 +137,7 @@ void InsetText::clear()
pars.clear();
pars.push_back(Paragraph());
pars.begin()->setInsetOwner(this);
pars.begin()->layout(old_layout);
pars.begin()->setLayout(old_layout);
}

View File

@ -77,18 +77,18 @@ void breakParagraph(BufferParams const & bparams,
// without doing that we get a crash when typing <Return> at the
// end of a paragraph
if (par.useEmptyLayout())
tmp->layout(bparams.textClass().emptyLayout());
tmp->setLayout(bparams.textClass().emptyLayout());
else
tmp->layout(bparams.textClass().defaultLayout());
tmp->setLayout(bparams.textClass().defaultLayout());
// layout stays the same with latex-environments
if (keep_layout) {
tmp->layout(par.layout());
tmp->setLayout(par.layout());
tmp->setLabelWidthString(par.params().labelWidthString());
tmp->params().depth(par.params().depth());
} else if (par.params().depth() > 0) {
Paragraph const & hook = pars[outerHook(par_offset, pars)];
tmp->layout(hook.layout());
tmp->setLayout(hook.layout());
// not sure the line below is useful
tmp->setLabelWidthString(par.params().labelWidthString());
tmp->params().depth(hook.params().depth());
@ -97,7 +97,7 @@ void breakParagraph(BufferParams const & bparams,
bool const isempty = (par.allowEmpty() && par.empty());
if (!isempty && (par.size() > pos || par.empty())) {
tmp->layout(par.layout());
tmp->setLayout(par.layout());
tmp->params().align(par.params().align());
tmp->setLabelWidthString(par.params().labelWidthString());
@ -144,12 +144,12 @@ void breakParagraph(BufferParams const & bparams,
par.params().clear();
// do not lose start of appendix marker (bug 4212)
par.params().startOfAppendix(soa);
par.layout(bparams.textClass().defaultLayout());
par.setLayout(bparams.textClass().defaultLayout());
}
// layout stays the same with latex-environments
if (keep_layout) {
par.layout(tmp->layout());
par.setLayout(tmp->layout());
par.setLabelWidthString(tmp->params().labelWidthString());
par.params().depth(tmp->params().depth());
}

View File

@ -505,7 +505,7 @@ void RowPainter::paintFirst()
FontInfo const font = getLabelFont();
FontMetrics const & fm = theFontMetrics(font);
docstring const str = par_.getLabelstring();
docstring const str = par_.labelString();
if (!str.empty()) {
double x = x_;
@ -551,8 +551,8 @@ void RowPainter::paintFirst()
layout->labeltype == LABEL_BIBLIO ||
layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)) {
FontInfo const font = getLabelFont();
if (!par_.getLabelstring().empty()) {
docstring const str = par_.getLabelstring();
docstring const str = par_.labelString();
if (!str.empty()) {
double spacing_val = 1.0;
if (!parparams.spacing().isDefault())
spacing_val = parparams.spacing().getValue();