#include "stdafx.h" #include "JSON_converters.h" #include "WB_QR.h" #include "OK_Dialog.h" #include #include #include JSON_converters::JSON_converters(QWidget *parent) : QWidget(parent) { setupUi(this); } QString number_of_errors(int errors, int files_no) { if (errors > 0) return (", " + QString::number(errors) + "из " + QString::number(files_no) + " с ошибками"); return ""; } void JSON_converters::on_JSON_to_PDF_Button_clicked() { int errors = 0; int progress = 0; PWSTR path; SHGetKnownFolderPath(FOLDERID_PublicDocuments, KF_FLAG_DEFAULT, NULL, &path); std::wstring strpath(path); CoTaskMemFree(path); QStringList filenames = QFileDialog::getOpenFileNames(this, "Выберите файлы JSON", QString::fromStdWString(strpath + L"\\WB_QR\\JSON"), "Файлы JSON (*.json)"); emit bar_maximum_Signal(filenames.size()); emit bar_progress_Signal(0); for (auto& i : filenames) { QFuture future = QtConcurrent::run(JSON_to_PDF, i.toStdString()); if (future.result() != 0) errors++; progress++; emit bar_progress_Signal(progress); } if (!filenames.isEmpty()) { OK_Dialog dialog(this->parentWidget()); dialog.Dialog_Text->setText("Файлы сконвертированы" + number_of_errors(errors, progress)); dialog.exec(); } } void JSON_converters::on_JSON_to_XLSX_Button_clicked() { int errors = 0; int progress = 0; PWSTR path; SHGetKnownFolderPath(FOLDERID_PublicDocuments, KF_FLAG_DEFAULT, NULL, &path); std::wstring strpath(path); CoTaskMemFree(path); QStringList filenames = QFileDialog::getOpenFileNames(this, "Выберите файлы JSON", QString::fromStdWString(strpath + L"\\WB_QR\\JSON"), "Файлы JSON (*.json)"); emit bar_maximum_Signal(filenames.size()); emit bar_progress_Signal(0); for (auto& i : filenames) { QFuture future = QtConcurrent::run(JSON_to_XLSX, i.toStdString()); if (future.result() != 0) errors++; progress++; emit bar_progress_Signal(progress); } if (!filenames.isEmpty()) { OK_Dialog dialog(this->parentWidget()); dialog.Dialog_Text->setText("Файлы сконвертированы" + number_of_errors(errors, progress)); dialog.exec(); } } void JSON_converters::paintEvent(QPaintEvent*) { QPainterPath path; path.lineTo(this->width(), 0); path.lineTo(this->width() - 1, this->height() - 1); path.lineTo(0, this->height() - 1); QPainter painter(this); painter.drawPath(path); update(); } JSON_converters::~JSON_converters() {}