Merge bitcoin-core/gui#214: qt: Disable requests context menu actions when appropriate

bb3da8fe41 qt: Disable requests context menu actions when appropriate (Jarol Rodriguez)

Pull request description:

  The recent requests table will allow you to copy data points even if they do not exist. This PR implements checks to disable the `copy label`, `copy message`, and `copy amount` context menu actions if the respective fields are empty. This brings the recent requests table context menu behavior closer to the behavior seen in the transaction view.

  On a payment request entry which does not have a value for label, message, or amount:
  | Master        | PR               |
  | ----------- | ----------- |
  |<img width="169" alt="Screen Shot 2021-02-19 at 1 22 28 AM" src="https://user-images.githubusercontent.com/23396902/108466086-167adc00-7251-11eb-8bd6-13984042bdb3.png">| <img width="169" alt="Screen Shot 2021-02-19 at 1 21 49 AM" src="https://user-images.githubusercontent.com/23396902/108466185-3e6a3f80-7251-11eb-9dd8-492ed07fd638.png">|

  `copy URI` never needs to be disabled as an entry in the recent requests table must have a URI even if it doesn't have a label, message, or amount. #213 will add a `copy address` context menu action. This also does not need a check as an entry must be associated with an address.

  Below are some more examples of how this PR will behave:
  **Has Label, Message, and Amount**
  <img width="780" alt="Screen Shot 2021-02-19 at 12 05 38 AM" src="https://user-images.githubusercontent.com/23396902/108466507-c18b9580-7251-11eb-8875-f3aeb9c4c8e9.png">

  **Has Label and Amount, but no Message**
  <img width="780" alt="Screen Shot 2021-02-19 at 12 05 58 AM" src="https://user-images.githubusercontent.com/23396902/108466421-9b65f580-7251-11eb-97eb-a3bfaa21fa7d.png">

ACKs for top commit:
  hebasto:
    re-ACK bb3da8fe41

Tree-SHA512: d98f1a6e05ebf6d9d056bc5754aca78ca7ecda93f497dba88187b947ca4a261eb7dc5e8c872956315acaa0008cc39320fb5806e17117e0c873090ad917ca4a3d
This commit is contained in:
MarcoFalke 2021-02-25 09:02:40 +01:00
commit 09bc7bfed1
No known key found for this signature in database
GPG key ID: D2EA4850E7528B25
2 changed files with 16 additions and 4 deletions

View file

@ -45,9 +45,9 @@ ReceiveCoinsDialog::ReceiveCoinsDialog(const PlatformStyle *_platformStyle, QWid
// context menu actions
QAction *copyURIAction = new QAction(tr("Copy URI"), this);
QAction* copyAddressAction = new QAction(tr("Copy address"), this);
QAction *copyLabelAction = new QAction(tr("Copy label"), this);
QAction *copyMessageAction = new QAction(tr("Copy message"), this);
QAction *copyAmountAction = new QAction(tr("Copy amount"), this);
copyLabelAction = new QAction(tr("Copy label"), this);
copyMessageAction = new QAction(tr("Copy message"), this);
copyAmountAction = new QAction(tr("Copy amount"), this);
// context menu
contextMenu = new QMenu(this);
@ -269,9 +269,18 @@ void ReceiveCoinsDialog::copyColumnToClipboard(int column)
// context menu
void ReceiveCoinsDialog::showMenu(const QPoint &point)
{
if (!selectedRow().isValid()) {
const QModelIndex sel = selectedRow();
if (!sel.isValid()) {
return;
}
// disable context menu actions when appropriate
const RecentRequestsTableModel* const submodel = model->getRecentRequestsTableModel();
const RecentRequestEntry& req = submodel->entry(sel.row());
copyLabelAction->setDisabled(req.recipient.label.isEmpty());
copyMessageAction->setDisabled(req.recipient.message.isEmpty());
copyAmountAction->setDisabled(req.recipient.amount == 0);
contextMenu->exec(QCursor::pos());
}

View file

@ -53,6 +53,9 @@ private:
Ui::ReceiveCoinsDialog *ui;
WalletModel *model;
QMenu *contextMenu;
QAction* copyLabelAction;
QAction* copyMessageAction;
QAction* copyAmountAction;
const PlatformStyle *platformStyle;
QModelIndex selectedRow();