UndoCommand: Move struct into implementation where applicable

This commit is contained in:
Lioncache
2025-12-16 22:54:25 -05:00
parent 2f45cfd06a
commit 481ad30094
8 changed files with 66 additions and 55 deletions

View File

@@ -84,10 +84,10 @@ void CCloneSelectionCommand::redo()
} }
// Clone outgoing links from source object; incoming ones are discarded // Clone outgoing links from source object; incoming ones are discarded
for (int iNode = 0; iNode < ClonedNodes.size(); iNode++) for (qsizetype iNode = 0; iNode < ClonedNodes.size(); iNode++)
{ {
CScriptObject *pSrc = static_cast<CScriptNode*>(ToClone[iNode])->Instance(); auto* pSrc = static_cast<CScriptNode*>(ToClone[iNode])->Instance();
CScriptObject *pClone = static_cast<CScriptNode*>(ClonedNodes[iNode])->Instance(); auto* pClone = static_cast<CScriptNode*>(ClonedNodes[iNode])->Instance();
for (size_t iLink = 0; iLink < pSrc->NumLinks(ELinkType::Outgoing); iLink++) for (size_t iLink = 0; iLink < pSrc->NumLinks(ELinkType::Outgoing); iLink++)
{ {

View File

@@ -6,6 +6,15 @@
#include <QCoreApplication> #include <QCoreApplication>
struct CRotateNodeCommand::SNodeRotate
{
CNodePtr pNode;
CVector3f InitialPos;
CQuaternion InitialRot;
CVector3f NewPos;
CQuaternion NewRot;
};
CRotateNodeCommand::CRotateNodeCommand() CRotateNodeCommand::CRotateNodeCommand()
: IUndoCommand(QCoreApplication::translate("CRotateNodeCommand", "Rotate")) : IUndoCommand(QCoreApplication::translate("CRotateNodeCommand", "Rotate"))
{ {
@@ -58,7 +67,7 @@ bool CRotateNodeCommand::mergeWith(const QUndoCommand *pkOther)
if (pkOther->id() == (int) EUndoCommand::RotateNodeCmd) if (pkOther->id() == (int) EUndoCommand::RotateNodeCmd)
{ {
const CRotateNodeCommand *pkCmd = static_cast<const CRotateNodeCommand*>(pkOther); const auto* pkCmd = static_cast<const CRotateNodeCommand*>(pkOther);
if (pkCmd->mCommandEnded) if (pkCmd->mCommandEnded)
{ {
@@ -68,7 +77,7 @@ bool CRotateNodeCommand::mergeWith(const QUndoCommand *pkOther)
if ((mpEditor == pkCmd->mpEditor) && (mNodeList.size() == pkCmd->mNodeList.size())) if ((mpEditor == pkCmd->mpEditor) && (mNodeList.size() == pkCmd->mNodeList.size()))
{ {
for (int iNode = 0; iNode < mNodeList.size(); iNode++) for (qsizetype iNode = 0; iNode < mNodeList.size(); iNode++)
{ {
mNodeList[iNode].NewPos = pkCmd->mNodeList[iNode].NewPos; mNodeList[iNode].NewPos = pkCmd->mNodeList[iNode].NewPos;
mNodeList[iNode].NewRot = pkCmd->mNodeList[iNode].NewRot; mNodeList[iNode].NewRot = pkCmd->mNodeList[iNode].NewRot;

View File

@@ -11,14 +11,8 @@ class INodeEditor;
class CRotateNodeCommand : public IUndoCommand class CRotateNodeCommand : public IUndoCommand
{ {
struct SNodeRotate struct SNodeRotate;
{
CNodePtr pNode;
CVector3f InitialPos;
CQuaternion InitialRot;
CVector3f NewPos;
CQuaternion NewRot;
};
QList<SNodeRotate> mNodeList; QList<SNodeRotate> mNodeList;
INodeEditor *mpEditor = nullptr; INodeEditor *mpEditor = nullptr;
bool mCommandEnded = false; bool mCommandEnded = false;

View File

@@ -6,6 +6,15 @@
#include <QCoreApplication> #include <QCoreApplication>
struct CScaleNodeCommand::SNodeScale
{
CNodePtr pNode;
CVector3f InitialPos;
CVector3f InitialScale;
CVector3f NewPos;
CVector3f NewScale;
};
CScaleNodeCommand::CScaleNodeCommand() CScaleNodeCommand::CScaleNodeCommand()
: IUndoCommand(QCoreApplication::translate("CScaleNodeCommand", "Scale")) : IUndoCommand(QCoreApplication::translate("CScaleNodeCommand", "Scale"))
{ {
@@ -38,9 +47,7 @@ CScaleNodeCommand::CScaleNodeCommand(INodeEditor *pEditor, const QList<CSceneNod
mpEditor->NotifySelectionTransformed(); mpEditor->NotifySelectionTransformed();
} }
CScaleNodeCommand::~CScaleNodeCommand() CScaleNodeCommand::~CScaleNodeCommand() = default;
{
}
int CScaleNodeCommand::id() const int CScaleNodeCommand::id() const
{ {
@@ -53,7 +60,7 @@ bool CScaleNodeCommand::mergeWith(const QUndoCommand *pkOther)
if (pkOther->id() == (int) EUndoCommand::ScaleNodeCmd) if (pkOther->id() == (int) EUndoCommand::ScaleNodeCmd)
{ {
const CScaleNodeCommand *pkCmd = static_cast<const CScaleNodeCommand*>(pkOther); const auto* pkCmd = static_cast<const CScaleNodeCommand*>(pkOther);
if (pkCmd->mCommandEnded) if (pkCmd->mCommandEnded)
{ {
@@ -63,7 +70,7 @@ bool CScaleNodeCommand::mergeWith(const QUndoCommand *pkOther)
if ((mpEditor == pkCmd->mpEditor) && (mNodeList.size() == pkCmd->mNodeList.size())) if ((mpEditor == pkCmd->mpEditor) && (mNodeList.size() == pkCmd->mNodeList.size()))
{ {
for (int iNode = 0; iNode < mNodeList.size(); iNode++) for (qsizetype iNode = 0; iNode < mNodeList.size(); iNode++)
{ {
mNodeList[iNode].NewPos = pkCmd->mNodeList[iNode].NewPos; mNodeList[iNode].NewPos = pkCmd->mNodeList[iNode].NewPos;
mNodeList[iNode].NewScale = pkCmd->mNodeList[iNode].NewScale; mNodeList[iNode].NewScale = pkCmd->mNodeList[iNode].NewScale;

View File

@@ -11,14 +11,8 @@ class INodeEditor;
class CScaleNodeCommand : public IUndoCommand class CScaleNodeCommand : public IUndoCommand
{ {
struct SNodeScale struct SNodeScale;
{
CNodePtr pNode;
CVector3f InitialPos;
CVector3f InitialScale;
CVector3f NewPos;
CVector3f NewScale;
};
QList<SNodeScale> mNodeList; QList<SNodeScale> mNodeList;
INodeEditor *mpEditor = nullptr; INodeEditor *mpEditor = nullptr;
bool mCommandEnded = false; bool mCommandEnded = false;

View File

@@ -6,6 +6,13 @@
#include <QCoreApplication> #include <QCoreApplication>
struct CTranslateNodeCommand::SNodeTranslate
{
CNodePtr pNode;
CVector3f InitialPos;
CVector3f NewPos;
};
CTranslateNodeCommand::CTranslateNodeCommand() CTranslateNodeCommand::CTranslateNodeCommand()
: IUndoCommand(QCoreApplication::translate("CTranslateNodeCommand", "Translate")) : IUndoCommand(QCoreApplication::translate("CTranslateNodeCommand", "Translate"))
{ {
@@ -30,6 +37,8 @@ CTranslateNodeCommand::CTranslateNodeCommand(INodeEditor *pEditor, const QList<C
mpEditor->NotifySelectionTransformed(); mpEditor->NotifySelectionTransformed();
} }
CTranslateNodeCommand::~CTranslateNodeCommand() = default;
int CTranslateNodeCommand::id() const int CTranslateNodeCommand::id() const
{ {
return (int) EUndoCommand::TranslateNodeCmd; return (int) EUndoCommand::TranslateNodeCmd;
@@ -37,11 +46,12 @@ int CTranslateNodeCommand::id() const
bool CTranslateNodeCommand::mergeWith(const QUndoCommand *pkOther) bool CTranslateNodeCommand::mergeWith(const QUndoCommand *pkOther)
{ {
if (mCommandEnded) return false; if (mCommandEnded)
return false;
if (pkOther->id() == (int) EUndoCommand::TranslateNodeCmd) if (pkOther->id() == (int) EUndoCommand::TranslateNodeCmd)
{ {
const CTranslateNodeCommand *pkCmd = static_cast<const CTranslateNodeCommand*>(pkOther); const auto* pkCmd = static_cast<const CTranslateNodeCommand*>(pkOther);
if (pkCmd->mCommandEnded) if (pkCmd->mCommandEnded)
{ {
@@ -51,7 +61,7 @@ bool CTranslateNodeCommand::mergeWith(const QUndoCommand *pkOther)
if ((mpEditor == pkCmd->mpEditor) && (mNodeList.size() == pkCmd->mNodeList.size())) if ((mpEditor == pkCmd->mpEditor) && (mNodeList.size() == pkCmd->mNodeList.size()))
{ {
for (int iNode = 0; iNode < mNodeList.size(); iNode++) for (qsizetype iNode = 0; iNode < mNodeList.size(); iNode++)
mNodeList[iNode].NewPos = pkCmd->mNodeList[iNode].NewPos; mNodeList[iNode].NewPos = pkCmd->mNodeList[iNode].NewPos;
return true; return true;

View File

@@ -11,12 +11,8 @@ class INodeEditor;
class CTranslateNodeCommand : public IUndoCommand class CTranslateNodeCommand : public IUndoCommand
{ {
struct SNodeTranslate struct SNodeTranslate;
{
CNodePtr pNode;
CVector3f InitialPos;
CVector3f NewPos;
};
QList<SNodeTranslate> mNodeList; QList<SNodeTranslate> mNodeList;
INodeEditor *mpEditor = nullptr; INodeEditor *mpEditor = nullptr;
bool mCommandEnded = false; bool mCommandEnded = false;
@@ -24,6 +20,7 @@ class CTranslateNodeCommand : public IUndoCommand
public: public:
CTranslateNodeCommand(); CTranslateNodeCommand();
CTranslateNodeCommand(INodeEditor *pEditor, const QList<CSceneNode*>& rkNodes, const CVector3f& rkDelta, ETransformSpace TransformSpace); CTranslateNodeCommand(INodeEditor *pEditor, const QList<CSceneNode*>& rkNodes, const CVector3f& rkDelta, ETransformSpace TransformSpace);
~CTranslateNodeCommand() override;
int id() const override; int id() const override;
bool mergeWith(const QUndoCommand *pkOther) override; bool mergeWith(const QUndoCommand *pkOther) override;

View File

@@ -97,9 +97,10 @@ int IEditPropertyCommand::id() const
bool IEditPropertyCommand::mergeWith(const QUndoCommand *pkOther) bool IEditPropertyCommand::mergeWith(const QUndoCommand *pkOther)
{ {
if (!mCommandEnded) if (mCommandEnded)
{ return false;
const IEditPropertyCommand* pkCmd = dynamic_cast<const IEditPropertyCommand*>(pkOther);
const auto* pkCmd = dynamic_cast<const IEditPropertyCommand*>(pkOther);
if (pkCmd && pkCmd->mpProperty == mpProperty) if (pkCmd && pkCmd->mpProperty == mpProperty)
{ {
@@ -111,7 +112,7 @@ bool IEditPropertyCommand::mergeWith(const QUndoCommand *pkOther)
if (TheirPointers.size() == MyPointers.size()) if (TheirPointers.size() == MyPointers.size())
{ {
for (int PtrIdx = 0; PtrIdx < MyPointers.size(); PtrIdx++) for (qsizetype PtrIdx = 0; PtrIdx < MyPointers.size(); PtrIdx++)
{ {
if (MyPointers[PtrIdx] != TheirPointers[PtrIdx]) if (MyPointers[PtrIdx] != TheirPointers[PtrIdx])
return false; return false;
@@ -123,7 +124,6 @@ bool IEditPropertyCommand::mergeWith(const QUndoCommand *pkOther)
return true; return true;
} }
} }
}
return false; return false;
} }