mirror of
https://github.com/leozide/leocad
synced 2024-12-26 21:58:44 +01:00
Merge pull request #902 from gerw/fix_search
Fix freeze for find/replace
This commit is contained in:
commit
061e5fbc43
3 changed files with 56 additions and 34 deletions
|
@ -2714,17 +2714,17 @@ void lcMainWindow::HandleCommand(lcCommandId CommandId)
|
|||
|
||||
case LC_EDIT_FIND_NEXT:
|
||||
if (ActiveModel)
|
||||
ActiveModel->FindReplacePiece(true, false);
|
||||
ActiveModel->FindReplacePiece(true, false, false);
|
||||
break;
|
||||
|
||||
case LC_EDIT_FIND_PREVIOUS:
|
||||
if (ActiveModel)
|
||||
ActiveModel->FindReplacePiece(false, false);
|
||||
ActiveModel->FindReplacePiece(false, false, false);
|
||||
break;
|
||||
|
||||
case LC_EDIT_FIND_ALL:
|
||||
if (ActiveModel)
|
||||
ActiveModel->FindReplacePiece(true, true);
|
||||
ActiveModel->FindReplacePiece(true, true, false);
|
||||
break;
|
||||
|
||||
case LC_EDIT_REPLACE:
|
||||
|
@ -2734,12 +2734,12 @@ void lcMainWindow::HandleCommand(lcCommandId CommandId)
|
|||
|
||||
case LC_EDIT_REPLACE_ALL:
|
||||
if (ActiveModel)
|
||||
ActiveModel->FindReplacePiece(true, true);
|
||||
ActiveModel->FindReplacePiece(true, true, true);
|
||||
break;
|
||||
|
||||
case LC_EDIT_REPLACE_NEXT:
|
||||
if (ActiveModel)
|
||||
ActiveModel->FindReplacePiece(true, false);
|
||||
ActiveModel->FindReplacePiece(true, false, true);
|
||||
break;
|
||||
|
||||
case LC_EDIT_SELECT_ALL:
|
||||
|
|
|
@ -4123,15 +4123,21 @@ void lcModel::UnhideAllPieces()
|
|||
SaveCheckpoint(tr("Unhide"));
|
||||
}
|
||||
|
||||
void lcModel::FindReplacePiece(bool SearchForward, bool FindAll)
|
||||
void lcModel::FindReplacePiece(bool SearchForward, bool FindAll, bool Replace)
|
||||
{
|
||||
if (mPieces.IsEmpty())
|
||||
return;
|
||||
|
||||
auto PieceMatches = [](const lcPiece* Piece)
|
||||
{
|
||||
const lcFindReplaceParams& Params = lcView::GetFindReplaceParams();
|
||||
const lcFindReplaceParams& Params = lcView::GetFindReplaceParams();
|
||||
|
||||
// Are we going to replace colors?
|
||||
const bool ReplaceColor = lcGetColorCode(Params.ReplaceColorIndex) != LC_COLOR_NOCOLOR;
|
||||
|
||||
// Check if we are supposed to actually replace something
|
||||
const bool Replacing = Replace && (ReplaceColor || Params.ReplacePieceInfo);
|
||||
|
||||
auto PieceMatches = [&Params](const lcPiece* Piece)
|
||||
{
|
||||
if (Params.FindInfo && Params.FindInfo != Piece->mPieceInfo)
|
||||
return false;
|
||||
|
||||
|
@ -4141,36 +4147,40 @@ void lcModel::FindReplacePiece(bool SearchForward, bool FindAll)
|
|||
return (lcGetColorCode(Params.FindColorIndex) == LC_COLOR_NOCOLOR) || (Piece->GetColorIndex() == Params.FindColorIndex);
|
||||
};
|
||||
|
||||
const lcFindReplaceParams& Params = lcView::GetFindReplaceParams();
|
||||
auto ReplacePiece = [&Params, ReplaceColor](lcPiece* Piece)
|
||||
{
|
||||
if (ReplaceColor)
|
||||
Piece->SetColorIndex(Params.ReplaceColorIndex);
|
||||
|
||||
if (Params.ReplacePieceInfo)
|
||||
Piece->SetPieceInfo(Params.ReplacePieceInfo, QString(), true);
|
||||
};
|
||||
|
||||
int StartIdx = mPieces.GetSize() - 1;
|
||||
|
||||
for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++)
|
||||
bool ReplacedSomething = false;
|
||||
|
||||
if (!FindAll)
|
||||
{
|
||||
lcPiece* Piece = mPieces[PieceIdx];
|
||||
// We have to find the currently focused piece, in order to find next/prev match and (optionally) to replace it
|
||||
lcPiece* const FocusedPiece = dynamic_cast<lcPiece*>(GetFocusObject());
|
||||
|
||||
if (Piece->IsFocused() && Piece->IsVisible(mCurrentStep))
|
||||
if (FocusedPiece)
|
||||
{
|
||||
if (PieceMatches(Piece))
|
||||
for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++)
|
||||
{
|
||||
const bool ReplaceColor = lcGetColorCode(Params.FindColorIndex) != LC_COLOR_NOCOLOR;
|
||||
|
||||
if (ReplaceColor)
|
||||
Piece->SetColorIndex(Params.ReplaceColorIndex);
|
||||
|
||||
if (Params.ReplacePieceInfo)
|
||||
Piece->SetPieceInfo(Params.ReplacePieceInfo, QString(), true);
|
||||
|
||||
if (ReplaceColor || Params.ReplacePieceInfo)
|
||||
if (FocusedPiece == mPieces[PieceIdx])
|
||||
{
|
||||
SaveCheckpoint(tr("Replacing Part"));
|
||||
gMainWindow->UpdateSelectedObjects(false);
|
||||
UpdateAllViews();
|
||||
gMainWindow->UpdateTimeline(false, true);
|
||||
StartIdx = PieceIdx;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
StartIdx = PieceIdx;
|
||||
break;
|
||||
if (Replacing && PieceMatches(FocusedPiece))
|
||||
{
|
||||
ReplacePiece(FocusedPiece);
|
||||
ReplacedSomething = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4192,13 +4202,17 @@ void lcModel::FindReplacePiece(bool SearchForward, bool FindAll)
|
|||
|
||||
lcPiece* Current = mPieces[CurrentIdx];
|
||||
|
||||
if (!Current->IsVisible(mCurrentStep))
|
||||
continue;
|
||||
|
||||
if (PieceMatches(Current))
|
||||
if (Current->IsVisible(mCurrentStep) && PieceMatches(Current))
|
||||
{
|
||||
if (FindAll)
|
||||
{
|
||||
Selection.Add(Current);
|
||||
if (Replacing)
|
||||
{
|
||||
ReplacePiece(Current);
|
||||
ReplacedSomething = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Focus = Current;
|
||||
|
@ -4214,6 +4228,14 @@ void lcModel::FindReplacePiece(bool SearchForward, bool FindAll)
|
|||
SetSelectionAndFocus(Selection, nullptr, 0, false);
|
||||
else
|
||||
ClearSelectionAndSetFocus(Focus, LC_PIECE_SECTION_POSITION, false);
|
||||
|
||||
if (ReplacedSomething)
|
||||
{
|
||||
SaveCheckpoint(tr("Replacing Part"));
|
||||
gMainWindow->UpdateSelectedObjects(false);
|
||||
UpdateAllViews();
|
||||
gMainWindow->UpdateTimeline(false, true);
|
||||
}
|
||||
}
|
||||
|
||||
void lcModel::UndoAction()
|
||||
|
|
|
@ -312,7 +312,7 @@ public:
|
|||
void UnhideSelectedPieces();
|
||||
void UnhideAllPieces();
|
||||
|
||||
void FindReplacePiece(bool SearchForward, bool FindAll);
|
||||
void FindReplacePiece(bool SearchForward, bool FindAll, bool Replace);
|
||||
|
||||
void UndoAction();
|
||||
void RedoAction();
|
||||
|
|
Loading…
Reference in a new issue