ensure we focus & select when focusedCard is set - fixes deletions

This commit is contained in:
Damien Elmes 2012-10-23 21:29:29 +09:00
parent f06d27220c
commit 971a69fdbc

View file

@ -149,27 +149,30 @@ class DataModel(QAbstractTableModel):
sm.clear() sm.clear()
# restore selection # restore selection
items = QItemSelection() items = QItemSelection()
focused = None
first = None
count = 0 count = 0
firstIdx = None
focusedIdx = None
for row, id in enumerate(self.cards): for row, id in enumerate(self.cards):
# if the id matches the focused card, note the index
if self.focusedCard == id:
focusedIdx = self.index(row, 0)
items.select(focusedIdx, focusedIdx)
self.focusedCard = None
# if the card was previously selected, select again
if id in self.selectedCards: if id in self.selectedCards:
count += 1 count += 1
idx = self.index(row, 0) idx = self.index(row, 0)
items.select(idx, idx) items.select(idx, idx)
if not first: # note down the first card of the selection, in case we don't
first = idx # have a focused card
# note idx of focused card if not firstIdx:
if self.focusedCard: firstIdx = idx
focused = idx # focus previously focused or first in selection
# avoid further comparisons idx = focusedIdx or firstIdx
self.focusedCard = None
# and focus previously focused or first in selection
focus = focused or first
tv = self.browser.form.tableView tv = self.browser.form.tableView
if focus: if idx:
tv.selectRow(focus.row()) tv.selectRow(idx.row())
tv.scrollTo(focus, tv.PositionAtCenter) tv.scrollTo(idx, tv.PositionAtCenter)
if count < 500: if count < 500:
# discard large selections; they're too slow # discard large selections; they're too slow
sm.select(items, QItemSelectionModel.SelectCurrent | sm.select(items, QItemSelectionModel.SelectCurrent |