mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 23:12:21 -04:00
undo, don't call cardCount() in titlebar, fix select facts
This commit is contained in:
parent
3bd8fd56b3
commit
ae831408b2
1 changed files with 27 additions and 34 deletions
|
@ -291,6 +291,7 @@ class Browser(QMainWindow):
|
||||||
self.setupEditor()
|
self.setupEditor()
|
||||||
self.setupCardInfo()
|
self.setupCardInfo()
|
||||||
self.updateFont()
|
self.updateFont()
|
||||||
|
self.onCheckpoint()
|
||||||
self.form.searchEdit.setFocus()
|
self.form.searchEdit.setFocus()
|
||||||
self.show()
|
self.show()
|
||||||
self.form.searchEdit.setText("is:recent")
|
self.form.searchEdit.setText("is:recent")
|
||||||
|
@ -397,7 +398,6 @@ class Browser(QMainWindow):
|
||||||
def onSearch(self):
|
def onSearch(self):
|
||||||
txt = unicode(self.form.searchEdit.text()).strip()
|
txt = unicode(self.form.searchEdit.text()).strip()
|
||||||
self.model.search(txt)
|
self.model.search(txt)
|
||||||
self.updateTitle()
|
|
||||||
show = not not self.model.cards
|
show = not not self.model.cards
|
||||||
self.form.cardLabel.setShown(show)
|
self.form.cardLabel.setShown(show)
|
||||||
self.form.fieldsArea.setShown(show)
|
self.form.fieldsArea.setShown(show)
|
||||||
|
@ -407,15 +407,15 @@ class Browser(QMainWindow):
|
||||||
def updateTitle(self):
|
def updateTitle(self):
|
||||||
selected = len(self.form.tableView.selectionModel().selectedRows())
|
selected = len(self.form.tableView.selectionModel().selectedRows())
|
||||||
self.setWindowTitle(ngettext("Browser (%(cur)d "
|
self.setWindowTitle(ngettext("Browser (%(cur)d "
|
||||||
"of %(tot)d card shown; %(sel)s)", "Browser (%(cur)d "
|
"card shown; %(sel)s)", "Browser (%(cur)d "
|
||||||
"of %(tot)d cards shown; %(sel)s)", self.deck.cardCount) %
|
"cards shown; %(sel)s)",
|
||||||
{
|
self.deck.cardCount) % {
|
||||||
"cur": len(self.model.cards),
|
"cur": len(self.model.cards),
|
||||||
"tot": self.deck.cardCount(),
|
"tot": self.deck.cardCount(),
|
||||||
"sel": ngettext("%d selected", "%d selected", selected) % selected
|
"sel": ngettext("%d selected", "%d selected", selected) % selected
|
||||||
} + " - " + self.deck.name())
|
} + " - " + self.deck.name())
|
||||||
|
|
||||||
# Table view
|
# Table view & editor
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
||||||
def setupTable(self):
|
def setupTable(self):
|
||||||
|
@ -428,6 +428,14 @@ class Browser(QMainWindow):
|
||||||
SIGNAL("selectionChanged(QItemSelection,QItemSelection)"),
|
SIGNAL("selectionChanged(QItemSelection,QItemSelection)"),
|
||||||
self.updateTitle)
|
self.updateTitle)
|
||||||
self.form.tableView.setItemDelegate(StatusDelegate(self, self.model))
|
self.form.tableView.setItemDelegate(StatusDelegate(self, self.model))
|
||||||
|
self.connect(self.form.tableView.selectionModel(),
|
||||||
|
SIGNAL("currentRowChanged(QModelIndex, QModelIndex)"),
|
||||||
|
self.rowChanged)
|
||||||
|
|
||||||
|
def setupEditor(self):
|
||||||
|
self.editor = aqt.editor.Editor(self.mw,
|
||||||
|
self.form.fieldsArea)
|
||||||
|
self.editor.stealFocus = False
|
||||||
|
|
||||||
def rowChanged(self, current, previous):
|
def rowChanged(self, current, previous):
|
||||||
self.currentRow = current
|
self.currentRow = current
|
||||||
|
@ -628,17 +636,6 @@ class Browser(QMainWindow):
|
||||||
item.setIcon(0, QIcon(":/icons/anki-tag.png"))
|
item.setIcon(0, QIcon(":/icons/anki-tag.png"))
|
||||||
root.addChild(item)
|
root.addChild(item)
|
||||||
|
|
||||||
# Editor
|
|
||||||
######################################################################
|
|
||||||
|
|
||||||
def setupEditor(self):
|
|
||||||
self.editor = aqt.editor.Editor(self.mw,
|
|
||||||
self.form.fieldsArea)
|
|
||||||
self.editor.stealFocus = False
|
|
||||||
self.connect(self.form.tableView.selectionModel(),
|
|
||||||
SIGNAL("currentRowChanged(QModelIndex, QModelIndex)"),
|
|
||||||
self.rowChanged)
|
|
||||||
|
|
||||||
# Card info
|
# Card info
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
||||||
|
@ -683,15 +680,15 @@ class Browser(QMainWindow):
|
||||||
self.form.tableView.selectionModel().selectedRows()]
|
self.form.tableView.selectionModel().selectedRows()]
|
||||||
|
|
||||||
def selectedFacts(self):
|
def selectedFacts(self):
|
||||||
return self.deck.db.column0("""
|
return self.deck.db.list("""
|
||||||
select distinct factId from cards
|
select distinct fid from cards
|
||||||
where id in (%s)""" % ",".join([
|
where id in %s""" % ids2str(
|
||||||
str(self.model.cards[idx.row()][0]) for idx in
|
[self.model.cards[idx.row()] for idx in
|
||||||
self.form.tableView.selectionModel().selectedRows()]))
|
self.form.tableView.selectionModel().selectedRows()]))
|
||||||
|
|
||||||
def selectedFactsAsCards(self):
|
def selectedFactsAsCards(self):
|
||||||
return self.deck.db.column0(
|
return self.deck.db.list(
|
||||||
"select id from cards where factId in (%s)" %
|
"select id from cards where fid in (%s)" %
|
||||||
",".join([str(s) for s in self.selectedFacts()]))
|
",".join([str(s) for s in self.selectedFacts()]))
|
||||||
|
|
||||||
def updateAfterCardChange(self):
|
def updateAfterCardChange(self):
|
||||||
|
@ -893,20 +890,16 @@ where id in %s""" % ids2str(sf))
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
||||||
def selectFacts(self):
|
def selectFacts(self):
|
||||||
self.deck.startProgress()
|
self.mw.progress.start()
|
||||||
sm = self.form.tableView.selectionModel()
|
sm = self.form.tableView.selectionModel()
|
||||||
sm.blockSignals(True)
|
items = QItemSelection()
|
||||||
cardIds = dict([(x, 1) for x in self.selectedFactsAsCards()])
|
cardIds = dict([(x, 1) for x in self.selectedFactsAsCards()])
|
||||||
for i, card in enumerate(self.model.cards):
|
for i, card in enumerate(self.model.cards):
|
||||||
if card[0] in cardIds:
|
if card in cardIds:
|
||||||
sm.select(self.model.index(i, 0),
|
idx = self.model.index(i, 0)
|
||||||
QItemSelectionModel.Select | QItemSelectionModel.Rows)
|
items.select(idx, idx)
|
||||||
if i % 100 == 0:
|
sm.select(items, QItemSelectionModel.SelectCurrent | QItemSelectionModel.Rows)
|
||||||
self.deck.updateProgress()
|
self.mw.progress.finish()
|
||||||
sm.blockSignals(False)
|
|
||||||
self.deck.finishProgress()
|
|
||||||
self.updateTitle()
|
|
||||||
self.updateAfterCardChange()
|
|
||||||
|
|
||||||
def invertSelection(self):
|
def invertSelection(self):
|
||||||
sm = self.form.tableView.selectionModel()
|
sm = self.form.tableView.selectionModel()
|
||||||
|
|
Loading…
Reference in a new issue