Select rows at once in perf viewer, and add copy-paste handler

This commit is contained in:
baldurk
2017-08-24 15:00:05 +01:00
parent 43a4cb5818
commit 15ecaf167c
3 changed files with 48 additions and 2 deletions
+33 -1
View File
@@ -23,6 +23,8 @@
******************************************************************************/
#include "RDTableWidget.h"
#include <QApplication>
#include <QClipboard>
#include <QDropEvent>
RDTableWidget::RDTableWidget(QWidget *parent) : QTableWidget(parent)
@@ -81,6 +83,36 @@ void RDTableWidget::dropEvent(QDropEvent *event)
void RDTableWidget::keyPressEvent(QKeyEvent *e)
{
QTableView::keyPressEvent(e);
if(!m_customCopyPaste && e->matches(QKeySequence::Copy))
{
QList<QTableWidgetItem *> items = selectedItems();
std::sort(items.begin(), items.end(), [this](QTableWidgetItem *a, QTableWidgetItem *b) {
if(row(a) != row(b))
return row(a) < row(b);
return column(a) < column(b);
});
int prevRow = row(items[0]);
QString clipboardText;
for(QTableWidgetItem *i : items)
{
clipboardText += i->text();
if(prevRow != row(i))
clipboardText += lit("\n");
else
clipboardText += lit(" | ");
}
QClipboard *clipboard = QApplication::clipboard();
clipboard->setText(clipboardText.trimmed());
}
else
{
QTableView::keyPressEvent(e);
}
emit(keyPress(e));
}
@@ -32,6 +32,8 @@ class RDTableWidget : public QTableWidget
public:
explicit RDTableWidget(QWidget *parent = 0);
bool customCopyPasteHandler() { return m_customCopyPaste; }
void setCustomCopyPasteHandler(bool custom) { m_customCopyPaste = custom; }
signals:
void keyPress(QKeyEvent *e);
@@ -39,4 +41,6 @@ private:
// implement reordering row drag-drop behaviour
void dropEvent(QDropEvent *event) override;
void keyPressEvent(QKeyEvent *e) override;
bool m_customCopyPaste = false;
};
+11 -1
View File
@@ -72,10 +72,13 @@
</layout>
</item>
<item>
<widget class="QTableWidget" name="counterResults">
<widget class="RDTableWidget" name="counterResults">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
@@ -83,6 +86,13 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>RDTableWidget</class>
<extends>QTableWidget</extends>
<header>Widgets/Extended/RDTableWidget.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>