Skip to content

Commit

Permalink
[GUI] One-click export accounting
Browse files Browse the repository at this point in the history
  • Loading branch information
random-zebra committed Mar 27, 2020
1 parent a3edc53 commit 2df5e68
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 158 deletions.
138 changes: 3 additions & 135 deletions src/qt/pivx/settings/forms/settingsexportcsv.ui
Expand Up @@ -174,64 +174,6 @@
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButtonSave">
<property name="minimumSize">
<size>
<width>220</width>
<height>50</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>220</width>
<height>50</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="text">
<string>Export Transactions</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>5</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="labelDivider">
<property name="minimumSize">
Expand All @@ -251,30 +193,14 @@
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Minimum</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>5</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayoutAddressesExport">
<property name="spacing">
<number>0</number>
</property>
<item>
<widget class="QWidget" name="filtersContainer" native="true">
<layout class="QHBoxLayout" name="horizontalLayout">
<widget class="QWidget" name="filtersContainer1" native="true">
<layout class="QHBoxLayout" name="horizontalLayout1">
<property name="spacing">
<number>0</number>
</property>
Expand All @@ -298,7 +224,7 @@
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<spacer name="horizontalSpacer1">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
Expand Down Expand Up @@ -347,64 +273,6 @@
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_6">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButtonExportAddress">
<property name="minimumSize">
<size>
<width>220</width>
<height>50</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>220</width>
<height>50</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="text">
<string>Export Address Book</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
Expand Down
37 changes: 18 additions & 19 deletions src/qt/pivx/settings/settingsexportcsv.cpp
Expand Up @@ -37,10 +37,6 @@ SettingsExportCSV::SettingsExportCSV(PIVXGUI* _window, QWidget *parent) :
setShadow(ui->pushButtonAddressDocuments);
ui->labelDivider->setProperty("cssClass", "container-divider");

// Buttons
setCssBtnPrimary(ui->pushButtonSave);
setCssBtnPrimary(ui->pushButtonExportAddress);

SortEdit* lineEdit = new SortEdit(ui->comboBoxSort);
connect(lineEdit, &SortEdit::Mouse_Pressed, [this](){ui->comboBoxSort->showPopup();});
setSortTx(ui->comboBoxSort, lineEdit);
Expand All @@ -55,32 +51,35 @@ SettingsExportCSV::SettingsExportCSV(PIVXGUI* _window, QWidget *parent) :
setFilterAddressBook(ui->comboBoxSortAddressType, lineEditAddressBook);
ui->comboBoxSortAddressType->setCurrentIndex(0);

connect(ui->pushButtonSave, &QPushButton::clicked, this, &SettingsExportCSV::exportClicked);
connect(ui->pushButtonDocuments, &QPushButton::clicked, [this](){selectFileOutput(true);});

connect(ui->pushButtonExportAddress, &QPushButton::clicked, this, &SettingsExportCSV::onExportAddressesClicked);
connect(ui->pushButtonAddressDocuments, &QPushButton::clicked, [this](){selectFileOutput(false);});
}

void SettingsExportCSV::selectFileOutput(const bool& isTxExport)
{
QString filenameRet = GUIUtil::getSaveFileName(this,
QString filename = GUIUtil::getSaveFileName(this,
isTxExport ? tr("Export CSV") : tr("Export Address List"), QString(),
isTxExport ? tr("PIVX_tx_csv_export(*.csv)") : tr("PIVX_addresses_csv_export(*.csv)"),
nullptr);

if (!filenameRet.isEmpty()) {
if (isTxExport) {
filename = filenameRet;
if (isTxExport) {
if (!filename.isEmpty()) {
ui->pushButtonDocuments->setText(filename);
exportTxes(filename);
} else {
ui->pushButtonDocuments->setText(tr("Select folder..."));
}
} else {
if (!filename.isEmpty()) {
ui->pushButtonAddressDocuments->setText(filename);
exportAddrs(filename);
} else {
filenameAddressBook = filenameRet;
ui->pushButtonAddressDocuments->setText(filenameAddressBook);
ui->pushButtonAddressDocuments->setText(tr("Select folder..."));
}
}
}

void SettingsExportCSV::exportClicked()
void SettingsExportCSV::exportTxes(const QString& filename)
{
if (filename.isNull()) {
inform(tr("Please select a folder to export the csv file first."));
Expand Down Expand Up @@ -152,9 +151,9 @@ void SettingsExportCSV::exportClicked()
}
}

void SettingsExportCSV::onExportAddressesClicked()
void SettingsExportCSV::exportAddrs(const QString& filename)
{
if (filenameAddressBook.isNull()) {
if (filename.isNull()) {
inform(tr("Please select a folder to export the csv file first."));
return;
}
Expand All @@ -178,7 +177,7 @@ void SettingsExportCSV::onExportAddressesClicked()
return;
}

CSVModelWriter writer(filenameAddressBook);
CSVModelWriter writer(filename);
// name, column, role
writer.setModel(addressFilter);
writer.addColumn("Label", AddressTableModel::Label, Qt::EditRole);
Expand All @@ -188,9 +187,9 @@ void SettingsExportCSV::onExportAddressesClicked()
}

if (fExport) {
inform(tr("Exporting Successful\nThe address book was successfully saved to %1.").arg(filenameAddressBook));
inform(tr("Exporting Successful\nThe address book was successfully saved to %1.").arg(filename));
} else {
inform(tr("Exporting Failed\nThere was an error trying to save the address list to %1. Please try again.").arg(filenameAddressBook));
inform(tr("Exporting Failed\nThere was an error trying to save the address list to %1. Please try again.").arg(filename));
}
}

Expand Down
6 changes: 2 additions & 4 deletions src/qt/pivx/settings/settingsexportcsv.h
Expand Up @@ -24,15 +24,13 @@ class SettingsExportCSV : public PWidget

private Q_SLOTS:
void selectFileOutput(const bool& isTxExport);
void exportClicked();
void onExportAddressesClicked();
void exportTxes(const QString& filename);
void exportAddrs(const QString& filename);

private:
Ui::SettingsExportCSV *ui;
TransactionFilterProxy* txFilter{nullptr};
QSortFilterProxyModel* addressFilter{nullptr};
QString filename;
QString filenameAddressBook;
};

#endif // SETTINGSEXPORTCSV_H

0 comments on commit 2df5e68

Please sign in to comment.