Change view model inheritance

This commit is contained in:
BasioMeusPuga
2017-11-26 14:12:57 +05:30
parent a5c17698cc
commit 255c5230b3
2 changed files with 12 additions and 11 deletions

View File

@@ -9,6 +9,7 @@
Remember files
Check files (hashes) upon restart
Show what on startup
Draw shadows
Library:
✓ sqlite3 for cover images cache
✓ sqlite3 for storing metadata
@@ -93,7 +94,6 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
self.last_open_tab = None
self.last_open_path = None
self.thread = None # Background Thread
self.viewModel = None
self.current_contentView = None # For fullscreening purposes
self.display_profiles = None
self.current_profile_index = None
@@ -353,22 +353,22 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
# Set a baseline model index in case the item gets deleted
# E.g It's open in a tab and deleted from the library
model_index = None
start_index = self.viewModel.index(0, 0)
start_index = self.lib_ref.view_model.index(0, 0)
# Find index of the model item that corresponds to the tab
matching_item = self.viewModel.match(
matching_item = self.lib_ref.view_model.match(
start_index,
QtCore.Qt.UserRole + 6,
current_tab.metadata['hash'],
1, QtCore.Qt.MatchExactly)
if matching_item:
model_row = matching_item[0].row()
model_index = self.viewModel.index(model_row, 0)
model_index = self.lib_ref.view_model.index(model_row, 0)
current_tab.metadata[
'position']['current_chapter'] = event + 1
if model_index:
self.viewModel.setData(
self.lib_ref.view_model.setData(
model_index, current_tab.metadata['position'], QtCore.Qt.UserRole + 7)
current_tab.change_chapter_tocBox()

View File

@@ -11,15 +11,16 @@ from widgets import MyAbsModel
class Library:
def __init__(self, parent):
self.parent_window = parent
self.view_model = None
self.proxy_model = None
def generate_model(self, mode, parsed_books=None):
# The QlistView widget needs to be populated
# with a model that inherits from QStandardItemModel
# self.parent_window.viewModel = QtGui.QStandardItemModel()
# with a model that inherits from QAbstractItemModel
# because I kinda sorta NEED the match() method
if mode == 'build':
self.parent_window.viewModel = MyAbsModel()
self.view_model = MyAbsModel()
books = database.DatabaseFunctions(
self.parent_window.database_path).fetch_data(
@@ -33,7 +34,7 @@ class Library:
return
elif mode == 'addition':
# Assumes parent_window.viewModel already exists and may be extended
# Assumes self.view_model already exists and may be extended
# Because any additional books have already been added to the
# database using background threads
@@ -117,11 +118,11 @@ class Library:
item.setData(i[8], QtCore.Qt.UserRole + 6) # File hash
item.setData(position, QtCore.Qt.UserRole + 7)
item.setIcon(QtGui.QIcon(img_pixmap))
self.parent_window.viewModel.appendRow(item)
self.view_model.appendRow(item)
def create_proxymodel(self):
self.proxy_model = QtCore.QSortFilterProxyModel()
self.proxy_model.setSourceModel(self.parent_window.viewModel)
self.proxy_model.setSourceModel(self.view_model)
s = QtCore.QSize(160, 250) # Set icon sizing here
self.parent_window.listView.setIconSize(s)
self.parent_window.listView.setModel(self.proxy_model)