Merge pull request #545 from BlueGreenMagick/draggable-field-pos

allow dragging fields to change its position
This commit is contained in:
Damien Elmes 2020-04-08 16:22:27 +10:00 committed by GitHub
commit cbb2ce6928
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -27,6 +27,8 @@ class FieldDialog(QDialog):
self.oldSortField = self.model["sortf"]
self.fillFields()
self.setupSignals()
self.form.fieldList.setDragDropMode(QAbstractItemView.InternalMove)
self.form.fieldList.dropEvent = self.onDrop
self.form.fieldList.setCurrentRow(0)
self.exec_()
@ -48,6 +50,17 @@ class FieldDialog(QDialog):
f.sortField.clicked.connect(self.onSortField)
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):
if idx == -1:
return
@ -115,6 +128,14 @@ class FieldDialog(QDialog):
return
if not 0 < pos <= l:
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()
f = self.model["flds"][self.currentIdx]
self.mw.progress.start()
@ -123,11 +144,6 @@ class FieldDialog(QDialog):
self.fillFields()
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):
self.currentIdx = idx
fld = self.model["flds"][idx]