5#if defined(HAVE_CONFIG_H)
6#include <config/bitcoin-config.h>
10#include <qt/forms/ui_addressbookpage.h>
21#include <QSortFilterProxyModel>
22#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
23#include <QRegularExpression>
33 : QSortFilterProxyModel(parent),
m_type(type) {
34 setDynamicSortFilter(
true);
35 setFilterCaseSensitivity(Qt::CaseInsensitive);
36 setSortCaseSensitivity(Qt::CaseInsensitive);
41 auto model = sourceModel();
51#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
52 const auto pattern = filterRegularExpression();
54 const auto pattern = filterRegExp();
56 return (model->data(address).toString().contains(pattern) ||
57 model->data(label).toString().contains(pattern));
62 Tabs _tab, QWidget *parent)
68 ui->newAddress->setIcon(QIcon());
69 ui->copyAddress->setIcon(QIcon());
70 ui->deleteAddress->setIcon(QIcon());
71 ui->exportButton->setIcon(QIcon());
74 ui->copyAddress->setIcon(
76 ui->deleteAddress->setIcon(
78 ui->exportButton->setIcon(
86 setWindowTitle(tr(
"Choose the address to send coins to"));
90 tr(
"Choose the address to receive coins with"));
93 connect(
ui->tableView, &QTableView::doubleClicked,
this,
95 ui->tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
96 ui->tableView->setFocus();
97 ui->closeButton->setText(tr(
"C&hoose"));
98 ui->exportButton->hide();
103 setWindowTitle(tr(
"Sending addresses"));
106 setWindowTitle(tr(
"Receiving addresses"));
113 ui->labelExplanation->setText(
114 tr(
"These are your Bitcoin addresses for sending payments. "
115 "Always check the amount and the receiving address before "
117 ui->deleteAddress->setVisible(
true);
118 ui->newAddress->setVisible(
true);
121 ui->labelExplanation->setText(
122 tr(
"These are your Bitcoin addresses for receiving payments. "
123 "Use the 'Create new receiving address' button in the "
124 "receive tab to create new addresses."));
125 ui->deleteAddress->setVisible(
false);
126 ui->newAddress->setVisible(
false);
131 QAction *copyAddressAction =
new QAction(tr(
"&Copy Address"),
this);
132 QAction *copyLabelAction =
new QAction(tr(
"Copy &Label"),
this);
133 QAction *editAction =
new QAction(tr(
"&Edit"),
this);
147 connect(copyAddressAction, &QAction::triggered,
this,
149 connect(copyLabelAction, &QAction::triggered,
this,
151 connect(editAction, &QAction::triggered,
this,
156 connect(
ui->tableView, &QWidget::customContextMenuRequested,
this,
159 connect(
ui->closeButton, &QPushButton::clicked,
this, &QDialog::accept);
169 this->
model = _model;
179 connect(
ui->searchLineEdit, &QLineEdit::textChanged,
proxyModel,
180 &QSortFilterProxyModel::setFilterWildcard);
183 ui->tableView->sortByColumn(0, Qt::AscendingOrder);
186 ui->tableView->horizontalHeader()->setSectionResizeMode(
188 ui->tableView->horizontalHeader()->setSectionResizeMode(
191 connect(
ui->tableView->selectionModel(),
192 &QItemSelectionModel::selectionChanged,
this,
196 connect(_model, &AddressTableModel::rowsInserted,
this,
215 if (!
ui->tableView->selectionModel()) {
218 QModelIndexList indexes =
ui->tableView->selectionModel()->selectedRows();
219 if (indexes.isEmpty()) {
227 dlg->setModel(
model);
228 QModelIndex origIndex =
proxyModel->mapToSource(indexes.at(0));
229 dlg->loadRow(origIndex.row());
250 QTableView *table =
ui->tableView;
251 if (!table->selectionModel()) {
255 QModelIndexList indexes = table->selectionModel()->selectedRows();
256 if (!indexes.isEmpty()) {
257 table->model()->removeRow(indexes.at(0).row());
263 QTableView *table =
ui->tableView;
264 if (!table->selectionModel()) {
268 if (table->selectionModel()->hasSelection()) {
272 ui->deleteAddress->setEnabled(
true);
273 ui->deleteAddress->setVisible(
true);
278 ui->deleteAddress->setEnabled(
false);
279 ui->deleteAddress->setVisible(
false);
283 ui->copyAddress->setEnabled(
true);
285 ui->deleteAddress->setEnabled(
false);
286 ui->copyAddress->setEnabled(
false);
291 QTableView *table =
ui->tableView;
292 if (!table->selectionModel() || !table->model()) {
297 QModelIndexList indexes =
300 for (
const QModelIndex &index : indexes) {
301 QVariant address = table->model()->data(index);
310 QDialog::done(retval);
317 tr(
"Comma separated file (*.csv)"),
nullptr);
319 if (filename.isNull()) {
330 if (!writer.
write()) {
331 QMessageBox::critical(
this, tr(
"Exporting Failed"),
332 tr(
"There was an error trying to save the "
333 "address list to %1. Please try again.")
339 QModelIndex index =
ui->tableView->indexAt(point);
340 if (index.isValid()) {
352 ui->tableView->setFocus();
353 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 ShowModalDialogAsynchronously(QDialog *dialog)
Shows a QDialog instance asynchronously, and deletes it on close.
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 ...