5#if defined(HAVE_CONFIG_H)
6#include <config/bitcoin-config.h>
10#include <qt/forms/ui_addressbookpage.h>
21#include <QSortFilterProxyModel>
28 : QSortFilterProxyModel(parent),
m_type(type) {
29 setDynamicSortFilter(
true);
30 setFilterCaseSensitivity(Qt::CaseInsensitive);
31 setSortCaseSensitivity(Qt::CaseInsensitive);
36 auto model = sourceModel();
46 if (filterRegExp().indexIn(model->data(address).toString()) < 0 &&
47 filterRegExp().indexIn(model->data(label).toString()) < 0) {
56 Tabs _tab, QWidget *parent)
62 ui->newAddress->setIcon(QIcon());
63 ui->copyAddress->setIcon(QIcon());
64 ui->deleteAddress->setIcon(QIcon());
65 ui->exportButton->setIcon(QIcon());
68 ui->copyAddress->setIcon(
70 ui->deleteAddress->setIcon(
72 ui->exportButton->setIcon(
80 setWindowTitle(tr(
"Choose the address to send coins to"));
84 tr(
"Choose the address to receive coins with"));
87 connect(
ui->tableView, &QTableView::doubleClicked,
this,
89 ui->tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
90 ui->tableView->setFocus();
91 ui->closeButton->setText(tr(
"C&hoose"));
92 ui->exportButton->hide();
97 setWindowTitle(tr(
"Sending addresses"));
100 setWindowTitle(tr(
"Receiving addresses"));
107 ui->labelExplanation->setText(
108 tr(
"These are your Bitcoin addresses for sending payments. "
109 "Always check the amount and the receiving address before "
111 ui->deleteAddress->setVisible(
true);
112 ui->newAddress->setVisible(
true);
115 ui->labelExplanation->setText(
116 tr(
"These are your Bitcoin addresses for receiving payments. "
117 "Use the 'Create new receiving address' button in the "
118 "receive tab to create new addresses."));
119 ui->deleteAddress->setVisible(
false);
120 ui->newAddress->setVisible(
false);
125 QAction *copyAddressAction =
new QAction(tr(
"&Copy Address"),
this);
126 QAction *copyLabelAction =
new QAction(tr(
"Copy &Label"),
this);
127 QAction *editAction =
new QAction(tr(
"&Edit"),
this);
141 connect(copyAddressAction, &QAction::triggered,
this,
143 connect(copyLabelAction, &QAction::triggered,
this,
145 connect(editAction, &QAction::triggered,
this,
150 connect(
ui->tableView, &QWidget::customContextMenuRequested,
this,
153 connect(
ui->closeButton, &QPushButton::clicked,
this, &QDialog::accept);
163 this->
model = _model;
173 connect(
ui->searchLineEdit, &QLineEdit::textChanged,
proxyModel,
174 &QSortFilterProxyModel::setFilterWildcard);
177 ui->tableView->sortByColumn(0, Qt::AscendingOrder);
180 ui->tableView->horizontalHeader()->setSectionResizeMode(
182 ui->tableView->horizontalHeader()->setSectionResizeMode(
185 connect(
ui->tableView->selectionModel(),
186 &QItemSelectionModel::selectionChanged,
this,
190 connect(_model, &AddressTableModel::rowsInserted,
this,
209 if (!
ui->tableView->selectionModel()) {
212 QModelIndexList indexes =
ui->tableView->selectionModel()->selectedRows();
213 if (indexes.isEmpty()) {
222 QModelIndex origIndex =
proxyModel->mapToSource(indexes.at(0));
244 QTableView *table =
ui->tableView;
245 if (!table->selectionModel()) {
249 QModelIndexList indexes = table->selectionModel()->selectedRows();
250 if (!indexes.isEmpty()) {
251 table->model()->removeRow(indexes.at(0).row());
257 QTableView *table =
ui->tableView;
258 if (!table->selectionModel()) {
262 if (table->selectionModel()->hasSelection()) {
266 ui->deleteAddress->setEnabled(
true);
267 ui->deleteAddress->setVisible(
true);
272 ui->deleteAddress->setEnabled(
false);
273 ui->deleteAddress->setVisible(
false);
277 ui->copyAddress->setEnabled(
true);
279 ui->deleteAddress->setEnabled(
false);
280 ui->copyAddress->setEnabled(
false);
285 QTableView *table =
ui->tableView;
286 if (!table->selectionModel() || !table->model()) {
291 QModelIndexList indexes =
294 for (
const QModelIndex &index : indexes) {
295 QVariant address = table->model()->data(index);
304 QDialog::done(retval);
311 tr(
"Comma separated file (*.csv)"),
nullptr);
313 if (filename.isNull()) {
324 if (!writer.
write()) {
325 QMessageBox::critical(
this, tr(
"Exporting Failed"),
326 tr(
"There was an error trying to save the "
327 "address list to %1. Please try again.")
333 QModelIndex index =
ui->tableView->indexAt(point);
334 if (index.isValid()) {
346 ui->tableView->setFocus();
347 ui->tableView->selectRow(idx.row());
Widget that shows a list of sending or receiving addresses.
void onEditAction()
Edit currently selected address entry (no button)
@ ForEditing
Open address book for editing.
@ ForSelection
Open address book to pick address.
void setModel(AddressTableModel *model)
void onCopyLabelAction()
Copy label of currently selected address entry to clipboard (no button)
QString newAddressToSelect
void done(int retval) override
AddressBookPage(const PlatformStyle *platformStyle, Mode mode, Tabs tab, QWidget *parent=nullptr)
void on_copyAddress_clicked()
Copy address of currently selected address entry to clipboard.
void on_exportButton_clicked()
Export button clicked.
void on_deleteAddress_clicked()
Delete currently selected address entry.
void contextualMenu(const QPoint &point)
Spawn contextual menu (right mouse menu) for address book entry.
AddressTableModel * model
void selectionChanged()
Set button states based on selected tab and selection.
void selectNewAddress(const QModelIndex &parent, int begin, int)
New entry/entries were added to address table.
void on_newAddress_clicked()
Create a new address for receiving coins and / or add a new address book entry.
AddressBookSortFilterProxyModel * proxyModel
bool filterAcceptsRow(int row, const QModelIndex &parent) const override
AddressBookSortFilterProxyModel(const QString &type, QObject *parent)
Qt model of the address book in the core.
@ TypeRole
Type of address (Send or Receive)
@ Address
Bitcoin address.
@ Label
User specified label.
QModelIndex index(int row, int column, const QModelIndex &parent) const override
static const QString Send
Specifies send address.
static const QString Receive
Specifies receive address.
Export a Qt table model to a CSV file.
bool write()
Perform export of the model to CSV.
void setModel(const QAbstractItemModel *model)
void addColumn(const QString &title, int column, int role=Qt::EditRole)
Dialog for editing an address and associated information.
void setModel(AddressTableModel *model)
QString getAddress() const
void handleCloseWindowShortcut(QWidget *w)
void copyEntryData(const QAbstractItemView *view, int column, int role)
Copy a field of the currently selected entry of a view to the clipboard.
QString getSaveFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedSuffixOut)
Get save filename, mimics QFileDialog::getSaveFileName, except that it appends a default suffix when ...