forked from osmocom/wireshark
Qt: Allow Drag-and-drop on info and protocol
Allow for drag-and-drop on info and protocol columns. Protocol columns may also be dragged to the display filter, everything else is dragged as plain-text and can just be used as text Change-Id: I0fff390580c22175efe50037b18d7199949fd8eb Reviewed-on: https://code.wireshark.org/review/33621 Petri-Dish: Roland Knall <rknall@gmail.com> Tested-by: Petri Dish Buildbot Reviewed-by: Roland Knall <rknall@gmail.com>
This commit is contained in:
parent
e4713e8745
commit
64badc5a3a
|
@ -658,24 +658,53 @@ void PacketList::mouseMoveEvent (QMouseEvent *event)
|
|||
if ( event->buttons() & Qt::LeftButton )
|
||||
{
|
||||
QModelIndex curIndex = indexAt(event->pos());
|
||||
|
||||
ctx_column_ = curIndex.column();
|
||||
QMimeData * mimeData = nullptr;
|
||||
QWidget * content = nullptr;
|
||||
|
||||
QString filter = getFilterFromRowAndColumn();
|
||||
if ( ! filter.isEmpty() )
|
||||
if ( ! filter.isEmpty() || get_column_format(curIndex.column()) == COL_PROTOCOL)
|
||||
{
|
||||
QString abbrev = filter.left(filter.indexOf(' '));
|
||||
QString abbrev;
|
||||
QString name = model()->headerData(ctx_column_, header()->orientation()).toString();
|
||||
|
||||
DisplayFilterMimeData * dfmd =
|
||||
new DisplayFilterMimeData(name, abbrev, filter);
|
||||
QDrag * drag = new QDrag(this);
|
||||
drag->setMimeData(dfmd);
|
||||
if ( ! filter.isEmpty() )
|
||||
{
|
||||
abbrev = filter.left(filter.indexOf(' '));
|
||||
}
|
||||
else
|
||||
{
|
||||
filter = model()->data(curIndex).toString().toLower();
|
||||
abbrev = filter;
|
||||
}
|
||||
|
||||
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);
|
||||
mimeData = new DisplayFilterMimeData(name, abbrev, filter);
|
||||
((DisplayFilterMimeData *)mimeData)->allowPlainText();
|
||||
content = new DragLabel(((DisplayFilterMimeData *)mimeData)->labelText(), this);
|
||||
}
|
||||
else
|
||||
{
|
||||
QString text = model()->data(curIndex).toString();
|
||||
if ( ! text.isEmpty() )
|
||||
{
|
||||
mimeData = new QMimeData();
|
||||
mimeData->setText(text);
|
||||
}
|
||||
}
|
||||
|
||||
if ( mimeData )
|
||||
{
|
||||
QDrag * drag = new QDrag(this);
|
||||
drag->setMimeData(mimeData);
|
||||
if ( content )
|
||||
{
|
||||
qreal dpr = window()->windowHandle()->devicePixelRatio();
|
||||
QPixmap pixmap= QPixmap(content->size() * dpr);
|
||||
pixmap.setDevicePixelRatio(dpr);
|
||||
content->render(&pixmap);
|
||||
drag->setPixmap(pixmap);
|
||||
}
|
||||
|
||||
drag->exec(Qt::CopyAction);
|
||||
}
|
||||
|
|
|
@ -9,15 +9,18 @@
|
|||
|
||||
#include <utils/wireshark_mime_data.h>
|
||||
|
||||
DisplayFilterMimeData::DisplayFilterMimeData(QString description, QString field, QString filter) :
|
||||
QMimeData(),
|
||||
description_(description),
|
||||
filter_(filter),
|
||||
field_(field)
|
||||
void WiresharkMimeData::allowPlainText()
|
||||
{
|
||||
setText(filter);
|
||||
setText(labelText());
|
||||
}
|
||||
|
||||
DisplayFilterMimeData::DisplayFilterMimeData(QString description, QString field, QString filter) :
|
||||
WiresharkMimeData(),
|
||||
description_(description),
|
||||
filter_(filter),
|
||||
field_(field)
|
||||
{}
|
||||
|
||||
QString DisplayFilterMimeData::description() const
|
||||
{
|
||||
return description_;
|
||||
|
@ -38,8 +41,13 @@ QString DisplayFilterMimeData::labelText() const
|
|||
return QString("%1\n%2").arg(description_, filter_);
|
||||
}
|
||||
|
||||
void DisplayFilterMimeData::allowPlainText()
|
||||
{
|
||||
setText(filter_);
|
||||
}
|
||||
|
||||
ToolbarEntryMimeData::ToolbarEntryMimeData(QString element, int pos) :
|
||||
QMimeData(),
|
||||
WiresharkMimeData(),
|
||||
element_(element),
|
||||
pos_(pos)
|
||||
{}
|
||||
|
|
|
@ -12,7 +12,13 @@
|
|||
|
||||
#include <QMimeData>
|
||||
|
||||
class DisplayFilterMimeData: public QMimeData {
|
||||
class WiresharkMimeData: public QMimeData {
|
||||
public:
|
||||
virtual QString labelText() const = 0;
|
||||
virtual void allowPlainText();
|
||||
};
|
||||
|
||||
class DisplayFilterMimeData: public WiresharkMimeData {
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
||||
|
@ -22,7 +28,8 @@ public:
|
|||
QString field() const;
|
||||
QString filter() const;
|
||||
|
||||
QString labelText() const;
|
||||
QString labelText() const override;
|
||||
void allowPlainText() override;
|
||||
|
||||
private:
|
||||
|
||||
|
@ -32,7 +39,7 @@ private:
|
|||
|
||||
};
|
||||
|
||||
class ToolbarEntryMimeData: public QMimeData {
|
||||
class ToolbarEntryMimeData: public WiresharkMimeData {
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
||||
|
@ -41,7 +48,7 @@ public:
|
|||
int position() const;
|
||||
QString element() const;
|
||||
|
||||
QString labelText() const;
|
||||
QString labelText() const override;
|
||||
|
||||
private:
|
||||
|
||||
|
|
Loading…
Reference in New Issue