Use scoped enum.

This commit is contained in:
Leonardo Zide 2020-05-03 13:04:40 -07:00
parent 13ae577533
commit 9fa660313a
3 changed files with 49 additions and 37 deletions

View file

@ -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<int>(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<int>(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:

View file

@ -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<lcObject*> 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<lcObject*>& 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
{

View file

@ -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