diff options
-rw-r--r-- | src/qt/addressbookpage.cpp | 57 | ||||
-rw-r--r-- | src/qt/addressbookpage.h | 3 | ||||
-rw-r--r-- | src/qt/bitcoingui.cpp | 25 | ||||
-rw-r--r-- | src/qt/bitcoingui.h | 1 | ||||
-rw-r--r-- | src/qt/transactionview.cpp | 4 |
5 files changed, 57 insertions, 33 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); + } +} diff --git a/src/qt/addressbookpage.h b/src/qt/addressbookpage.h index c4039523af..53c7728c8c 100644 --- a/src/qt/addressbookpage.h +++ b/src/qt/addressbookpage.h @@ -11,6 +11,7 @@ class AddressTableModel; QT_BEGIN_NAMESPACE class QTableView; class QItemSelection; +class QSortFilterProxyModel; QT_END_NAMESPACE class AddressBookPage : public QDialog @@ -36,6 +37,7 @@ public: public slots: void done(int retval); + void exportClicked(); private: Ui::AddressBookPage *ui; @@ -43,6 +45,7 @@ private: Mode mode; Tabs tab; QString returnValue; + QSortFilterProxyModel *proxyModel; QTableView *getCurrentTable(); diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 5291951334..94bd9765e3 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -184,7 +184,6 @@ void BitcoinGUI::createActions() connect(optionsAction, SIGNAL(triggered()), this, SLOT(optionsClicked())); connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutClicked())); connect(openBitcoinAction, SIGNAL(triggered()), this, SLOT(show())); - connect(exportAction, SIGNAL(triggered()), this, SLOT(exportClicked())); } void BitcoinGUI::setClientModel(ClientModel *clientModel) @@ -440,28 +439,39 @@ void BitcoinGUI::gotoOverviewPage() { overviewAction->setChecked(true); centralWidget->setCurrentWidget(overviewPage); + exportAction->setEnabled(false); + disconnect(exportAction, SIGNAL(triggered()), 0, 0); } void BitcoinGUI::gotoHistoryPage() { historyAction->setChecked(true); centralWidget->setCurrentWidget(transactionsPage); + exportAction->setEnabled(true); + disconnect(exportAction, SIGNAL(triggered()), 0, 0); + connect(exportAction, SIGNAL(triggered()), transactionView, SLOT(exportClicked())); } void BitcoinGUI::gotoAddressBookPage() { addressBookAction->setChecked(true); centralWidget->setCurrentWidget(addressBookPage); - exportAction->setEnabled(false); // TODO + + exportAction->setEnabled(true); + disconnect(exportAction, SIGNAL(triggered()), 0, 0); + connect(exportAction, SIGNAL(triggered()), addressBookPage, SLOT(exportClicked())); } void BitcoinGUI::gotoReceiveCoinsPage() { receiveCoinsAction->setChecked(true); centralWidget->setCurrentWidget(receiveCoinsPage); - exportAction->setEnabled(false); // TODO + + exportAction->setEnabled(true); + disconnect(exportAction, SIGNAL(triggered()), 0, 0); + connect(exportAction, SIGNAL(triggered()), receiveCoinsPage, SLOT(exportClicked())); } void BitcoinGUI::gotoSendCoinsPage() @@ -469,13 +479,8 @@ void BitcoinGUI::gotoSendCoinsPage() sendCoinsAction->setChecked(true); sendCoinsPage->clear(); centralWidget->setCurrentWidget(sendCoinsPage); - exportAction->setEnabled(false); -} -void BitcoinGUI::exportClicked() -{ - // Redirect to the right view, as soon as export for other views - // (such as address book) is implemented. - transactionView->exportClicked(); + exportAction->setEnabled(false); + disconnect(exportAction, SIGNAL(triggered()), 0, 0); } diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index b82818aa3f..6f4ca19146 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -103,7 +103,6 @@ private slots: void aboutClicked(); void trayIconActivated(QSystemTrayIcon::ActivationReason reason); void incomingTransaction(const QModelIndex & parent, int start, int end); - void exportClicked(); }; #endif diff --git a/src/qt/transactionview.cpp b/src/qt/transactionview.cpp index 53c33c7c48..03df422605 100644 --- a/src/qt/transactionview.cpp +++ b/src/qt/transactionview.cpp @@ -241,10 +241,6 @@ void TransactionView::exportClicked() tr("Export Transaction Data"), QDir::currentPath(), tr("Comma separated file (*.csv)")); - if(!filename.endsWith(".csv")) - { - filename += ".csv"; - } CSVModelWriter writer(filename); |