#65 - Export transactions to CSV
This commit is contained in:
@@ -51,6 +51,9 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
// Backup wallet.dat
|
||||
QObject::connect(ui->actionBackup_wallet_dat, &QAction::triggered, this, &MainWindow::backupWalletDat);
|
||||
|
||||
// Export transactions
|
||||
QObject::connect(ui->actionExport_transactions, &QAction::triggered, this, &MainWindow::exportTransactions);
|
||||
|
||||
// z-Board.net
|
||||
QObject::connect(ui->actionz_board_net, &QAction::triggered, this, &MainWindow::postToZBoard);
|
||||
|
||||
@@ -649,6 +652,25 @@ void MainWindow::importPrivKey() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Export transaction history into a CSV file
|
||||
*/
|
||||
void MainWindow::exportTransactions() {
|
||||
// First, get the export file name
|
||||
QString exportName = "zcash-transactions-" + QDateTime::currentDateTime().toString("yyyyMMdd") + ".csv";
|
||||
|
||||
QUrl csvName = QFileDialog::getSaveFileUrl(this,
|
||||
tr("Export transactions"), exportName, "CSV file (*.csv)");
|
||||
|
||||
if (csvName.isEmpty())
|
||||
return;
|
||||
|
||||
if (!rpc->getTransactionsModel()->exportToCsv(csvName.toLocalFile())) {
|
||||
QMessageBox::critical(this, tr("Error"),
|
||||
tr("Error exporting transactions, file was not saved"), QMessageBox::Ok);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Backup the wallet.dat file. This is kind of a hack, since it has to read from the filesystem rather than an RPC call
|
||||
* This might fail for various reasons - Remote zcashd, non-standard locations, custom params passed to zcashd, many others
|
||||
|
||||
@@ -94,6 +94,7 @@ private:
|
||||
void exportAllKeys();
|
||||
void exportKeys(QString addr = "");
|
||||
void backupWalletDat();
|
||||
void exportTransactions();
|
||||
|
||||
void doImport(QList<QString>* keys);
|
||||
|
||||
|
||||
@@ -346,8 +346,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>928</width>
|
||||
<height>380</height>
|
||||
<width>920</width>
|
||||
<height>334</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="sendToLayout">
|
||||
@@ -978,7 +978,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>968</width>
|
||||
<height>19</height>
|
||||
<height>22</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuFile">
|
||||
@@ -989,6 +989,8 @@
|
||||
<addaction name="actionExport_All_Private_Keys"/>
|
||||
<addaction name="actionBackup_wallet_dat"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionExport_transactions"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionExit"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuHelp">
|
||||
@@ -1086,6 +1088,11 @@
|
||||
<string>&Backup wallet.dat</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionExport_transactions">
|
||||
<property name="text">
|
||||
<string>Export transactions</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<customwidgets>
|
||||
|
||||
@@ -46,10 +46,10 @@ public:
|
||||
void watchTxStatus();
|
||||
void addNewTxToWatch(Tx tx, const QString& newOpid);
|
||||
|
||||
BalancesTableModel* getBalancesModel() { return balancesTableModel; }
|
||||
const QList<QString>* getAllZAddresses() { return zaddresses; }
|
||||
const QList<UnspentOutput>* getUTXOs() { return utxos; }
|
||||
const QMap<QString, double>* getAllBalances() { return allBalances; }
|
||||
const TxTableModel* getTransactionsModel() { return transactionsTableModel; }
|
||||
const QList<QString>* getAllZAddresses() { return zaddresses; }
|
||||
const QList<UnspentOutput>* getUTXOs() { return utxos; }
|
||||
const QMap<QString, double>* getAllBalances() { return allBalances; }
|
||||
|
||||
void newZaddr(bool sapling, const std::function<void(json)>& cb);
|
||||
void newTaddr(const std::function<void(json)>& cb);
|
||||
|
||||
@@ -39,6 +39,37 @@ void TxTableModel::addTData(const QList<TransactionItem>& data) {
|
||||
updateAllData();
|
||||
}
|
||||
|
||||
bool TxTableModel::exportToCsv(QString fileName) const {
|
||||
if (!modeldata)
|
||||
return false;
|
||||
|
||||
QFile file(fileName);
|
||||
if (!file.open(QIODevice::ReadWrite | QIODevice::Truncate))
|
||||
return false;
|
||||
|
||||
QTextStream out(&file); // we will serialize the data into the file
|
||||
|
||||
// Write headers
|
||||
for (int i = 0; i < headers.length(); i++) {
|
||||
out << "\"" << headers[i] << "\"";
|
||||
}
|
||||
out << "\"Memo\"";
|
||||
out << endl;
|
||||
|
||||
// Write out each row
|
||||
for (int row = 0; row < modeldata->length(); row++) {
|
||||
for (int col = 0; col < headers.length(); col++) {
|
||||
out << "\"" << data(index(row, col), Qt::DisplayRole).toString() << "\",";
|
||||
}
|
||||
// Memo
|
||||
out << "\"" << modeldata->at(row).memo << "\"";
|
||||
out << endl;
|
||||
}
|
||||
|
||||
file.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
void TxTableModel::updateAllData() {
|
||||
auto newmodeldata = new QList<TransactionItem>();
|
||||
|
||||
|
||||
@@ -19,6 +19,8 @@ public:
|
||||
QString getMemo(int row);
|
||||
QString getAddr(int row);
|
||||
|
||||
bool exportToCsv(QString fileName) const;
|
||||
|
||||
int rowCount(const QModelIndex &parent) const;
|
||||
int columnCount(const QModelIndex &parent) const;
|
||||
QVariant data(const QModelIndex &index, int role) const;
|
||||
|
||||
Reference in New Issue
Block a user