From f17a13827844eb8e0dd208827fee32bf254ec544 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Thu, 5 Sep 2002 12:58:10 +0000 Subject: [PATCH] some further counter work git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5208 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 15 ++++++++++++++ src/counters.C | 24 +++++++--------------- src/counters.h | 9 ++------- src/text2.C | 54 +++++++++++++++++++++++++++++++++++++++----------- 4 files changed, 66 insertions(+), 36 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 6c81472a7f..561a89ca75 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,18 @@ +2002-09-05 Lars Gullik Bjønnes + + * text2.C (setCounter): lookup the counter with layouts latexname + instead of by section number. + (setCounter): use a hackish way to lookup the correct enum + counter. + a float name->type change + reset enum couners with counter name directly instead of depth value. + + * counters.C (Counters): remove the push_backs, change to use the + float type not the float name. + (labelItem): remove unused string, float name->type change + + * counters.h: don't include vector, loose the enums and sects vectors + 2002-09-04 Lars Gullik Bjønnes * lyxtextclass.C (TextClassTags): add TC_FLOAT diff --git a/src/counters.C b/src/counters.C index 27fbc7ae3a..5b0de59417 100644 --- a/src/counters.C +++ b/src/counters.C @@ -83,30 +83,18 @@ Counters::Counters() newCounter("paragraph", "subsubsection"); newCounter("subparagraph", "paragraph"); - sects.push_back("chapter"); - sects.push_back("section"); - sects.push_back("subsection"); - sects.push_back("subsubsection"); - sects.push_back("paragraph"); - sects.push_back("subparagraph"); - // Enumeration counters: newCounter("enumi"); newCounter("enumii", "enumi"); newCounter("enumiii", "enumii"); newCounter("enumiv", "enumiii"); - enums.push_back("enumi"); - enums.push_back("enumii"); - enums.push_back("enumiii"); - enums.push_back("enumiv"); - // Biblio: newCounter("bibitem"); // Float counters: - newCounter("Figure"); - newCounter("Table"); + newCounter("figure"); + newCounter("table"); } @@ -295,13 +283,15 @@ string Counters::labelItem(string const & ctr, string const & langtype, bool first) { - ostringstream s, o; + ostringstream s; + ostringstream o; + CounterList::iterator it = counterList.find(ctr); if (it == counterList.end()) { lyxerr << "Counter does not exist." << endl; return ""; } - string mstr = it->second.master(); + if (!first) { s << "." << value(ctr); } else { @@ -344,7 +334,7 @@ string Counters::numberLabel(string const & ctr, } else if (ctr == "subparagraph" && head <= 5) { s << numberLabel("paragraph", numbertype, langtype, head) << labelItem("subparagraph", numbertype, langtype, head == 5); - } else if (ctr == "Figure" || ctr == "Table") { + } else if (ctr == "figure" || ctr == "table") { // figure, table, ... lyxerr << "Counter:" << ctr << endl; s << numberLabel("chapter", numbertype, langtype, head) diff --git a/src/counters.h b/src/counters.h index 69c4983be8..d1c0ef59af 100644 --- a/src/counters.h +++ b/src/counters.h @@ -20,7 +20,7 @@ #include "LString.h" #include -#include + /// This represents a single counter. class Counter { @@ -41,9 +41,8 @@ public: string master() const; /// sets the master counter for this counter void setMaster(string const & m); - /// - private: + /// int value_; /// contains master counter name; master counter is the counter /// that, if stepped (incremented) zeroes this counter. E.g. @@ -96,10 +95,6 @@ public: string const & labeltype, string const & langtype = "latin", int head = 0); - /// Maps numbers to enumeration of sectioning counter name strings. - std::vector enums; - std::vector sects; - private: /// Maps counter (layout) names to actual counters. typedef std::map CounterList; diff --git a/src/text2.C b/src/text2.C index 790b4a75ff..dbb946bb37 100644 --- a/src/text2.C +++ b/src/text2.C @@ -1266,12 +1266,13 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par) const if (layout->labeltype >= LABEL_COUNTER_CHAPTER) { int i = layout->labeltype - LABEL_COUNTER_CHAPTER; - string numbertype, langtype; + string numbertype; + string langtype; ostringstream s; if (i >= 0 && i <= buf->params.secnumdepth) { - buf->counters().step(buf->counters().sects[i]); + buf->counters().step(layout->latexname()); // Is there a label? Useful for Chapter layout if (!par->params().appendix()) { @@ -1298,8 +1299,9 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par) const langtype = "latin"; } - s << buf->counters().numberLabel(buf->counters().sects[i], - numbertype, langtype, head); + s << buf->counters() + .numberLabel(layout->latexname(), + numbertype, langtype, head); par->params().labelString(par->params().labelString() + s.str().c_str()); // We really want to remove the c_str as soon as @@ -1310,18 +1312,39 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par) const } else if (layout->labeltype < LABEL_COUNTER_ENUMI) { buf->counters().reset("enum"); } else if (layout->labeltype == LABEL_COUNTER_ENUMI) { - buf->counters().step(buf->counters().enums[par->enumdepth]); + // FIXME + // Yes I know this is a really, really! bad solution + // (Lgb) + string enumcounter("enum"); + + switch (par->enumdepth) { + case 2: + enumcounter += 'i'; + case 1: + enumcounter += 'i'; + case 0: + enumcounter += 'i'; + break; + case 3: + enumcounter += "iv"; + break; + default: + // not a valid enumdepth... + break; + } - s << buf->counters().numberLabel(buf->counters().enums[par->enumdepth], - "enumeration", langtype); - par->params().labelString(s.str().c_str()); + buf->counters().step(enumcounter); + s << buf->counters() + .numberLabel(enumcounter, + "enumeration", langtype); + par->params().labelString(s.str().c_str()); } } else if (layout->labeltype == LABEL_BIBLIO) {// ale970302 buf->counters().step("bibitem"); int number = buf->counters().value("bibitem"); if (!par->bibkey) { - InsetCommandParams p("bibitem" ); + InsetCommandParams p("bibitem"); par->bibkey = new InsetBibKey(p); } par->bibkey->setCounter(number); @@ -1351,7 +1374,7 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par) const Floating const & fl = textclass.floats().getType(static_cast(in)->type()); - buf->counters().step(fl.name()); + buf->counters().step(fl.type()); // Doesn't work... yet. ostringstream o; @@ -1369,8 +1392,15 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par) const // reset the enumeration counter. They are always resetted // when there is any other layout between - for (int i = par->enumdepth; i < 4; ++i) { - buf->counters().set(buf->counters().enums[i], 0); + switch (par->enumdepth) { + case 0: + buf->counters().reset("enumi"); + case 1: + buf->counters().reset("enumii"); + case 2: + buf->counters().reset("enumiii"); + case 3: + buf->counters().reset("enumiv"); } } } -- 2.39.2