Skip to content

Commit 63e98ee

Browse files
committed
Implement clipboard copy of selected item for emv-viewer
1 parent d54a9fe commit 63e98ee

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

viewer/emv-viewer-mainwindow.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <QtCore/QTimer>
3232
#include <QtWidgets/QApplication>
3333
#include <QtWidgets/QScrollBar>
34+
#include <QtGui/QClipboard>
3435
#include <QtGui/QDesktopServices>
3536

3637
EmvViewerMainWindow::EmvViewerMainWindow(
@@ -290,6 +291,16 @@ void EmvViewerMainWindow::on_treeView_itemPressed(QTreeWidgetItem* item, int col
290291
displayLegal();
291292
}
292293

294+
void EmvViewerMainWindow::on_treeView_itemCopyClicked(QTreeWidgetItem* item)
295+
{
296+
if (!item) {
297+
return;
298+
}
299+
300+
QString str = treeView->toClipboardText(item, QStringLiteral(" "), 0);
301+
QApplication::clipboard()->setText(str);
302+
}
303+
293304
void EmvViewerMainWindow::on_descriptionText_linkActivated(const QString& link)
294305
{
295306
// Open link using external application

viewer/emv-viewer-mainwindow.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ private slots: // connect-by-name helper functions
5959
void on_decodeFieldsCheckBox_stateChanged(int state);
6060
void on_decodeObjectsCheckBox_stateChanged(int state);
6161
void on_treeView_itemPressed(QTreeWidgetItem* item, int column);
62+
void on_treeView_itemCopyClicked(QTreeWidgetItem* item);
6263
void on_descriptionText_linkActivated(const QString& link);
6364

6465
protected:

viewer/emvtreeview.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ void EmvTreeView::currentChanged(const QModelIndex& current, const QModelIndex&
114114
QTreeWidgetItem* currentItem = itemFromIndex(current);
115115
if (currentItem) {
116116
EmvTreeItemCopyButton* button = new EmvTreeItemCopyButton(this);
117+
connect(button, &QPushButton::clicked, this, [this, currentItem]() {
118+
emit itemCopyClicked(currentItem);
119+
});
117120
setItemWidget(currentItem, 1, button);
118121
}
119122
}

viewer/emvtreeview.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ public slots:
5353
void setDecodeObjects(bool enabled);
5454
void setCopyButtonEnabled(bool enabled) { m_copyButtonEnabled = enabled; }
5555

56+
signals:
57+
void itemCopyClicked(QTreeWidgetItem* item);
58+
5659
public:
5760
QString toClipboardText(const QString& prefix, unsigned int depth) const;
5861
QString toClipboardText(const QTreeWidgetItem* item, const QString& prefix, unsigned int depth) const;

0 commit comments

Comments
 (0)