mirror of
https://github.com/leozide/leocad
synced 2024-12-27 21:58:37 +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:
|
case LC_EDIT_FIND_NEXT:
|
||||||
if (ActiveModel)
|
if (ActiveModel)
|
||||||
ActiveModel->FindReplacePiece(true, false);
|
ActiveModel->FindReplacePiece(true, false, false);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LC_EDIT_FIND_PREVIOUS:
|
case LC_EDIT_FIND_PREVIOUS:
|
||||||
if (ActiveModel)
|
if (ActiveModel)
|
||||||
ActiveModel->FindReplacePiece(false, false);
|
ActiveModel->FindReplacePiece(false, false, false);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LC_EDIT_FIND_ALL:
|
case LC_EDIT_FIND_ALL:
|
||||||
if (ActiveModel)
|
if (ActiveModel)
|
||||||
ActiveModel->FindReplacePiece(true, true);
|
ActiveModel->FindReplacePiece(true, true, false);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LC_EDIT_REPLACE:
|
case LC_EDIT_REPLACE:
|
||||||
|
@ -2734,12 +2734,12 @@ void lcMainWindow::HandleCommand(lcCommandId CommandId)
|
||||||
|
|
||||||
case LC_EDIT_REPLACE_ALL:
|
case LC_EDIT_REPLACE_ALL:
|
||||||
if (ActiveModel)
|
if (ActiveModel)
|
||||||
ActiveModel->FindReplacePiece(true, true);
|
ActiveModel->FindReplacePiece(true, true, true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LC_EDIT_REPLACE_NEXT:
|
case LC_EDIT_REPLACE_NEXT:
|
||||||
if (ActiveModel)
|
if (ActiveModel)
|
||||||
ActiveModel->FindReplacePiece(true, false);
|
ActiveModel->FindReplacePiece(true, false, true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LC_EDIT_SELECT_ALL:
|
case LC_EDIT_SELECT_ALL:
|
||||||
|
|
|
@ -4123,15 +4123,21 @@ void lcModel::UnhideAllPieces()
|
||||||
SaveCheckpoint(tr("Unhide"));
|
SaveCheckpoint(tr("Unhide"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcModel::FindReplacePiece(bool SearchForward, bool FindAll)
|
void lcModel::FindReplacePiece(bool SearchForward, bool FindAll, bool Replace)
|
||||||
{
|
{
|
||||||
if (mPieces.IsEmpty())
|
if (mPieces.IsEmpty())
|
||||||
return;
|
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)
|
if (Params.FindInfo && Params.FindInfo != Piece->mPieceInfo)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -4141,36 +4147,40 @@ void lcModel::FindReplacePiece(bool SearchForward, bool FindAll)
|
||||||
return (lcGetColorCode(Params.FindColorIndex) == LC_COLOR_NOCOLOR) || (Piece->GetColorIndex() == Params.FindColorIndex);
|
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;
|
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 (FocusedPiece == mPieces[PieceIdx])
|
||||||
|
|
||||||
if (ReplaceColor)
|
|
||||||
Piece->SetColorIndex(Params.ReplaceColorIndex);
|
|
||||||
|
|
||||||
if (Params.ReplacePieceInfo)
|
|
||||||
Piece->SetPieceInfo(Params.ReplacePieceInfo, QString(), true);
|
|
||||||
|
|
||||||
if (ReplaceColor || Params.ReplacePieceInfo)
|
|
||||||
{
|
{
|
||||||
SaveCheckpoint(tr("Replacing Part"));
|
StartIdx = PieceIdx;
|
||||||
gMainWindow->UpdateSelectedObjects(false);
|
break;
|
||||||
UpdateAllViews();
|
|
||||||
gMainWindow->UpdateTimeline(false, true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
StartIdx = PieceIdx;
|
if (Replacing && PieceMatches(FocusedPiece))
|
||||||
break;
|
{
|
||||||
|
ReplacePiece(FocusedPiece);
|
||||||
|
ReplacedSomething = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4192,13 +4202,17 @@ void lcModel::FindReplacePiece(bool SearchForward, bool FindAll)
|
||||||
|
|
||||||
lcPiece* Current = mPieces[CurrentIdx];
|
lcPiece* Current = mPieces[CurrentIdx];
|
||||||
|
|
||||||
if (!Current->IsVisible(mCurrentStep))
|
if (Current->IsVisible(mCurrentStep) && PieceMatches(Current))
|
||||||
continue;
|
|
||||||
|
|
||||||
if (PieceMatches(Current))
|
|
||||||
{
|
{
|
||||||
if (FindAll)
|
if (FindAll)
|
||||||
|
{
|
||||||
Selection.Add(Current);
|
Selection.Add(Current);
|
||||||
|
if (Replacing)
|
||||||
|
{
|
||||||
|
ReplacePiece(Current);
|
||||||
|
ReplacedSomething = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Focus = Current;
|
Focus = Current;
|
||||||
|
@ -4214,6 +4228,14 @@ void lcModel::FindReplacePiece(bool SearchForward, bool FindAll)
|
||||||
SetSelectionAndFocus(Selection, nullptr, 0, false);
|
SetSelectionAndFocus(Selection, nullptr, 0, false);
|
||||||
else
|
else
|
||||||
ClearSelectionAndSetFocus(Focus, LC_PIECE_SECTION_POSITION, false);
|
ClearSelectionAndSetFocus(Focus, LC_PIECE_SECTION_POSITION, false);
|
||||||
|
|
||||||
|
if (ReplacedSomething)
|
||||||
|
{
|
||||||
|
SaveCheckpoint(tr("Replacing Part"));
|
||||||
|
gMainWindow->UpdateSelectedObjects(false);
|
||||||
|
UpdateAllViews();
|
||||||
|
gMainWindow->UpdateTimeline(false, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcModel::UndoAction()
|
void lcModel::UndoAction()
|
||||||
|
|
|
@ -312,7 +312,7 @@ public:
|
||||||
void UnhideSelectedPieces();
|
void UnhideSelectedPieces();
|
||||||
void UnhideAllPieces();
|
void UnhideAllPieces();
|
||||||
|
|
||||||
void FindReplacePiece(bool SearchForward, bool FindAll);
|
void FindReplacePiece(bool SearchForward, bool FindAll, bool Replace);
|
||||||
|
|
||||||
void UndoAction();
|
void UndoAction();
|
||||||
void RedoAction();
|
void RedoAction();
|
||||||
|
|
Loading…
Reference in a new issue