diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index 2a3a7e818..182dfe46d 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -116,8 +116,45 @@ Q_GLOBAL_STATIC_WITH_ARGS(const QString, autosavePrefix, (QLatin1String(".autosa // String below need for getting translation for key Ctrl Q_GLOBAL_STATIC_WITH_ARGS(const QString, strQShortcut, (QLatin1String("QShortcut"))) // Context Q_GLOBAL_STATIC_WITH_ARGS(const QString, strCtrl, (QLatin1String("Ctrl"))) // String + +//--------------------------------------------------------------------------------------------------------------------- +QVector SortDetailsForLayout(const QHash *allDetails, + const QString &nameRegex = QString()) +{ + QVector details; + QHash::const_iterator i = allDetails->constBegin(); + + if (nameRegex.isEmpty()) + { + while (i != allDetails->constEnd()) + { + if (i.value().IsInLayout()) + { + details.append(DetailForLayout(i.key(), i.value())); + } + + ++i; + } + } + else + { + QRegularExpression nameRe(nameRegex); + while (i != allDetails->constEnd()) + { + if (nameRe.match(i.value().GetName()).hasMatch()) + { + details.append(DetailForLayout(i.key(), i.value())); + } + + ++i; + } + } + + return details; } +} // anonymous namespace + //--------------------------------------------------------------------------------------------------------------------- /** * @brief MainWindow constructor. @@ -2579,7 +2616,7 @@ void MainWindow::ActionLayout(bool checked) ui->actionDetails->setChecked(false); ui->actionLayout->setChecked(true); - QHash details; + QVector details; if(not qApp->getOpeningPattern()) { const QHash *allDetails = pattern->DataPieces(); @@ -2593,15 +2630,7 @@ void MainWindow::ActionLayout(bool checked) } else { - QHash::const_iterator i = allDetails->constBegin(); - while (i != allDetails->constEnd()) - { - if (i.value().IsInLayout()) - { - details.insert(i.key(), i.value()); - } - ++i; - } + details = SortDetailsForLayout(allDetails); if (details.count() == 0) { @@ -4867,17 +4896,7 @@ void MainWindow::ExportLayoutAs() //--------------------------------------------------------------------------------------------------------------------- void MainWindow::ExportDetailsAs() { - const QHash *allDetails = pattern->DataPieces(); - QHash::const_iterator i = allDetails->constBegin(); - QHash detailsInLayout; - while (i != allDetails->constEnd()) - { - if (i.value().IsInLayout()) - { - detailsInLayout.insert(i.key(), i.value()); - } - ++i; - } + QVector detailsInLayout = SortDetailsForLayout(pattern->DataPieces()); if (detailsInLayout.count() == 0) { @@ -5199,7 +5218,7 @@ void MainWindow::ZoomFirstShow() //--------------------------------------------------------------------------------------------------------------------- bool MainWindow::DoExport(const VCommandLinePtr &expParams) { - QHash details; + QVector details; if(not qApp->getOpeningPattern()) { const QHash *allDetails = pattern->DataPieces(); @@ -5211,32 +5230,7 @@ bool MainWindow::DoExport(const VCommandLinePtr &expParams) } else { - const QString nameRegex = expParams->OptExportSuchDetails(); - if (nameRegex.isEmpty()) - { - QHash::const_iterator i = allDetails->constBegin(); - while (i != allDetails->constEnd()) - { - if (i.value().IsInLayout()) - { - details.insert(i.key(), i.value()); - } - ++i; - } - } - else - { - const QRegularExpression nameRe(nameRegex); - QHash::const_iterator i = allDetails->constBegin(); - while (i != allDetails->constEnd()) - { - if (nameRe.match(i.value().GetName()).hasMatch()) - { - details.insert(i.key(), i.value()); - } - ++i; - } - } + details = SortDetailsForLayout(allDetails, expParams->OptExportSuchDetails()); if (details.count() == 0) { diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index 4823b7155..d27e7e5d8 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -60,6 +60,7 @@ #include #include #include +#include #if defined(Q_OS_WIN32) && QT_VERSION >= QT_VERSION_CHECK(5, 7, 0) #include @@ -799,22 +800,50 @@ void MainWindowsNoGUI::PrintTiled() } //--------------------------------------------------------------------------------------------------------------------- -QVector MainWindowsNoGUI::PrepareDetailsForLayout(const QHash &details) +QVector MainWindowsNoGUI::PrepareDetailsForLayout(const QVector &details) { - QVector listDetails; - if (not details.isEmpty()) + if (details.isEmpty()) { - QHash::const_iterator i = details.constBegin(); - while (i != details.constEnd()) - { - VAbstractTool *tool = qobject_cast(VAbstractPattern::getTool(i.key())); - SCASSERT(tool != nullptr) - listDetails.append(VLayoutPiece::Create(i.value(), tool->getData())); - ++i; - } + return QVector(); } - return listDetails; + std::function PrepareDetail = [](const DetailForLayout &data) + { + VAbstractTool *tool = qobject_cast(VAbstractPattern::getTool(data.id)); + SCASSERT(tool != nullptr) + return VLayoutPiece::Create(data.piece, tool->getData()); + }; + + QProgressDialog progress(tr("Preparing details for layout"), QString(), 0, details.size()); + progress.setWindowModality(Qt::ApplicationModal); + + QFutureWatcher futureWatcher; + QObject::connect(&futureWatcher, &QFutureWatcher::finished, &progress, &QProgressDialog::reset); + QObject::connect(&futureWatcher, &QFutureWatcher::progressRangeChanged, &progress, + &QProgressDialog::setRange); + QObject::connect(&futureWatcher, &QFutureWatcher::progressValueChanged, &progress, + &QProgressDialog::setValue); + + futureWatcher.setFuture(QtConcurrent::mapped(details, PrepareDetail)); + + if (qApp->IsGUIMode()) + { + progress.exec(); + } + + futureWatcher.waitForFinished(); + + QVector layautDetails; + layautDetails.resize(details.size()); + const QFuture future = futureWatcher.future(); + + QFuture::const_iterator i; + for (i = future.constBegin(); i != future.constEnd(); ++i) + { + layautDetails.append(*i); + } + + return layautDetails; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/valentina/mainwindowsnogui.h b/src/app/valentina/mainwindowsnogui.h index 5892d2f61..c3a3c1ac4 100644 --- a/src/app/valentina/mainwindowsnogui.h +++ b/src/app/valentina/mainwindowsnogui.h @@ -48,6 +48,22 @@ class QWinTaskbarButton; class QWinTaskbarProgress; #endif +QT_WARNING_PUSH +QT_WARNING_DISABLE_GCC("-Weffc++") + +struct DetailForLayout { + DetailForLayout() = default; + + DetailForLayout(quint32 id, const VPiece &piece) + : id(id), piece(piece) + {} + + quint32 id{NULL_ID}; + VPiece piece; +}; + +QT_WARNING_POP + class MainWindowsNoGUI : public VAbstractMainWindow { Q_OBJECT @@ -103,7 +119,7 @@ protected: QWinTaskbarProgress *m_taskbarProgress; #endif - static QVector PrepareDetailsForLayout(const QHash &details); + static QVector PrepareDetailsForLayout(const QVector &details); void ExportData(const QVector &listDetails);