forked from osmocom/wireshark
Qt: Include Column Headings with Edit -> Copy -> Plain Text / CSV
Bug: 16215 Change-Id: Ie59aa354be055831055a294724f8d7b800d35d90 Reviewed-on: https://code.wireshark.org/review/35153 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
1859b35f5a
commit
b7ce4e3f7a
|
@ -1951,17 +1951,24 @@ void MainWindow::actionEditCopyTriggered(MainWindow::CopySelected selection_type
|
||||||
{
|
{
|
||||||
QList<int> rows = packet_list_->selectedRows();
|
QList<int> rows = packet_list_->selectedRows();
|
||||||
QStringList content;
|
QStringList content;
|
||||||
|
|
||||||
|
PacketList::SummaryCopyType copyType = PacketList::CopyAsText;
|
||||||
|
if (selection_type == CopyListAsCSV)
|
||||||
|
copyType = PacketList::CopyAsCSV;
|
||||||
|
else if (selection_type == CopyListAsYAML)
|
||||||
|
copyType = PacketList::CopyAsYAML;
|
||||||
|
|
||||||
|
if ((copyType == PacketList::CopyAsText) ||
|
||||||
|
(copyType == PacketList::CopyAsCSV)) {
|
||||||
|
QString headerEntry = packet_list_->createHeaderSummaryText(copyType);
|
||||||
|
content << headerEntry;
|
||||||
|
}
|
||||||
foreach (int row, rows)
|
foreach (int row, rows)
|
||||||
{
|
{
|
||||||
QModelIndex idx = packet_list_->model()->index(row, 0);
|
QModelIndex idx = packet_list_->model()->index(row, 0);
|
||||||
if (! idx.isValid())
|
if (! idx.isValid())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
PacketList::SummaryCopyType copyType = PacketList::CopyAsText;
|
|
||||||
if (selection_type == CopyListAsCSV)
|
|
||||||
copyType = PacketList::CopyAsCSV;
|
|
||||||
else if (selection_type == CopyListAsYAML)
|
|
||||||
copyType = PacketList::CopyAsYAML;
|
|
||||||
QString entry = packet_list_->createSummaryText(idx, copyType);
|
QString entry = packet_list_->createSummaryText(idx, copyType);
|
||||||
content << entry;
|
content << entry;
|
||||||
}
|
}
|
||||||
|
|
|
@ -366,6 +366,30 @@ void PacketList::colorsChanged()
|
||||||
setStyleSheet(active_style + inactive_style + hover_style);
|
setStyleSheet(active_style + inactive_style + hover_style);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString PacketList::joinSummaryRow(QStringList col_parts, int row, SummaryCopyType type)
|
||||||
|
{
|
||||||
|
QString copy_text;
|
||||||
|
switch (type) {
|
||||||
|
case CopyAsCSV:
|
||||||
|
copy_text = "\"";
|
||||||
|
copy_text += col_parts.join("\",\"");
|
||||||
|
copy_text += "\"";
|
||||||
|
break;
|
||||||
|
case CopyAsYAML:
|
||||||
|
copy_text = "----\n";
|
||||||
|
copy_text += QString("# Packet %1 from %2\n").arg(row).arg(cap_file_->filename);
|
||||||
|
copy_text += "- ";
|
||||||
|
copy_text += col_parts.join("\n- ");
|
||||||
|
copy_text += "\n";
|
||||||
|
break;
|
||||||
|
case CopyAsText:
|
||||||
|
default:
|
||||||
|
copy_text = col_parts.join("\t");
|
||||||
|
}
|
||||||
|
|
||||||
|
return copy_text;
|
||||||
|
}
|
||||||
|
|
||||||
void PacketList::drawRow (QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
void PacketList::drawRow (QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
QTreeView::drawRow(painter, option, index);
|
QTreeView::drawRow(painter, option, index);
|
||||||
|
@ -1751,27 +1775,19 @@ QString PacketList::createSummaryText(QModelIndex idx, SummaryCopyType type)
|
||||||
col_parts << packet_list_model_->data(packet_list_model_->index(row, col), Qt::DisplayRole).toString();
|
col_parts << packet_list_model_->data(packet_list_model_->index(row, col), Qt::DisplayRole).toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return joinSummaryRow(col_parts, row, type);
|
||||||
|
}
|
||||||
|
|
||||||
QString copy_text;
|
QString PacketList::createHeaderSummaryText(SummaryCopyType type)
|
||||||
switch (type) {
|
{
|
||||||
case CopyAsCSV:
|
QStringList col_parts;
|
||||||
copy_text = "\"";
|
for (int col = 0; col < packet_list_model_->columnCount(); ++col)
|
||||||
copy_text += col_parts.join("\",\"");
|
{
|
||||||
copy_text += "\"";
|
if (get_column_visible(col)) {
|
||||||
break;
|
col_parts << packet_list_model_->headerData(col, Qt::Orientation::Horizontal, Qt::DisplayRole).toString();
|
||||||
case CopyAsYAML:
|
}
|
||||||
copy_text = "----\n";
|
|
||||||
copy_text += QString("# Packet %1 from %2\n").arg(row).arg(cap_file_->filename);
|
|
||||||
copy_text += "- ";
|
|
||||||
copy_text += col_parts.join("\n- ");
|
|
||||||
copy_text += "\n";
|
|
||||||
break;
|
|
||||||
case CopyAsText:
|
|
||||||
default:
|
|
||||||
copy_text = col_parts.join("\t");
|
|
||||||
}
|
}
|
||||||
|
return joinSummaryRow(col_parts, 0, type);
|
||||||
return copy_text;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PacketList::copySummary()
|
void PacketList::copySummary()
|
||||||
|
|
|
@ -88,6 +88,7 @@ public:
|
||||||
QList<int> selectedRows(bool useFrameNum = false);
|
QList<int> selectedRows(bool useFrameNum = false);
|
||||||
|
|
||||||
QString createSummaryText(QModelIndex idx, SummaryCopyType type);
|
QString createSummaryText(QModelIndex idx, SummaryCopyType type);
|
||||||
|
QString createHeaderSummaryText(SummaryCopyType type);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
@ -146,6 +147,7 @@ private:
|
||||||
void applyRecentColumnWidths();
|
void applyRecentColumnWidths();
|
||||||
void scrollViewChanged(bool at_end);
|
void scrollViewChanged(bool at_end);
|
||||||
void colorsChanged();
|
void colorsChanged();
|
||||||
|
QString joinSummaryRow(QStringList col_parts, int row, SummaryCopyType type);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void packetDissectionChanged();
|
void packetDissectionChanged();
|
||||||
|
|
Loading…
Reference in New Issue