diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2011-07-09 10:53:55 +0200 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2011-07-09 10:54:17 +0200 |
commit | f54d59ba4a9136a79734ac399433b0e74b1bec00 (patch) | |
tree | f16f3c5a0ef80b9bbda5fe7d264ab5db3969c859 /src/qt/addressbookpage.cpp | |
parent | 2eace48d9a50e5393f3627bcd0614ed9b262794a (diff) |
add export functionality for address book / receiving addresses
Diffstat (limited to 'src/qt/addressbookpage.cpp')
-rw-r--r-- | src/qt/addressbookpage.cpp | 57 |
1 files changed, 39 insertions, 18 deletions
diff --git a/src/qt/addressbookpage.cpp b/src/qt/addressbookpage.cpp index 5127eb6009..4f629fc262 100644 --- a/src/qt/addressbookpage.cpp +++ b/src/qt/addressbookpage.cpp @@ -3,9 +3,12 @@ #include "addresstablemodel.h" #include "editaddressdialog.h" +#include "csvmodelwriter.h" #include <QSortFilterProxyModel> #include <QClipboard> +#include <QFileDialog> +#include <QMessageBox> #include <QDebug> AddressBookPage::AddressBookPage(Mode mode, Tabs tab, QWidget *parent) : @@ -51,29 +54,24 @@ void AddressBookPage::setModel(AddressTableModel *model) // Refresh list from core model->updateList(); + proxyModel = new QSortFilterProxyModel(this); + proxyModel->setSourceModel(model); + proxyModel->setDynamicSortFilter(true); switch(tab) { - case ReceivingTab: { + case ReceivingTab: // Receive filter - QSortFilterProxyModel *receive_model = new QSortFilterProxyModel(this); - receive_model->setSourceModel(model); - receive_model->setDynamicSortFilter(true); - receive_model->setFilterRole(AddressTableModel::TypeRole); - receive_model->setFilterFixedString(AddressTableModel::Receive); - ui->tableView->setModel(receive_model); - ui->tableView->sortByColumn(0, Qt::AscendingOrder); - } break; - case SendingTab: { + proxyModel->setFilterRole(AddressTableModel::TypeRole); + proxyModel->setFilterFixedString(AddressTableModel::Receive); + break; + case SendingTab: // Send filter - QSortFilterProxyModel *send_model = new QSortFilterProxyModel(this); - send_model->setSourceModel(model); - send_model->setDynamicSortFilter(true); - send_model->setFilterRole(AddressTableModel::TypeRole); - send_model->setFilterFixedString(AddressTableModel::Send); - ui->tableView->setModel(send_model); - ui->tableView->sortByColumn(0, Qt::AscendingOrder); - } break; + proxyModel->setFilterRole(AddressTableModel::TypeRole); + proxyModel->setFilterFixedString(AddressTableModel::Send); + break; } + ui->tableView->setModel(proxyModel); + ui->tableView->sortByColumn(0, Qt::AscendingOrder); // Set column widths ui->tableView->horizontalHeader()->resizeSection( @@ -179,3 +177,26 @@ void AddressBookPage::done(int retval) QDialog::done(retval); } + +void AddressBookPage::exportClicked() +{ + // CSV is currently the only supported format + QString filename = QFileDialog::getSaveFileName( + this, + tr("Export Address Book Data"), + QDir::currentPath(), + tr("Comma separated file (*.csv)")); + + CSVModelWriter writer(filename); + + // name, column, role + writer.setModel(proxyModel); + writer.addColumn("Label", AddressTableModel::Label, Qt::EditRole); + writer.addColumn("Address", AddressTableModel::Address, Qt::EditRole); + + if(!writer.write()) + { + QMessageBox::critical(this, tr("Error exporting"), tr("Could not write to file %1.").arg(filename), + QMessageBox::Abort, QMessageBox::Abort); + } +} |