mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 14:32:22 -04:00
allow dragging fields to change its position
This commit is contained in:
parent
6ecf2ffa2c
commit
6b3d6bec55
1 changed files with 21 additions and 5 deletions
|
@ -27,6 +27,8 @@ class FieldDialog(QDialog):
|
||||||
self.oldSortField = self.model["sortf"]
|
self.oldSortField = self.model["sortf"]
|
||||||
self.fillFields()
|
self.fillFields()
|
||||||
self.setupSignals()
|
self.setupSignals()
|
||||||
|
self.form.fieldList.setDragDropMode(QAbstractItemView.InternalMove)
|
||||||
|
self.form.fieldList.dropEvent = self.onDrop
|
||||||
self.form.fieldList.setCurrentRow(0)
|
self.form.fieldList.setCurrentRow(0)
|
||||||
self.exec_()
|
self.exec_()
|
||||||
|
|
||||||
|
@ -48,6 +50,17 @@ class FieldDialog(QDialog):
|
||||||
f.sortField.clicked.connect(self.onSortField)
|
f.sortField.clicked.connect(self.onSortField)
|
||||||
f.buttonBox.helpRequested.connect(self.onHelp)
|
f.buttonBox.helpRequested.connect(self.onHelp)
|
||||||
|
|
||||||
|
def onDrop(self, ev):
|
||||||
|
fieldList = self.form.fieldList
|
||||||
|
indicatorPos = fieldList.dropIndicatorPosition()
|
||||||
|
dropPos = fieldList.indexAt(ev.pos()).row()
|
||||||
|
if indicatorPos == QAbstractItemView.OnViewport: # to bottom
|
||||||
|
self.moveField(fieldList.count())
|
||||||
|
elif indicatorPos == QAbstractItemView.AboveItem:
|
||||||
|
self.moveField(dropPos)
|
||||||
|
elif indicatorPos == QAbstractItemView.BelowItem:
|
||||||
|
self.moveField(dropPos + 1)
|
||||||
|
|
||||||
def onRowChange(self, idx):
|
def onRowChange(self, idx):
|
||||||
if idx == -1:
|
if idx == -1:
|
||||||
return
|
return
|
||||||
|
@ -115,6 +128,14 @@ class FieldDialog(QDialog):
|
||||||
return
|
return
|
||||||
if not 0 < pos <= l:
|
if not 0 < pos <= l:
|
||||||
return
|
return
|
||||||
|
self.moveField(pos)
|
||||||
|
|
||||||
|
def onSortField(self):
|
||||||
|
# don't allow user to disable; it makes no sense
|
||||||
|
self.form.sortField.setChecked(True)
|
||||||
|
self.model["sortf"] = self.form.fieldList.currentRow()
|
||||||
|
|
||||||
|
def moveField(self, pos):
|
||||||
self.saveField()
|
self.saveField()
|
||||||
f = self.model["flds"][self.currentIdx]
|
f = self.model["flds"][self.currentIdx]
|
||||||
self.mw.progress.start()
|
self.mw.progress.start()
|
||||||
|
@ -123,11 +144,6 @@ class FieldDialog(QDialog):
|
||||||
self.fillFields()
|
self.fillFields()
|
||||||
self.form.fieldList.setCurrentRow(pos - 1)
|
self.form.fieldList.setCurrentRow(pos - 1)
|
||||||
|
|
||||||
def onSortField(self):
|
|
||||||
# don't allow user to disable; it makes no sense
|
|
||||||
self.form.sortField.setChecked(True)
|
|
||||||
self.model["sortf"] = self.form.fieldList.currentRow()
|
|
||||||
|
|
||||||
def loadField(self, idx):
|
def loadField(self, idx):
|
||||||
self.currentIdx = idx
|
self.currentIdx = idx
|
||||||
fld = self.model["flds"][idx]
|
fld = self.model["flds"][idx]
|
||||||
|
|
Loading…
Reference in a new issue