Fix GUI freezing while nesting.

This commit is contained in:
Roman Telezhynskyi 2023-09-03 13:52:03 +03:00
parent a33ad45e37
commit 812c0b84d7
4 changed files with 23 additions and 29 deletions

View File

@ -37,6 +37,7 @@
- Support for Dark mode. - Support for Dark mode.
- Fix issue with passing incorrect number of dimension to Tape. - Fix issue with passing incorrect number of dimension to Tape.
- New option: Pointer mode. - New option: Pointer mode.
- Fix GUI freezing while nesting.
# Valentina 0.7.52 September 12, 2022 # Valentina 0.7.52 September 12, 2022
- Fix crash when default locale is ru. - Fix crash when default locale is ru.

View File

@ -193,7 +193,7 @@ auto MainWindowsNoGUI::GenerateLayout(VLayoutGenerator &lGenerator) -> bool
#if defined(Q_OS_WIN32) && QT_VERSION < QT_VERSION_CHECK(6, 0, 0) && QT_VERSION >= QT_VERSION_CHECK(5, 7, 0) #if defined(Q_OS_WIN32) && QT_VERSION < QT_VERSION_CHECK(6, 0, 0) && QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
QTimer *progressTimer = nullptr; QTimer *progressTimer = nullptr;
#endif #endif
QSharedPointer<DialogLayoutProgress> progress; QSharedPointer<DialogLayoutProgress> progress;
if (VApplication::IsGUIMode()) if (VApplication::IsGUIMode())
{ {
@ -206,10 +206,10 @@ auto MainWindowsNoGUI::GenerateLayout(VLayoutGenerator &lGenerator) -> bool
[this, timer]() { m_taskbarProgress->setValue(static_cast<int>(timer.elapsed() / 1000)); }); [this, timer]() { m_taskbarProgress->setValue(static_cast<int>(timer.elapsed() / 1000)); });
progressTimer->start(1000); progressTimer->start(1000);
#endif #endif
progress = QSharedPointer<DialogLayoutProgress>( progress = QSharedPointer<DialogLayoutProgress>(
new DialogLayoutProgress(timer, lGenerator.GetNestingTimeMSecs(), this)); new DialogLayoutProgress(timer, lGenerator.GetNestingTimeMSecs(), this));
connect(progress.data(), &DialogLayoutProgress::Abort, &lGenerator, &VLayoutGenerator::Abort); connect(progress.data(), &DialogLayoutProgress::Abort, &lGenerator, &VLayoutGenerator::Abort);
connect(progress.data(), &DialogLayoutProgress::Timeout, &lGenerator, &VLayoutGenerator::Timeout); connect(progress.data(), &DialogLayoutProgress::Timeout, &lGenerator, &VLayoutGenerator::Timeout);
@ -278,7 +278,15 @@ auto MainWindowsNoGUI::GenerateLayout(VLayoutGenerator &lGenerator) -> bool
break; break;
} }
lGenerator.Generate(timer, lGenerator.GetNestingTimeMSecs(), nestingState); {
QEventLoop wait;
QFutureWatcher<void> fw;
fw.setFuture(
QtConcurrent::run([&lGenerator, timer, nestingState]()
{ lGenerator.Generate(timer, lGenerator.GetNestingTimeMSecs(), nestingState); }));
QObject::connect(&fw, &QFutureWatcher<void>::finished, &wait, &QEventLoop::quit);
wait.exec();
}
if (IsTimeout()) if (IsTimeout())
{ {
@ -380,12 +388,14 @@ auto MainWindowsNoGUI::GenerateLayout(VLayoutGenerator &lGenerator) -> bool
break; break;
} }
nestingState = lGenerator.State();
if (nestingState == LayoutErrors::PrepareLayoutError || nestingState == LayoutErrors::ProcessStoped || if (nestingState == LayoutErrors::PrepareLayoutError || nestingState == LayoutErrors::ProcessStoped ||
nestingState == LayoutErrors::TerminatedByException || nestingState == LayoutErrors::TerminatedByException)
(nestingState == LayoutErrors::NoError && not qFuzzyIsNull(lGenerator.GetEfficiencyCoefficient()) && {
efficiency >= lGenerator.GetEfficiencyCoefficient())) break;
}
if (nestingState == LayoutErrors::NoError && not qFuzzyIsNull(lGenerator.GetEfficiencyCoefficient()) &&
efficiency >= lGenerator.GetEfficiencyCoefficient())
{ {
if (not lGenerator.IsPreferOneSheetSolution() || lGenerator.PapersCount() == 1) if (not lGenerator.IsPreferOneSheetSolution() || lGenerator.PapersCount() == 1)
{ {

View File

@ -214,8 +214,6 @@ void VLayoutGenerator::Generate(const QElapsedTimer &timer, qint64 timeout, Layo
return; return;
} }
QCoreApplication::processEvents();
if (stopGeneration.load()) if (stopGeneration.load())
{ {
break; break;

View File

@ -238,27 +238,12 @@ auto VPosition::ArrangeDetail(const VPositionData &data, std::atomic_bool *stop,
watcher.setFuture(QtConcurrent::mapped(jobs, Nest)); watcher.setFuture(QtConcurrent::mapped(jobs, Nest));
while (not watcher.isStarted()) QEventLoop wait;
{ QObject::connect(&watcher, &QFutureWatcher<VBestSquare>::finished, &wait, &QEventLoop::quit);
QCoreApplication::processEvents(); wait.exec();
QThread::msleep(250);
}
// Wait for done
do
{
QCoreApplication::processEvents();
QThread::msleep(250);
} while (watcher.isRunning() && not stop->load());
if (stop->load()) if (stop->load())
{ {
do
{
QCoreApplication::processEvents();
QThread::msleep(250);
} while (watcher.isRunning());
return bestResult; return bestResult;
} }