mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-05-05 09:30:44 +00:00
Implement copy-paste handler for RDTableView
This commit is contained in:
@@ -24,11 +24,14 @@
|
||||
|
||||
#include "RDTableView.h"
|
||||
#include <QAbstractButton>
|
||||
#include <QApplication>
|
||||
#include <QClipboard>
|
||||
#include <QHeaderView>
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
#include <QPen>
|
||||
#include <QScrollBar>
|
||||
#include "Code/QRDUtils.h"
|
||||
#include "RDHeaderView.h"
|
||||
|
||||
RDTableView::RDTableView(QWidget *parent) : QTableView(parent)
|
||||
@@ -137,6 +140,73 @@ void RDTableView::setPinnedColumns(int numColumns)
|
||||
m_horizontalHeader->setPinnedColumns(numColumns);
|
||||
}
|
||||
|
||||
void RDTableView::keyPressEvent(QKeyEvent *e)
|
||||
{
|
||||
if(e == QKeySequence::Copy)
|
||||
{
|
||||
QModelIndexList sel = selectionModel()->selectedIndexes();
|
||||
|
||||
if(!sel.isEmpty())
|
||||
{
|
||||
int stackWidths[16];
|
||||
int *heapWidths = NULL;
|
||||
|
||||
int colCount = model()->columnCount();
|
||||
|
||||
if(colCount >= 16)
|
||||
heapWidths = new int[colCount];
|
||||
|
||||
int *widths = heapWidths ? heapWidths : stackWidths;
|
||||
|
||||
for(int i = 0; i < colCount; i++)
|
||||
widths[i] = 0;
|
||||
|
||||
int top = sel[0].row(), bottom = sel[0].row();
|
||||
int left = sel[0].column(), right = sel[0].column();
|
||||
|
||||
// align the copied data so that each column is the same width
|
||||
for(QModelIndex idx : sel)
|
||||
{
|
||||
QString text = model()->data(idx).toString();
|
||||
widths[idx.column()] = qMax(widths[idx.column()], text.count());
|
||||
|
||||
top = qMin(top, idx.row());
|
||||
bottom = qMax(bottom, idx.row());
|
||||
left = qMin(left, idx.column());
|
||||
right = qMax(right, idx.column());
|
||||
}
|
||||
|
||||
// only align up to 50 characters so one really long item doesn't mess up the whole thing
|
||||
for(int i = 0; i < colCount; i++)
|
||||
widths[i] = qMin(50, widths[i]);
|
||||
|
||||
QString clipData;
|
||||
for(int row = top; row <= bottom; row++)
|
||||
{
|
||||
for(int col = left; col <= right; col++)
|
||||
{
|
||||
QString format = col == left ? lit("%1") : lit(" %1");
|
||||
QString text = model()->data(model()->index(row, col)).toString();
|
||||
|
||||
clipData += format.arg(text, -widths[col]);
|
||||
}
|
||||
|
||||
clipData += lit("\n");
|
||||
}
|
||||
|
||||
QClipboard *clipboard = QApplication::clipboard();
|
||||
clipboard->setText(clipData.trimmed());
|
||||
|
||||
delete[] heapWidths;
|
||||
}
|
||||
|
||||
e->accept();
|
||||
return;
|
||||
}
|
||||
|
||||
return QTableView::keyPressEvent(e);
|
||||
}
|
||||
|
||||
void RDTableView::paintEvent(QPaintEvent *e)
|
||||
{
|
||||
const int gridWidth = showGrid() ? 1 : 0;
|
||||
|
||||
@@ -56,6 +56,7 @@ public:
|
||||
void setPinnedColumns(int numColumns);
|
||||
int pinnedColumns() const { return m_pinnedColumns; }
|
||||
protected:
|
||||
void keyPressEvent(QKeyEvent *e) override;
|
||||
void paintEvent(QPaintEvent *e) override;
|
||||
void updateGeometries() override;
|
||||
void scrollContentsBy(int dx, int dy) override;
|
||||
|
||||
Reference in New Issue
Block a user