qt_standardmodel: only use proxymodel when appropriate
This commit is contained in:
@@ -75,8 +75,7 @@ class HistoryList(MyTreeView, AcceptFileDragDrop):
|
||||
|
||||
def should_hide(self, proxy_row):
|
||||
if self.start_timestamp and self.end_timestamp:
|
||||
source_idx = self.proxy.mapToSource(self.proxy.index(proxy_row, 0))
|
||||
item = self.std_model.itemFromIndex(source_idx)
|
||||
item = self.item_from_coordinate(proxy_row, 0)
|
||||
txid = item.data(self.TX_HASH_ROLE)
|
||||
date = self.transactions[txid]['date']
|
||||
if date:
|
||||
@@ -418,9 +417,8 @@ class HistoryList(MyTreeView, AcceptFileDragDrop):
|
||||
# TODO update unconfirmed tx'es
|
||||
|
||||
def on_edited(self, index, user_role, text):
|
||||
column = index.column()
|
||||
index = self.proxy.mapToSource(index)
|
||||
item = self.std_model.itemFromIndex(index)
|
||||
row, column = index.row(), index.column()
|
||||
item = self.item_from_coordinate(row, column)
|
||||
key = item.data(self.TX_HASH_ROLE)
|
||||
# fixme
|
||||
if column == 2:
|
||||
@@ -441,7 +439,7 @@ class HistoryList(MyTreeView, AcceptFileDragDrop):
|
||||
|
||||
def mouseDoubleClickEvent(self, event: QMouseEvent):
|
||||
idx = self.indexAt(event.pos())
|
||||
item = self.std_model.itemFromIndex(self.proxy.mapToSource(idx))
|
||||
item = self.item_from_coordinate(idx.row(), idx.column())
|
||||
if not item or item.isEditable():
|
||||
super().mouseDoubleClickEvent(event)
|
||||
elif item:
|
||||
|
||||
@@ -468,15 +468,12 @@ class MyTreeView(QTreeView):
|
||||
pt.setX(50)
|
||||
self.customContextMenuRequested.emit(pt)
|
||||
|
||||
def createEditor(self, parent, option, index):
|
||||
def createEditor(self, parent, option, idx):
|
||||
self.editor = QStyledItemDelegate.createEditor(self.itemDelegate(),
|
||||
parent, option, index)
|
||||
persistent = QPersistentModelIndex(index)
|
||||
user_role = index.data(Qt.UserRole)
|
||||
parent, option, idx)
|
||||
item = self.item_from_coordinate(idx.row(), idx.column())
|
||||
user_role = item.data(Qt.UserRole)
|
||||
assert user_role is not None
|
||||
idx = QModelIndex(persistent)
|
||||
index = self.proxy.mapToSource(idx)
|
||||
item = self.std_model.itemFromIndex(index)
|
||||
prior_text = item.text()
|
||||
def editing_finished():
|
||||
# Long-time QT bug - pressing Enter to finish editing signals
|
||||
@@ -524,6 +521,14 @@ class MyTreeView(QTreeView):
|
||||
"""
|
||||
pass
|
||||
|
||||
def item_from_coordinate(self, row_num, column):
|
||||
if isinstance(self.model(), QSortFilterProxyModel):
|
||||
idx = self.model().mapToSource(self.model().index(row_num, column))
|
||||
return self.model().sourceModel().itemFromIndex(idx)
|
||||
else:
|
||||
idx = self.model().index(row_num, column)
|
||||
return self.model().itemFromIndex(idx)
|
||||
|
||||
def hide_row(self, row_num):
|
||||
"""
|
||||
row_num is for self.model(). So if there is a proxy, it is the row number
|
||||
@@ -535,12 +540,7 @@ class MyTreeView(QTreeView):
|
||||
self.setRowHidden(row_num, QModelIndex(), False)
|
||||
return
|
||||
for column in self.filter_columns:
|
||||
if isinstance(self.model(), QSortFilterProxyModel):
|
||||
idx = self.model().mapToSource(self.model().index(row_num, column))
|
||||
item = self.model().sourceModel().itemFromIndex(idx)
|
||||
else:
|
||||
idx = self.model().index(row_num, column)
|
||||
item = self.model().itemFromIndex(idx)
|
||||
item = self.item_from_coordinate(row_num, column)
|
||||
txt = item.text().lower()
|
||||
if self.current_filter in txt:
|
||||
# the filter matched, but the date filter might apply
|
||||
|
||||
Reference in New Issue
Block a user