From 715dd78287934c2dcb6de54b0a9be48b2237f9e6 Mon Sep 17 00:00:00 2001 From: Alexander Taylor Date: Wed, 30 Apr 2025 21:16:54 -0400 Subject: Make Triage Summary tables multi-select + copyable. Closes #6562. --- examples/triage/entry.cpp | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'examples/triage/entry.cpp') diff --git a/examples/triage/entry.cpp b/examples/triage/entry.cpp index f66634f1..c62b9c36 100644 --- a/examples/triage/entry.cpp +++ b/examples/triage/entry.cpp @@ -1,5 +1,8 @@ #include #include +#include +#include +#include #include "entry.h" #include "view.h" #include "fontsettings.h" @@ -167,6 +170,9 @@ EntryTreeView::EntryTreeView(EntryWidget* parent, TriageView* view, BinaryViewRe setRootIsDecorated(false); setUniformRowHeights(true); setSortingEnabled(true); + setSelectionMode(QAbstractItemView::ExtendedSelection); + setSelectionBehavior(QAbstractItemView::SelectRows); + setAllColumnsShowFocus(true); sortByColumn(AddressColumn, Qt::AscendingOrder); setColumnWidth(AddressColumn, 90); @@ -175,6 +181,44 @@ EntryTreeView::EntryTreeView(EntryWidget* parent, TriageView* view, BinaryViewRe connect(selectionModel(), &QItemSelectionModel::currentChanged, this, &EntryTreeView::entrySelected); connect(this, &QTreeView::doubleClicked, this, &EntryTreeView::entryDoubleClicked); + + m_actionHandler.bindAction("Copy", UIAction([this]() { copySelection(); }, [this]() { return canCopySelection(); })); +} + +void EntryTreeView::copySelection() +{ + if (!model() || !selectionModel()) + return; + + QModelIndexList rows = selectionModel()->selectedRows(); + if (rows.isEmpty()) + return; + + std::sort(rows.begin(), rows.end(), [](const QModelIndex& a, const QModelIndex& b) { return a.row() < b.row(); }); + + QStringList lines; + for (const QModelIndex& rowIndex : rows) + { + QStringList cells; + for (int column = 0; column < m_model->columnCount(QModelIndex()); column++) + { + if (isColumnHidden(column)) + continue; + + QModelIndex idx = m_model->index(rowIndex.row(), column, QModelIndex()); + cells << m_model->data(idx, Qt::DisplayRole).toString(); + } + lines << cells.join("\t"); + } + + if (QClipboard* clipboard = QGuiApplication::clipboard()) + clipboard->setText(lines.join("\n")); +} + + +bool EntryTreeView::canCopySelection() const +{ + return !selectionModel()->selectedRows().isEmpty(); } @@ -258,6 +302,12 @@ void EntryTreeView::keyPressEvent(QKeyEvent* event) if (sel.size() != 0) entryDoubleClicked(sel[0]); } + else if (event->matches(QKeySequence::Copy)) + { + copySelection(); + event->accept(); + return; + } QTreeView::keyPressEvent(event); } -- cgit v1.3.1