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
This commit is contained in:
Jürgen Spitzmüller 2010-01-30 10:51:24 +00:00
parent c0d42b97ee
commit e0d2a2adff
4 changed files with 372 additions and 188 deletions

View File

@ -27,8 +27,8 @@
#include <QLineEdit>
#include <QCheckBox>
#include <QListWidget>
#include <QListWidgetItem>
#include <QTreeWidget>
#include <QTreeWidgetItem>
#include <QPushButton>
#include <QToolTip>
#include <QCloseEvent>
@ -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<QListWidgetItem *> selections = refsLW->selectedItems();
QList<QTreeWidgetItem *> 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));
// <enter> 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<docstring>::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())
@ -344,7 +375,35 @@ void GuiRef::redoRefs()
caseInsensitiveLessThan /*defined above*/);
}
refsLW->addItems(refsStrings);
if (groupCB->isChecked()) {
QList<QTreeWidgetItem *> 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<QTreeWidgetItem *> 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_);

View File

@ -19,7 +19,7 @@
#include <vector>
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();

View File

@ -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_; }

View File

@ -6,7 +6,7 @@
<x>0</x>
<y>0</y>
<width>386</width>
<height>423</height>
<height>479</height>
</rect>
</property>
<property name="windowTitle" >
@ -16,35 +16,108 @@
<bool>true</bool>
</property>
<layout class="QGridLayout" >
<item row="0" column="0" colspan="2" >
<widget class="QLabel" name="refsL" >
<property name="text" >
<string>La&amp;bels in:</string>
</property>
<property name="buddy" >
<cstring>bufferCO</cstring>
</property>
</widget>
</item>
<item row="0" column="2" >
<widget class="QComboBox" name="bufferCO" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>7</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="1" column="0" colspan="3" >
<widget class="QListWidget" name="refsLW" />
</item>
<item row="2" column="0" colspan="3" >
<property name="margin" >
<number>9</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item row="7" column="0" colspan="3" >
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QPushButton" name="updatePB" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>3</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip" >
<string>Update the label list</string>
</property>
<property name="text" >
<string>&amp;Update</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType" >
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" >
<size>
<width>31</width>
<height>30</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="okPB" >
<property name="text" >
<string>&amp;OK</string>
</property>
<property name="autoDefault" >
<bool>true</bool>
</property>
<property name="default" >
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="applyPB" >
<property name="text" >
<string>&amp;Apply</string>
</property>
<property name="autoDefault" >
<bool>false</bool>
</property>
<property name="default" >
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="closePB" >
<property name="text" >
<string>&amp;Close</string>
</property>
<property name="autoDefault" >
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item row="3" column="0" colspan="3" >
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QCheckBox" name="sortCB" >
<property name="toolTip" >
@ -68,64 +141,94 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="groupCB" >
<property name="toolTip" >
<string>Group labels by prefix (e.g. "sec:")</string>
</property>
<property name="text" >
<string>Grou&amp;p</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" >
<item>
<widget class="QPushButton" name="updatePB" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>3</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip" >
<string>Update the label list</string>
</property>
<property name="text" >
<string>&amp;Update</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="gotoPB" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>3</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text" >
<string>&amp;Go to Label</string>
</property>
</widget>
</item>
</layout>
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="gotoPB" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>3</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text" >
<string>&amp;Go to Label</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="3" column="0" >
<widget class="QLabel" name="referenceL" >
<item row="0" column="0" colspan="2" >
<widget class="QLabel" name="refsL" >
<property name="text" >
<string>&amp;Label:</string>
<string>La&amp;bels in:</string>
</property>
<property name="buddy" >
<cstring>bufferCO</cstring>
</property>
</widget>
</item>
<item row="0" column="2" >
<widget class="QComboBox" name="bufferCO" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>7</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="6" column="0" >
<widget class="QLabel" name="nameL" >
<property name="enabled" >
<bool>false</bool>
</property>
<property name="text" >
<string>&amp;Name:</string>
</property>
<property name="alignment" >
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<property name="buddy" >
<cstring>referenceED</cstring>
<cstring>nameED</cstring>
</property>
</widget>
</item>
<item row="3" column="1" colspan="2" >
<widget class="QLineEdit" name="referenceED" />
<item row="6" column="1" colspan="2" >
<widget class="QLineEdit" name="nameED" >
<property name="enabled" >
<bool>false</bool>
</property>
</widget>
</item>
<item row="4" column="0" >
<item row="5" column="0" >
<widget class="QLabel" name="typeLA" >
<property name="text" >
<string>&amp;Format:</string>
@ -138,7 +241,7 @@
</property>
</widget>
</item>
<item row="4" column="1" colspan="2" >
<item row="5" column="1" colspan="2" >
<widget class="QComboBox" name="typeCO" >
<property name="sizePolicy" >
<sizepolicy>
@ -183,96 +286,93 @@
</item>
</widget>
</item>
<item row="5" column="0" >
<widget class="QLabel" name="nameL" >
<property name="enabled" >
<bool>false</bool>
</property>
<item row="4" column="0" >
<widget class="QLabel" name="referenceL" >
<property name="text" >
<string>&amp;Name:</string>
<string>&amp;Label:</string>
</property>
<property name="alignment" >
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<property name="buddy" >
<cstring>nameED</cstring>
<cstring>referenceED</cstring>
</property>
</widget>
</item>
<item row="5" column="1" colspan="2" >
<widget class="QLineEdit" name="nameED" >
<property name="enabled" >
<bool>false</bool>
</property>
</widget>
<item row="4" column="1" colspan="2" >
<widget class="QLineEdit" name="referenceED" />
</item>
<item row="6" column="0" colspan="3" >
<layout class="QHBoxLayout" >
<property name="spacing" >
<number>6</number>
<item row="1" column="0" colspan="3" >
<widget class="QTreeWidget" name="refsTW" />
</item>
<item row="2" column="0" colspan="3" >
<widget class="QFrame" name="frame" >
<property name="frameShape" >
<enum>QFrame::StyledPanel</enum>
</property>
<property name="margin" >
<number>0</number>
<property name="frameShadow" >
<enum>QFrame::Plain</enum>
</property>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType" >
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0" >
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="okPB" >
<property name="text" >
<string>&amp;OK</string>
</property>
<property name="autoDefault">
<bool>true</bool>
</property>
<property name="default" >
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="applyPB" >
<property name="text" >
<string>&amp;Apply</string>
</property>
<property name="autoDefault" >
<bool>false</bool>
</property>
<property name="default">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="closePB" >
<property name="text" >
<string>&amp;Close</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
<layout class="QGridLayout" >
<property name="margin" >
<number>9</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item row="1" column="1" >
<widget class="QCheckBox" name="csFindCB" >
<property name="text" >
<string>Case-sensiti&amp;ve</string>
</property>
</widget>
</item>
<item row="0" column="1" >
<widget class="QLineEdit" name="findLE" >
<property name="toolTip" >
<string>Enter the text to search for and press Enter or click the button to search</string>
</property>
<property name="text" >
<string/>
</property>
</widget>
</item>
<item row="0" column="2" >
<widget class="QPushButton" name="searchPB" >
<property name="enabled" >
<bool>false</bool>
</property>
<property name="toolTip" >
<string>Click or press Enter in the search box to search</string>
</property>
<property name="text" >
<string>&amp;Search</string>
</property>
<property name="autoDefault" >
<bool>false</bool>
</property>
</widget>
</item>
<item row="0" column="0" >
<widget class="QLabel" name="findKeysLA" >
<property name="text" >
<string>Searc&amp;h:</string>
</property>
<property name="alignment" >
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<property name="buddy" >
<cstring>findLE</cstring>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>bufferCO</tabstop>
<tabstop>refsLW</tabstop>
<tabstop>sortCB</tabstop>
<tabstop>updatePB</tabstop>
<tabstop>gotoPB</tabstop>