allow dragging fields to change its position

This commit is contained in:
BlueGreenMagick 2020-04-07 16:42:33 +09:00
parent 6ecf2ffa2c
commit 6b3d6bec55

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]