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 )
|
if ( event->buttons() & Qt::LeftButton )
|
||||||
{
|
{
|
||||||
QModelIndex curIndex = indexAt(event->pos());
|
QModelIndex curIndex = indexAt(event->pos());
|
||||||
|
|
||||||
ctx_column_ = curIndex.column();
|
ctx_column_ = curIndex.column();
|
||||||
|
QMimeData * mimeData = nullptr;
|
||||||
|
QWidget * content = nullptr;
|
||||||
|
|
||||||
QString filter = getFilterFromRowAndColumn();
|
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();
|
QString name = model()->headerData(ctx_column_, header()->orientation()).toString();
|
||||||
|
|
||||||
DisplayFilterMimeData * dfmd =
|
if ( ! filter.isEmpty() )
|
||||||
new DisplayFilterMimeData(name, abbrev, filter);
|
{
|
||||||
QDrag * drag = new QDrag(this);
|
abbrev = filter.left(filter.indexOf(' '));
|
||||||
drag->setMimeData(dfmd);
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
filter = model()->data(curIndex).toString().toLower();
|
||||||
|
abbrev = filter;
|
||||||
|
}
|
||||||
|
|
||||||
DragLabel * content = new DragLabel(dfmd->labelText(), this);
|
mimeData = new DisplayFilterMimeData(name, abbrev, filter);
|
||||||
qreal dpr = window()->windowHandle()->devicePixelRatio();
|
((DisplayFilterMimeData *)mimeData)->allowPlainText();
|
||||||
QPixmap pixmap(content->size() * dpr);
|
content = new DragLabel(((DisplayFilterMimeData *)mimeData)->labelText(), this);
|
||||||
pixmap.setDevicePixelRatio(dpr);
|
}
|
||||||
content->render(&pixmap);
|
else
|
||||||
drag->setPixmap(pixmap);
|
{
|
||||||
|
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);
|
drag->exec(Qt::CopyAction);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,15 +9,18 @@
|
||||||
|
|
||||||
#include <utils/wireshark_mime_data.h>
|
#include <utils/wireshark_mime_data.h>
|
||||||
|
|
||||||
DisplayFilterMimeData::DisplayFilterMimeData(QString description, QString field, QString filter) :
|
void WiresharkMimeData::allowPlainText()
|
||||||
QMimeData(),
|
|
||||||
description_(description),
|
|
||||||
filter_(filter),
|
|
||||||
field_(field)
|
|
||||||
{
|
{
|
||||||
setText(filter);
|
setText(labelText());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DisplayFilterMimeData::DisplayFilterMimeData(QString description, QString field, QString filter) :
|
||||||
|
WiresharkMimeData(),
|
||||||
|
description_(description),
|
||||||
|
filter_(filter),
|
||||||
|
field_(field)
|
||||||
|
{}
|
||||||
|
|
||||||
QString DisplayFilterMimeData::description() const
|
QString DisplayFilterMimeData::description() const
|
||||||
{
|
{
|
||||||
return description_;
|
return description_;
|
||||||
|
@ -38,8 +41,13 @@ QString DisplayFilterMimeData::labelText() const
|
||||||
return QString("%1\n%2").arg(description_, filter_);
|
return QString("%1\n%2").arg(description_, filter_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DisplayFilterMimeData::allowPlainText()
|
||||||
|
{
|
||||||
|
setText(filter_);
|
||||||
|
}
|
||||||
|
|
||||||
ToolbarEntryMimeData::ToolbarEntryMimeData(QString element, int pos) :
|
ToolbarEntryMimeData::ToolbarEntryMimeData(QString element, int pos) :
|
||||||
QMimeData(),
|
WiresharkMimeData(),
|
||||||
element_(element),
|
element_(element),
|
||||||
pos_(pos)
|
pos_(pos)
|
||||||
{}
|
{}
|
||||||
|
|
|
@ -12,7 +12,13 @@
|
||||||
|
|
||||||
#include <QMimeData>
|
#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
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -22,7 +28,8 @@ public:
|
||||||
QString field() const;
|
QString field() const;
|
||||||
QString filter() const;
|
QString filter() const;
|
||||||
|
|
||||||
QString labelText() const;
|
QString labelText() const override;
|
||||||
|
void allowPlainText() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -32,7 +39,7 @@ private:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class ToolbarEntryMimeData: public QMimeData {
|
class ToolbarEntryMimeData: public WiresharkMimeData {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -41,7 +48,7 @@ public:
|
||||||
int position() const;
|
int position() const;
|
||||||
QString element() const;
|
QString element() const;
|
||||||
|
|
||||||
QString labelText() const;
|
QString labelText() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue