]> git.lyx.org Git - lyx.git/commitdiff
some further counter work
authorLars Gullik Bjønnes <larsbj@gullik.org>
Thu, 5 Sep 2002 12:58:10 +0000 (12:58 +0000)
committerLars Gullik Bjønnes <larsbj@gullik.org>
Thu, 5 Sep 2002 12:58:10 +0000 (12:58 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5208 a592a061-630c-0410-9148-cb99ea01b6c8

src/ChangeLog
src/counters.C
src/counters.h
src/text2.C

index 6c81472a7f4cc5ea1742a206c4f58ac5949c0149..561a89ca75745470f8c8d552003eaad7a2ed9995 100644 (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 
index 27fbc7ae3a556159b01c8e7c5a03691214d46bc7..5b0de5941712e2beb852940d7f38bd8cf84da4e2 100644 (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)
index 69c4983be810e318b611d813671966d9e2bae068..d1c0ef59af0ad94246d9e6fee1ab76e508953f2f 100644 (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;
index 790b4a75ffe505f059f6e0e05d83806c8ee3bc25..dbb946bb37e656d052fc2e85172d6ffa13bffe3c 100644 (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");
+
+                       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<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");
                }
        }
 }