Optimize calling position validations.

This commit is contained in:
Roman Telezhynskyi 2024-04-11 18:38:43 +03:00
parent b4c009502b
commit 14e542b412
5 changed files with 86 additions and 78 deletions

View File

@ -123,13 +123,14 @@ void VPLayout::AddPiece(const VPPiecePtr &piece)
VPPiece::CleanPosition(piece); VPPiece::CleanPosition(piece);
if (not m_pieces.contains(piece->GetUniqueID())) const QString uniqueId = piece->GetUniqueID();
if (not m_pieces.contains(uniqueId))
{ {
m_pieces.insert(piece->GetUniqueID(), piece); m_pieces.insert(uniqueId, piece);
} }
else else
{ {
VPPiecePtr const oldPiece = m_pieces.value(piece->GetUniqueID()); VPPiecePtr const oldPiece = m_pieces.value(uniqueId);
if (not oldPiece.isNull()) if (not oldPiece.isNull())
{ {
oldPiece->Update(piece); oldPiece->Update(piece);
@ -137,7 +138,7 @@ void VPLayout::AddPiece(const VPPiecePtr &piece)
} }
else else
{ {
m_pieces.insert(piece->GetUniqueID(), piece); m_pieces.insert(uniqueId, piece);
} }
} }
} }
@ -327,15 +328,7 @@ void VPLayout::SetFocusedSheet(const VPSheetPtr &focusedSheet)
m_focusedSheet = focusedSheet.isNull() ? m_sheets.constFirst() : focusedSheet; m_focusedSheet = focusedSheet.isNull() ? m_sheets.constFirst() : focusedSheet;
} }
if (LayoutSettings().GetWarningSuperpositionOfPieces()) CheckPiecesPositionValidity(m_focusedSheet);
{
m_focusedSheet->ValidateSuperpositionOfPieces();
}
if (LayoutSettings().GetWarningPieceGapePosition())
{
m_focusedSheet->ValidatePieceGapePosition();
}
emit ActiveSheetChanged(m_focusedSheet); emit ActiveSheetChanged(m_focusedSheet);
} }
@ -352,6 +345,12 @@ auto VPLayout::GetTrashSheet() -> VPSheetPtr
return m_trashSheet; return m_trashSheet;
} }
//---------------------------------------------------------------------------------------------------------------------
auto VPLayout::LayoutSettings() const -> const VPLayoutSettings &
{
return m_layoutSettings;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto VPLayout::LayoutSettings() -> VPLayoutSettings & auto VPLayout::LayoutSettings() -> VPLayoutSettings &
{ {
@ -427,12 +426,32 @@ void VPLayout::Clear()
void VPLayout::CheckPiecesPositionValidity() const void VPLayout::CheckPiecesPositionValidity() const
{ {
for (const auto &sheet : m_sheets) for (const auto &sheet : m_sheets)
{
CheckPiecesPositionValidity(sheet);
}
}
//---------------------------------------------------------------------------------------------------------------------
void VPLayout::CheckPiecesPositionValidity(const VPSheetPtr &sheet) const
{ {
if (not sheet.isNull()) if (not sheet.isNull())
{ {
sheet->ValidateSuperpositionOfPieces(); const VPLayoutSettings &settings = LayoutSettings();
if (settings.GetWarningPiecesOutOfBound())
{
sheet->ValidatePiecesOutOfBound(); sheet->ValidatePiecesOutOfBound();
} }
if (settings.GetWarningSuperpositionOfPieces())
{
sheet->ValidateSuperpositionOfPieces();
}
if (settings.GetWarningPieceGapePosition())
{
sheet->ValidatePieceGapePosition();
}
} }
} }

View File

@ -78,6 +78,7 @@ public:
void AddTrashSheet(const VPSheetPtr &sheet); void AddTrashSheet(const VPSheetPtr &sheet);
auto GetTrashSheet() -> VPSheetPtr; auto GetTrashSheet() -> VPSheetPtr;
auto LayoutSettings() const -> const VPLayoutSettings &;
auto LayoutSettings() -> VPLayoutSettings &; auto LayoutSettings() -> VPLayoutSettings &;
auto PiecesForSheet(const VPSheetPtr &sheet) const -> QList<VPPiecePtr>; auto PiecesForSheet(const VPSheetPtr &sheet) const -> QList<VPPiecePtr>;
@ -90,6 +91,7 @@ public:
void Clear(); void Clear();
void CheckPiecesPositionValidity() const; void CheckPiecesPositionValidity() const;
void CheckPiecesPositionValidity(const VPSheetPtr &sheet) const;
auto TileFactory() const -> QSharedPointer<VPTileFactory>; auto TileFactory() const -> QSharedPointer<VPTileFactory>;
void SetTileFactory(const QSharedPointer<VPTileFactory> &newTileFactory); void SetTileFactory(const QSharedPointer<VPTileFactory> &newTileFactory);

View File

@ -515,7 +515,7 @@ void VPSheet::ValidateSuperpositionOfPieces() const
for (const auto &piece : pieces) for (const auto &piece : pieces)
{ {
if (piece.isNull()) if (piece.isNull() || piece->OutOfBound())
{ {
continue; continue;
} }
@ -557,7 +557,7 @@ void VPSheet::ValidateSuperpositionOfPieces() const
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPSheet::ValidatePieceGapePosition() const void VPSheet::ValidatePieceGapePosition(const VPPiecePtr &piece) const
{ {
VPLayoutPtr const layout = GetLayout(); VPLayoutPtr const layout = GetLayout();
if (layout.isNull()) if (layout.isNull())
@ -571,13 +571,9 @@ void VPSheet::ValidatePieceGapePosition() const
return; return;
} }
QList<VPPiecePtr> const pieces = GetPieces(); if (piece.isNull() || piece->HasSuperpositionWithPieces() || piece->OutOfBound())
for (const auto &piece : pieces)
{ {
if (piece.isNull()) return;
{
continue;
} }
const bool oldInvalidPieceGapPosition = piece->HasInvalidPieceGapPosition(); const bool oldInvalidPieceGapPosition = piece->HasInvalidPieceGapPosition();
@ -587,6 +583,8 @@ void VPSheet::ValidatePieceGapePosition() const
path1 = VPPiece::PrepareStickyPath(path1); path1 = VPPiece::PrepareStickyPath(path1);
bool hasInvalidPieceGapPosition = false; bool hasInvalidPieceGapPosition = false;
QList<VPPiecePtr> const pieces = GetPieces();
for (const auto &p : pieces) for (const auto &p : pieces)
{ {
if (p.isNull() || piece == p) if (p.isNull() || piece == p)
@ -618,6 +616,15 @@ void VPSheet::ValidatePieceGapePosition() const
} }
} }
} }
//---------------------------------------------------------------------------------------------------------------------
void VPSheet::ValidatePieceGapePosition() const
{
QList<VPPiecePtr> const pieces = GetPieces();
for (const auto &piece : pieces)
{
ValidatePieceGapePosition(piece);
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -770,7 +777,7 @@ void VPSheet::CheckPiecePositionValidity(const VPPiecePtr &piece) const
if (layout->LayoutSettings().GetWarningPieceGapePosition()) if (layout->LayoutSettings().GetWarningPieceGapePosition())
{ {
ValidatePieceGapePosition(); ValidatePieceGapePosition(piece);
} }
} }

View File

@ -184,6 +184,7 @@ public:
void SetTrashSheet(bool newTrashSheet); void SetTrashSheet(bool newTrashSheet);
void ValidateSuperpositionOfPieces() const; void ValidateSuperpositionOfPieces() const;
void ValidatePieceGapePosition(const VPPiecePtr &piece) const;
void ValidatePieceGapePosition() const; void ValidatePieceGapePosition() const;
void ValidatePieceOutOfBound(const VPPiecePtr &piece) const; void ValidatePieceOutOfBound(const VPPiecePtr &piece) const;
void ValidatePiecesOutOfBound() const; void ValidatePiecesOutOfBound() const;

View File

@ -1112,8 +1112,7 @@ void VPMainWindow::InitMarginsData(const QString &suffix)
LayoutWasSaved(false); LayoutWasSaved(false);
m_layout->TileFactory()->RefreshTileInfos(); m_layout->TileFactory()->RefreshTileInfos();
m_graphicsView->RefreshLayout(); m_graphicsView->RefreshLayout();
m_layout->CheckPiecesPositionValidity(sheet);
sheet->ValidatePiecesOutOfBound();
} }
} }
}); });
@ -2131,11 +2130,9 @@ void VPMainWindow::SheetPaperSizeChanged()
{ {
RotatePiecesToGrainline(); RotatePiecesToGrainline();
} }
else
VPSheetPtr const sheet = m_layout->GetFocusedSheet();
if (not sheet.isNull())
{ {
sheet->ValidatePiecesOutOfBound(); m_layout->CheckPiecesPositionValidity(m_layout->GetFocusedSheet());
} }
} }
@ -3878,7 +3875,7 @@ void VPMainWindow::on_SheetMarginChanged()
LayoutWasSaved(false); LayoutWasSaved(false);
sheet->ValidatePiecesOutOfBound(); m_layout->CheckPiecesPositionValidity(sheet);
} }
m_graphicsView->RefreshLayout(); m_graphicsView->RefreshLayout();
@ -4880,11 +4877,7 @@ void VPMainWindow::LayoutWarningPieceGapePosition_toggled(bool checked)
LayoutWasSaved(false); LayoutWasSaved(false);
if (checked) if (checked)
{ {
VPSheetPtr const sheet = m_layout->GetFocusedSheet(); m_layout->CheckPiecesPositionValidity(m_layout->GetFocusedSheet());
if (not sheet.isNull())
{
sheet->ValidatePieceGapePosition();
}
} }
m_graphicsView->RefreshPieces(); m_graphicsView->RefreshPieces();
} }
@ -4899,11 +4892,7 @@ void VPMainWindow::LayoutWarningPiecesSuperposition_toggled(bool checked)
LayoutWasSaved(false); LayoutWasSaved(false);
if (checked) if (checked)
{ {
VPSheetPtr const sheet = m_layout->GetFocusedSheet(); m_layout->CheckPiecesPositionValidity(m_layout->GetFocusedSheet());
if (not sheet.isNull())
{
sheet->ValidateSuperpositionOfPieces();
}
} }
m_graphicsView->RefreshPieces(); m_graphicsView->RefreshPieces();
} }
@ -4919,11 +4908,7 @@ void VPMainWindow::LayoutWarningPiecesOutOfBound_toggled(bool checked)
if (checked) if (checked)
{ {
VPSheetPtr const sheet = m_layout->GetFocusedSheet(); m_layout->CheckPiecesPositionValidity(m_layout->GetFocusedSheet());
if (not sheet.isNull())
{
sheet->ValidatePiecesOutOfBound();
}
} }
m_graphicsView->RefreshPieces(); m_graphicsView->RefreshPieces();
} }
@ -4936,13 +4921,7 @@ void VPMainWindow::LayoutCutOnFold_toggled(bool checked)
{ {
m_layout->LayoutSettings().SetCutOnFold(checked); m_layout->LayoutSettings().SetCutOnFold(checked);
LayoutWasSaved(false); LayoutWasSaved(false);
m_layout->CheckPiecesPositionValidity(m_layout->GetFocusedSheet());
VPSheetPtr const sheet = m_layout->GetFocusedSheet();
if (not sheet.isNull())
{
sheet->ValidatePiecesOutOfBound();
}
m_graphicsView->RefreshLayout(); m_graphicsView->RefreshLayout();
} }
} }