GuiDocument: Add filter to modules selection

Sorting by category is needs more work, since the GuiIdListModel is
not suitable for trees.
This commit is contained in:
Juergen Spitzmueller 2019-04-05 11:52:37 +02:00
parent fa79ff2db2
commit 38fbbf07cd
3 changed files with 203 additions and 74 deletions

View File

@ -264,7 +264,7 @@ public:
///
ModuleSelectionManager(QObject * parent,
QTreeView * availableLV,
QListView * selectedLV,
QTreeView * selectedLV,
QPushButton * addPB,
QPushButton * delPB,
QPushButton * upPB,
@ -1523,6 +1523,9 @@ GuiDocument::GuiDocument(GuiView & lv)
modulesModule->availableLV->header()->setVisible(false);
setSectionResizeMode(modulesModule->availableLV->header(), QHeaderView::ResizeToContents);
modulesModule->availableLV->header()->setStretchLastSection(false);
modulesModule->selectedLV->header()->setVisible(false);
setSectionResizeMode(modulesModule->selectedLV->header(), QHeaderView::ResizeToContents);
modulesModule->selectedLV->header()->setStretchLastSection(false);
selectionManager =
new ModuleSelectionManager(this, modulesModule->availableLV,
modulesModule->selectedLV,
@ -1530,11 +1533,34 @@ GuiDocument::GuiDocument(GuiView & lv)
modulesModule->deletePB,
modulesModule->upPB,
modulesModule->downPB,
availableModel(), selectedModel(), this);
availableModel(), selectedModel(), this);
connect(selectionManager, SIGNAL(updateHook()),
this, SLOT(updateModuleInfo()));
connect(selectionManager, SIGNAL(selectionChanged()),
this, SLOT(modulesChanged()));
// The filter bar
filter_ = new FancyLineEdit(this);
filter_->setButtonPixmap(FancyLineEdit::Right, getPixmap("images/", "editclear", "svgz,png"));
filter_->setButtonVisible(FancyLineEdit::Right, true);
filter_->setButtonToolTip(FancyLineEdit::Right, qt_("Clear text"));
filter_->setAutoHideButton(FancyLineEdit::Right, true);
filter_->setPlaceholderText(qt_("All avail. modules"));
modulesModule->moduleFilterBarL->addWidget(filter_, 0);
modulesModule->findModulesLA->setBuddy(filter_);
connect(filter_, SIGNAL(rightButtonClicked()),
this, SLOT(resetModuleFilter()));
connect(filter_, SIGNAL(textEdited(QString)),
this, SLOT(moduleFilterChanged(QString)));
connect(filter_, SIGNAL(returnPressed()),
this, SLOT(moduleFilterPressed()));
#if (QT_VERSION < 0x050000)
connect(filter_, SIGNAL(downPressed()),
modulesModule->availableLV, SLOT(setFocus()));
#else
connect(filter_, &FancyLineEdit::downPressed,
modulesModule->availableLV, [=](){ focusAndHighlight(modulesModule->availableLV); });
#endif
// PDF support
@ -1722,6 +1748,52 @@ void GuiDocument::slotButtonBox(QAbstractButton * button)
}
void GuiDocument::filterModules(QString const & str)
{
updateAvailableModules();
if (str.isEmpty())
return;
modules_av_model_.clear();
list<modInfoStruct> modInfoList = getModuleInfo();
// Sort names according to the locale
modInfoList.sort([](modInfoStruct const & a, modInfoStruct const & b) {
return 0 < b.name.localeAwareCompare(a.name);
});
int i = 0;
for (modInfoStruct const & m : modInfoList) {
if (m.name.contains(str, Qt::CaseInsensitive) || contains(m.id, fromqstr(str))) {
modules_av_model_.insertRow(i, m.name, m.id, m.description);
++i;
}
}
}
void GuiDocument::moduleFilterChanged(const QString & text)
{
if (!text.isEmpty()) {
filterModules(filter_->text());
return;
}
filterModules(filter_->text());
filter_->setFocus();
}
void GuiDocument::moduleFilterPressed()
{
filterModules(filter_->text());
}
void GuiDocument::resetModuleFilter()
{
filter_->setText(QString());
filterModules(filter_->text());
}
void GuiDocument::includeonlyClicked(QTreeWidgetItem * item, int)
{
if (item == 0)
@ -4693,6 +4765,8 @@ GuiDocument::modInfoStruct GuiDocument::modInfo(LyXModule const & mod)
modInfoStruct m;
m.id = mod.getID();
m.name = toqstr(translateIfPossible(from_utf8(mod.getName())));
m.category = mod.category().empty() ? qt_("Miscellaneous")
: toqstr(translateIfPossible(from_utf8(mod.category())));
QString desc = toqstr(translateIfPossible(from_utf8(mod.getDescription())));
// Find the first sentence of the description
QTextBoundaryFinder bf(QTextBoundaryFinder::Sentence, desc);
@ -4712,8 +4786,7 @@ void GuiDocument::loadModuleInfo()
{
moduleNames_.clear();
for (LyXModule const & mod : theModuleList)
if (mod.category().substr(0, 8) != "Citation")
moduleNames_.push_back(modInfo(mod));
moduleNames_.push_back(modInfo(mod));
}

View File

@ -155,6 +155,9 @@ private Q_SLOTS:
void allPackagesAuto();
void allPackagesAlways();
void allPackagesNot();
void moduleFilterPressed();
void moduleFilterChanged(const QString & text);
void resetModuleFilter();
private:
/// validate listings parameters and return an error message, if any
QString validateListingsParameters();
@ -219,6 +222,9 @@ private:
/// selected modules
GuiIdListModel modules_sel_model_;
/// Module filter
FancyLineEdit * filter_;
/// return false if validate_listings_params returns error
bool isValid();
@ -249,6 +255,7 @@ private:
QString name;
std::string id;
QString description;
QString category;
};
///
static modInfoStruct modInfo(LyXModule const & mod);
@ -305,6 +312,8 @@ private:
///
void checkPossibleCiteEngines();
///
void filterModules(QString const & string);
///
BufferParams bp_;
/// List of names of available modules
std::list<modInfoStruct> moduleNames_;

View File

@ -1,136 +1,159 @@
<ui version="4.0" >
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ModulesUi</class>
<widget class="QWidget" name="ModulesUi" >
<property name="geometry" >
<widget class="QWidget" name="ModulesUi">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>407</width>
<height>340</height>
<height>343</height>
</rect>
</property>
<property name="windowTitle" >
<property name="windowTitle">
<string/>
</property>
<layout class="QGridLayout" >
<property name="margin" >
<number>9</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item row="1" column="0" >
<widget class="QTextBrowser" name="infoML" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Maximum" hsizetype="Expanding" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize" >
<size>
<width>16777215</width>
<height>120</height>
</size>
</property>
</widget>
</item>
<item row="0" column="0" >
<layout class="QHBoxLayout" >
<property name="spacing" >
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<layout class="QHBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="margin" >
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QVBoxLayout" >
<property name="spacing" >
<layout class="QVBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="margin" >
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="availmodL" >
<property name="frameShape" >
<widget class="QLabel" name="availmodL">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="text" >
<property name="text">
<string>A&amp;vailable:</string>
</property>
<property name="buddy" >
<property name="buddy">
<cstring>availableLV</cstring>
</property>
</widget>
</item>
<item>
<widget class="QTreeView" name="availableLV" >
<property name="rootIsDecorated" >
<widget class="QTreeView" name="availableLV">
<property name="rootIsDecorated">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QLabel" name="findModulesLA">
<property name="text">
<string>&amp;Filter:</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="moduleFilterBarL"/>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" >
<property name="spacing" >
<layout class="QVBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="margin" >
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<spacer>
<property name="orientation" >
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0" >
<property name="sizeType">
<enum>QSizePolicy::Minimum</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>51</width>
<height>20</height>
</size>
</property>
<property name="sizeType">
<enum>QSizePolicy::Minimum</enum>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="addPB" >
<property name="text" >
<widget class="QPushButton" name="addPB">
<property name="text">
<string>A&amp;dd</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="deletePB" >
<property name="text" >
<widget class="QPushButton" name="deletePB">
<property name="text">
<string>De&amp;lete</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="upPB" >
<property name="text" >
<widget class="QPushButton" name="upPB">
<property name="text">
<string>&amp;Up</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="downPB" >
<property name="text" >
<widget class="QPushButton" name="downPB">
<property name="text">
<string>Do&amp;wn</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0" >
<property name="sizeHint" stdset="0">
<size>
<width>60</width>
<height>16</height>
@ -141,27 +164,36 @@
</layout>
</item>
<item>
<layout class="QVBoxLayout" >
<property name="spacing" >
<layout class="QVBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="margin" >
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="selmodL" >
<property name="text" >
<widget class="QLabel" name="selmodL">
<property name="text">
<string>S&amp;elected:</string>
</property>
<property name="buddy" >
<property name="buddy">
<cstring>selectedLV</cstring>
</property>
</widget>
</item>
<item>
<widget class="QListView" name="selectedLV" >
<property name="editTriggers" >
<set>QAbstractItemView::NoEditTriggers</set>
<widget class="QTreeView" name="selectedLV">
<property name="rootIsDecorated">
<bool>false</bool>
</property>
</widget>
</item>
@ -169,6 +201,22 @@
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QTextBrowser" name="infoML">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>120</height>
</size>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>
@ -177,11 +225,10 @@
<tabstop>deletePB</tabstop>
<tabstop>upPB</tabstop>
<tabstop>downPB</tabstop>
<tabstop>selectedLV</tabstop>
<tabstop>infoML</tabstop>
</tabstops>
<includes>
<include location="local" >qt_i18n.h</include>
<include location="local">qt_i18n.h</include>
</includes>
<resources/>
<connections/>