From 19c7e4cd40962356b979704b1232faa7bce2e352 Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Thu, 25 Aug 2022 05:48:55 -0500 Subject: [PATCH] hoping to fix the moving items in leftdock --- src/qml/presenter/LeftDock.qml | 24 ++++++------------------ src/serviceitemmodel.cpp | 22 +++++++++++++--------- 2 files changed, 19 insertions(+), 27 deletions(-) diff --git a/src/qml/presenter/LeftDock.qml b/src/qml/presenter/LeftDock.qml index bd16ffd..e49b4dd 100644 --- a/src/qml/presenter/LeftDock.qml +++ b/src/qml/presenter/LeftDock.qml @@ -59,6 +59,7 @@ ColumnLayout { clip: true spacing: 3 property int indexDragged + property int moveToIndex property int draggedY addDisplaced: Transition { @@ -255,24 +256,11 @@ ColumnLayout { } function updateDrag(y) { - var newIndex; - print(serviceItemList.indexAt(0,y)); - serviceItemList.draggedY = y; - if (y < 30) { - indexedHLRec.y = 0; - newIndex = 0; - moveRequested(indexDragged, newIndex) - } - else if (y < 80) { - indexedHLRec.y = 50; - newIndex = 1; - moveRequested(indexDragged, newIndex) - } - else if (y < 130) { - indexedHLRec.y = 100; - newIndex = 2; - moveRequested(indexDragged, newIndex) - } + if (moveToIndex === serviceItemList.indexAt(0,y)) + return; + else + moveToIndex = serviceItemList.indexAt(0,y); + moveRequested(indexDragged, moveToIndex); } function moveRequested(oldIndex, newIndex) { diff --git a/src/serviceitemmodel.cpp b/src/serviceitemmodel.cpp index 5118060..d29d9ae 100644 --- a/src/serviceitemmodel.cpp +++ b/src/serviceitemmodel.cpp @@ -183,16 +183,20 @@ bool ServiceItemModel::move(int sourceIndex, int destIndex) { qDebug() << index(destIndex).row(); // beginResetModel(); QModelIndex parent = index(sourceIndex).parent(); - if (sourceIndex >= 0 && sourceIndex != destIndex && destIndex >= 0 && destIndex < rowCount() && sourceIndex < rowCount()) { - qDebug() << "starting move of: " << "source: " << sourceIndex << "dest: " << destIndex; - bool begsuc = beginMoveRows(QModelIndex(), sourceIndex, sourceIndex, QModelIndex(), destIndex); - if (begsuc) - m_items.move(sourceIndex, destIndex); - endMoveRows(); + if (sourceIndex >= 0 && sourceIndex != destIndex && + destIndex >= -1 && destIndex < rowCount() && + sourceIndex < rowCount()) { + qDebug() << "starting move: " << "source: " << sourceIndex << "dest: " << destIndex; + bool begsuc = beginMoveRows(QModelIndex(), sourceIndex, + sourceIndex, QModelIndex(), destIndex); + if (begsuc) { + if (destIndex = -1) + m_item.move(sourceIndex, 0); + else + m_items.move(sourceIndex, destIndex); + endMoveRows(); + } } - // endResetModel(); - // emit dataChanged(index(sourceIndex), QModelIndex()); - // qDebug() << success; return true; }