Separate QSortFilterProxyModel creation and updating

This commit is contained in:
BasioMeusPuga
2017-11-11 06:08:51 +05:30
parent 093c272996
commit 28bfcc4f52
2 changed files with 14 additions and 9 deletions

View File

@@ -20,6 +20,7 @@
Check files (hashes) upon restart Check files (hashes) upon restart
Recursive file addition Recursive file addition
Show what on startup Show what on startup
Maybe include icons for emblems
mobi, azw support mobi, azw support
txt, doc, djvu support txt, doc, djvu support
pdf support? pdf support?
@@ -71,8 +72,8 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
self.libraryToolBar = LibraryToolBar(self) self.libraryToolBar = LibraryToolBar(self)
self.libraryToolBar.addButton.triggered.connect(self.add_books) self.libraryToolBar.addButton.triggered.connect(self.add_books)
self.libraryToolBar.deleteButton.triggered.connect(self.delete_books) self.libraryToolBar.deleteButton.triggered.connect(self.delete_books)
self.libraryToolBar.filterEdit.textChanged.connect(self.reload_listview) self.libraryToolBar.filterEdit.textChanged.connect(self.only_update_listview)
self.libraryToolBar.sortingBox.activated.connect(self.reload_listview) self.libraryToolBar.sortingBox.activated.connect(self.only_update_listview)
self.addToolBar(self.libraryToolBar) self.addToolBar(self.libraryToolBar)
self.bookToolBar = BookToolBar(self) self.bookToolBar = BookToolBar(self)
@@ -177,10 +178,14 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
msg_box.show() msg_box.show()
msg_box.exec_() msg_box.exec_()
def only_update_listview(self):
self.lib_ref.update_proxyModel()
def reload_listview(self): def reload_listview(self):
if not self.viewModel: if not self.viewModel:
self.lib_ref.generate_model() self.lib_ref.generate_model()
self.lib_ref.update_listView() self.lib_ref.create_proxyModel()
self.lib_ref.update_proxyModel()
def tab_switch(self): def tab_switch(self):
if self.tabWidget.currentIndex() == 0: if self.tabWidget.currentIndex() == 0:

View File

@@ -98,10 +98,14 @@ class Library:
item.setIcon(QtGui.QIcon(img_pixmap)) item.setIcon(QtGui.QIcon(img_pixmap))
self.parent_window.viewModel.appendRow(item) self.parent_window.viewModel.appendRow(item)
def create_proxyModel(self):
def update_listView(self):
self.proxy_model = QtCore.QSortFilterProxyModel() self.proxy_model = QtCore.QSortFilterProxyModel()
self.proxy_model.setSourceModel(self.parent_window.viewModel) self.proxy_model.setSourceModel(self.parent_window.viewModel)
s = QtCore.QSize(160, 250) # Set icon sizing here
self.parent_window.listView.setIconSize(s)
self.parent_window.listView.setModel(self.proxy_model)
def update_proxyModel(self):
self.proxy_model.setFilterRole(QtCore.Qt.UserRole + 4) self.proxy_model.setFilterRole(QtCore.Qt.UserRole + 4)
self.proxy_model.setFilterCaseSensitivity(QtCore.Qt.CaseInsensitive) self.proxy_model.setFilterCaseSensitivity(QtCore.Qt.CaseInsensitive)
self.proxy_model.setFilterWildcard(self.parent_window.libraryToolBar.filterEdit.text()) self.proxy_model.setFilterWildcard(self.parent_window.libraryToolBar.filterEdit.text())
@@ -114,10 +118,6 @@ class Library:
QtCore.Qt.UserRole + self.parent_window.libraryToolBar.sortingBox.currentIndex()) QtCore.Qt.UserRole + self.parent_window.libraryToolBar.sortingBox.currentIndex())
self.proxy_model.sort(0) self.proxy_model.sort(0)
s = QtCore.QSize(160, 250) # Set icon sizing here
self.parent_window.listView.setIconSize(s)
self.parent_window.listView.setModel(self.proxy_model)
class Settings: class Settings:
def __init__(self, parent): def __init__(self, parent):