From 9fa660313a3dfb84dee0e7b7a90dd5ba632921c5 Mon Sep 17 00:00:00 2001 From: Leonardo Zide Date: Sun, 3 May 2020 13:04:40 -0700 Subject: [PATCH] Use scoped enum. --- common/lc_mainwindow.cpp | 44 ++++++++++++++++++++++++---------------- common/lc_model.cpp | 22 ++++++++++---------- common/lc_model.h | 20 ++++++++++-------- 3 files changed, 49 insertions(+), 37 deletions(-) diff --git a/common/lc_mainwindow.cpp b/common/lc_mainwindow.cpp index a771286b..c10b6a91 100644 --- a/common/lc_mainwindow.cpp +++ b/common/lc_mainwindow.cpp @@ -89,7 +89,7 @@ lcMainWindow::lcMainWindow() { memset(mActions, 0, sizeof(mActions)); - mTransformType = LC_TRANSFORM_RELATIVE_TRANSLATION; + mTransformType = lcTransformType::RelativeTranslation; mColorIndex = lcGetColorIndex(4); mTool = LC_TOOL_SELECT; @@ -102,7 +102,7 @@ lcMainWindow::lcMainWindow() mRelativeTransform = true; mLocalTransform = false; mCurrentPieceInfo = nullptr; - mSelectionMode = lcSelectionMode::SINGLE; + mSelectionMode = lcSelectionMode::Single; mModelTabWidget = nullptr; memset(&mSearchOptions, 0, sizeof(mSearchOptions)); @@ -1667,9 +1667,12 @@ void lcMainWindow::SetLocalTransform(bool SelectionTransform) void lcMainWindow::SetTransformType(lcTransformType TransformType) { + if (TransformType < lcTransformType::First || TransformType >= lcTransformType::Count) + return; + mTransformType = TransformType; - const char* IconNames[] = + const char* IconNames[static_cast(lcTransformType::Count)] = { ":/resources/edit_transform_absolute_translation.png", ":/resources/edit_transform_relative_translation.png", @@ -1677,11 +1680,9 @@ void lcMainWindow::SetTransformType(lcTransformType TransformType) ":/resources/edit_transform_relative_rotation.png" }; - if (TransformType >= 0 && TransformType <= 3) - { - mActions[LC_EDIT_TRANSFORM_ABSOLUTE_TRANSLATION + TransformType]->setChecked(true); - mActions[LC_EDIT_TRANSFORM]->setIcon(QIcon(IconNames[TransformType])); - } + int TransformIndex = static_cast(TransformType); + mActions[LC_EDIT_TRANSFORM_ABSOLUTE_TRANSLATION + TransformIndex]->setChecked(true); + mActions[LC_EDIT_TRANSFORM]->setIcon(QIcon(IconNames[TransformIndex])); } void lcMainWindow::SetCurrentPieceInfo(PieceInfo* Info) @@ -2105,19 +2106,19 @@ void lcMainWindow::UpdateSelectionMode() { switch (mSelectionMode) { - case lcSelectionMode::SINGLE: + case lcSelectionMode::Single: mActions[LC_EDIT_SELECTION_SINGLE]->setChecked(true); break; - case lcSelectionMode::PIECE: + case lcSelectionMode::Piece: mActions[LC_EDIT_SELECTION_PIECE]->setChecked(true); break; - case lcSelectionMode::COLOR: + case lcSelectionMode::Color: mActions[LC_EDIT_SELECTION_COLOR]->setChecked(true); break; - case lcSelectionMode::PIECE_COLOR: + case lcSelectionMode::PieceColor: mActions[LC_EDIT_SELECTION_PIECE_COLOR]->setChecked(true); break; } @@ -2609,19 +2610,19 @@ void lcMainWindow::HandleCommand(lcCommandId CommandId) break; case LC_EDIT_SELECTION_SINGLE: - SetSelectionMode(lcSelectionMode::SINGLE); + SetSelectionMode(lcSelectionMode::Single); break; case LC_EDIT_SELECTION_PIECE: - SetSelectionMode(lcSelectionMode::PIECE); + SetSelectionMode(lcSelectionMode::Piece); break; case LC_EDIT_SELECTION_COLOR: - SetSelectionMode(lcSelectionMode::COLOR); + SetSelectionMode(lcSelectionMode::Color); break; case LC_EDIT_SELECTION_PIECE_COLOR: - SetSelectionMode(lcSelectionMode::PIECE_COLOR); + SetSelectionMode(lcSelectionMode::PieceColor); break; case LC_VIEW_SPLIT_HORIZONTAL: @@ -3139,10 +3140,19 @@ void lcMainWindow::HandleCommand(lcCommandId CommandId) break; case LC_EDIT_TRANSFORM_ABSOLUTE_TRANSLATION: + SetTransformType(lcTransformType::AbsoluteTranslation); + break; + case LC_EDIT_TRANSFORM_RELATIVE_TRANSLATION: + SetTransformType(lcTransformType::RelativeTranslation); + break; + case LC_EDIT_TRANSFORM_ABSOLUTE_ROTATION: + SetTransformType(lcTransformType::AbsoluteRotation); + break; + case LC_EDIT_TRANSFORM_RELATIVE_ROTATION: - SetTransformType((lcTransformType)(CommandId - LC_EDIT_TRANSFORM_ABSOLUTE_TRANSLATION)); + SetTransformType(lcTransformType::RelativeRotation); break; case LC_EDIT_ACTION_SELECT: diff --git a/common/lc_model.cpp b/common/lc_model.cpp index ceada2f4..a07aa0c4 100644 --- a/common/lc_model.cpp +++ b/common/lc_model.cpp @@ -3002,19 +3002,19 @@ void lcModel::TransformSelectedObjects(lcTransformType TransformType, const lcVe { switch (TransformType) { - case LC_TRANSFORM_ABSOLUTE_TRANSLATION: + case lcTransformType::AbsoluteTranslation: MoveSelectedObjects(Transform, false, false, true, true); break; - case LC_TRANSFORM_RELATIVE_TRANSLATION: + case lcTransformType::RelativeTranslation: MoveSelectedObjects(Transform, true, false, true, true); break; - case LC_TRANSFORM_ABSOLUTE_ROTATION: + case lcTransformType::AbsoluteRotation: RotateSelectedPieces(Transform, false, false, true, true); break; - case LC_TRANSFORM_RELATIVE_ROTATION: + case lcTransformType::RelativeRotation: RotateSelectedPieces(Transform, true, false, true, true); break; } @@ -3599,22 +3599,22 @@ lcArray lcModel::GetSelectionModePieces(lcPiece* SelectedPiece) const switch (gMainWindow->GetSelectionMode()) { - case lcSelectionMode::SINGLE: + case lcSelectionMode::Single: break; - case lcSelectionMode::PIECE: + case lcSelectionMode::Piece: for (lcPiece* Piece : mPieces) if (Piece->IsVisible(mCurrentStep) && Piece->mPieceInfo == Info && Piece != SelectedPiece) Pieces.Add(Piece); break; - case lcSelectionMode::COLOR: + case lcSelectionMode::Color: for (lcPiece* Piece : mPieces) if (Piece->IsVisible(mCurrentStep) && Piece->mColorIndex == ColorIndex && Piece != SelectedPiece) Pieces.Add(Piece); break; - case lcSelectionMode::PIECE_COLOR: + case lcSelectionMode::PieceColor: for (lcPiece* Piece : mPieces) if (Piece->IsVisible(mCurrentStep) && Piece->mPieceInfo == Info && Piece->mColorIndex == ColorIndex && Piece != SelectedPiece) Pieces.Add(Piece); @@ -3678,7 +3678,7 @@ void lcModel::FocusOrDeselectObject(const lcObjectSection& ObjectSection) { lcPiece* Piece = (lcPiece*)Object; - if (gMainWindow->GetSelectionMode() == lcSelectionMode::SINGLE) + if (gMainWindow->GetSelectionMode() == lcSelectionMode::Single) SelectGroup(Piece->GetTopGroup(), IsSelected); else { @@ -3787,7 +3787,7 @@ void lcModel::RemoveFromSelection(const lcArray& Objects) { lcPiece* Piece = (lcPiece*)SelectedObject; - if (gMainWindow->GetSelectionMode() == lcSelectionMode::SINGLE) + if (gMainWindow->GetSelectionMode() == lcSelectionMode::Single) SelectGroup(Piece->GetTopGroup(), false); else { @@ -3828,7 +3828,7 @@ void lcModel::RemoveFromSelection(const lcObjectSection& ObjectSection) { lcPiece* Piece = (lcPiece*)SelectedObject; - if (gMainWindow->GetSelectionMode() == lcSelectionMode::SINGLE) + if (gMainWindow->GetSelectionMode() == lcSelectionMode::Single) SelectGroup(Piece->GetTopGroup(), false); else { diff --git a/common/lc_model.h b/common/lc_model.h index 0b86bc62..c88443ea 100644 --- a/common/lc_model.h +++ b/common/lc_model.h @@ -22,18 +22,20 @@ class lcGLWidget; enum class lcSelectionMode { - SINGLE, - PIECE, - COLOR, - PIECE_COLOR + Single, + Piece, + Color, + PieceColor }; -enum lcTransformType +enum class lcTransformType { - LC_TRANSFORM_ABSOLUTE_TRANSLATION, - LC_TRANSFORM_RELATIVE_TRANSLATION, - LC_TRANSFORM_ABSOLUTE_ROTATION, - LC_TRANSFORM_RELATIVE_ROTATION + First, + AbsoluteTranslation = First, + RelativeTranslation, + AbsoluteRotation, + RelativeRotation, + Count }; enum lcBackgroundType