From: Juergen Spitzmueller Date: Fri, 5 Apr 2019 09:52:37 +0000 (+0200) Subject: GuiDocument: Add filter to modules selection X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=c9cc84d1a4b553946f8beb322f95b4a090550bae;p=features.git GuiDocument: Add filter to modules selection Sorting by category is needs more work, since the GuiIdListModel is not suitable for trees. --- diff --git a/src/frontends/qt4/GuiDocument.cpp b/src/frontends/qt4/GuiDocument.cpp index 59e04aa73e..3d84dc610b 100644 --- a/src/frontends/qt4/GuiDocument.cpp +++ b/src/frontends/qt4/GuiDocument.cpp @@ -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 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)); } diff --git a/src/frontends/qt4/GuiDocument.h b/src/frontends/qt4/GuiDocument.h index eebd2675f4..4f41faad32 100644 --- a/src/frontends/qt4/GuiDocument.h +++ b/src/frontends/qt4/GuiDocument.h @@ -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 moduleNames_; diff --git a/src/frontends/qt4/ui/ModulesUi.ui b/src/frontends/qt4/ui/ModulesUi.ui index 472a0a22c2..0bfeb39c05 100644 --- a/src/frontends/qt4/ui/ModulesUi.ui +++ b/src/frontends/qt4/ui/ModulesUi.ui @@ -1,136 +1,159 @@ - + + ModulesUi - - + + 0 0 407 - 340 + 343 - + - - - 9 - - - 6 - - - - - - 0 - 0 - + + + + + 6 - - - 16777215 - 120 - + + 0 - - - - - - 6 + + 0 - + + 0 + + 0 - - + + 6 - + + 0 + + + 0 + + + 0 + + 0 - - + + QFrame::NoFrame - + A&vailable: - + availableLV - - + + false + + + + + + &Filter: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + + - - + + 6 - + + 0 + + + 0 + + + 0 + + 0 - + Qt::Horizontal - + + QSizePolicy::Minimum + + 51 20 - - QSizePolicy::Minimum - - - + + A&dd - - + + De&lete - - + + &Up - - + + Do&wn - + Qt::Vertical - + 60 16 @@ -141,27 +164,36 @@ - - + + 6 - + + 0 + + + 0 + + + 0 + + 0 - - + + S&elected: - + selectedLV - - - QAbstractItemView::NoEditTriggers + + + false @@ -169,6 +201,22 @@ + + + + + 0 + 0 + + + + + 16777215 + 120 + + + + @@ -177,11 +225,10 @@ deletePB upPB downPB - selectedLV infoML - qt_i18n.h + qt_i18n.h