some further counter work

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5208 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Lars Gullik Bjønnes 2002-09-05 12:58:10 +00:00
parent 4d42b1d8aa
commit f17a138278
4 changed files with 66 additions and 36 deletions

View File

@ -1,3 +1,18 @@
2002-09-05 Lars Gullik Bjønnes <larsbj@gullik.net>
* 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 <larsbj@gullik.net>
* lyxtextclass.C (TextClassTags): add TC_FLOAT

View File

@ -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)

View File

@ -20,7 +20,7 @@
#include "LString.h"
#include <map>
#include <vector>
/// 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<string> enums;
std::vector<string> sects;
private:
/// Maps counter (layout) names to actual counters.
typedef std::map<string, Counter> CounterList;

View File

@ -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");
s << buf->counters().numberLabel(buf->counters().enums[par->enumdepth],
"enumeration", langtype);
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;
}
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<InsetFloat*>(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");
}
}
}