group improvements

- set groups now supports setting cards from fact
- editor doesn't set cards when fact group is changed
- card group and fact group can be displayed separately
- window title doesn't bother to calculate total card count
This commit is contained in:
Damien Elmes 2011-04-18 05:22:14 +09:00
parent b5df36f458
commit dac9f0584b
5 changed files with 159 additions and 38 deletions

View file

@ -44,7 +44,7 @@ class AddCards(QDialog):
print "focus lost" print "focus lost"
def setupEditor(self): def setupEditor(self):
self.editor = aqt.editor.Editor(self.mw, self.form.fieldsArea) self.editor = aqt.editor.Editor(self.mw, self.form.fieldsArea, True)
def setupChooser(self): def setupChooser(self):
self.modelChooser = aqt.modelchooser.ModelChooser( self.modelChooser = aqt.modelchooser.ModelChooser(

View file

@ -226,8 +226,10 @@ class DeckModel(QAbstractTableModel):
if c.type == 0: if c.type == 0:
return _("(new)") return _("(new)")
return "%d%%" % (c.factor/10) return "%d%%" % (c.factor/10)
elif type == "group": elif type == "cardGroup":
return self.browser.mw.deck.groupName(c.gid) return self.browser.mw.deck.groupName(c.gid)
elif type == "factGroup":
return self.browser.mw.deck.groupName(c.fact().gid)
# def limitContent(self, txt): # def limitContent(self, txt):
# if "<c>" in txt: # if "<c>" in txt:
@ -336,7 +338,7 @@ class Browser(QMainWindow):
c = self.connect; f = self.form; s = SIGNAL("triggered()") c = self.connect; f = self.form; s = SIGNAL("triggered()")
c(f.actionAddItems, s, self.mw.onAddCard) c(f.actionAddItems, s, self.mw.onAddCard)
c(f.actionDelete, s, self.deleteCards) c(f.actionDelete, s, self.deleteCards)
c(f.actionChangeGroup, s, self.changeGroup) c(f.actionSetGroup, s, self.setGroup)
c(f.actionAddTag, s, self.addTags) c(f.actionAddTag, s, self.addTags)
c(f.actionDeleteTag, s, self.deleteTags) c(f.actionDeleteTag, s, self.deleteTags)
c(f.actionReschedule, s, self.reschedule) c(f.actionReschedule, s, self.reschedule)
@ -400,7 +402,8 @@ class Browser(QMainWindow):
('question', _("Question")), ('question', _("Question")),
('answer', _("Answer")), ('answer', _("Answer")),
('template', _("Card")), ('template', _("Card")),
('group', _("Group")), ('cardGroup', _("Card Group")),
('factGroup', _("Fact Group")),
('factFld', _("Sort Field")), ('factFld', _("Sort Field")),
('factCrt', _("Created")), ('factCrt', _("Created")),
('factMod', _("Edited")), ('factMod', _("Edited")),
@ -454,12 +457,11 @@ 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 " cur = len(self.model.cards)
"card shown; %(sel)s)", "Browser (%(cur)d " self.setWindowTitle(ngettext("Browser (%(cur)d card shown; %(sel)s)",
"cards shown; %(sel)s)", "Browser (%(cur)d cards shown; %(sel)s)",
self.deck.cardCount) % { cur) % {
"cur": len(self.model.cards), "cur": cur,
"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())
return selected return selected
@ -527,9 +529,10 @@ class Browser(QMainWindow):
def onSortChanged(self, idx, ord): def onSortChanged(self, idx, ord):
type = self.model.activeCols[idx] type = self.model.activeCols[idx]
noSort = ("question", "answer", "template", "group") noSort = ("question", "answer", "template", "cardGroup", "factGroup")
if type in noSort: if type in noSort:
showInfo(_("Please choose a different column to sort by.")) showInfo(_("Sorting on this column is not supported. Please "
"choose another."))
type = self.deck.conf['sortType'] type = self.deck.conf['sortType']
if self.deck.conf['sortType'] != type: if self.deck.conf['sortType'] != type:
self.deck.conf['sortType'] = type self.deck.conf['sortType'] = type
@ -793,37 +796,39 @@ where id in %s""" % ids2str(sf))
# Group change # Group change
###################################################################### ######################################################################
def changeGroup(self): def setGroup(self):
d = QDialog(self) d = QDialog(self)
d.setWindowModality(Qt.WindowModal) d.setWindowModality(Qt.WindowModal)
l = QVBoxLayout() frm = aqt.forms.setgroup.Ui_Dialog()
d.setLayout(l) frm.setupUi(d)
lab = QLabel(_("Put cards in group:"))
l.addWidget(lab)
from aqt.tagedit import TagEdit from aqt.tagedit import TagEdit
te = TagEdit(d, type=1) te = TagEdit(d, type=1)
l.addWidget(te) frm.groupBox.layout().insertWidget(0, te)
te.setDeck(self.deck) te.setDeck(self.deck)
cf = QCheckBox(_("Change facts too")) d.connect(d, SIGNAL("accepted()"), lambda: self.onSetGroup(frm, te))
l.addWidget(cf) d.show()
bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) te.setFocus()
bb.connect(bb, SIGNAL("accepted()"), d, SLOT("accept()"))
bb.connect(bb, SIGNAL("rejected()"), d, SLOT("reject()")) def onSetGroup(self, frm, te):
l.addWidget(bb) self.model.beginReset()
if d.exec_(): self.mw.checkpoint(_("Set Group"))
if frm.selGroup.isChecked():
gid = self.deck.groupId(unicode(te.text())) gid = self.deck.groupId(unicode(te.text()))
self.model.beginReset()
self.mw.checkpoint(_("Set Group"))
self.deck.db.execute( self.deck.db.execute(
"update cards set gid = ? where id in " + ids2str( "update cards set gid = ? where id in " + ids2str(
self.selectedCards()), gid) self.selectedCards()), gid)
if cf.isChecked(): if frm.moveFacts.isChecked():
self.deck.db.execute( self.deck.db.execute(
"update facts set gid = ? where id in " + ids2str( "update facts set gid = ? where id in " + ids2str(
self.selectedFacts()), gid) self.selectedFacts()), gid)
self.onSearch(reset=False) else:
self.mw.requireReset() print "updating cards"
self.model.endReset() self.deck.db.execute("""
update cards set gid = (select gid from facts where id = cards.fid)
where id in %s""" % ids2str(self.selectedCards()))
self.onSearch(reset=False)
self.mw.requireReset()
self.model.endReset()
# Tags # Tags
###################################################################### ######################################################################

View file

@ -187,11 +187,12 @@ $(function () {
# caller is responsible for resetting fact on reset # caller is responsible for resetting fact on reset
class Editor(object): class Editor(object):
def __init__(self, mw, widget): def __init__(self, mw, widget, editableGroup=False):
self.widget = widget self.widget = widget
self.mw = mw self.mw = mw
self.fact = None self.fact = None
self.stealFocus = True self.stealFocus = True
self.editableGroup = editableGroup
self._loaded = False self._loaded = False
self._keepButtons = False self._keepButtons = False
# current card, for card layout # current card, for card layout
@ -465,7 +466,10 @@ class Editor(object):
tb.setSpacing(12) tb.setSpacing(12)
tb.setMargin(6) tb.setMargin(6)
# group # group
l = QLabel(_("Group")) if self.editableGroup:
l = QLabel(_("Group"))
else:
l = QLabel(_("Fact Group"))
tb.addWidget(l, 0, 0) tb.addWidget(l, 0, 0)
self.group = aqt.tagedit.TagEdit(self.widget, type=1) self.group = aqt.tagedit.TagEdit(self.widget, type=1)
self.group.connect(self.group, SIGNAL("lostFocus"), self.group.connect(self.group, SIGNAL("lostFocus"),
@ -496,7 +500,6 @@ class Editor(object):
if not self.fact: if not self.fact:
return return
self.fact.gid = self.mw.deck.groupId(unicode(self.group.text())) self.fact.gid = self.mw.deck.groupId(unicode(self.group.text()))
self.fact.updateCardGids()
self.fact.tags = parseTags(unicode(self.tags.text())) self.fact.tags = parseTags(unicode(self.tags.text()))
self.fact.flush() self.fact.flush()
runHook("tagsAndGroupUpdated", self.fact) runHook("tagsAndGroupUpdated", self.fact)

View file

@ -211,7 +211,7 @@
<addaction name="actionAddItems"/> <addaction name="actionAddItems"/>
<addaction name="actionAddCards"/> <addaction name="actionAddCards"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionChangeGroup"/> <addaction name="actionSetGroup"/>
<addaction name="actionAddTag"/> <addaction name="actionAddTag"/>
<addaction name="actionDeleteTag"/> <addaction name="actionDeleteTag"/>
<addaction name="separator"/> <addaction name="separator"/>
@ -267,7 +267,7 @@
<addaction name="actionAddItems"/> <addaction name="actionAddItems"/>
<addaction name="actionAddCards"/> <addaction name="actionAddCards"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionChangeGroup"/> <addaction name="actionSetGroup"/>
<addaction name="actionAddTag"/> <addaction name="actionAddTag"/>
<addaction name="actionDeleteTag"/> <addaction name="actionDeleteTag"/>
<addaction name="separator"/> <addaction name="separator"/>
@ -549,13 +549,13 @@
<string>Find &amp;Duplicates...</string> <string>Find &amp;Duplicates...</string>
</property> </property>
</action> </action>
<action name="actionChangeGroup"> <action name="actionSetGroup">
<property name="icon"> <property name="icon">
<iconset resource="icons.qrc"> <iconset resource="icons.qrc">
<normaloff>:/icons/stock_group.png</normaloff>:/icons/stock_group.png</iconset> <normaloff>:/icons/stock_group.png</normaloff>:/icons/stock_group.png</iconset>
</property> </property>
<property name="text"> <property name="text">
<string>Change Group</string> <string>Set Group</string>
</property> </property>
<property name="shortcut"> <property name="shortcut">
<string>Ctrl+G</string> <string>Ctrl+G</string>

113
designer/setgroup.ui Normal file
View file

@ -0,0 +1,113 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>291</width>
<height>188</height>
</rect>
</property>
<property name="windowTitle">
<string>Anki</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QRadioButton" name="selGroup">
<property name="text">
<string>Move cards to chosen group:</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string/>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QCheckBox" name="moveFacts">
<property name="text">
<string>Move facts too</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QRadioButton" name="factGroup">
<property name="text">
<string>Move cards to their fact's group</string>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>Dialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>224</x>
<y>192</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>213</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>Dialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>292</x>
<y>198</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>213</y>
</hint>
</hints>
</connection>
<connection>
<sender>selGroup</sender>
<signal>toggled(bool)</signal>
<receiver>groupBox</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>188</x>
<y>19</y>
</hint>
<hint type="destinationlabel">
<x>343</x>
<y>53</y>
</hint>
</hints>
</connection>
</connections>
</ui>