From: Jürgen Spitzmüller Date: Sat, 30 Jan 2010 10:51:24 +0000 (+0000) Subject: Add search and grouping facility to Crossref dialog (bug #6304). X-Git-Tag: 2.0.0~4191 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=e0d2a2adff18aa869dc5ded6129ddee5a872e27e;p=features.git Add search and grouping facility to Crossref dialog (bug #6304). git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@33268 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/frontends/qt4/GuiRef.cpp b/src/frontends/qt4/GuiRef.cpp index d98a507b37..93f8193fc2 100644 --- a/src/frontends/qt4/GuiRef.cpp +++ b/src/frontends/qt4/GuiRef.cpp @@ -27,8 +27,8 @@ #include #include -#include -#include +#include +#include #include #include #include @@ -52,9 +52,12 @@ GuiRef::GuiRef(GuiView & lv) sortCB->setEnabled(false); caseSensitiveCB->setEnabled(false); caseSensitiveCB->setChecked(false); - refsLW->setEnabled(false); + refsTW->setEnabled(false); gotoPB->setEnabled(false); + refsTW->setColumnCount(1); + refsTW->header()->setVisible(false); + connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK())); connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply())); connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose())); @@ -65,18 +68,24 @@ GuiRef::GuiRef(GuiView & lv) this, SLOT(changed_adaptor())); connect(referenceED, SIGNAL(textChanged(QString)), this, SLOT(changed_adaptor())); + connect(findLE, SIGNAL(returnPressed()), + this, SLOT(on_searchPB_clicked())); + connect(csFindCB, SIGNAL(clicked()), + this, SLOT(on_searchPB_clicked())); connect(nameED, SIGNAL(textChanged(QString)), this, SLOT(changed_adaptor())); - connect(refsLW, SIGNAL(itemClicked(QListWidgetItem *)), - this, SLOT(refHighlighted(QListWidgetItem *))); - connect(refsLW, SIGNAL(itemSelectionChanged()), + connect(refsTW, SIGNAL(itemClicked(QTreeWidgetItem *, int)), + this, SLOT(refHighlighted(QTreeWidgetItem *))); + connect(refsTW, SIGNAL(itemSelectionChanged()), this, SLOT(selectionChanged())); - connect(refsLW, SIGNAL(itemDoubleClicked(QListWidgetItem *)), - this, SLOT(refSelected(QListWidgetItem *))); + connect(refsTW, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), + this, SLOT(refSelected(QTreeWidgetItem *))); connect(sortCB, SIGNAL(clicked()), this, SLOT(sortToggled())); connect(caseSensitiveCB, SIGNAL(clicked()), this, SLOT(caseSensitiveToggled())); + connect(groupCB, SIGNAL(clicked()), + this, SLOT(groupToggled())); connect(gotoPB, SIGNAL(clicked()), this, SLOT(gotoClicked())); connect(updatePB, SIGNAL(clicked()), @@ -88,7 +97,7 @@ GuiRef::GuiRef(GuiView & lv) bc().setOK(okPB); bc().setApply(applyPB); bc().setCancel(closePB); - bc().addReadOnly(refsLW); + bc().addReadOnly(refsTW); bc().addReadOnly(sortCB); bc().addReadOnly(caseSensitiveCB); bc().addReadOnly(nameED); @@ -118,50 +127,55 @@ void GuiRef::selectionChanged() if (isBufferReadonly()) return; - QList selections = refsLW->selectedItems(); + QList selections = refsTW->selectedItems(); if (selections.isEmpty()) return; - QListWidgetItem * sel = selections.first(); + QTreeWidgetItem * sel = selections.first(); refHighlighted(sel); return; } -void GuiRef::refHighlighted(QListWidgetItem * sel) +void GuiRef::refHighlighted(QTreeWidgetItem * sel) { if (isBufferReadonly()) return; -/* int const cur_item = refsLW->currentRow(); + if (sel->childCount() > 0) { + sel->setExpanded(true); + return; + } + +/* int const cur_item = refsTW->currentRow(); bool const cur_item_selected = cur_item >= 0 ? refsLB->isSelected(cur_item) : false;*/ - bool const cur_item_selected = refsLW->isItemSelected(sel); + bool const cur_item_selected = refsTW->isItemSelected(sel); if (cur_item_selected) - referenceED->setText(sel->text()); + referenceED->setText(sel->text(0)); if (at_ref_) gotoRef(); gotoPB->setEnabled(true); if (typeAllowed()) typeCO->setEnabled(true); - if (nameAllowed()) - nameED->setEnabled(true); + nameED->setHidden(!nameAllowed()); + nameL->setHidden(!nameAllowed()); } -void GuiRef::refSelected(QListWidgetItem * sel) +void GuiRef::refSelected(QTreeWidgetItem * sel) { if (isBufferReadonly()) return; -/* int const cur_item = refsLW->currentRow(); +/* int const cur_item = refsTW->currentRow(); bool const cur_item_selected = cur_item >= 0 ? refsLB->isSelected(cur_item) : false;*/ - bool const cur_item_selected = refsLW->isItemSelected(sel); + bool const cur_item_selected = refsTW->isItemSelected(sel); if (cur_item_selected) - referenceED->setText(sel->text()); + referenceED->setText(sel->text(0)); // or double click, inserts ref and closes dialog slotOK(); } @@ -180,8 +194,15 @@ void GuiRef::caseSensitiveToggled() } +void GuiRef::groupToggled() +{ + redoRefs(); +} + + void GuiRef::updateClicked() { + findLE->clear(); updateRefs(); } @@ -217,7 +238,8 @@ void GuiRef::updateContents() referenceED->setText(toqstr(params_["reference"])); nameED->setText(toqstr(params_["name"])); - nameED->setReadOnly(!nameAllowed() && !isBufferReadonly()); + nameED->setHidden(!nameAllowed() && !isBufferReadonly()); + nameL->setHidden(!nameAllowed() && !isBufferReadonly()); // restore type settings for new insets if (params_["reference"].empty()) @@ -321,20 +343,29 @@ void GuiRef::redoRefs() { // Prevent these widgets from emitting any signals whilst // we modify their state. - refsLW->blockSignals(true); + refsTW->blockSignals(true); referenceED->blockSignals(true); - refsLW->setUpdatesEnabled(false); + refsTW->setUpdatesEnabled(false); - refsLW->clear(); + refsTW->clear(); // need this because Qt will send a highlight() here for // the first item inserted QString const oldSelection(referenceED->text()); QStringList refsStrings; + QStringList refsCategories; + refsCategories.append(qt_("No prefix")); vector::const_iterator iter; - for (iter = refs_.begin(); iter != refs_.end(); ++iter) - refsStrings.append(toqstr(*iter)); + for (iter = refs_.begin(); iter != refs_.end(); ++iter) { + QString const lab = toqstr(*iter); + refsStrings.append(lab); + if (groupCB->isChecked() && lab.contains(":")) { + QString const pref = lab.split(':')[0]; + if (!pref.isEmpty() && !refsCategories.contains(pref)) + refsCategories.append(pref); + } + } if (sortCB->isEnabled() && sortCB->isChecked()) { if(caseSensitiveCB->isEnabled() && caseSensitiveCB->isChecked()) @@ -343,8 +374,36 @@ void GuiRef::redoRefs() qSort(refsStrings.begin(), refsStrings.end(), caseInsensitiveLessThan /*defined above*/); } - - refsLW->addItems(refsStrings); + + if (groupCB->isChecked()) { + QList refsCats; + for (int i = 0; i < refsCategories.size(); ++i) { + QString const cat = refsCategories.at(i); + QTreeWidgetItem * item = new QTreeWidgetItem(refsTW); + item->setText(0, cat); + for (int i = 0; i < refsStrings.size(); ++i) { + QString const ref = refsStrings.at(i); + if ((ref.startsWith(cat + QString(":"))) + || (cat == qt_("No prefix") + && !ref.contains(":"))) { + QTreeWidgetItem * child = + new QTreeWidgetItem(item); + child->setText(0, ref); + item->addChild(child); + } + } + refsCats.append(item); + } + refsTW->addTopLevelItems(refsCats); + } else { + QList refsItems; + for (int i = 0; i < refsStrings.size(); ++i) { + QTreeWidgetItem * item = new QTreeWidgetItem(refsTW); + item->setText(0, refsStrings.at(i)); + refsItems.append(item); + } + refsTW->addTopLevelItems(refsItems); + } referenceED->setText(oldSelection); @@ -354,23 +413,24 @@ void GuiRef::redoRefs() bool const newInset = oldSelection.isEmpty(); QString textToFind = newInset ? last_reference_ : oldSelection; last_reference_.clear(); - for (int i = 0; i != refsLW->count(); ++i) { - QListWidgetItem * item = refsLW->item(i); - if (textToFind == item->text()) { - refsLW->setCurrentItem(item); - refsLW->setItemSelected(item, !newInset); + QTreeWidgetItemIterator it(refsTW); + while (*it) { + if ((*it)->text(0) == textToFind) { + refsTW->setCurrentItem(*it); + refsTW->setItemSelected(*it, !newInset); //Make sure selected item is visible - refsLW->scrollToItem(item); + refsTW->scrollToItem(*it); last_reference_ = textToFind; break; } + ++it; } } - refsLW->setUpdatesEnabled(true); - refsLW->update(); + refsTW->setUpdatesEnabled(true); + refsTW->update(); // Re-activate the emission of signals by these widgets. - refsLW->blockSignals(false); + refsTW->blockSignals(false); referenceED->blockSignals(false); } @@ -386,9 +446,9 @@ void GuiRef::updateRefs() } sortCB->setEnabled(!refs_.empty()); caseSensitiveCB->setEnabled(sortCB->isEnabled() && sortCB->isChecked()); - refsLW->setEnabled(!refs_.empty()); - // refsLW should only be the focus proxy when it is enabled - setFocusProxy(refs_.empty() ? 0 : refsLW); + refsTW->setEnabled(!refs_.empty()); + // refsTW should only be the focus proxy when it is enabled + setFocusProxy(refs_.empty() ? 0 : refsTW); gotoPB->setEnabled(!refs_.empty()); redoRefs(); } @@ -413,6 +473,27 @@ void GuiRef::gotoBookmark() } +void GuiRef::on_findLE_textChanged(const QString & text) +{ + searchPB->setDisabled(text.isEmpty()); +} + + +void GuiRef::on_searchPB_clicked() +{ + QTreeWidgetItemIterator it(refsTW); + Qt::CaseSensitivity cs = csFindCB->isChecked() ? + Qt::CaseSensitive : Qt::CaseInsensitive; + while (*it) { + (*it)->setHidden( + (*it)->childCount() == 0 + && !(*it)->text(0).contains(findLE->text(), cs) + ); + ++it; + } +} + + bool GuiRef::initialiseParams(std::string const & data) { InsetCommand::string2params("ref", data, params_); diff --git a/src/frontends/qt4/GuiRef.h b/src/frontends/qt4/GuiRef.h index b931f70280..3f0abfe262 100644 --- a/src/frontends/qt4/GuiRef.h +++ b/src/frontends/qt4/GuiRef.h @@ -19,7 +19,7 @@ #include -class QListWidgetItem; +class QTreeWidgetItem; namespace lyx { namespace frontend { @@ -34,11 +34,14 @@ public: private Q_SLOTS: void changed_adaptor(); void gotoClicked(); - void refHighlighted(QListWidgetItem *); + void on_findLE_textChanged(const QString &); + void on_searchPB_clicked(); + void refHighlighted(QTreeWidgetItem *); void selectionChanged(); - void refSelected(QListWidgetItem *); + void refSelected(QTreeWidgetItem *); void sortToggled(); void caseSensitiveToggled(); + void groupToggled(); void updateClicked(); void resetDialog(); void dialogRejected(); diff --git a/src/frontends/qt4/Menus.cpp b/src/frontends/qt4/Menus.cpp index 8de4f83257..71220f590b 100644 --- a/src/frontends/qt4/Menus.cpp +++ b/src/frontends/qt4/Menus.cpp @@ -205,7 +205,7 @@ public: Kind kind() const { return kind_; } /// the action (if relevant) FuncRequest const & func() const { return func_; } - /// returns true if the entry should be ommited when disabled + /// returns true if the entry should be omitted when disabled bool optional() const { return optional_; } /// returns the status of the lfun associated with this entry FuncStatus const & status() const { return status_; } diff --git a/src/frontends/qt4/ui/RefUi.ui b/src/frontends/qt4/ui/RefUi.ui index ea651eb273..b74883e17e 100644 --- a/src/frontends/qt4/ui/RefUi.ui +++ b/src/frontends/qt4/ui/RefUi.ui @@ -6,7 +6,7 @@ 0 0 386 - 423 + 479 @@ -16,35 +16,108 @@ true - - - - La&bels in: - - - bufferCO + + 9 + + + 6 + + + + + 0 - - - - - - - 7 - 0 - 0 - 0 - + + 6 - - - - + + + + + 3 + 0 + 0 + 0 + + + + Update the label list + + + &Update + + + + + + + Qt::Horizontal + + + QSizePolicy::Expanding + + + + 31 + 30 + + + + + + + + &OK + + + true + + + true + + + + + + + &Apply + + + false + + + false + + + + + + + &Close + + + false + + + + - + + + 0 + + + 6 + + + 0 + + + 6 + @@ -68,64 +141,94 @@ - - - - - - - - 3 - 0 - 0 - 0 - - + - Update the label list + Group labels by prefix (e.g. "sec:") - &Update - - - - - - - - 3 - 0 - 0 - 0 - - - - &Go to Label + Grou&p + + + + Qt::Horizontal + + + + 20 + 20 + + + + + + + + + 3 + 0 + 0 + 0 + + + + &Go to Label + + + - - + + - &Label: + La&bels in: + + + bufferCO + + + + + + + + 7 + 0 + 0 + 0 + + + + + + + + false + + + &Name: Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - referenceED + nameED - - + + + + false + + - + &Format: @@ -138,7 +241,7 @@ - + @@ -183,96 +286,93 @@ - - - - false - + + - &Name: + &Label: Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - nameED + referenceED - - - - false - - + + - - - - 6 + + + + + + + QFrame::StyledPanel - - 0 + + QFrame::Plain - - - - Qt::Horizontal - - - QSizePolicy::Expanding - - - - 20 - 20 - - - - - - - - &OK - - - true - - - true - - - - - - - &Apply - - - false - - - false - - - - - - - &Close - - - false - - - - + + + 9 + + + 6 + + + + + Case-sensiti&ve + + + + + + + Enter the text to search for and press Enter or click the button to search + + + + + + + + + + false + + + Click or press Enter in the search box to search + + + &Search + + + false + + + + + + + Searc&h: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + findLE + + + + + bufferCO - refsLW sortCB updatePB gotoPB