save csv with correct umlauts even on windows

This commit is contained in:
Martin Brodbeck 2018-08-16 12:40:19 +02:00
parent cfa59a38ac
commit 00f870b0c3
4 changed files with 23 additions and 14 deletions

View file

@ -8,6 +8,8 @@
#include <numeric> #include <numeric>
#include <sstream> #include <sstream>
namespace fs = std::filesystem;
Marketplace::Marketplace() Marketplace::Marketplace()
{ {
auto seller = std::make_unique<Seller>("Max", "Mustermann"); auto seller = std::make_unique<Seller>("Max", "Mustermann");
@ -168,10 +170,10 @@ void Marketplace::setSalesToDelete(int cashPointNo)
}); });
} }
void Marketplace::exportReportToCSV(const std::string& filename, int feeInPercent, int maxFeeInEuro) void Marketplace::exportReportToCSV(const fs::path& filePath, int feeInPercent, int maxFeeInEuro)
{ {
const char delimiter = ','; const char delimiter = ',';
std::ofstream file(filename); std::ofstream file(filePath);
file << "Verk.Nr." << delimiter << "Nachname" << delimiter << "Vorname" << delimiter file << "Verk.Nr." << delimiter << "Nachname" << delimiter << "Vorname" << delimiter
<< "Anz. gemeldet" << delimiter << "Anz. verkauft" << delimiter << "Umsatz" << delimiter << "Anz. gemeldet" << delimiter << "Anz. verkauft" << delimiter << "Umsatz" << delimiter

View file

@ -5,6 +5,7 @@
#include "sale.h" #include "sale.h"
#include "seller.h" #include "seller.h"
#include <filesystem>
#include <vector> #include <vector>
class ExcelReader; class ExcelReader;
@ -52,7 +53,8 @@ class Marketplace
void clear(); void clear();
void exportReportToCSV(const std::string& filename, int feeInPercent, int maxFeeInEuro); void exportReportToCSV(const std::filesystem::path& filePath, int feeInPercent,
int maxFeeInEuro);
friend class ExcelReader; friend class ExcelReader;

View file

@ -360,7 +360,8 @@ void MainWindow::onPrintSaleReceiptButtonClicked([[maybe_unused]] bool checked)
auto indexes = selModel->selectedRows(); auto indexes = selModel->selectedRows();
auto& sale = marketplace_->getSales().at(indexes[0].row()); auto& sale = marketplace_->getSales().at(indexes[0].row());
auto printerDevice = convertToPosPrinterDevice(posPrinterDevice.toStdString(), posPrinterEndpoint.toStdString()); auto printerDevice =
convertToPosPrinterDevice(posPrinterDevice.toStdString(), posPrinterEndpoint.toStdString());
std::unique_ptr<PosPrinter> printer; std::unique_ptr<PosPrinter> printer;

View file

@ -5,6 +5,8 @@
#include <posprinter.h> #include <posprinter.h>
#include <utils.h> #include <utils.h>
#include <filesystem>
#include <QFileDialog> #include <QFileDialog>
#include <QFontDatabase> #include <QFontDatabase>
#include <QPainter> #include <QPainter>
@ -12,6 +14,8 @@
#include <QtPrintSupport/QPrintDialog> #include <QtPrintSupport/QPrintDialog>
#include <QtPrintSupport/QPrinter> #include <QtPrintSupport/QPrinter>
namespace fs = std::filesystem;
ReportDialog::ReportDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(parent, f) ReportDialog::ReportDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(parent, f)
{ {
ui_.setupUi(this); ui_.setupUi(this);
@ -37,14 +41,15 @@ void ReportDialog::onExportCsvButtonClicked()
int feeInPercent = settings.value("global/feeInPercent").toInt(); int feeInPercent = settings.value("global/feeInPercent").toInt();
int maxFeeInEuro = settings.value("global/maxFeeInEuro").toInt(); int maxFeeInEuro = settings.value("global/maxFeeInEuro").toInt();
QFileDialog fileDialog(this); auto filename = QFileDialog::getSaveFileName(this, "Verkäufer exportieren", QString(),
fileDialog.setFileMode(QFileDialog::AnyFile); "CSV Dateien (*.csv)");
fileDialog.setNameFilter("CSV Files (*.csv)");
fileDialog.setAcceptMode(QFileDialog::AcceptSave); if (filename.isEmpty())
if (fileDialog.exec()) { return;
market_->exportReportToCSV(fileDialog.selectedFiles().at(0).toStdString(), feeInPercent,
maxFeeInEuro); fs::path filePath(filename.toStdWString());
}
market_->exportReportToCSV(filePath, feeInPercent, maxFeeInEuro);
} }
void ReportDialog::onPrintReportButtonClicked() void ReportDialog::onPrintReportButtonClicked()
@ -159,8 +164,7 @@ void ReportDialog::onPrintReportButtonClicked()
content += QString("Verkaufte Artikel: %1 (%L2 %)\n\n") content += QString("Verkaufte Artikel: %1 (%L2 %)\n\n")
.arg(numArticlesSold, 6) .arg(numArticlesSold, 6)
.arg(percentArticlesSold, 0, 'f', 2); .arg(percentArticlesSold, 0, 'f', 2);
content += content += QString("Gesamtumsatz: %1\n").arg(market_->getOverallSumAsString().c_str(), 10);
QString("Gesamtumsatz: %1\n").arg(market_->getOverallSumAsString().c_str(), 10);
content += content +=
QString("Ausgezahlt: %1\n") QString("Ausgezahlt: %1\n")
.arg(market_->getOverallPaymentAsString(feeInPercent, maxFeeInEuro * 100).c_str(), 10); .arg(market_->getOverallPaymentAsString(feeInPercent, maxFeeInEuro * 100).c_str(), 10);