Skip to content

Commit 47ace42

Browse files
committed
Merge #8918: Qt: Add "Copy URI" to payment request context menu
21f5a63 Qt: Add "Copy URI" to payment request context menu (Luke Dashjr)
2 parents 763828d + 21f5a63 commit 47ace42

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

src/qt/receivecoinsdialog.cpp

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,21 @@ ReceiveCoinsDialog::ReceiveCoinsDialog(const PlatformStyle *_platformStyle, QWid
4343
}
4444

4545
// context menu actions
46+
QAction *copyURIAction = new QAction(tr("Copy URI"), this);
4647
QAction *copyLabelAction = new QAction(tr("Copy label"), this);
4748
QAction *copyMessageAction = new QAction(tr("Copy message"), this);
4849
QAction *copyAmountAction = new QAction(tr("Copy amount"), this);
4950

5051
// context menu
5152
contextMenu = new QMenu();
53+
contextMenu->addAction(copyURIAction);
5254
contextMenu->addAction(copyLabelAction);
5355
contextMenu->addAction(copyMessageAction);
5456
contextMenu->addAction(copyAmountAction);
5557

5658
// context menu signals
5759
connect(ui->recentRequestsView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showMenu(QPoint)));
60+
connect(copyURIAction, SIGNAL(triggered()), this, SLOT(copyURI()));
5861
connect(copyLabelAction, SIGNAL(triggered()), this, SLOT(copyLabel()));
5962
connect(copyMessageAction, SIGNAL(triggered()), this, SLOT(copyMessage()));
6063
connect(copyAmountAction, SIGNAL(triggered()), this, SLOT(copyAmount()));
@@ -228,30 +231,50 @@ void ReceiveCoinsDialog::keyPressEvent(QKeyEvent *event)
228231
this->QDialog::keyPressEvent(event);
229232
}
230233

231-
// copy column of selected row to clipboard
232-
void ReceiveCoinsDialog::copyColumnToClipboard(int column)
234+
QModelIndex ReceiveCoinsDialog::selectedRow()
233235
{
234236
if(!model || !model->getRecentRequestsTableModel() || !ui->recentRequestsView->selectionModel())
235-
return;
237+
return QModelIndex();
236238
QModelIndexList selection = ui->recentRequestsView->selectionModel()->selectedRows();
237239
if(selection.empty())
238-
return;
240+
return QModelIndex();
239241
// correct for selection mode ContiguousSelection
240242
QModelIndex firstIndex = selection.at(0);
243+
return firstIndex;
244+
}
245+
246+
// copy column of selected row to clipboard
247+
void ReceiveCoinsDialog::copyColumnToClipboard(int column)
248+
{
249+
QModelIndex firstIndex = selectedRow();
250+
if (!firstIndex.isValid()) {
251+
return;
252+
}
241253
GUIUtil::setClipboard(model->getRecentRequestsTableModel()->data(firstIndex.child(firstIndex.row(), column), Qt::EditRole).toString());
242254
}
243255

244256
// context menu
245257
void ReceiveCoinsDialog::showMenu(const QPoint &point)
246258
{
247-
if(!model || !model->getRecentRequestsTableModel() || !ui->recentRequestsView->selectionModel())
248-
return;
249-
QModelIndexList selection = ui->recentRequestsView->selectionModel()->selectedRows();
250-
if(selection.empty())
259+
if (!selectedRow().isValid()) {
251260
return;
261+
}
252262
contextMenu->exec(QCursor::pos());
253263
}
254264

265+
// context menu action: copy URI
266+
void ReceiveCoinsDialog::copyURI()
267+
{
268+
QModelIndex sel = selectedRow();
269+
if (!sel.isValid()) {
270+
return;
271+
}
272+
273+
const RecentRequestsTableModel * const submodel = model->getRecentRequestsTableModel();
274+
const QString uri = GUIUtil::formatBitcoinURI(submodel->entry(sel.row()).recipient);
275+
GUIUtil::setClipboard(uri);
276+
}
277+
255278
// context menu action: copy label
256279
void ReceiveCoinsDialog::copyLabel()
257280
{

src/qt/receivecoinsdialog.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public Q_SLOTS:
6060
QMenu *contextMenu;
6161
const PlatformStyle *platformStyle;
6262

63+
QModelIndex selectedRow();
6364
void copyColumnToClipboard(int column);
6465
virtual void resizeEvent(QResizeEvent *event);
6566

@@ -71,6 +72,7 @@ private Q_SLOTS:
7172
void recentRequestsView_selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
7273
void updateDisplayUnit();
7374
void showMenu(const QPoint &point);
75+
void copyURI();
7476
void copyLabel();
7577
void copyMessage();
7678
void copyAmount();

0 commit comments

Comments
 (0)