mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 13:03:17 +01:00
add export functionality for address book / receiving addresses
This commit is contained in:
parent
2eace48d9a
commit
f54d59ba4a
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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();
|
||||
disconnect(exportAction, SIGNAL(triggered()), 0, 0);
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user