From bce032d062fb0125dc0963e20ffeb1a2528cbec1 Mon Sep 17 00:00:00 2001 From: Niakr1s Date: Tue, 26 Nov 2019 04:33:55 +0300 Subject: [PATCH] refactored onNewXMLFiles to produse single large xmlSpatials vector, for one progressbar --- src/gui/xmltreeview.cpp | 46 ++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/src/gui/xmltreeview.cpp b/src/gui/xmltreeview.cpp index 3e7fe84..02b5537 100644 --- a/src/gui/xmltreeview.cpp +++ b/src/gui/xmltreeview.cpp @@ -64,38 +64,42 @@ void XMLTreeView::onNewXMLFiles(QVector xmlFiles) { << xmlFiles.size() << " files"; std::thread([=] { int sz = xmlFiles.size(); - emit startProcessingXMLsSignal(sz); + // emit startProcessingXMLsSignal(sz); QStringList errPaths; + rrt::xmlSpatials_t allSpatials; std::vector threads; for (int i = 0; i != sz; ++i) { - auto t = std::thread([=, &errPaths, &xmlFiles] { + try { + auto xml = std::make_shared( + xmlFiles[i].absoluteFilePath().toStdWString()); + auto xmlSpatials = xml->xmlSpatials(); + allSpatials.insert(allSpatials.end(), xmlSpatials.begin(), + xmlSpatials.end()); + // emit oneXMLProcessedSignal(i, sz); try { - auto xml = std::make_shared( - xmlFiles[i].absoluteFilePath().toStdWString()); - - emit oneXMLProcessedSignal(i, sz); - emit newXMLSpatialsSignal(xml->xmlSpatials(), false); - try { - bf::path newPath = xml->renameFile(); - bf::path dataPath = dataPath_ / newPath.filename(); - if (!bf::exists(dataPath)) { - bf::copy(newPath, dataPath); - } - } catch (std::exception& e) { - BOOST_LOG_TRIVIAL(error) << e.what(); + bf::path newPath = xml->renameFile(); + bf::path dataPath = dataPath_ / newPath.filename(); + if (!bf::exists(dataPath)) { + bf::copy(newPath, dataPath); } + } catch (std::exception& e) { + BOOST_LOG_TRIVIAL(error) << e.what(); + } + auto t = std::thread([=] { emit DBBeginSignal(); rrt::DB::get()->pushToDB(*xml); emit DBEndSignal(); + }); + threads.push_back(std::move(t)); - } catch (std::exception& e) { - BOOST_LOG_TRIVIAL(error) << e.what(); - errPaths.push_back(xmlFiles[i].fileName()); - } - }); - threads.push_back(std::move(t)); + } catch (std::exception& e) { + BOOST_LOG_TRIVIAL(error) << e.what(); + errPaths.push_back(xmlFiles[i].fileName()); + } } + emit newXMLSpatialsSignal(allSpatials, false); + for (auto& t : threads) { t.join(); }