Skip to content

Commit 21f5a63

Browse files
committed
Qt: Add "Copy URI" to payment request context menu
1 parent 3cd836c commit 21f5a63

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, QWidg
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()));
@@ -227,30 +230,50 @@ void ReceiveCoinsDialog::keyPressEvent(QKeyEvent *event)
227230
this->QDialog::keyPressEvent(event);
228231
}
229232

230-
// copy column of selected row to clipboard
231-
void ReceiveCoinsDialog::copyColumnToClipboard(int column)
233+
QModelIndex ReceiveCoinsDialog::selectedRow()
232234
{
233235
if(!model || !model->getRecentRequestsTableModel() || !ui->recentRequestsView->selectionModel())
234-
return;
236+
return QModelIndex();
235237
QModelIndexList selection = ui->recentRequestsView->selectionModel()->selectedRows();
236238
if(selection.empty())
237-
return;
239+
return QModelIndex();
238240
// correct for selection mode ContiguousSelection
239241
QModelIndex firstIndex = selection.at(0);
242+
return firstIndex;
243+
}
244+
245+
// copy column of selected row to clipboard
246+
void ReceiveCoinsDialog::copyColumnToClipboard(int column)
247+
{
248+
QModelIndex firstIndex = selectedRow();
249+
if (!firstIndex.isValid()) {
250+
return;
251+
}
240252
GUIUtil::setClipboard(model->getRecentRequestsTableModel()->data(firstIndex.child(firstIndex.row(), column), Qt::EditRole).toString());
241253
}
242254

243255
// context menu
244256
void ReceiveCoinsDialog::showMenu(const QPoint &point)
245257
{
246-
if(!model || !model->getRecentRequestsTableModel() || !ui->recentRequestsView->selectionModel())
247-
return;
248-
QModelIndexList selection = ui->recentRequestsView->selectionModel()->selectedRows();
249-
if(selection.empty())
258+
if (!selectedRow().isValid()) {
250259
return;
260+
}
251261
contextMenu->exec(QCursor::pos());
252262
}
253263

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

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)