From 666f90cdbb15b33d2f3f0b643e3bd66512f7b852 Mon Sep 17 00:00:00 2001 From: Richard Kimberly Heck Date: Sat, 2 May 2020 23:00:17 -0400 Subject: [PATCH] Use GuiNames for counters. --- src/Counters.cpp | 24 +++++++++++++++++++++++- src/Counters.h | 6 ++++++ src/frontends/qt/GuiCounter.cpp | 15 +++++++++------ 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/src/Counters.cpp b/src/Counters.cpp index 830c7e0b7a..42e10e8362 100644 --- a/src/Counters.cpp +++ b/src/Counters.cpp @@ -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; diff --git a/src/Counters.h b/src/Counters.h index 77e1f118fa..92643c1bd5 100644 --- a/src/Counters.h +++ b/src/Counters.h @@ -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 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. diff --git a/src/frontends/qt/GuiCounter.cpp b/src/frontends/qt/GuiCounter.cpp index c3e3265d3e..9b8fbb666d 100644 --- a/src/frontends/qt/GuiCounter.cpp +++ b/src/frontends/qt/GuiCounter.cpp @@ -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 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 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(valueSB->value()); params.setCmdName(fromqstr(actionCB->itemData(actionCB->currentIndex()).toString())); params["lyxonly"] = from_ascii(lyxonlyXB->isChecked() ? "true" : "false"); -- 2.39.2