Browse Source

qt_standardmodel: only use proxymodel when appropriate

master
Janus 7 years ago committed by ThomasV
parent
commit
72957f4d51
  1. 10
      electrum/gui/qt/history_list.py
  2. 26
      electrum/gui/qt/util.py

10
electrum/gui/qt/history_list.py

@ -75,8 +75,7 @@ class HistoryList(MyTreeView, AcceptFileDragDrop):
def should_hide(self, proxy_row): def should_hide(self, proxy_row):
if self.start_timestamp and self.end_timestamp: if self.start_timestamp and self.end_timestamp:
source_idx = self.proxy.mapToSource(self.proxy.index(proxy_row, 0)) item = self.item_from_coordinate(proxy_row, 0)
item = self.std_model.itemFromIndex(source_idx)
txid = item.data(self.TX_HASH_ROLE) txid = item.data(self.TX_HASH_ROLE)
date = self.transactions[txid]['date'] date = self.transactions[txid]['date']
if date: if date:
@ -418,9 +417,8 @@ class HistoryList(MyTreeView, AcceptFileDragDrop):
# TODO update unconfirmed tx'es # TODO update unconfirmed tx'es
def on_edited(self, index, user_role, text): def on_edited(self, index, user_role, text):
column = index.column() row, column = index.row(), index.column()
index = self.proxy.mapToSource(index) item = self.item_from_coordinate(row, column)
item = self.std_model.itemFromIndex(index)
key = item.data(self.TX_HASH_ROLE) key = item.data(self.TX_HASH_ROLE)
# fixme # fixme
if column == 2: if column == 2:
@ -441,7 +439,7 @@ class HistoryList(MyTreeView, AcceptFileDragDrop):
def mouseDoubleClickEvent(self, event: QMouseEvent): def mouseDoubleClickEvent(self, event: QMouseEvent):
idx = self.indexAt(event.pos()) 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(): if not item or item.isEditable():
super().mouseDoubleClickEvent(event) super().mouseDoubleClickEvent(event)
elif item: elif item:

26
electrum/gui/qt/util.py

@ -468,15 +468,12 @@ class MyTreeView(QTreeView):
pt.setX(50) pt.setX(50)
self.customContextMenuRequested.emit(pt) self.customContextMenuRequested.emit(pt)
def createEditor(self, parent, option, index): def createEditor(self, parent, option, idx):
self.editor = QStyledItemDelegate.createEditor(self.itemDelegate(), self.editor = QStyledItemDelegate.createEditor(self.itemDelegate(),
parent, option, index) parent, option, idx)
persistent = QPersistentModelIndex(index) item = self.item_from_coordinate(idx.row(), idx.column())
user_role = index.data(Qt.UserRole) user_role = item.data(Qt.UserRole)
assert user_role is not None assert user_role is not None
idx = QModelIndex(persistent)
index = self.proxy.mapToSource(idx)
item = self.std_model.itemFromIndex(index)
prior_text = item.text() prior_text = item.text()
def editing_finished(): def editing_finished():
# Long-time QT bug - pressing Enter to finish editing signals # Long-time QT bug - pressing Enter to finish editing signals
@ -524,6 +521,14 @@ class MyTreeView(QTreeView):
""" """
pass 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): def hide_row(self, row_num):
""" """
row_num is for self.model(). So if there is a proxy, it is the row number 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) self.setRowHidden(row_num, QModelIndex(), False)
return return
for column in self.filter_columns: for column in self.filter_columns:
if isinstance(self.model(), QSortFilterProxyModel): item = self.item_from_coordinate(row_num, column)
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)
txt = item.text().lower() txt = item.text().lower()
if self.current_filter in txt: if self.current_filter in txt:
# the filter matched, but the date filter might apply # the filter matched, but the date filter might apply

Loading…
Cancel
Save