diff --git a/src/qml/presenter/ServiceList.qml b/src/qml/presenter/ServiceList.qml index 31a89a5..c19d905 100644 --- a/src/qml/presenter/ServiceList.qml +++ b/src/qml/presenter/ServiceList.qml @@ -280,6 +280,8 @@ ColumnLayout { return; if (newIndex === -1) newIndex = 0; + if (newIndex >= serviceItemList.count) + newIndex = serviceItemList.count; print("moveRequested: ", oldIndex, newIndex); serviceItemModel.move(oldIndex, newIndex); indexDragged = newIndex; @@ -359,32 +361,23 @@ ColumnLayout { /* text: "Down" */ icon.name: "arrow-down" onTriggered: { - const oldid = serviceItemList.currentIndex; - if (oldid + 1 >= serviceItemList.count) + const id = serviceItemList.currentIndex; + if (id + 1 >= serviceItemList.count) { showPassiveNotification("wow you dummy you can't got further down"); return; }; - const newid = findId(serviceItemList.currentIndex + 2); - showPassiveNotification(oldid + " " + newid); - showPassiveNotification("Down"); - const ans = serviceItemModel.move(oldid, newid); + showPassiveNotification("moving ", id, " down"); + const ans = serviceItemModel.moveDown(id); if (ans) { - serviceItemList.currentIndex = newid - 1; + serviceItemList.currentIndex = id + 1; showPassiveNotification("move was successful, newid: " + serviceItemList.currentIndex); } else - showPassiveNotification("move was unsuccessful, newid: " - + newid); - - function findId(id) { - if (id >= serviceItemList.count) - return serviceItemList.count; - else - return id; - } + showPassiveNotification("move was unsuccessful, id: " + + id); } }, Kirigami.Action { diff --git a/src/serviceitemmodel.cpp b/src/serviceitemmodel.cpp index f97b83c..d172b0b 100644 --- a/src/serviceitemmodel.cpp +++ b/src/serviceitemmodel.cpp @@ -234,21 +234,34 @@ bool ServiceItemModel::move(int sourceIndex, int destIndex) { return false; } -bool ServiceItemModel::move(int sourceIndex, int destIndex, bool simple) { - qDebug() << index(sourceIndex).row(); - qDebug() << index(destIndex).row(); - QModelIndex parent = index(sourceIndex).parent(); +bool ServiceItemModel::moveDown(int id) { + qDebug() << index(id).row(); + qDebug() << index(id + 1).row(); + QModelIndex parent = index(id).parent(); + + bool begsuc = beginMoveRows(parent, id, + id, parent, id + 2); + if (begsuc) { + int dest = id + 1; + if (dest >= m_items.size()) + { + qDebug() << "dest too big, moving to end"; + m_items.move(id, m_items.size() - 1); + } + else + m_items.move(id, dest); + endMoveRows(); + return true; + } + return false; +} + +bool ServiceItemModel::moveUp(int id) { + qDebug() << index(id).row(); + qDebug() << index(id - 1).row(); + QModelIndex parent = index(id).parent(); + - if (simple) - { - if (moveRow(parent, sourceIndex, parent, destIndex)) - return true; - else - { - qDebug() << "not sure..."; - return false; - } - } return false; } diff --git a/src/serviceitemmodel.h b/src/serviceitemmodel.h index 1a76624..ae6a3ed 100644 --- a/src/serviceitemmodel.h +++ b/src/serviceitemmodel.h @@ -61,7 +61,8 @@ public: const QString &backgroundType, const QStringList &text); Q_INVOKABLE void removeItem(int index); Q_INVOKABLE bool move(int sourceIndex, int destIndex); - Q_INVOKABLE bool move(int sourceIndex, int destIndex, bool simple); + Q_INVOKABLE bool moveDown(int index); + Q_INVOKABLE bool moveUp(int index); Q_INVOKABLE QVariantMap getItem(int index) const; private: