X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt%2FGuiRef.cpp;h=9b9144377a244428820f1d6b64fb57faff5572cf;hb=8863d6d785358680d05b4b34b35ca09a15cccb82;hp=28361906ea4fef4dae89fa4528c9e3d24981fb12;hpb=55da675efa725a37604988917f436bce058d1583;p=lyx.git diff --git a/src/frontends/qt/GuiRef.cpp b/src/frontends/qt/GuiRef.cpp index 28361906ea..9b9144377a 100644 --- a/src/frontends/qt/GuiRef.cpp +++ b/src/frontends/qt/GuiRef.cpp @@ -22,6 +22,7 @@ #include "Cursor.h" #include "FancyLineEdit.h" #include "FuncRequest.h" +#include "PDFOptions.h" #include "qt_helpers.h" @@ -59,13 +60,8 @@ GuiRef::GuiRef(GuiView & lv) filter_->setClearButton(true); filter_->setPlaceholderText(qt_("All available labels")); filter_->setToolTip(qt_("Enter string to filter the list of available labels")); -#if (QT_VERSION < 0x050000) - connect(filter_, SIGNAL(downPressed()), - refsTW, SLOT(setFocus())); -#else connect(filter_, &FancyLineEdit::downPressed, refsTW, [this](){ focusAndHighlight(refsTW); }); -#endif filterBarL->addWidget(filter_, 0); findKeysLA->setBuddy(filter_); @@ -114,6 +110,8 @@ GuiRef::GuiRef(GuiView & lv) this, SLOT(changed_adaptor())); connect(noprefixCB, SIGNAL(clicked()), this, SLOT(changed_adaptor())); + connect(nolinkCB, SIGNAL(clicked()), + this, SLOT(changed_adaptor())); enableBoxes(); @@ -147,9 +145,12 @@ void GuiRef::enableBoxes() bool const isLabelOnly = (reftype == "labelonly"); bool const usingRefStyle = buffer().params().use_refstyle; bool const intext = bufferview()->cursor().inTexted(); + bool const hyper_on = buffer().params().pdfoptions().use_hyperref; pluralCB->setEnabled(intext && isFormatted && usingRefStyle); capsCB->setEnabled(intext && isFormatted && usingRefStyle); noprefixCB->setEnabled(intext && isLabelOnly); + // disabling of hyperlinks not supported by formatted references + nolinkCB->setEnabled(hyper_on && intext && !isFormatted && !isLabelOnly); } @@ -202,7 +203,7 @@ void GuiRef::refHighlighted(QTreeWidgetItem * sel) bool const cur_item_selected = sel->isSelected(); if (cur_item_selected) - referenceED->setText(sel->text(0)); + referenceED->setText(sel->data(0, Qt::UserRole).toString()); if (at_ref_) gotoRef(); @@ -236,7 +237,7 @@ void GuiRef::refSelected(QTreeWidgetItem * sel) bool const cur_item_selected = sel->isSelected(); if (cur_item_selected) - referenceED->setText(sel->text(0)); + referenceED->setText(sel->data(0, Qt::UserRole).toString()); // or double click, inserts ref and closes dialog slotOK(); } @@ -343,6 +344,7 @@ void GuiRef::updateContents() pluralCB->setChecked(params_["plural"] == "true"); capsCB->setChecked(params_["caps"] == "true"); noprefixCB->setChecked(params_["noprefix"] == "true"); + nolinkCB->setChecked(params_["nolink"] == "true"); // insert buffer list bufferCO->clear(); @@ -385,6 +387,8 @@ void GuiRef::applyView() from_ascii("true") : from_ascii("false"); params_["noprefix"] = noprefixCB->isChecked() ? from_ascii("true") : from_ascii("false"); + params_["nolink"] = nolinkCB->isChecked() ? + from_ascii("true") : from_ascii("false"); restored_buffer_ = bufferCO->currentIndex(); } @@ -419,6 +423,11 @@ void GuiRef::gotoRef() at_ref_ = !at_ref_; } +inline bool caseInsensitiveLessThanVec(QPair const & s1, QPair const & s2) +{ + return s1.first.toLower() < s2.first.toLower(); +} + inline bool caseInsensitiveLessThan(QString const & s1, QString const & s2) { return s1.toLower() < s2.toLower(); @@ -439,13 +448,17 @@ void GuiRef::redoRefs() // the first item inserted QString const oldSelection(referenceED->text()); - QStringList refsStrings; + // Plain label and GUI string. This might get resorted below + QVector> refsNames; + // List of categories (prefixes) QStringList refsCategories; - vector::const_iterator iter; + // Do we have a prefix-less label at all? bool noprefix = false; + vector>::const_iterator iter; for (iter = refs_.begin(); iter != refs_.end(); ++iter) { - QString const lab = toqstr(*iter); - refsStrings.append(lab); + // first: plain label name, second: gui name + QString const lab = toqstr((*iter).first); + refsNames.append({lab, toqstr((*iter).second)}); if (groupCB->isChecked()) { if (lab.contains(":")) { QString const pref = lab.split(':')[0]; @@ -469,11 +482,12 @@ void GuiRef::redoRefs() QString const sort_method = sortingCO->isEnabled() ? sortingCO->itemData(sortingCO->currentIndex()).toString() : QString(); + // Sort items if so requested. if (sort_method == "nocase") - sort(refsStrings.begin(), refsStrings.end(), - caseInsensitiveLessThan /*defined above*/); + sort(refsNames.begin(), refsNames.end(), + caseInsensitiveLessThanVec /*defined above*/); else if (sort_method == "case") - sort(refsStrings.begin(), refsStrings.end()); + sort(refsNames.begin(), refsNames.end()); if (groupCB->isChecked()) { QList refsCats; @@ -481,14 +495,16 @@ void GuiRef::redoRefs() QString const & cat = refsCategories.at(i); QTreeWidgetItem * item = new QTreeWidgetItem(refsTW); item->setText(0, cat); - for (int j = 0; j < refsStrings.size(); ++j) { - QString const & ref = refsStrings.at(j); + for (int j = 0; j < refsNames.size(); ++j) { + QString const ref = refsNames.at(j).first; if ((ref.startsWith(cat + QString(":"))) || (cat == qt_("") && (!ref.mid(1).contains(":") || ref.left(1).contains(":")))) { QTreeWidgetItem * child = new QTreeWidgetItem(item); - child->setText(0, ref); + QString const val = refsNames.at(j).second; + child->setText(0, val); + child->setData(0, Qt::UserRole, ref); item->addChild(child); } } @@ -497,9 +513,12 @@ void GuiRef::redoRefs() refsTW->addTopLevelItems(refsCats); } else { QList refsItems; - for (int i = 0; i < refsStrings.size(); ++i) { + for (int i = 0; i < refsNames.size(); ++i) { QTreeWidgetItem * item = new QTreeWidgetItem(refsTW); - item->setText(0, refsStrings.at(i)); + QString const ref = refsNames.at(i).first; + QString const val = refsNames.at(i).second; + item->setText(0, val); + item->setData(0, Qt::UserRole, ref); refsItems.append(item); } refsTW->addTopLevelItems(refsItems);