Qt: Add Drag-and-Drop to Packetlist

Allow cells to be used in drag-and-drop operations

Change-Id: I6eeb5e32076ba9dddc73265e213e8cfeae1f0783
Reviewed-on: https://code.wireshark.org/review/33604
Petri-Dish: Roland Knall <rknall@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Roland Knall <rknall@gmail.com>
This commit is contained in:
Roland Knall 2019-06-14 14:16:51 -07:00
parent d370f54c47
commit 20246cf005
1 changed files with 27 additions and 0 deletions

View File

@ -49,6 +49,8 @@
#include <ui/qt/utils/variant_pointer.h>
#include <ui/qt/models/pref_models.h>
#include <ui/qt/widgets/packet_list_header.h>
#include <ui/qt/utils/wireshark_mime_data.h>
#include <ui/qt/widgets/drag_label.h>
#include <QAction>
#include <QActionGroup>
@ -66,6 +68,7 @@
#include <QTextEdit>
#include <QTimerEvent>
#include <QTreeWidget>
#include <QWindow>
#ifdef Q_OS_WIN
#include "wsutil/file_util.h"
@ -648,6 +651,30 @@ void PacketList::mousePressEvent (QMouseEvent *event)
setAutoScroll(false);
QTreeView::mousePressEvent(event);
setAutoScroll(true);
QModelIndex curIndex = indexAt(event->pos());
ctx_column_ = curIndex.column();
QString filter = getFilterFromRowAndColumn();
if ( ! filter.isEmpty() )
{
QString abbrev = filter.left(filter.indexOf(' '));
QString name = model()->headerData(ctx_column_, header()->orientation()).toString();
DisplayFilterMimeData * dfmd =
new DisplayFilterMimeData(name, abbrev, filter);
QDrag * drag = new QDrag(this);
drag->setMimeData(dfmd);
DragLabel * content = new DragLabel(dfmd->labelText(), this);
qreal dpr = window()->windowHandle()->devicePixelRatio();
QPixmap pixmap(content->size() * dpr);
pixmap.setDevicePixelRatio(dpr);
content->render(&pixmap);
drag->setPixmap(pixmap);
drag->exec(Qt::CopyAction);
}
}
void PacketList::resizeEvent(QResizeEvent *event)