#65 - Export transactions to CSV
This commit is contained in:
@@ -51,6 +51,9 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
// Backup wallet.dat
|
// Backup wallet.dat
|
||||||
QObject::connect(ui->actionBackup_wallet_dat, &QAction::triggered, this, &MainWindow::backupWalletDat);
|
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
|
// z-Board.net
|
||||||
QObject::connect(ui->actionz_board_net, &QAction::triggered, this, &MainWindow::postToZBoard);
|
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
|
* 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
|
* 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 exportAllKeys();
|
||||||
void exportKeys(QString addr = "");
|
void exportKeys(QString addr = "");
|
||||||
void backupWalletDat();
|
void backupWalletDat();
|
||||||
|
void exportTransactions();
|
||||||
|
|
||||||
void doImport(QList<QString>* keys);
|
void doImport(QList<QString>* keys);
|
||||||
|
|
||||||
|
|||||||
@@ -346,8 +346,8 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>928</width>
|
<width>920</width>
|
||||||
<height>380</height>
|
<height>334</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="sendToLayout">
|
<layout class="QVBoxLayout" name="sendToLayout">
|
||||||
@@ -978,7 +978,7 @@
|
|||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>968</width>
|
<width>968</width>
|
||||||
<height>19</height>
|
<height>22</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QMenu" name="menuFile">
|
<widget class="QMenu" name="menuFile">
|
||||||
@@ -989,6 +989,8 @@
|
|||||||
<addaction name="actionExport_All_Private_Keys"/>
|
<addaction name="actionExport_All_Private_Keys"/>
|
||||||
<addaction name="actionBackup_wallet_dat"/>
|
<addaction name="actionBackup_wallet_dat"/>
|
||||||
<addaction name="separator"/>
|
<addaction name="separator"/>
|
||||||
|
<addaction name="actionExport_transactions"/>
|
||||||
|
<addaction name="separator"/>
|
||||||
<addaction name="actionExit"/>
|
<addaction name="actionExit"/>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QMenu" name="menuHelp">
|
<widget class="QMenu" name="menuHelp">
|
||||||
@@ -1086,6 +1088,11 @@
|
|||||||
<string>&Backup wallet.dat</string>
|
<string>&Backup wallet.dat</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="actionExport_transactions">
|
||||||
|
<property name="text">
|
||||||
|
<string>Export transactions</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<layoutdefault spacing="6" margin="11"/>
|
<layoutdefault spacing="6" margin="11"/>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
|
|||||||
@@ -46,10 +46,10 @@ public:
|
|||||||
void watchTxStatus();
|
void watchTxStatus();
|
||||||
void addNewTxToWatch(Tx tx, const QString& newOpid);
|
void addNewTxToWatch(Tx tx, const QString& newOpid);
|
||||||
|
|
||||||
BalancesTableModel* getBalancesModel() { return balancesTableModel; }
|
const TxTableModel* getTransactionsModel() { return transactionsTableModel; }
|
||||||
const QList<QString>* getAllZAddresses() { return zaddresses; }
|
const QList<QString>* getAllZAddresses() { return zaddresses; }
|
||||||
const QList<UnspentOutput>* getUTXOs() { return utxos; }
|
const QList<UnspentOutput>* getUTXOs() { return utxos; }
|
||||||
const QMap<QString, double>* getAllBalances() { return allBalances; }
|
const QMap<QString, double>* getAllBalances() { return allBalances; }
|
||||||
|
|
||||||
void newZaddr(bool sapling, const std::function<void(json)>& cb);
|
void newZaddr(bool sapling, const std::function<void(json)>& cb);
|
||||||
void newTaddr(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();
|
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() {
|
void TxTableModel::updateAllData() {
|
||||||
auto newmodeldata = new QList<TransactionItem>();
|
auto newmodeldata = new QList<TransactionItem>();
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ public:
|
|||||||
QString getMemo(int row);
|
QString getMemo(int row);
|
||||||
QString getAddr(int row);
|
QString getAddr(int row);
|
||||||
|
|
||||||
|
bool exportToCsv(QString fileName) const;
|
||||||
|
|
||||||
int rowCount(const QModelIndex &parent) const;
|
int rowCount(const QModelIndex &parent) const;
|
||||||
int columnCount(const QModelIndex &parent) const;
|
int columnCount(const QModelIndex &parent) const;
|
||||||
QVariant data(const QModelIndex &index, int role) const;
|
QVariant data(const QModelIndex &index, int role) const;
|
||||||
|
|||||||
Reference in New Issue
Block a user