UndoVariableChange.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #ifndef CRYINCLUDE_EDITOR_UNDO_UNDOVARIABLECHANGE_H
  9. #define CRYINCLUDE_EDITOR_UNDO_UNDOVARIABLECHANGE_H
  10. #pragma once
  11. #include "IUndoObject.h"
  12. #include "Util/Variable.h"
  13. class CAttributeItem;
  14. //////////////////////////////////////////////////////////////////////////
  15. //! Undo object for Variable in property control..
  16. class CUndoVariableChange
  17. : public IUndoObject
  18. {
  19. public:
  20. CUndoVariableChange(IVariable* var, const char* undoDescription, const char* editorObjfullname = 0)
  21. {
  22. // Stores the current state of this object.
  23. assert(var != 0);
  24. m_undoDescription = undoDescription;
  25. m_var = var;
  26. m_undo = m_var->Clone(false);
  27. m_EditorObjFullName = editorObjfullname;
  28. }
  29. protected:
  30. virtual int GetSize()
  31. {
  32. int size = sizeof(*this);
  33. //if (m_var)
  34. //size += m_var->GetSize();
  35. if (m_undo)
  36. {
  37. size += m_undo->GetSize();
  38. }
  39. if (m_redo)
  40. {
  41. size += m_redo->GetSize();
  42. }
  43. return size;
  44. }
  45. virtual QString GetDescription()
  46. {
  47. return m_undoDescription;
  48. }
  49. virtual void Undo(bool bUndo)
  50. {
  51. if (bUndo)
  52. {
  53. m_redo = m_var->Clone(false);
  54. }
  55. m_var->CopyValue(m_undo);
  56. }
  57. virtual void Redo()
  58. {
  59. if (m_redo)
  60. {
  61. m_var->CopyValue(m_redo);
  62. }
  63. }
  64. virtual QString GetEditorObjectName()
  65. {
  66. return m_EditorObjFullName;
  67. };
  68. void SetEditorObjName(const char* fullname)
  69. {
  70. m_EditorObjFullName = fullname;
  71. }
  72. private:
  73. QString m_undoDescription;
  74. QString m_EditorObjFullName; // Add related editor object name so we can track undo by editor object
  75. TSmartPtr<IVariable> m_undo;
  76. TSmartPtr<IVariable> m_redo;
  77. TSmartPtr<IVariable> m_var;
  78. };
  79. //////////////////////////////////////////////////////////////////////////
  80. // Confetti Start
  81. // This undoobject class is responsible for recording varialeundo action reqiure QTUI reaction.
  82. // This class will store a CAttributeView. Editor plugin is responsible for deal with QTUI actions.
  83. class CUndoQTUIVariableChange
  84. : public CUndoVariableChange
  85. {
  86. public:
  87. CUndoQTUIVariableChange(IVariable* var, CAttributeItem* widget, const char* undoDescription, const char* editorObjfullname = 0)
  88. : CUndoVariableChange(var, undoDescription, editorObjfullname)
  89. {
  90. // Stores the current state of this object.
  91. m_uiWidget = widget;
  92. }
  93. CAttributeItem* getWidget() const
  94. {
  95. return m_uiWidget;
  96. }
  97. private:
  98. CAttributeItem* m_uiWidget;
  99. };
  100. // Confetti End
  101. ////////////////////////////////////////////////////////////////////////
  102. #endif // CRYINCLUDE_EDITOR_UNDO_UNDO_H