]> git.lyx.org Git - features.git/commitdiff
Use GuiNames for counters.
authorRichard Kimberly Heck <rikiheck@lyx.org>
Sun, 3 May 2020 03:00:17 +0000 (23:00 -0400)
committerRichard Kimberly Heck <rikiheck@lyx.org>
Sun, 3 May 2020 03:17:16 +0000 (23:17 -0400)
src/Counters.cpp
src/Counters.h
src/frontends/qt/GuiCounter.cpp

index 830c7e0b7a9ede0b933579273fad6d53ccfc5a73..42e10e83621774856bc7dcc992ddb41d36bbba26 100644 (file)
@@ -56,12 +56,14 @@ bool Counter::read(Lexer & lex)
                CT_LABELSTRING_APPENDIX,
                CT_PRETTYFORMAT,
                CT_INITIALVALUE,
+               CT_GUINAME,
                CT_END
        };
 
        LexerKeyword counterTags[] = {
                { "end", CT_END },
-         { "initialvalue", CT_INITIALVALUE},
+               { "guiname", CT_GUINAME },
+               { "initialvalue", CT_INITIALVALUE},
                { "labelstring", CT_LABELSTRING },
                { "labelstringappendix", CT_LABELSTRING_APPENDIX },
                { "prettyformat", CT_PRETTYFORMAT },
@@ -112,6 +114,10 @@ bool Counter::read(Lexer & lex)
                                lex.next();
                                labelstringappendix_ = lex.getDocString();
                                break;
+                       case CT_GUINAME:
+                               lex.next();
+                               guiname_ = lex.getDocString();
+                               break;
                        case CT_END:
                                getout = true;
                                break;
@@ -349,6 +355,22 @@ void Counters::step(docstring const & ctr, UpdateType utype)
 }
 
 
+docstring const & Counters::guiName(docstring const & cntr) const
+{
+       CounterList::const_iterator it = counterList_.find(cntr);
+       if (it == counterList_.end()) {
+               lyxerr << "step: Counter does not exist: "
+                          << to_utf8(cntr) << endl;
+               return empty_docstring();
+       }
+
+       docstring const & guiname = it->second.guiName();
+       if (guiname.empty())
+               return cntr;
+       return guiname;
+}
+
+
 void Counters::reset()
 {
        appendix_ = false;
index 77e1f118fa751573a147b78fc1896b2f0cd17868..92643c1bd5870414ae142e6ae342c2d9e9518037 100644 (file)
@@ -67,6 +67,8 @@ public:
        /// Similar, but used for formatted references in XHTML output.
        /// E.g., for a section counter it might be "section \thesection"
        docstring const & prettyFormat() const { return prettyformat_; }
+       ///
+       docstring const & guiName() const { return guiname_; }
 
        /// Returns a map of LaTeX-like strings to format the counter.
        /** For each language, the string is similar to what one gets
@@ -97,6 +99,8 @@ private:
        docstring labelstringappendix_;
        /// Similar, but used for formatted references in XHTML output
        docstring prettyformat_;
+       ///
+       docstring guiname_;
        /// Cache of the labelstring with \\the<counter> expressions expanded,
        /// indexed by language
        mutable StringMap flatlabelstring_;
@@ -174,6 +178,8 @@ public:
        /// format given by Counter::prettyFormat().
        docstring prettyCounter(docstring const & cntr,
                               std::string const & lang) const;
+       ///
+       docstring const & guiName(docstring const & cntr) const;
        /// Are we in appendix?
        bool appendix() const { return appendix_; }
        /// Set the state variable indicating whether we are in appendix.
index c3e3265d3e1853efa020a8e84c547040075a83d9..9b8fbb666da59ef031e96f08cbc68d6dc7ecce5d 100644 (file)
@@ -59,7 +59,7 @@ GuiCounter::GuiCounter(GuiView & lv, QWidget * parent) :
 void GuiCounter::processParams(InsetCommandParams const & params)
 {
        QString const & counter = toqstr(params["counter"]);
-       int c = counterCB->findText(counter);
+       int c = counterCB->findData(counter);
        counterCB->setCurrentIndex(c);
 
        QString cmd = toqstr(params.getCmdName());
@@ -85,10 +85,13 @@ void GuiCounter::fillCombos()
        if (!bv)
                return;
        
-       std::vector<docstring> counts = 
-               bv->buffer().params().documentClass().counters().listOfCounters();
-       for (auto const & c : counts)
-               counterCB->addItem(toqstr(c));
+       Counters const & cntrs =
+               bv->buffer().params().documentClass().counters();
+       std::vector<docstring> counts = cntrs.listOfCounters();
+       for (auto const & c : counts) {
+               docstring const & guiname = cntrs.guiName(c);
+               counterCB->addItem(toqstr(guiname), toqstr(c));
+       }
 }
 
 
@@ -118,7 +121,7 @@ docstring GuiCounter::dialogToParams() const
 {
        InsetCommandParams params(insetCode());
 
-       params["counter"] = qstring_to_ucs4(counterCB->currentText());
+       params["counter"] = qstring_to_ucs4(counterCB->itemData(counterCB->currentIndex()).toString());
        params["value"] = convert<docstring>(valueSB->value());
        params.setCmdName(fromqstr(actionCB->itemData(actionCB->currentIndex()).toString()));
        params["lyxonly"] = from_ascii(lyxonlyXB->isChecked() ? "true" : "false");