]> git.lyx.org Git - lyx.git/commitdiff
Display equation/theorem numbers in insert cross reference dialog.
authorAlexander Dunlap <alexander.dunlap@gmail.com>
Wed, 26 Jul 2023 17:35:42 +0000 (13:35 -0400)
committerRichard Kimberly Heck <rikiheck@lyx.org>
Wed, 26 Jul 2023 17:35:42 +0000 (13:35 -0400)
Fixes bug #11466,

13 files changed:
src/Buffer.cpp
src/Buffer.h
src/Counters.cpp
src/Counters.h
src/TextClass.cpp
src/TocBackend.h
src/frontends/qt/GuiRef.cpp
src/frontends/qt/GuiRef.h
src/frontends/qt/ui/RefUi.ui
src/insets/InsetFlex.cpp
src/insets/InsetLabel.cpp
src/insets/InsetLabel.h
src/mathed/InsetMathHull.cpp

index e837a9b55284ed282d5dcd51620c62c20a2f46b9..1f90df3ed18c543572321e84cecb9a288af52ffa 100644 (file)
@@ -2422,7 +2422,7 @@ void Buffer::validate(LaTeXFeatures & features) const
 }
 
 
-void Buffer::getLabelList(vector<std::pair<docstring, docstring>> & list) const
+void Buffer::getLabelList(vector<std::tuple<docstring, docstring, docstring>> & list) const
 {
        // If this is a child document, use the master's list instead.
        if (parent()) {
@@ -2433,8 +2433,9 @@ void Buffer::getLabelList(vector<std::pair<docstring, docstring>> & list) const
        list.clear();
        shared_ptr<Toc> toc = d->toc_backend.toc("label");
        for (auto const & tocit : *toc) {
-               if (tocit.depth() == 0)
-                       list.push_back(make_pair(tocit.str(), tocit.asString()));
+               if (tocit.depth() == 0) {
+                       list.push_back(make_tuple(tocit.str(), tocit.asString(),tocit.prettyStr()));
+               }
        }
 }
 
index 4905efb45d03ddc1dec8e8f424addf8596af8006..de27084af983c9924027d53e6104ba95222739f2 100644 (file)
@@ -534,8 +534,9 @@ public:
        void invalidateCiteLabels() const;
        ///
        bool citeLabelsValid() const;
-       /// two strings: plain label name and label as gui string
-       void getLabelList(std::vector<std::pair<docstring, docstring>> &) const;
+       /// three strings: plain label name, label as gui string, and
+       /// dereferenced label name
+       void getLabelList(std::vector<std::tuple<docstring, docstring, docstring>> &) const;
 
        /// This removes the .aux and .bbl files from the temp dir.
        void removeBiblioTempFiles() const;
index d7f8630adf482c5abe7f80b7419ec32abfd573fa..8f2c60e461a941173af2b9a07181c3bc1931fdaf 100644 (file)
@@ -42,9 +42,10 @@ Counter::Counter()
 
 
 Counter::Counter(docstring const & mc, docstring const & ls,
-               docstring const & lsa, docstring const & guiname)
+               docstring const & lsa, docstring const & prettyformat,
+               docstring const & guiname)
        : initial_value_(0), saved_value_(0), parent_(mc), labelstring_(ls),
-         labelstringappendix_(lsa), guiname_(guiname)
+         labelstringappendix_(lsa), prettyformat_(prettyformat), guiname_(guiname)
 {
        reset();
 }
@@ -130,6 +131,12 @@ bool Counter::read(Lexer & lex)
                                getout = true;
                                break;
                }
+               if (prettyformat_ == "") { // fall back on GuiName if PrettyFormat is empty
+                       if (guiname_ == "")
+                               prettyformat_ = from_ascii("##");
+                       else
+                               prettyformat_ = "## (" + guiname_ + " counter)";
+               }
        }
 
        // Here if have a full counter if getout == true
@@ -220,6 +227,7 @@ void Counters::newCounter(docstring const & newc,
                          docstring const & parentc,
                          docstring const & ls,
                          docstring const & lsa,
+                         docstring const & prettyformat,
                          docstring const & guiname)
 {
        if (!parentc.empty() && !hasCounter(parentc)) {
@@ -228,7 +236,7 @@ void Counters::newCounter(docstring const & newc,
                       << endl;
                return;
        }
-       counterList_[newc] = Counter(parentc, ls, lsa, guiname);
+       counterList_[newc] = Counter(parentc, ls, lsa, prettyformat, guiname);
 }
 
 
@@ -344,7 +352,7 @@ void Counters::stepParent(docstring const & ctr, UpdateType utype)
 }
 
 
-void Counters::step(docstring const & ctr, UpdateType utype)
+void Counters::step(docstring const & ctr, UpdateType /* deleted */)
 {
        CounterList::iterator it = counterList_.find(ctr);
        if (it == counterList_.end()) {
@@ -354,11 +362,9 @@ void Counters::step(docstring const & ctr, UpdateType utype)
        }
 
        it->second.step();
-       if (utype == OutputUpdate) {
-               LBUFERR(!counter_stack_.empty());
-               counter_stack_.pop_back();
-               counter_stack_.push_back(ctr);
-       }
+       LBUFERR(!counter_stack_.empty());
+       counter_stack_.pop_back();
+       counter_stack_.push_back(ctr);
 
        resetChildren(ctr);
 }
index 57fff35faee57d094245a4870e88955f338fc6d3..41ee930583781f86cbcc525c8d930e7144825a1f 100644 (file)
@@ -35,7 +35,8 @@ public:
        Counter();
        ///
        Counter(docstring const & mc, docstring const & ls,
-               docstring const & lsa, docstring const & guiname);
+               docstring const & lsa, docstring const & prettyformat,
+               docstring const & guiname);
        /// \return true on success
        bool read(Lexer & lex);
        ///
@@ -129,6 +130,7 @@ public:
                        docstring const & parentc,
                        docstring const & ls,
                        docstring const & lsa,
+                       docstring const & prettyformat,
                        docstring const & guiname);
        /// Checks whether the given counter exists.
        bool hasCounter(docstring const & c) const;
index d99004f7aab28507272405a32bcd69cfb1c28cc9..b6a7887ed8d7d3a15312b2e5a688028075d98e3c 100644 (file)
@@ -1624,12 +1624,14 @@ bool TextClass::readFloat(Lexer & lexrc)
                // each float has its own counter
                counters_.newCounter(from_ascii(type), from_ascii(within),
                                docstring(), docstring(),
+                               bformat(_("%1$s ##"), _(name)),
                                bformat(_("%1$s (Float)"), _(name)));
                // also define sub-float counters
                docstring const subtype = "sub-" + from_ascii(type);
                counters_.newCounter(subtype, from_ascii(type),
                                "\\alph{" + subtype + "}", docstring(),
-                                bformat(_("Sub-%1$s (Float)"), _(name)));
+                               bformat(_("Sub-%1$s ##"), _(name)),
+                               bformat(_("Sub-%1$s (Float)"), _(name)));
        }
        return getout;
 }
index c3a178d12ff32900da9df475aa283f2500b4ab5b..7ad36fec66399b92f23c77b9166915bd24b2fea1 100644 (file)
@@ -73,6 +73,10 @@ public:
        ///
        void str(docstring const & s) { str_ = s; }
        ///
+       docstring const & prettyStr() const { return pretty_str_; }
+       ///
+       void prettyStr (docstring const & s) { pretty_str_ = s; }
+       ///
        bool isOutput() const { return output_; }
        ///
        bool isMissing() const { return missing_; }
@@ -93,6 +97,8 @@ private:
        int depth_;
        /// Full item string
        docstring str_;
+       /// Dereferenced name, for labels (e.g. Label 5.2 instead of lem:foobar)
+       docstring pretty_str_;
        /// Is this item in a note, inactive branch, etc?
        bool output_;
        /// Is this item missing, e.g. missing label?
index 9b9144377a244428820f1d6b64fb57faff5572cf..5fb317d64117f3301df5f91f3ead3fe82186ba97 100644 (file)
@@ -73,9 +73,6 @@ GuiRef::GuiRef(GuiView & lv)
        buttonBox->button(QDialogButtonBox::Reset)->setText(qt_("&Update"));
        buttonBox->button(QDialogButtonBox::Reset)->setToolTip(qt_("Update the label list"));
 
-       refsTW->setColumnCount(1);
-       refsTW->header()->setVisible(false);
-
        connect(this, SIGNAL(rejected()), this, SLOT(dialogRejected()));
 
        connect(typeCO, SIGNAL(activated(int)),
@@ -423,9 +420,9 @@ void GuiRef::gotoRef()
        at_ref_ = !at_ref_;
 }
 
-inline bool caseInsensitiveLessThanVec(QPair<QString, QString> const & s1, QPair<QString, QString> const & s2)
+inline bool caseInsensitiveLessThanVec(std::tuple<QString, QString, QString> const & s1, std::tuple<QString, QString, QString> const & s2)
 {
-       return s1.first.toLower() < s2.first.toLower();
+       return std::get<0>(s1).toLower() < std::get<0>(s2).toLower();
 }
 
 inline bool caseInsensitiveLessThan(QString const & s1, QString const & s2)
@@ -448,17 +445,19 @@ void GuiRef::redoRefs()
        // the first item inserted
        QString const oldSelection(referenceED->text());
 
-       // Plain label and GUI string. This might get resorted below
-       QVector<QPair<QString, QString>> refsNames;
+       // Plain label, GUI string, and dereferenced string.
+       // This might get resorted below
+       QVector<std::tuple<QString, QString,QString>> refsNames;
        // List of categories (prefixes)
        QStringList refsCategories;
        // Do we have a prefix-less label at all?
        bool noprefix = false;
-       vector<std::pair<docstring, docstring>>::const_iterator iter;
+       vector<std::tuple<docstring, docstring,docstring>>::const_iterator iter;
        for (iter = refs_.begin(); iter != refs_.end(); ++iter) {
-               // first: plain label name, second: gui name
-               QString const lab = toqstr((*iter).first);
-               refsNames.append({lab, toqstr((*iter).second)});
+               // first: plain label name, second: gui name, third: pretty name
+               QString const lab = toqstr(std::get<0>(*iter));
+               refsNames.append({lab, toqstr(std::get<1>(*iter)),
+                                   toqstr(std::get<2>(*iter))});
                if (groupCB->isChecked()) {
                        if (lab.contains(":")) {
                                QString const pref = lab.split(':')[0];
@@ -473,7 +472,7 @@ void GuiRef::redoRefs()
                                noprefix = true;
                }
        }
-       // sort categories case-intensively
+       // sort categories case-insensitively
        sort(refsCategories.begin(), refsCategories.end(),
                  caseInsensitiveLessThan /*defined above*/);
        if (noprefix)
@@ -496,15 +495,17 @@ void GuiRef::redoRefs()
                        QTreeWidgetItem * item = new QTreeWidgetItem(refsTW);
                        item->setText(0, cat);
                        for (int j = 0; j < refsNames.size(); ++j) {
-                               QString const ref = refsNames.at(j).first;
+                               QString const ref = std::get<0>(refsNames.at(j));
                                if ((ref.startsWith(cat + QString(":")))
                                    || (cat == qt_("<No prefix>")
                                       && (!ref.mid(1).contains(":") || ref.left(1).contains(":")))) {
                                                QTreeWidgetItem * child =
                                                        new QTreeWidgetItem(item);
-                                               QString const val = refsNames.at(j).second;
+                                               QString const val = std::get<1>(refsNames.at(j));
+                                               QString const pretty = std::get<2>(refsNames.at(j));
                                                child->setText(0, val);
                                                child->setData(0, Qt::UserRole, ref);
+                                               child->setText(1, pretty);
                                                item->addChild(child);
                                }
                        }
@@ -515,10 +516,12 @@ void GuiRef::redoRefs()
                QList<QTreeWidgetItem *> refsItems;
                for (int i = 0; i < refsNames.size(); ++i) {
                        QTreeWidgetItem * item = new QTreeWidgetItem(refsTW);
-                       QString const ref = refsNames.at(i).first;
-                       QString const val = refsNames.at(i).second;
+                       QString const ref = std::get<0>(refsNames.at(i));
+                       QString const val = std::get<1>(refsNames.at(i));
+                       QString const pretty = std::get<2>(refsNames.at(i));
                        item->setText(0, val);
                        item->setData(0, Qt::UserRole, ref);
+                       item->setText(1, pretty);
                        refsItems.append(item);
                }
                refsTW->addTopLevelItems(refsItems);
@@ -605,6 +608,7 @@ void GuiRef::filterLabels()
                (*it)->setHidden(
                        (*it)->childCount() == 0
                        && !(*it)->text(0).contains(filter_->text(), cs)
+                       && !(*it)->text(1).contains(filter_->text(), cs)
                );
                ++it;
        }
index 4bd50e57a83e7b88d2c782bb6a38d340feee0954..7f8860bd5355c52b933619399bc0ce5244e52eba 100644 (file)
@@ -106,9 +106,10 @@ private:
        int restored_buffer_;
        /// store the last active buffer
        int active_buffer_;
-       /// the references as two strings: plain label name and label as gui string
+       /// the references as three strings: plain label name, label as gui
+       /// string, and pretty dereferenced name ("Lemma 3")
        /// FIXME: might be a good idea to use a custom struct
-       std::vector<std::pair<docstring, docstring>> refs_;
+       std::vector<std::tuple<docstring, docstring, docstring>> refs_;
 };
 
 } // namespace frontend
index a8391e0542bc2488b4f0d04cc0a5faac4927b95a..dac7d7f4b78c150dffba31510a089bbc777312d6 100644 (file)
   <layout class="QGridLayout" name="gridLayout_2">
    <item row="2" column="0">
     <widget class="QTreeWidget" name="refsTW">
+     <property name="columnCount">
+      <number>2</number>
+     </property>
+     <attribute name="headerDefaultSectionSize">
+      <number>200</number>
+     </attribute>
+     <attribute name="headerStretchLastSection">
+      <bool>true</bool>
+     </attribute>
+     <column>
+      <property name="text">
+       <string>Label</string>
+      </property>
+     </column>
      <column>
       <property name="text">
-       <string>1</string>
+       <string>Reference counter value</string>
       </property>
      </column>
     </widget>
index 30ed7bf04586c30fb6c99fbb980859fdb6f7c53e..91c0b8cea1fd872eb4bf8cfe09811f5aed3744db 100644 (file)
@@ -164,6 +164,7 @@ void InsetFlex::updateBuffer(ParIterator const & it, UpdateType utype, bool cons
                docstring const eqlabel = deleted ? from_ascii("#")
                        : cnts.theCounter(equation, it->getParLanguage(bp)->code());
                cnts.newCounter(equation, parentequation,
+                               eqlabel + from_ascii("\\alph{equation}"),
                                eqlabel + from_ascii("\\alph{equation}"),
                                eqlabel + from_ascii("\\alph{equation}"),
                                cnts.guiName(parentequation));
index e143f83e29b066f54e5a77b826450589908aec85..1f0a0459ac581b317127ac57d19abce92fc1a4ba 100644 (file)
@@ -156,7 +156,7 @@ docstring InsetLabel::screenLabel() const
 }
 
 
-void InsetLabel::updateBuffer(ParIterator const & it, UpdateType utype, bool const /*deleted*/)
+void InsetLabel::updateBuffer(ParIterator const & it, UpdateType, bool const /*deleted*/)
 {
        docstring const & label = getParam("name");
 
@@ -184,19 +184,24 @@ void InsetLabel::updateBuffer(ParIterator const & it, UpdateType utype, bool con
        buffer().setInsetLabel(label, this, active);
        screen_label_ = label;
 
-       if (utype == OutputUpdate) {
-               // save info on the active counter
-               Counters const & cnts =
-                       buffer().masterBuffer()->params().documentClass().counters();
-               active_counter_ = cnts.currentCounter();
-               Language const * lang = it->getParLanguage(buffer().params());
-               if (lang && !active_counter_.empty()) {
+       // save info on the active counter
+       Counters & cnts =
+               buffer().masterBuffer()->params().documentClass().counters();
+       active_counter_ = cnts.currentCounter();
+       Language const * lang = it->getParLanguage(buffer().params());
+       if (lang && !active_counter_.empty()) {
+               if (active_counter_ != from_ascii("equation")) {
                        counter_value_ = cnts.theCounter(active_counter_, lang->code());
                        pretty_counter_ = cnts.prettyCounter(active_counter_, lang->code());
                } else {
+                       // For equations, the counter value and pretty counter
+                       // value will be set by the parent InsetMathHull.
                        counter_value_ = from_ascii("#");
-                       pretty_counter_ = from_ascii("#");
+                       pretty_counter_ = from_ascii("");
                }
+       } else {
+               counter_value_ = from_ascii("#");
+               pretty_counter_ = from_ascii("#");
        }
 }
 
@@ -212,7 +217,9 @@ void InsetLabel::addToToc(DocIterator const & cpit, bool output_active,
 
        // We put both  active and inactive labels to the outliner
        shared_ptr<Toc> toc = backend.toc("label");
-       toc->push_back(TocItem(cpit, 0, screen_label_, output_active));
+       TocItem toc_item = TocItem(cpit, 0, screen_label_, output_active);
+       toc_item.prettyStr(pretty_counter_);
+       toc->push_back(toc_item);
        // The refs get assigned only to the active label. If no active one exists,
        // assign the (BROKEN) refs to the first inactive one.
        if (buffer().insetLabel(label, true) == this || !buffer().activeLabel(label)) {
index 8032ce764938bc5b21eab10022a410121f0db4c6..5cd4a88ddc9a891eafdf4cf7b71d4ddd1714a287 100644 (file)
@@ -30,6 +30,8 @@ public:
        ///
        docstring const & prettyCounter() const { return pretty_counter_; }
        ///
+       void setPrettyCounter(docstring pc) { pretty_counter_ = pc; }
+       ///
        int rowFlags() const override { return CanBreakBefore | CanBreakAfter; }
        /// Updates only the label string, doesn't handle undo nor references.
        void updateLabel(docstring const & new_label, bool const active = true);
index b33bb0d7114828b8ac3e54f1ac990a611be8b8b1..954f5651aa7a58a7ac11b36f485223b32c15edae 100644 (file)
@@ -313,8 +313,10 @@ void InsetMathHull::addToToc(DocIterator const & pit, bool output_active,
        for (row_type row = 0; row != nrows(); ++row) {
                if (!numbered(row))
                        continue;
-               if (label_[row])
+               if (label_[row]) {
+                       label_[row]->setPrettyCounter(_("Equation ") + numbers_[row]);
                        label_[row]->addToToc(pit, output_active, utype, backend);
+               }
                docstring label = nicelabel(row);
                if (first == last)
                        // this is the only equation