From c37500050d267177ace194ba8a95f67c6b0f15c2 Mon Sep 17 00:00:00 2001 From: Richard Kimberly Heck Date: Sat, 2 May 2020 20:33:03 -0400 Subject: [PATCH 1/1] =?utf8?q?More=20polishing=20of=20counter=20dialog.=20?= =?utf8?q?Thanks=20to=20J=C3=BCrgen=20for=20help.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Also, remove the 'display value' option. We will move this to InsetInfo at some point. --- lib/lyx2lyx/lyx_2_4.py | 6 -- src/frontends/qt/GuiCounter.cpp | 25 +------- src/frontends/qt/ui/CounterUi.ui | 107 ++++++++++++++----------------- src/insets/InsetCounter.cpp | 79 ++++++++--------------- src/insets/InsetCounter.h | 2 - 5 files changed, 76 insertions(+), 143 deletions(-) diff --git a/lib/lyx2lyx/lyx_2_4.py b/lib/lyx2lyx/lyx_2_4.py index 98173dfaa6..d32ff7903d 100644 --- a/lib/lyx2lyx/lyx_2_4.py +++ b/lib/lyx2lyx/lyx_2_4.py @@ -3730,12 +3730,6 @@ def revert_counter_inset(document): ert = put_cmd_in_ert("\\addtocounter{%s}{%s}" % (cnt, val)) elif cmd == "reset": ert = put_cmd_in_ert("\\setcounter{%s}{0}" % (cnt)) - elif cmd == "value": - vty = get_quoted_value(document.body, "vtype", i, j) - if not vty: - document.warning("Can't convert counter inset at line %d!" % i) - else: - ert = put_cmd_in_ert("\\%s{%s}" % (vty, cnt)) elif cmd == "save": needed_counters[cnt] = 1 savecnt = "LyXSave" + cnt diff --git a/src/frontends/qt/GuiCounter.cpp b/src/frontends/qt/GuiCounter.cpp index 6deed4b8d2..c3e3265d3e 100644 --- a/src/frontends/qt/GuiCounter.cpp +++ b/src/frontends/qt/GuiCounter.cpp @@ -42,8 +42,6 @@ GuiCounter::GuiCounter(GuiView & lv, QWidget * parent) : this, SIGNAL(changed())); connect(valueSB, SIGNAL(valueChanged(int)), this, SIGNAL(changed())); - connect(vtypeCB, SIGNAL(currentIndexChanged(int)), - this, SIGNAL(changed())); connect(lyxonlyXB, SIGNAL(clicked()), this, SIGNAL(changed())); @@ -55,15 +53,6 @@ GuiCounter::GuiCounter(GuiView & lv, QWidget * parent) : docstring guistring = translateIfPossible(from_ascii(c.second)); actionCB->addItem(toqstr(guistring), toqstr(c.first)); } - - std::map const & vt = - InsetCounter::valueTable; - vtypeCB->clear(); - vtypeCB->addItem("", ""); - for (auto const & v : vt) { - docstring guistring = translateIfPossible(from_ascii(v.second)); - vtypeCB->addItem(toqstr(guistring), toqstr(v.first)); - } } @@ -84,13 +73,6 @@ void GuiCounter::processParams(InsetCommandParams const & params) int val = convert(params["value"]); valueSB->setValue(val); - cmd = toqstr(params["vtype"]); - c = cmd.isEmpty() ? 0 : vtypeCB->findData(cmd); - if (c < 0) { - c = 0; - LYXERR0("Unable to find " << cmd << " in GuiCounter!"); - } - vtypeCB->setCurrentIndex(c); lyxonlyXB->setChecked(support::lowercase(params["lyxonly"]) == "true"); } @@ -139,7 +121,6 @@ docstring GuiCounter::dialogToParams() const params["counter"] = qstring_to_ucs4(counterCB->currentText()); params["value"] = convert(valueSB->value()); params.setCmdName(fromqstr(actionCB->itemData(actionCB->currentIndex()).toString())); - params["vtype"] = qstring_to_ucs4(vtypeCB->itemData(vtypeCB->currentIndex()).toString()); params["lyxonly"] = from_ascii(lyxonlyXB->isChecked() ? "true" : "false"); return from_utf8(InsetCounter::params2string(params)); } @@ -147,7 +128,6 @@ docstring GuiCounter::dialogToParams() const bool GuiCounter::checkWidgets(bool readonly) const { - bool const cmdIsValue = actionCB->itemData(actionCB->currentIndex()).toString() == "value"; bool const cmdIsSet = actionCB->itemData(actionCB->currentIndex()).toString() == "set"; bool const cmdIsAddTo = actionCB->itemData(actionCB->currentIndex()).toString() == "addto"; counterCB->setEnabled(!readonly); @@ -157,13 +137,10 @@ bool GuiCounter::checkWidgets(bool readonly) const valueSB->setRange(-10000, 10000); else valueSB->setRange(0, 10000); - vtypeLA->setEnabled(!readonly && cmdIsValue); - vtypeCB->setEnabled(!readonly && cmdIsValue); return InsetParamsWidget::checkWidgets() && !readonly && !counterCB->currentText().isEmpty() && - !actionCB->currentText().isEmpty() && - !(cmdIsValue && vtypeCB->currentText().isEmpty()); + !actionCB->currentText().isEmpty(); } diff --git a/src/frontends/qt/ui/CounterUi.ui b/src/frontends/qt/ui/CounterUi.ui index 16300a89ae..72370d2a43 100644 --- a/src/frontends/qt/ui/CounterUi.ui +++ b/src/frontends/qt/ui/CounterUi.ui @@ -13,10 +13,10 @@ - - - - + + + + C&ounter: @@ -26,7 +26,7 @@ - + @@ -39,7 +39,11 @@ - + + + + + &Action: @@ -49,7 +53,7 @@ - + @@ -58,71 +62,41 @@ - SET counter value; ADD TO (or subtract from) counter value; RESET counter to zero; SAVE counter value; RESTORE previously saved counter value; DISPLAY counter value + SET counter to specified value; ADD TO (or subtract from) counter value; RESET counter to zero; SAVE counter value for later restoring; RESTORE previously saved counter value - - - - &Value: - - - valueSB - - - - - - - - - 10000 - - - - - - - Qt::Horizontal - - - - 13 - 39 - - - - - - - - - - Display Format - - - vtypeCB + + + + 10000 - - - - - 0 - 0 - - - + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + - + Affect counters only in LyX, not in output - Qt::LeftToRight + Qt::RightToLeft &LyX Only @@ -131,6 +105,19 @@ + + + + Qt::Vertical + + + + 20 + 40 + + + + diff --git a/src/insets/InsetCounter.cpp b/src/insets/InsetCounter.cpp index 32f7c6428c..a6e4d0d56d 100644 --- a/src/insets/InsetCounter.cpp +++ b/src/insets/InsetCounter.cpp @@ -60,12 +60,11 @@ InsetCounter::InsetCounter(InsetCounter const & ir) const map InsetCounter::counterTable = { - {"set", N_("Set Counter")}, - {"addto", N_("Add To Counter")}, - {"reset", N_("Reset To 0")}, + {"set", N_("Set Counter To")}, + {"addto", N_("Increase Counter By")}, + {"reset", N_("Reset Counter To 0")}, {"save", N_("Save Value of Counter")}, {"restore", N_("Restore Value of Counter")}, - {"value", N_("Display Value of Counter")} }; @@ -80,7 +79,6 @@ ParamInfo const & InsetCounter::findInfo(string const & /* cmdName */) if (param_info_.empty()) { param_info_.add("counter", ParamInfo::LYX_INTERNAL); param_info_.add("value", ParamInfo::LYX_INTERNAL); - param_info_.add("vtype", ParamInfo::LYX_INTERNAL); param_info_.add("lyxonly", ParamInfo::LYX_INTERNAL); } return param_info_; @@ -112,8 +110,6 @@ void InsetCounter::latex(otexstream & os, OutputParams const &) const cnts.restoreValue(cntr); os << "\\setcounter{" << cntr << "{\\value{" << lyxSaveCounter() << "}}"; - } else if (cmd == "value") { - os << "\\the" << cntr << "{}"; } } @@ -133,26 +129,8 @@ int InsetCounter::plaintext(odocstringstream & os, } -void InsetCounter::trackCounters(string const & cmd) const -{ - Counters & cnts = buffer().params().documentClass().counters(); - docstring cntr = getParam("counter"); - if (cmd == "set") { - docstring const & val = getParam("value"); - cnts.set(cntr, convert(val)); - } else if (cmd == "addto") { - docstring const & val = getParam("value"); - cnts.addto(cntr, convert(val)); - } else if (cmd == "reset") { - cnts.reset(cntr); - } else if (cmd == "save") { - cnts.saveValue(cntr); - } else if (cmd == "restore") { - cnts.restoreValue(cntr); - } -} - - +#if 0 +// save this code until we get it working in InsetInfo const map InsetCounter::valueTable = { {"Roman", N_("Roman Uppercase")}, @@ -180,40 +158,43 @@ docstring InsetCounter::value() const { LATTEST(false); return empty_docstring(); } +#endif +void InsetCounter::trackCounters(string const & cmd) const +{ + Counters & cnts = buffer().params().documentClass().counters(); + docstring cntr = getParam("counter"); + if (cmd == "set") { + docstring const & val = getParam("value"); + cnts.set(cntr, convert(val)); + } else if (cmd == "addto") { + docstring const & val = getParam("value"); + cnts.addto(cntr, convert(val)); + } else if (cmd == "reset") { + cnts.reset(cntr); + } else if (cmd == "save") { + cnts.saveValue(cntr); + } else if (cmd == "restore") { + cnts.restoreValue(cntr); + } +} -int InsetCounter::docbook(odocstream & os, OutputParams const &) const +int InsetCounter::docbook(odocstream &, OutputParams const &) const { // Here, we need to track counter values ourselves, // since unlike in the LaTeX case, there is no external // mechanism for doing that. - string const cmd = getCmdName(); - if (cmd == "value") { - docstring cntr = getParam("counter"); - Counters & cnts = buffer().params().documentClass().counters(); - if (cnts.hasCounter(cntr)) - os << cnts.value(cntr); - } else - trackCounters(cmd); - + trackCounters(getCmdName()); return 0; } -docstring InsetCounter::xhtml(XHTMLStream & xs, OutputParams const &) const +docstring InsetCounter::xhtml(XHTMLStream &, OutputParams const &) const { // Here, we need to track counter values ourselves, // since unlike in the LaTeX case, there is no external // mechanism for doing that. - string const cmd = getCmdName(); - if (cmd == "value") { - docstring cntr = getParam("counter"); - Counters & cnts = buffer().params().documentClass().counters(); - if (cnts.hasCounter(cntr)) - xs << cnts.value(cntr); - } else - trackCounters(cmd); - + trackCounters(getCmdName()); return docstring(); } @@ -250,11 +231,7 @@ void InsetCounter::updateBuffer(ParIterator const &, UpdateType, bool const) cnts.restoreValue(cntr); screen_label_ = bformat(_("Counter: Restore %1$s"), cntr); tooltip_ = bformat(_("Restore value of counter %1$s"), cntr); - } else if (cmd == "value") { - screen_label_ = bformat(_("Counter: Value %1$s"), cntr); - tooltip_ = bformat(_("Display value of counter %1$s"), cntr); } - } diff --git a/src/insets/InsetCounter.h b/src/insets/InsetCounter.h index 44d909c384..92c547e432 100644 --- a/src/insets/InsetCounter.h +++ b/src/insets/InsetCounter.h @@ -82,8 +82,6 @@ private: docstring screenLabel() const { return screen_label_; } //@} /// - docstring value() const; - /// docstring lyxSaveCounter() const; /// void trackCounters(std::string const & cmd) const; -- 2.39.2