From 70f93744948be66f275aa3624996817e4256d689 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Thu, 25 Jul 2024 13:25:33 +0200 Subject: [PATCH] bit enhanced drag/drop, now it is way more robust than it was before, there are still some cases when "workaround" behavior has to be used but it atleast now drops where/how it should --- src/librssguard/core/feedsproxymodel.cpp | 28 ++++++++++-------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/src/librssguard/core/feedsproxymodel.cpp b/src/librssguard/core/feedsproxymodel.cpp index c5b3f043c..4ce11595f 100644 --- a/src/librssguard/core/feedsproxymodel.cpp +++ b/src/librssguard/core/feedsproxymodel.cpp @@ -168,6 +168,10 @@ bool FeedsProxyModel::canDropMimeData(const QMimeData* data, int row, int column, const QModelIndex& parent) const { + if (action != Qt::DropAction::MoveAction) { + return false; + } + QByteArray dragged_items_data = data->data(QSL(MIME_TYPE_ITEM_POINTER)); QDataStream stream(&dragged_items_data, QIODevice::OpenModeFlag::ReadOnly); const bool order_change = row >= 0 && !m_sortAlphabetically; @@ -184,7 +188,8 @@ bool FeedsProxyModel::canDropMimeData(const QMimeData* data, // Dragged item must service root, feed or category. // - // If row is less then zero, it means we are moving dragged item into new parent. + // If row is less than zero, it means we are moving dragged item into new parent. If row is at least + // zero, then we are sorting the dragged item. // // Otherwise the target row identifies the item just below the drop target placement insertion line. QModelIndex target_idx = order_change ? mapToSource(index(row, 0, parent)) : target_parent; @@ -198,14 +203,12 @@ bool FeedsProxyModel::canDropMimeData(const QMimeData* data, switch (dragged_item->kind()) { case RootItem::Kind::Feed: + case RootItem::Kind::Category: // Feeds can be reordered or inserted under service root or category. + // Categories can be reordered or inserted under service root or another category. return target_parent_item->kind() == RootItem::Kind::Category || target_parent_item->kind() == RootItem::Kind::ServiceRoot; - case RootItem::Kind::Category: - // Categories can be reordered or inserted under service root or another category. - break; - case RootItem::Kind::ServiceRoot: // Service root cannot be inserted under different parent, can only be reordered. if (!order_change) { @@ -216,20 +219,11 @@ bool FeedsProxyModel::canDropMimeData(const QMimeData* data, } default: - return false; + break; } - - return false; - /* - auto can_drop = target_item->kind() == RootItem::Kind::ServiceRoot || - target_item->kind() == RootItem::Kind::Category || target_item->kind() == RootItem::Kind::Feed; - - return QSortFilterProxyModel::canDropMimeData(data, action, row, column, parent) && can_drop; - */ - } - else { - return false; } + + return false; } bool FeedsProxyModel::dropMimeData(const QMimeData* data,