Better check more frequently if user want cancel creation layout.

--HG--
branch : feature
This commit is contained in:
dismine 2015-01-16 16:45:56 +02:00
parent 4fb5a048ca
commit f8d210e720
3 changed files with 30 additions and 10 deletions

View file

@ -94,7 +94,6 @@ void VLayoutGenerator::Generate()
{ {
if (stopGeneration) if (stopGeneration)
{ {
state = LayoutErrors::ProcessStoped;
break; break;
} }
@ -104,7 +103,7 @@ void VLayoutGenerator::Generate()
if (bank->LeftArrange() > 0) if (bank->LeftArrange() > 0)
{ {
const int index = bank->GetTiket(); const int index = bank->GetTiket();
if (paper.ArrangeDetail(bank->GetDetail(index))) if (paper.ArrangeDetail(bank->GetDetail(index), stopGeneration))
{ {
bank->Arranged(index); bank->Arranged(index);
emit Arranged(bank->ArrangedCount()); emit Arranged(bank->ArrangedCount());
@ -113,6 +112,11 @@ void VLayoutGenerator::Generate()
{ {
bank->NotArranged(index); bank->NotArranged(index);
} }
if (stopGeneration)
{
break;
}
} }
else else
{ {
@ -160,6 +164,7 @@ QList<QGraphicsItem *> VLayoutGenerator::GetItems() const
void VLayoutGenerator::Abort() void VLayoutGenerator::Abort()
{ {
stopGeneration = true; stopGeneration = true;
state = LayoutErrors::ProcessStoped;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View file

@ -183,7 +183,7 @@ void VLayoutPaper::SetPaperIndex(quint32 index)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
bool VLayoutPaper::ArrangeDetail(const VLayoutDetail &detail) bool VLayoutPaper::ArrangeDetail(const VLayoutDetail &detail, bool &stop)
{ {
// First need set size of paper // First need set size of paper
if (d->paperHeight <= 0 || d->paperWidth <= 0) if (d->paperHeight <= 0 || d->paperWidth <= 0)
@ -200,11 +200,11 @@ bool VLayoutPaper::ArrangeDetail(const VLayoutDetail &detail)
if (Count() == 0) if (Count() == 0)
{ {
return AddToBlankSheet(detail); return AddToBlankSheet(detail, stop);
} }
else else
{ {
return AddToSheet(detail); return AddToSheet(detail, stop);
} }
} }
@ -215,7 +215,7 @@ int VLayoutPaper::Count() const
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
bool VLayoutPaper::AddToBlankSheet(const VLayoutDetail &detail) bool VLayoutPaper::AddToBlankSheet(const VLayoutDetail &detail, bool &stop)
{ {
BestResult bestResult; BestResult bestResult;
@ -225,6 +225,11 @@ bool VLayoutPaper::AddToBlankSheet(const VLayoutDetail &detail)
{ {
QCoreApplication::processEvents(); QCoreApplication::processEvents();
if (stop)
{
return false;
}
// We should use copy of the detail. // We should use copy of the detail.
VLayoutDetail workDetail = detail; VLayoutDetail workDetail = detail;
@ -244,6 +249,11 @@ bool VLayoutPaper::AddToBlankSheet(const VLayoutDetail &detail)
{ {
QCoreApplication::processEvents(); QCoreApplication::processEvents();
if (stop)
{
return false;
}
// We should use copy of the detail. // We should use copy of the detail.
VLayoutDetail workDetail = detail; VLayoutDetail workDetail = detail;
@ -265,7 +275,7 @@ bool VLayoutPaper::AddToBlankSheet(const VLayoutDetail &detail)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
bool VLayoutPaper::AddToSheet(const VLayoutDetail &detail) bool VLayoutPaper::AddToSheet(const VLayoutDetail &detail, bool &stop)
{ {
BestResult bestResult; BestResult bestResult;
@ -278,6 +288,11 @@ bool VLayoutPaper::AddToSheet(const VLayoutDetail &detail)
{ {
QCoreApplication::processEvents(); QCoreApplication::processEvents();
if (stop)
{
return false;
}
int dEdge = i;// For mirror detail edge will be different int dEdge = i;// For mirror detail edge will be different
if (CheckCombineEdges(workDetail, j, dEdge)) if (CheckCombineEdges(workDetail, j, dEdge))
{ {

View file

@ -60,7 +60,7 @@ public:
void SetPaperIndex(quint32 index); void SetPaperIndex(quint32 index);
bool ArrangeDetail(const VLayoutDetail &detail); bool ArrangeDetail(const VLayoutDetail &detail, bool &stop);
int Count() const; int Count() const;
QGraphicsItem *GetItem() const; QGraphicsItem *GetItem() const;
@ -81,8 +81,8 @@ private:
EdgeError = 2 EdgeError = 2
}; };
bool AddToBlankSheet(const VLayoutDetail &detail); bool AddToBlankSheet(const VLayoutDetail &detail, bool &stop);
bool AddToSheet(const VLayoutDetail &detail); bool AddToSheet(const VLayoutDetail &detail, bool &stop);
bool CheckCombineEdges(VLayoutDetail &detail, int j, int &dEdge) const; bool CheckCombineEdges(VLayoutDetail &detail, int j, int &dEdge) const;
bool CheckRotationEdges(VLayoutDetail &detail, int j, int dEdge, int angle) const; bool CheckRotationEdges(VLayoutDetail &detail, int j, int dEdge, int angle) const;