Skip to content

Commit

Permalink
refactored onNewXMLFiles to produse single large xmlSpatials vector, for
Browse files Browse the repository at this point in the history
one progressbar
  • Loading branch information
Niakr1s committed Nov 26, 2019
1 parent faf5337 commit bce032d
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions src/gui/xmltreeview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,38 +64,42 @@ void XMLTreeView::onNewXMLFiles(QVector<QFileInfo> xmlFiles) {
<< xmlFiles.size() << " files";
std::thread([=] {
int sz = xmlFiles.size();
emit startProcessingXMLsSignal(sz);
// emit startProcessingXMLsSignal(sz);
QStringList errPaths;
rrt::xmlSpatials_t allSpatials;
std::vector<std::thread> threads;
for (int i = 0; i != sz; ++i) {
auto t = std::thread([=, &errPaths, &xmlFiles] {
try {
auto xml = std::make_shared<rrt::XML>(
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<rrt::XML>(
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();
}
Expand Down

0 comments on commit bce032d

Please sign in to comment.