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);
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
{
VPPiecePtr const oldPiece = m_pieces.value(piece->GetUniqueID());
VPPiecePtr const oldPiece = m_pieces.value(uniqueId);
if (not oldPiece.isNull())
{
oldPiece->Update(piece);
@ -137,7 +138,7 @@ void VPLayout::AddPiece(const VPPiecePtr &piece)
}
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;
}
if (LayoutSettings().GetWarningSuperpositionOfPieces())
{
m_focusedSheet->ValidateSuperpositionOfPieces();
}
if (LayoutSettings().GetWarningPieceGapePosition())
{
m_focusedSheet->ValidatePieceGapePosition();
}
CheckPiecesPositionValidity(m_focusedSheet);
emit ActiveSheetChanged(m_focusedSheet);
}
@ -352,6 +345,12 @@ auto VPLayout::GetTrashSheet() -> VPSheetPtr
return m_trashSheet;
}
//---------------------------------------------------------------------------------------------------------------------
auto VPLayout::LayoutSettings() const -> const VPLayoutSettings &
{
return m_layoutSettings;
}
//---------------------------------------------------------------------------------------------------------------------
auto VPLayout::LayoutSettings() -> VPLayoutSettings &
{
@ -428,11 +427,31 @@ void VPLayout::CheckPiecesPositionValidity() const
{
for (const auto &sheet : m_sheets)
{
CheckPiecesPositionValidity(sheet);
}
}
//---------------------------------------------------------------------------------------------------------------------
void VPLayout::CheckPiecesPositionValidity(const VPSheetPtr &sheet) const
{
if (not sheet.isNull())
{
sheet->ValidateSuperpositionOfPieces();
const VPLayoutSettings &settings = LayoutSettings();
if (settings.GetWarningPiecesOutOfBound())
{
sheet->ValidatePiecesOutOfBound();
}
if (settings.GetWarningSuperpositionOfPieces())
{
sheet->ValidateSuperpositionOfPieces();
}
if (settings.GetWarningPieceGapePosition())
{
sheet->ValidatePieceGapePosition();
}
}
}

View File

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

View File

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

View File

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

View File

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