Fixing issue with progress bar in console mode.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2019-04-03 13:29:42 +03:00
parent 878320fe90
commit c26d4d0942
3 changed files with 46 additions and 9 deletions

View File

@ -215,8 +215,7 @@ bool MainWindowsNoGUI::GenerateLayout(VLayoutGenerator& lGenerator)
QTimer *progressTimer = nullptr; QTimer *progressTimer = nullptr;
#endif #endif
QScopedPointer<DialogLayoutProgress> progress(new DialogLayoutProgress(timer, lGenerator.GetNestingTime()*60000, QSharedPointer<DialogLayoutProgress> progress;
this));
if (VApplication::IsGUIMode()) if (VApplication::IsGUIMode())
{ {
#if defined(Q_OS_WIN32) && QT_VERSION >= QT_VERSION_CHECK(5, 7, 0) #if defined(Q_OS_WIN32) && QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
@ -230,23 +229,48 @@ bool MainWindowsNoGUI::GenerateLayout(VLayoutGenerator& lGenerator)
}); });
progressTimer->start(1000); progressTimer->start(1000);
#endif #endif
progress = QSharedPointer<DialogLayoutProgress>(
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);
}
progress->Start(); progress->Start();
}
else
{
// Because the progress bar dialog will not terminate nesting we must create separate timer for this
auto *progressTimer = new QTimer(this);
connect(progressTimer, &QTimer::timeout, this, [timer, &lGenerator, progressTimer]()
{
const int timeout = static_cast<int>(lGenerator.GetNestingTimeMSecs() - timer.elapsed());
if (timeout <= 1000)
{
lGenerator.Timeout();
progressTimer->stop();
progressTimer->deleteLater();
}
});
progressTimer->start(1000);
}
LayoutErrors nestingState = LayoutErrors::NoError; LayoutErrors nestingState = LayoutErrors::NoError;
auto IsTimeout = [&progress, &lGenerator, timer, &nestingState]() auto IsTimeout = [&progress, &lGenerator, timer, &nestingState]()
{ {
if (timer.hasExpired(lGenerator.GetNestingTime() * 60000)) if (timer.hasExpired(lGenerator.GetNestingTimeMSecs()))
{ {
if (nestingState != LayoutErrors::EmptyPaperError) if (nestingState != LayoutErrors::EmptyPaperError)
{ {
nestingState = LayoutErrors::Timeout; nestingState = LayoutErrors::Timeout;
} }
progress->Finished();
if (VApplication::IsGUIMode())
{
progress->Finished();
}
return true; return true;
} }
return false; return false;
@ -268,7 +292,7 @@ bool MainWindowsNoGUI::GenerateLayout(VLayoutGenerator& lGenerator)
break; break;
} }
lGenerator.Generate(timer, lGenerator.GetNestingTime()*60000); lGenerator.Generate(timer, lGenerator.GetNestingTimeMSecs());
if (IsTimeout()) if (IsTimeout())
{ {
@ -284,7 +308,10 @@ bool MainWindowsNoGUI::GenerateLayout(VLayoutGenerator& lGenerator)
if (efficiency < layoutEfficiency) if (efficiency < layoutEfficiency)
{ {
efficiency = layoutEfficiency; efficiency = layoutEfficiency;
progress->Efficiency(efficiency); if (VApplication::IsGUIMode())
{
progress->Efficiency(efficiency);
}
CleanLayout(); CleanLayout();
papers = lGenerator.GetPapersItems();// Blank sheets papers = lGenerator.GetPapersItems();// Blank sheets
@ -348,7 +375,10 @@ bool MainWindowsNoGUI::GenerateLayout(VLayoutGenerator& lGenerator)
} }
} }
progress->Finished(); if (VApplication::IsGUIMode())
{
progress->Finished();
}
#if defined(Q_OS_WIN32) && QT_VERSION >= QT_VERSION_CHECK(5, 7, 0) #if defined(Q_OS_WIN32) && QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
if (VApplication::IsGUIMode()) if (VApplication::IsGUIMode())

View File

@ -732,6 +732,12 @@ int VLayoutGenerator::GetNestingTime() const
return nestingTime; return nestingTime;
} }
//---------------------------------------------------------------------------------------------------------------------
int VLayoutGenerator::GetNestingTimeMSecs() const
{
return nestingTime * 60000;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VLayoutGenerator::SetNestingTime(int value) void VLayoutGenerator::SetNestingTime(int value)
{ {

View File

@ -73,6 +73,7 @@ public:
void SetPaperWidth(qreal value); void SetPaperWidth(qreal value);
int GetNestingTime() const; int GetNestingTime() const;
int GetNestingTimeMSecs() const;
void SetNestingTime(int value); void SetNestingTime(int value);
qreal GetEfficiencyCoefficient() const; qreal GetEfficiencyCoefficient() const;