From 6f3ebafc4629a51445380973754f8bbaad1d3061 Mon Sep 17 00:00:00 2001 From: BlueGreenMagick <50060875+BlueGreenMagick@users.noreply.github.com> Date: Tue, 26 May 2020 18:27:38 +0900 Subject: [PATCH 1/2] fix drag drop field repositioning --- qt/aqt/fields.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/qt/aqt/fields.py b/qt/aqt/fields.py index 55b854063..f0c6fb03b 100644 --- a/qt/aqt/fields.py +++ b/qt/aqt/fields.py @@ -59,12 +59,17 @@ class FieldDialog(QDialog): fieldList = self.form.fieldList indicatorPos = fieldList.dropIndicatorPosition() dropPos = fieldList.indexAt(ev.pos()).row() - if indicatorPos == QAbstractItemView.OnViewport: # to bottom - self.moveField(fieldList.count()) + idx = self.currentIdx + if indicatorPos == QAbstractItemView.OnViewport: # to bottom. + movePos = fieldList.count() - 1 elif indicatorPos == QAbstractItemView.AboveItem: - self.moveField(dropPos) + movePos = dropPos elif indicatorPos == QAbstractItemView.BelowItem: - self.moveField(dropPos + 1) + movePos = dropPos + 1 + # the item in idx is removed thus subtract 1. + if idx < dropPos: + movePos -= 1 + self.moveField(movePos + 1) # convert to 1 based. def onRowChange(self, idx): if idx == -1: From ce512014f29bf6716babe7af1d77b8e08decb481 Mon Sep 17 00:00:00 2001 From: BlueGreenMagick <50060875+BlueGreenMagick@users.noreply.github.com> Date: Tue, 26 May 2020 18:59:53 +0900 Subject: [PATCH 2/2] do nothing if dropPos == idx since such move won't change the field position and when trying to move the field below itself may lead to it being moved below the next field --- qt/aqt/fields.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/qt/aqt/fields.py b/qt/aqt/fields.py index f0c6fb03b..ea6652871 100644 --- a/qt/aqt/fields.py +++ b/qt/aqt/fields.py @@ -60,6 +60,8 @@ class FieldDialog(QDialog): indicatorPos = fieldList.dropIndicatorPosition() dropPos = fieldList.indexAt(ev.pos()).row() idx = self.currentIdx + if dropPos == idx: + return if indicatorPos == QAbstractItemView.OnViewport: # to bottom. movePos = fieldList.count() - 1 elif indicatorPos == QAbstractItemView.AboveItem: