Bitcoin ABC 0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
receivecoinsdialog.cpp
Go to the documentation of this file.
1// Copyright (c) 2011-2016 The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#include <wallet/wallet.h>
6
7#include <qt/forms/ui_receivecoinsdialog.h>
9
11#include <qt/optionsmodel.h>
12#include <qt/platformstyle.h>
15#include <qt/walletmodel.h>
16
17#include <QAction>
18#include <QCursor>
19#include <QMessageBox>
20#include <QScrollBar>
21#include <QTextDocument>
22
24 QWidget *parent)
25 : QDialog(parent), ui(new Ui::ReceiveCoinsDialog),
26 columnResizingFixer(nullptr), model(nullptr),
27 platformStyle(_platformStyle) {
28 ui->setupUi(this);
29
30 if (!_platformStyle->getImagesOnButtons()) {
31 ui->clearButton->setIcon(QIcon());
32 ui->receiveButton->setIcon(QIcon());
33 ui->showRequestButton->setIcon(QIcon());
34 ui->removeRequestButton->setIcon(QIcon());
35 } else {
36 ui->clearButton->setIcon(
37 _platformStyle->SingleColorIcon(":/icons/remove"));
38 ui->receiveButton->setIcon(
39 _platformStyle->SingleColorIcon(":/icons/receiving_addresses"));
40 ui->showRequestButton->setIcon(
41 _platformStyle->SingleColorIcon(":/icons/edit"));
42 ui->removeRequestButton->setIcon(
43 _platformStyle->SingleColorIcon(":/icons/remove"));
44 }
45
46 // context menu actions
47 QAction *copyURIAction = new QAction(tr("Copy URI"), this);
48 QAction *copyLabelAction = new QAction(tr("Copy label"), this);
49 QAction *copyMessageAction = new QAction(tr("Copy message"), this);
50 QAction *copyAmountAction = new QAction(tr("Copy amount"), this);
51
52 // context menu
53 contextMenu = new QMenu(this);
54 contextMenu->addAction(copyURIAction);
55 contextMenu->addAction(copyLabelAction);
57 contextMenu->addAction(copyAmountAction);
58
59 // context menu signals
60 connect(ui->recentRequestsView, &QWidget::customContextMenuRequested, this,
62 connect(copyURIAction, &QAction::triggered, this,
64 connect(copyLabelAction, &QAction::triggered, this,
66 connect(copyMessageAction, &QAction::triggered, this,
68 connect(copyAmountAction, &QAction::triggered, this,
70
71 connect(ui->clearButton, &QPushButton::clicked, this,
73}
74
76 this->model = _model;
77
78 if (_model && _model->getOptionsModel()) {
80 RecentRequestsTableModel::Date, Qt::DescendingOrder);
84
85 QTableView *tableView = ui->recentRequestsView;
86
87 tableView->verticalHeader()->hide();
88 tableView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
89 tableView->setModel(_model->getRecentRequestsTableModel());
90 tableView->setAlternatingRowColors(true);
91 tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
92 tableView->setSelectionMode(QAbstractItemView::ContiguousSelection);
93 tableView->setColumnWidth(RecentRequestsTableModel::Date,
95 tableView->setColumnWidth(RecentRequestsTableModel::Label,
97 tableView->setColumnWidth(RecentRequestsTableModel::Amount,
99
100 connect(tableView->selectionModel(),
101 &QItemSelectionModel::selectionChanged, this,
103 // Last 2 columns are set by the columnResizingFixer, when the table
104 // geometry is ready.
107
108 // Set the button to be enabled or disabled based on whether the wallet
109 // can give out new addresses.
110 ui->receiveButton->setEnabled(model->wallet().canGetAddresses());
111
112 // Enable/disable the receive button if the wallet is now able/unable to
113 // give out new addresses.
115 ui->receiveButton->setEnabled(model->wallet().canGetAddresses());
116 });
117 }
118}
119
123
125 ui->reqAmount->clear();
126 ui->reqLabel->setText("");
127 ui->reqMessage->setText("");
129}
130
134
138
140 if (model && model->getOptionsModel()) {
141 ui->reqAmount->setDisplayUnit(
143 }
144}
145
149 return;
150 }
151
152 QString address;
153 QString label = ui->reqLabel->text();
154 /* Generate new receiving address */
157 label, "", address_type);
158
161 // Success
162 SendCoinsRecipient info(address, label, ui->reqAmount->value(),
163 ui->reqMessage->text());
165 dialog->setAttribute(Qt::WA_DeleteOnClose);
166 dialog->setModel(model);
167 dialog->setInfo(info);
168 dialog->show();
169
170 /* Store request for later reference */
172 break;
173 }
175 QMessageBox::critical(this, windowTitle(),
176 tr("Could not unlock wallet."),
177 QMessageBox::Ok, QMessageBox::Ok);
178 break;
180 QMessageBox::critical(this, windowTitle(),
181 tr("Could not generate new %1 address")
182 .arg(QString::fromStdString(
184 QMessageBox::Ok, QMessageBox::Ok);
185 break;
186 // These aren't valid return values for our action
190 assert(false);
191 }
192 clear();
193}
194
196 const QModelIndex &index) {
200 dialog->setModel(model);
201 dialog->setInfo(submodel->entry(index.row()).recipient);
202 dialog->setAttribute(Qt::WA_DeleteOnClose);
203 dialog->show();
204}
205
208 // Enable Show/Remove buttons only if anything is selected.
209 bool enable =
210 !ui->recentRequestsView->selectionModel()->selectedRows().isEmpty();
211 ui->showRequestButton->setEnabled(enable);
212 ui->removeRequestButton->setEnabled(enable);
213}
214
217 !ui->recentRequestsView->selectionModel()) {
218 return;
219 }
221 ui->recentRequestsView->selectionModel()->selectedRows();
222
223 for (const QModelIndex &index : selection) {
225 }
226}
227
230 !ui->recentRequestsView->selectionModel()) {
231 return;
232 }
234 ui->recentRequestsView->selectionModel()->selectedRows();
235 if (selection.empty()) {
236 return;
237 }
238 // correct for selection mode ContiguousSelection
241 firstIndex.row(), selection.length(), firstIndex.parent());
242}
243
244// We override the virtual resizeEvent of the QWidget to adjust tables column
245// sizes as the tables width is proportional to the dialogs width.
250
253 !ui->recentRequestsView->selectionModel()) {
254 return QModelIndex();
255 }
257 ui->recentRequestsView->selectionModel()->selectedRows();
258 if (selection.empty()) {
259 return QModelIndex();
260 }
261 // correct for selection mode ContiguousSelection
263 return firstIndex;
264}
265
266// copy column of selected row to clipboard
269 if (!firstIndex.isValid()) {
270 return;
271 }
273 ->index(firstIndex.row(), column)
274 .data(Qt::EditRole)
275 .toString());
276}
277
278// context menu
280 if (!selectedRow().isValid()) {
281 return;
282 }
283 contextMenu->exec(QCursor::pos());
284}
285
286// context menu action: copy URI
289 if (!sel.isValid()) {
290 return;
291 }
292
295 const QString uri =
296 GUIUtil::formatBitcoinURI(submodel->entry(sel.row()).recipient);
298}
299
300// context menu action: copy label
304
305// context menu action: copy message
309
310// context menu action: copy amount
EditStatus getEditStatus() const
@ WALLET_UNLOCK_FAILURE
Wallet could not be unlocked to create new receiving address.
@ NO_CHANGES
No changes were made during edit operation.
@ INVALID_ADDRESS
Unparseable address.
@ KEY_GENERATION_FAILURE
Generating a new public key for a receiving address failed.
@ OK
Everything ok.
@ DUPLICATE_ADDRESS
Address already in address book.
QString addRow(const QString &type, const QString &label, const QString &address, const OutputType address_type)
static const QString Receive
Specifies receive address.
Makes a QTableView last column feel as if it was being resized from its left border.
Definition guiutil.h:227
int getDisplayUnit() const
void displayUnitChanged(int unit)
Dialog for requesting payment of bitcoins.
Ui::ReceiveCoinsDialog * ui
void on_recentRequestsView_doubleClicked(const QModelIndex &index)
GUIUtil::TableViewLastColumnResizingFixer * columnResizingFixer
void recentRequestsView_selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
void setModel(WalletModel *model)
void showMenu(const QPoint &point)
ReceiveCoinsDialog(const PlatformStyle *platformStyle, QWidget *parent=nullptr)
virtual void resizeEvent(QResizeEvent *event) override
void copyColumnToClipboard(int column)
Model for list of recently generated payment requests / bitcoincash: URIs.
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
void sort(int column, Qt::SortOrder order=Qt::AscendingOrder) override
void addNewRequest(const SendCoinsRecipient &recipient)
Interface to Bitcoin wallet from Qt view code.
Definition walletmodel.h:47
AddressTableModel * getAddressTableModel()
OptionsModel * getOptionsModel()
interfaces::Wallet & wallet() const
RecentRequestsTableModel * getRecentRequestsTableModel()
void canGetAddressesChanged()
virtual bool canGetAddresses() const =0
virtual OutputType getDefaultAddressType()=0
QString formatBitcoinURI(const SendCoinsRecipient &info)
Definition guiutil.cpp:210
void setClipboard(const QString &str)
Definition guiutil.cpp:776
const std::string & FormatOutputType(OutputType type)
OutputType
Definition outputtype.h:16
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
Definition random.h:85
assert(!tx.IsCoinBase())