Bitcoin ABC 0.30.7
P2P Digital Currency
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);
56 contextMenu->addAction(copyMessageAction);
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
121 delete ui;
122}
123
125 ui->reqAmount->clear();
126 ui->reqLabel->setText("");
127 ui->reqMessage->setText("");
129}
130
132 clear();
133}
134
136 clear();
137}
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 */
155 OutputType address_type = model->wallet().getDefaultAddressType();
157 label, "", address_type);
158
160 case AddressTableModel::EditStatus::OK: {
161 // Success
162 SendCoinsRecipient info(address, label, ui->reqAmount->value(),
163 ui->reqMessage->text());
164 ReceiveRequestDialog *dialog = new ReceiveRequestDialog(this);
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 }
174 case AddressTableModel::EditStatus::WALLET_UNLOCK_FAILURE:
175 QMessageBox::critical(this, windowTitle(),
176 tr("Could not unlock wallet."),
177 QMessageBox::Ok, QMessageBox::Ok);
178 break;
179 case AddressTableModel::EditStatus::KEY_GENERATION_FAILURE:
180 QMessageBox::critical(this, windowTitle(),
181 tr("Could not generate new %1 address")
182 .arg(QString::fromStdString(
183 FormatOutputType(address_type))),
184 QMessageBox::Ok, QMessageBox::Ok);
185 break;
186 // These aren't valid return values for our action
187 case AddressTableModel::EditStatus::INVALID_ADDRESS:
188 case AddressTableModel::EditStatus::DUPLICATE_ADDRESS:
189 case AddressTableModel::EditStatus::NO_CHANGES:
190 assert(false);
191 }
192 clear();
193}
194
196 const QModelIndex &index) {
197 const RecentRequestsTableModel *submodel =
199 ReceiveRequestDialog *dialog = new ReceiveRequestDialog(this);
200 dialog->setModel(model);
201 dialog->setInfo(submodel->entry(index.row()).recipient);
202 dialog->setAttribute(Qt::WA_DeleteOnClose);
203 dialog->show();
204}
205
207 const QItemSelection &selected, const QItemSelection &deselected) {
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 }
220 QModelIndexList selection =
221 ui->recentRequestsView->selectionModel()->selectedRows();
222
223 for (const QModelIndex &index : selection) {
225 }
226}
227
230 !ui->recentRequestsView->selectionModel()) {
231 return;
232 }
233 QModelIndexList selection =
234 ui->recentRequestsView->selectionModel()->selectedRows();
235 if (selection.empty()) {
236 return;
237 }
238 // correct for selection mode ContiguousSelection
239 QModelIndex firstIndex = selection.at(0);
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.
246void ReceiveCoinsDialog::resizeEvent(QResizeEvent *event) {
247 QWidget::resizeEvent(event);
249}
250
253 !ui->recentRequestsView->selectionModel()) {
254 return QModelIndex();
255 }
256 QModelIndexList selection =
257 ui->recentRequestsView->selectionModel()->selectedRows();
258 if (selection.empty()) {
259 return QModelIndex();
260 }
261 // correct for selection mode ContiguousSelection
262 QModelIndex firstIndex = selection.at(0);
263 return firstIndex;
264}
265
266// copy column of selected row to clipboard
268 QModelIndex firstIndex = selectedRow();
269 if (!firstIndex.isValid()) {
270 return;
271 }
273 ->index(firstIndex.row(), column)
274 .data(Qt::EditRole)
275 .toString());
276}
277
278// context menu
279void ReceiveCoinsDialog::showMenu(const QPoint &point) {
280 if (!selectedRow().isValid()) {
281 return;
282 }
283 contextMenu->exec(QCursor::pos());
284}
285
286// context menu action: copy URI
288 QModelIndex sel = selectedRow();
289 if (!sel.isValid()) {
290 return;
291 }
292
293 const RecentRequestsTableModel *const submodel =
295 const QString uri =
296 GUIUtil::formatBitcoinURI(submodel->entry(sel.row()).recipient);
298}
299
300// context menu action: copy label
303}
304
305// context menu action: copy message
308}
309
310// context menu action: copy amount
313}
EditStatus getEditStatus() const
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
Definition: optionsmodel.h:97
void displayUnitChanged(int unit)
QIcon SingleColorIcon(const QString &filename) const
Colorize an icon (given filename) with the icon color.
bool getImagesOnButtons() const
Definition: platformstyle.h:20
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)
void setModel(WalletModel *model)
void setInfo(const SendCoinsRecipient &info)
SendCoinsRecipient recipient
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
const RecentRequestEntry & entry(int row) const
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
Definition: walletmodel.h:150
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)
Definition: outputtype.cpp:27
OutputType
Definition: outputtype.h:16
assert(!tx.IsCoinBase())