Browse Source

add export functionality for address book / receiving addresses

miguelfreitas
Wladimir J. van der Laan 14 years ago
parent
commit
f54d59ba4a
  1. 57
      src/qt/addressbookpage.cpp
  2. 3
      src/qt/addressbookpage.h
  3. 25
      src/qt/bitcoingui.cpp
  4. 1
      src/qt/bitcoingui.h
  5. 4
      src/qt/transactionview.cpp

57
src/qt/addressbookpage.cpp

@ -3,9 +3,12 @@
#include "addresstablemodel.h" #include "addresstablemodel.h"
#include "editaddressdialog.h" #include "editaddressdialog.h"
#include "csvmodelwriter.h"
#include <QSortFilterProxyModel> #include <QSortFilterProxyModel>
#include <QClipboard> #include <QClipboard>
#include <QFileDialog>
#include <QMessageBox>
#include <QDebug> #include <QDebug>
AddressBookPage::AddressBookPage(Mode mode, Tabs tab, QWidget *parent) : AddressBookPage::AddressBookPage(Mode mode, Tabs tab, QWidget *parent) :
@ -51,29 +54,24 @@ void AddressBookPage::setModel(AddressTableModel *model)
// Refresh list from core // Refresh list from core
model->updateList(); model->updateList();
proxyModel = new QSortFilterProxyModel(this);
proxyModel->setSourceModel(model);
proxyModel->setDynamicSortFilter(true);
switch(tab) switch(tab)
{ {
case ReceivingTab: { case ReceivingTab:
// Receive filter // Receive filter
QSortFilterProxyModel *receive_model = new QSortFilterProxyModel(this); proxyModel->setFilterRole(AddressTableModel::TypeRole);
receive_model->setSourceModel(model); proxyModel->setFilterFixedString(AddressTableModel::Receive);
receive_model->setDynamicSortFilter(true); break;
receive_model->setFilterRole(AddressTableModel::TypeRole); case SendingTab:
receive_model->setFilterFixedString(AddressTableModel::Receive);
ui->tableView->setModel(receive_model);
ui->tableView->sortByColumn(0, Qt::AscendingOrder);
} break;
case SendingTab: {
// Send filter // Send filter
QSortFilterProxyModel *send_model = new QSortFilterProxyModel(this); proxyModel->setFilterRole(AddressTableModel::TypeRole);
send_model->setSourceModel(model); proxyModel->setFilterFixedString(AddressTableModel::Send);
send_model->setDynamicSortFilter(true); break;
send_model->setFilterRole(AddressTableModel::TypeRole);
send_model->setFilterFixedString(AddressTableModel::Send);
ui->tableView->setModel(send_model);
ui->tableView->sortByColumn(0, Qt::AscendingOrder);
} break;
} }
ui->tableView->setModel(proxyModel);
ui->tableView->sortByColumn(0, Qt::AscendingOrder);
// Set column widths // Set column widths
ui->tableView->horizontalHeader()->resizeSection( ui->tableView->horizontalHeader()->resizeSection(
@ -179,3 +177,26 @@ void AddressBookPage::done(int retval)
QDialog::done(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);
}
}

3
src/qt/addressbookpage.h

@ -11,6 +11,7 @@ class AddressTableModel;
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QTableView; class QTableView;
class QItemSelection; class QItemSelection;
class QSortFilterProxyModel;
QT_END_NAMESPACE QT_END_NAMESPACE
class AddressBookPage : public QDialog class AddressBookPage : public QDialog
@ -36,6 +37,7 @@ public:
public slots: public slots:
void done(int retval); void done(int retval);
void exportClicked();
private: private:
Ui::AddressBookPage *ui; Ui::AddressBookPage *ui;
@ -43,6 +45,7 @@ private:
Mode mode; Mode mode;
Tabs tab; Tabs tab;
QString returnValue; QString returnValue;
QSortFilterProxyModel *proxyModel;
QTableView *getCurrentTable(); QTableView *getCurrentTable();

25
src/qt/bitcoingui.cpp

@ -184,7 +184,6 @@ void BitcoinGUI::createActions()
connect(optionsAction, SIGNAL(triggered()), this, SLOT(optionsClicked())); connect(optionsAction, SIGNAL(triggered()), this, SLOT(optionsClicked()));
connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutClicked())); connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutClicked()));
connect(openBitcoinAction, SIGNAL(triggered()), this, SLOT(show())); connect(openBitcoinAction, SIGNAL(triggered()), this, SLOT(show()));
connect(exportAction, SIGNAL(triggered()), this, SLOT(exportClicked()));
} }
void BitcoinGUI::setClientModel(ClientModel *clientModel) void BitcoinGUI::setClientModel(ClientModel *clientModel)
@ -440,28 +439,39 @@ void BitcoinGUI::gotoOverviewPage()
{ {
overviewAction->setChecked(true); overviewAction->setChecked(true);
centralWidget->setCurrentWidget(overviewPage); centralWidget->setCurrentWidget(overviewPage);
exportAction->setEnabled(false); exportAction->setEnabled(false);
disconnect(exportAction, SIGNAL(triggered()), 0, 0);
} }
void BitcoinGUI::gotoHistoryPage() void BitcoinGUI::gotoHistoryPage()
{ {
historyAction->setChecked(true); historyAction->setChecked(true);
centralWidget->setCurrentWidget(transactionsPage); centralWidget->setCurrentWidget(transactionsPage);
exportAction->setEnabled(true); exportAction->setEnabled(true);
disconnect(exportAction, SIGNAL(triggered()), 0, 0);
connect(exportAction, SIGNAL(triggered()), transactionView, SLOT(exportClicked()));
} }
void BitcoinGUI::gotoAddressBookPage() void BitcoinGUI::gotoAddressBookPage()
{ {
addressBookAction->setChecked(true); addressBookAction->setChecked(true);
centralWidget->setCurrentWidget(addressBookPage); 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() void BitcoinGUI::gotoReceiveCoinsPage()
{ {
receiveCoinsAction->setChecked(true); receiveCoinsAction->setChecked(true);
centralWidget->setCurrentWidget(receiveCoinsPage); 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() void BitcoinGUI::gotoSendCoinsPage()
@ -469,13 +479,8 @@ void BitcoinGUI::gotoSendCoinsPage()
sendCoinsAction->setChecked(true); sendCoinsAction->setChecked(true);
sendCoinsPage->clear(); sendCoinsPage->clear();
centralWidget->setCurrentWidget(sendCoinsPage); centralWidget->setCurrentWidget(sendCoinsPage);
exportAction->setEnabled(false);
}
void BitcoinGUI::exportClicked() exportAction->setEnabled(false);
{ disconnect(exportAction, SIGNAL(triggered()), 0, 0);
// Redirect to the right view, as soon as export for other views
// (such as address book) is implemented.
transactionView->exportClicked();
} }

1
src/qt/bitcoingui.h

@ -103,7 +103,6 @@ private slots:
void aboutClicked(); void aboutClicked();
void trayIconActivated(QSystemTrayIcon::ActivationReason reason); void trayIconActivated(QSystemTrayIcon::ActivationReason reason);
void incomingTransaction(const QModelIndex & parent, int start, int end); void incomingTransaction(const QModelIndex & parent, int start, int end);
void exportClicked();
}; };
#endif #endif

4
src/qt/transactionview.cpp

@ -241,10 +241,6 @@ void TransactionView::exportClicked()
tr("Export Transaction Data"), tr("Export Transaction Data"),
QDir::currentPath(), QDir::currentPath(),
tr("Comma separated file (*.csv)")); tr("Comma separated file (*.csv)"));
if(!filename.endsWith(".csv"))
{
filename += ".csv";
}
CSVModelWriter writer(filename); CSVModelWriter writer(filename);

Loading…
Cancel
Save