Allow filtering authors/tags when creating virtual library based on them. Fixes #1966537 [[Enhancement] Filter when creating a Virtual library](https://bugs.launchpad.net/calibre/+bug/1966537)

This commit is contained in:
Kovid Goyal 2022-03-31 12:11:52 +05:30
parent 22a6e41f6d
commit 7095708004
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -9,7 +9,7 @@ from gettext import pgettext
from qt.core import ( from qt.core import (
QAbstractItemView, QAction, QComboBox, QDialog, QDialogButtonBox, QFrame, QAbstractItemView, QAction, QComboBox, QDialog, QDialogButtonBox, QFrame,
QGridLayout, QIcon, QLabel, QLineEdit, QListView, QMenu, QRadioButton, QSize, QGridLayout, QIcon, QLabel, QLineEdit, QListView, QMenu, QRadioButton, QSize,
QStringListModel, Qt, QTextBrowser, QVBoxLayout QStringListModel, Qt, QTextBrowser, QVBoxLayout, QSortFilterProxyModel
) )
from calibre.gui2 import error_dialog, gprefs, question_dialog from calibre.gui2 import error_dialog, gprefs, question_dialog
@ -30,9 +30,18 @@ class SelectNames(QDialog): # {{{
self.la = la = QLabel(_('Create a Virtual library based on %s') % txt) self.la = la = QLabel(_('Create a Virtual library based on %s') % txt)
l.addWidget(la) l.addWidget(la)
self.filter = f = QLineEdit(self)
f.setPlaceholderText(_('Filter {}').format(txt))
f.setClearButtonEnabled(True)
l.addWidget(f)
self.model = QStringListModel(sorted(names, key=sort_key)) self.model = QStringListModel(sorted(names, key=sort_key))
self.pmodel = QSortFilterProxyModel(self)
self.pmodel.setFilterCaseSensitivity(Qt.CaseSensitivity.CaseInsensitive)
f.textChanged.connect(self.pmodel.setFilterFixedString)
self.pmodel.setSourceModel(self.model)
self._names = QListView(self) self._names = QListView(self)
self._names.setModel(self.model) self._names.setModel(self.pmodel)
self._names.setSelectionMode(QAbstractItemView.SelectionMode.MultiSelection) self._names.setSelectionMode(QAbstractItemView.SelectionMode.MultiSelection)
l.addWidget(self._names) l.addWidget(self._names)