6 #include <qt/forms/ui_addressbookpage.h> 16 #include <QMessageBox> 17 #include <QSortFilterProxyModel> 18 #include <QRegularExpression> 26 : QSortFilterProxyModel(parent)
29 setDynamicSortFilter(
true);
30 setFilterCaseSensitivity(Qt::CaseInsensitive);
31 setSortCaseSensitivity(Qt::CaseInsensitive);
37 auto model = sourceModel();
46 const auto pattern = filterRegularExpression();
47 return (model->data(address).toString().contains(pattern) ||
48 model->data(label).toString().contains(pattern));
61 ui->newAddress->setIcon(QIcon());
62 ui->copyAddress->setIcon(QIcon());
63 ui->deleteAddress->setIcon(QIcon());
64 ui->exportButton->setIcon(QIcon());
75 case SendingTab: setWindowTitle(tr(
"Choose the address to send coins to"));
break;
76 case ReceivingTab: setWindowTitle(tr(
"Choose the address to receive coins with"));
break;
78 connect(
ui->tableView, &QTableView::doubleClicked,
this, &QDialog::accept);
79 ui->tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
80 ui->tableView->setFocus();
81 ui->closeButton->setText(tr(
"C&hoose"));
82 ui->exportButton->hide();
87 ui->labelExplanation->setText(tr(
"These are your Bitcoin addresses for sending payments. Always check the amount and the receiving address before sending coins."));
88 ui->deleteAddress->setVisible(
true);
89 ui->newAddress->setVisible(
true);
92 ui->labelExplanation->setText(tr(
"These are your Bitcoin addresses for receiving payments. Use the 'Create new receiving address' button in the receive tab to create new addresses.\nSigning is only possible with addresses of the type 'legacy'."));
93 ui->deleteAddress->setVisible(
false);
94 ui->newAddress->setVisible(
false);
109 connect(
ui->closeButton, &QPushButton::clicked,
this, &QDialog::accept);
121 this->
model = _model;
129 connect(
ui->searchLineEdit, &QLineEdit::textChanged,
proxyModel, &QSortFilterProxyModel::setFilterWildcard);
132 ui->tableView->sortByColumn(0, Qt::AscendingOrder);
138 connect(
ui->tableView->selectionModel(), &QItemSelectionModel::selectionChanged,
163 if(!
ui->tableView->selectionModel())
165 QModelIndexList indexes =
ui->tableView->selectionModel()->selectedRows();
166 if(indexes.isEmpty())
173 dlg->setModel(
model);
174 QModelIndex origIndex =
proxyModel->mapToSource(indexes.at(0));
175 dlg->loadRow(origIndex.row());
198 QTableView *table =
ui->tableView;
199 if(!table->selectionModel())
202 QModelIndexList indexes = table->selectionModel()->selectedRows();
203 if(!indexes.isEmpty())
205 table->model()->removeRow(indexes.at(0).row());
212 QTableView *table =
ui->tableView;
213 if(!table->selectionModel())
216 if(table->selectionModel()->hasSelection())
222 ui->deleteAddress->setEnabled(
true);
223 ui->deleteAddress->setVisible(
true);
227 ui->deleteAddress->setEnabled(
false);
228 ui->deleteAddress->setVisible(
false);
231 ui->copyAddress->setEnabled(
true);
235 ui->deleteAddress->setEnabled(
false);
236 ui->copyAddress->setEnabled(
false);
242 QTableView *table =
ui->tableView;
243 if(!table->selectionModel() || !table->model())
249 for (
const QModelIndex& index : indexes) {
250 QVariant address = table->model()->data(index);
260 QDialog::done(retval);
267 tr(
"Export Address List"), QString(),
270 tr(
"Comma separated file") + QLatin1String(
" (*.csv)"),
nullptr);
272 if (filename.isNull())
282 if(!writer.
write()) {
283 QMessageBox::critical(
this, tr(
"Exporting Failed"),
286 tr(
"There was an error trying to save the address list to %1. Please try again.").arg(filename));
292 QModelIndex index =
ui->tableView->indexAt(point);
305 ui->tableView->setFocus();
306 ui->tableView->selectRow(idx.row());
318 case SendingTab: setWindowTitle(tr(
"Sending addresses - %1").arg(walletName));
break;
319 case ReceivingTab: setWindowTitle(tr(
"Receiving addresses - %1").arg(walletName));
break;
AddressBookPage(const PlatformStyle *platformStyle, Mode mode, Tabs tab, QWidget *parent=nullptr)
void on_newAddress_clicked()
Create a new address for receiving coins and / or add a new address book entry.
void onCopyLabelAction()
Copy label of currently selected address entry to clipboard (no button)
void addColumn(const QString &title, int column, int role=Qt::EditRole)
Utility functions used by the Bitcoin Qt UI.
void setModel(AddressTableModel *model)
void onEditAction()
Edit currently selected address entry (no button)
AddressTableModel * model
void updateWindowsTitleWithWalletName()
void on_exportButton_clicked()
Export button clicked.
Open address book for editing.
Open address book to pick address.
void ShowModalDialogAsynchronously(QDialog *dialog)
Shows a QDialog instance asynchronously, and deletes it on close.
Export a Qt table model to a CSV file.
QString newAddressToSelect
static const QString Send
Specifies send address.
constexpr auto dialog_flags
void selectNewAddress(const QModelIndex &parent, int begin, int)
New entry/entries were added to address table.
void setModel(AddressTableModel *model)
void handleCloseWindowShortcut(QWidget *w)
AddressBookSortFilterProxyModel * proxyModel
AddressBookSortFilterProxyModel(const QString &type, QObject *parent)
void on_copyAddress_clicked()
Copy address of currently selected address entry to clipboard.
Widget that shows a list of sending or receiving addresses.
void copyEntryData(const QAbstractItemView *view, int column, int role)
Copy a field of the currently selected entry of a view to the clipboard.
Qt model of the address book in the core.
void done(int retval) override
void selectionChanged()
Set button states based on selected tab and selection.
void setModel(const QAbstractItemModel *model)
QString GetWalletDisplayName() const
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 ...
static const QString Receive
Specifies receive address.
Dialog for editing an address and associated information.
bool filterAcceptsRow(int row, const QModelIndex &parent) const override
QString getAddress() const
void contextualMenu(const QPoint &point)
Spawn contextual menu (right mouse menu) for address book entry.
void on_deleteAddress_clicked()
Delete currently selected address entry.
QModelIndex index(int row, int column, const QModelIndex &parent) const override
bool write()
Perform export of the model to CSV.
Type of address (Send or Receive)