Let search results be dragged onto a folio like the tree

While a collection search is active the tree is replaced by the flat
ranked list, and that list had no drag support: dragging a result only
moved the selection. Anyone used to searching and then dragging lost the
drag as soon as they typed.

The tree's drag is moved into a static ElementsTreeView::execElementDrag()
taking the source widget, and the results list uses it from the path each
row already carries, so the drag content and pixmap are the same.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G2d2Zi8BfrYRPX88zhaoFG
This commit is contained in:
ispyisail
2026-09-27 01:56:46 +12:00
parent db387525e2
commit 926bbcf75f
3 changed files with 47 additions and 4 deletions
@@ -55,6 +55,32 @@
#include <QStatusBar>
#include <QLineEdit>
namespace {
/**
@brief The SearchResultsView class
The flat list of search results. Rows are not backed by the collection
model, so the drag is built here from the path each row carries, with
the same content and pixmap as a drag from the tree.
*/
class SearchResultsView : public QListView
{
public:
using QListView::QListView;
protected:
void startDrag(Qt::DropActions supportedActions) override
{
const QString path =
currentIndex().data(Qt::UserRole + 2).toString();
if (path.isEmpty()) {
QListView::startDrag(supportedActions);
return;
}
ElementsTreeView::execElementDrag(this, ElementsLocation(path));
}
};
}
/**
@brief ElementsCollectionWidget::ElementsCollectionWidget
Default constructor.
@@ -230,8 +256,9 @@ void ElementsCollectionWidget::setUpWidget()
//ranked list instead, and takes the tab widget's place while a search
//is active.
m_search_model = new QStandardItemModel(this);
m_search_results = new QListView(this);
m_search_results = new SearchResultsView(this);
m_search_results->setModel(m_search_model);
m_search_results->setDragDropMode(QAbstractItemView::DragOnly);
m_search_results->setIconSize(QSize(50, 50));
m_search_results->setUniformItemSizes(false);
m_search_results->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);