Changeset View
Changeset View
Standalone View
Standalone View
src/qt/addressbookpage.cpp
Show First 20 Lines • Show All 93 Lines • ▼ Show 20 Lines | AddressBookPage::AddressBookPage(const PlatformStyle *platformStyle, Mode _mode, | ||||
QAction *editAction = new QAction(tr("&Edit"), this); | QAction *editAction = new QAction(tr("&Edit"), this); | ||||
deleteAction = new QAction(ui->deleteAddress->text(), this); | deleteAction = new QAction(ui->deleteAddress->text(), this); | ||||
// Build context menu | // Build context menu | ||||
contextMenu = new QMenu(this); | contextMenu = new QMenu(this); | ||||
contextMenu->addAction(copyAddressAction); | contextMenu->addAction(copyAddressAction); | ||||
contextMenu->addAction(copyLabelAction); | contextMenu->addAction(copyLabelAction); | ||||
contextMenu->addAction(editAction); | contextMenu->addAction(editAction); | ||||
if (tab == SendingTab) contextMenu->addAction(deleteAction); | if (tab == SendingTab) { | ||||
contextMenu->addAction(deleteAction); | |||||
} | |||||
contextMenu->addSeparator(); | contextMenu->addSeparator(); | ||||
// Connect signals for context menu actions | // Connect signals for context menu actions | ||||
connect(copyAddressAction, SIGNAL(triggered()), this, | connect(copyAddressAction, SIGNAL(triggered()), this, | ||||
SLOT(on_copyAddress_clicked())); | SLOT(on_copyAddress_clicked())); | ||||
connect(copyLabelAction, SIGNAL(triggered()), this, | connect(copyLabelAction, SIGNAL(triggered()), this, | ||||
SLOT(onCopyLabelAction())); | SLOT(onCopyLabelAction())); | ||||
connect(editAction, SIGNAL(triggered()), this, SLOT(onEditAction())); | connect(editAction, SIGNAL(triggered()), this, SLOT(onEditAction())); | ||||
connect(deleteAction, SIGNAL(triggered()), this, | connect(deleteAction, SIGNAL(triggered()), this, | ||||
SLOT(on_deleteAddress_clicked())); | SLOT(on_deleteAddress_clicked())); | ||||
connect(ui->tableView, SIGNAL(customContextMenuRequested(QPoint)), this, | connect(ui->tableView, SIGNAL(customContextMenuRequested(QPoint)), this, | ||||
SLOT(contextualMenu(QPoint))); | SLOT(contextualMenu(QPoint))); | ||||
connect(ui->closeButton, SIGNAL(clicked()), this, SLOT(accept())); | connect(ui->closeButton, SIGNAL(clicked()), this, SLOT(accept())); | ||||
} | } | ||||
AddressBookPage::~AddressBookPage() { | AddressBookPage::~AddressBookPage() { | ||||
delete ui; | delete ui; | ||||
} | } | ||||
void AddressBookPage::setModel(AddressTableModel *_model) { | void AddressBookPage::setModel(AddressTableModel *_model) { | ||||
this->model = _model; | this->model = _model; | ||||
if (!_model) return; | if (!_model) { | ||||
return; | |||||
} | |||||
proxyModel = new QSortFilterProxyModel(this); | proxyModel = new QSortFilterProxyModel(this); | ||||
proxyModel->setSourceModel(_model); | proxyModel->setSourceModel(_model); | ||||
proxyModel->setDynamicSortFilter(true); | proxyModel->setDynamicSortFilter(true); | ||||
proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive); | proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive); | ||||
proxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive); | proxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive); | ||||
switch (tab) { | switch (tab) { | ||||
case ReceivingTab: | case ReceivingTab: | ||||
Show All 31 Lines | void AddressBookPage::on_copyAddress_clicked() { | ||||
GUIUtil::copyEntryData(ui->tableView, AddressTableModel::Address); | GUIUtil::copyEntryData(ui->tableView, AddressTableModel::Address); | ||||
} | } | ||||
void AddressBookPage::onCopyLabelAction() { | void AddressBookPage::onCopyLabelAction() { | ||||
GUIUtil::copyEntryData(ui->tableView, AddressTableModel::Label); | GUIUtil::copyEntryData(ui->tableView, AddressTableModel::Label); | ||||
} | } | ||||
void AddressBookPage::onEditAction() { | void AddressBookPage::onEditAction() { | ||||
if (!model) return; | if (!model) { | ||||
return; | |||||
} | |||||
if (!ui->tableView->selectionModel()) return; | if (!ui->tableView->selectionModel()) { | ||||
return; | |||||
} | |||||
QModelIndexList indexes = ui->tableView->selectionModel()->selectedRows(); | QModelIndexList indexes = ui->tableView->selectionModel()->selectedRows(); | ||||
if (indexes.isEmpty()) return; | if (indexes.isEmpty()) { | ||||
return; | |||||
} | |||||
EditAddressDialog dlg(tab == SendingTab | EditAddressDialog dlg(tab == SendingTab | ||||
? EditAddressDialog::EditSendingAddress | ? EditAddressDialog::EditSendingAddress | ||||
: EditAddressDialog::EditReceivingAddress, | : EditAddressDialog::EditReceivingAddress, | ||||
this); | this); | ||||
dlg.setModel(model); | dlg.setModel(model); | ||||
QModelIndex origIndex = proxyModel->mapToSource(indexes.at(0)); | QModelIndex origIndex = proxyModel->mapToSource(indexes.at(0)); | ||||
dlg.loadRow(origIndex.row()); | dlg.loadRow(origIndex.row()); | ||||
dlg.exec(); | dlg.exec(); | ||||
} | } | ||||
void AddressBookPage::on_newAddress_clicked() { | void AddressBookPage::on_newAddress_clicked() { | ||||
if (!model) return; | if (!model) { | ||||
return; | |||||
} | |||||
EditAddressDialog dlg(tab == SendingTab | EditAddressDialog dlg(tab == SendingTab | ||||
? EditAddressDialog::NewSendingAddress | ? EditAddressDialog::NewSendingAddress | ||||
: EditAddressDialog::NewReceivingAddress, | : EditAddressDialog::NewReceivingAddress, | ||||
this); | this); | ||||
dlg.setModel(model); | dlg.setModel(model); | ||||
if (dlg.exec()) { | if (dlg.exec()) { | ||||
newAddressToSelect = dlg.getAddress(); | newAddressToSelect = dlg.getAddress(); | ||||
} | } | ||||
} | } | ||||
void AddressBookPage::on_deleteAddress_clicked() { | void AddressBookPage::on_deleteAddress_clicked() { | ||||
QTableView *table = ui->tableView; | QTableView *table = ui->tableView; | ||||
if (!table->selectionModel()) return; | if (!table->selectionModel()) { | ||||
return; | |||||
} | |||||
QModelIndexList indexes = table->selectionModel()->selectedRows(); | QModelIndexList indexes = table->selectionModel()->selectedRows(); | ||||
if (!indexes.isEmpty()) { | if (!indexes.isEmpty()) { | ||||
table->model()->removeRow(indexes.at(0).row()); | table->model()->removeRow(indexes.at(0).row()); | ||||
} | } | ||||
} | } | ||||
void AddressBookPage::selectionChanged() { | void AddressBookPage::selectionChanged() { | ||||
// Set button states based on selected tab and selection | // Set button states based on selected tab and selection | ||||
QTableView *table = ui->tableView; | QTableView *table = ui->tableView; | ||||
if (!table->selectionModel()) return; | if (!table->selectionModel()) { | ||||
return; | |||||
} | |||||
if (table->selectionModel()->hasSelection()) { | if (table->selectionModel()->hasSelection()) { | ||||
switch (tab) { | switch (tab) { | ||||
case SendingTab: | case SendingTab: | ||||
// In sending tab, allow deletion of selection | // In sending tab, allow deletion of selection | ||||
ui->deleteAddress->setEnabled(true); | ui->deleteAddress->setEnabled(true); | ||||
ui->deleteAddress->setVisible(true); | ui->deleteAddress->setVisible(true); | ||||
deleteAction->setEnabled(true); | deleteAction->setEnabled(true); | ||||
Show All 9 Lines | void AddressBookPage::selectionChanged() { | ||||
} else { | } else { | ||||
ui->deleteAddress->setEnabled(false); | ui->deleteAddress->setEnabled(false); | ||||
ui->copyAddress->setEnabled(false); | ui->copyAddress->setEnabled(false); | ||||
} | } | ||||
} | } | ||||
void AddressBookPage::done(int retval) { | void AddressBookPage::done(int retval) { | ||||
QTableView *table = ui->tableView; | QTableView *table = ui->tableView; | ||||
if (!table->selectionModel() || !table->model()) return; | if (!table->selectionModel() || !table->model()) { | ||||
return; | |||||
} | |||||
// Figure out which address was selected, and return it | // Figure out which address was selected, and return it | ||||
QModelIndexList indexes = | QModelIndexList indexes = | ||||
table->selectionModel()->selectedRows(AddressTableModel::Address); | table->selectionModel()->selectedRows(AddressTableModel::Address); | ||||
for (const QModelIndex &index : indexes) { | for (const QModelIndex &index : indexes) { | ||||
QVariant address = table->model()->data(index); | QVariant address = table->model()->data(index); | ||||
returnValue = address.toString(); | returnValue = address.toString(); | ||||
} | } | ||||
if (returnValue.isEmpty()) { | if (returnValue.isEmpty()) { | ||||
// If no address entry selected, return rejected | // If no address entry selected, return rejected | ||||
retval = Rejected; | retval = Rejected; | ||||
} | } | ||||
QDialog::done(retval); | QDialog::done(retval); | ||||
} | } | ||||
void AddressBookPage::on_exportButton_clicked() { | void AddressBookPage::on_exportButton_clicked() { | ||||
// CSV is currently the only supported format | // CSV is currently the only supported format | ||||
QString filename = | QString filename = | ||||
GUIUtil::getSaveFileName(this, tr("Export Address List"), QString(), | GUIUtil::getSaveFileName(this, tr("Export Address List"), QString(), | ||||
tr("Comma separated file (*.csv)"), nullptr); | tr("Comma separated file (*.csv)"), nullptr); | ||||
if (filename.isNull()) return; | if (filename.isNull()) { | ||||
return; | |||||
} | |||||
CSVModelWriter writer(filename); | CSVModelWriter writer(filename); | ||||
// name, column, role | // name, column, role | ||||
writer.setModel(proxyModel); | writer.setModel(proxyModel); | ||||
writer.addColumn("Label", AddressTableModel::Label, Qt::EditRole); | writer.addColumn("Label", AddressTableModel::Label, Qt::EditRole); | ||||
writer.addColumn("Address", AddressTableModel::Address, Qt::EditRole); | writer.addColumn("Address", AddressTableModel::Address, Qt::EditRole); | ||||
Show All 27 Lines |