CSerializedUndoManagerComp.h
Go to the documentation of this file.
1 #ifndef idoc_CSerializedUndoManagerComp_included
2 #define idoc_CSerializedUndoManagerComp_included
3 
4 
5 // Qt includes
6 #include <QtCore/QList>
7 
8 // ACF includes
9 #include <istd/TDelPtr.h>
10 #include <iser/ISerializable.h>
13 #include <icomp/CComponentBase.h>
14 #include <idoc/IUndoManager.h>
15 
16 
17 namespace idoc
18 {
19 
20 
26  public icomp::CComponentBase,
27  public imod::TSingleModelObserverBase<iser::ISerializable>,
28  virtual public IUndoManager
29 {
30 public:
33 
34  I_BEGIN_COMPONENT(CSerializedUndoManagerComp);
35  I_REGISTER_INTERFACE(idoc::IUndoManager);
36  I_REGISTER_INTERFACE(idoc::IDocumentStateComparator);
37  I_REGISTER_INTERFACE(imod::IObserver);
38  I_ASSIGN(m_maxBufferSizeAttrPtr, "MaxBufferSize", "Maximal memory size of the Undo-buffer in MByte", false, 100);
39  I_END_COMPONENT;
40 
42 
43  // reimplemented (idoc::IUndoManager)
44  virtual int GetAvailableUndoSteps() const;
45  virtual int GetAvailableRedoSteps() const;
46  virtual QString GetUndoLevelDescription(int stepIndex) const;
47  virtual QString GetRedoLevelDescription(int stepIndex) const;
48  virtual void ResetUndo();
49  virtual bool DoUndo(int steps = 1);
50  virtual bool DoRedo(int steps = 1);
51 
52  // reimplemented (imod::IObserver)
53  virtual bool OnModelAttached(imod::IModel* modelPtr, istd::IChangeable::ChangeSet& changeMask);
54  virtual bool OnModelDetached(imod::IModel* modelPtr);
55 
56 protected:
58  struct UndoStepInfo
59  {
61  QString description;
62  };
63  typedef QList<UndoStepInfo> UndoList;
64 
65  bool DoListShift(int steps, UndoList& fromList, UndoList& toList);
66 
67  // reimplemented (imod::TSingleModelObserverBase<iser::ISerializable>)
68  virtual iser::ISerializable* CastFromModel(imod::IModel* modelPtr) const;
69 
70  // reimplemented (imod::IObserver)
71  virtual void BeforeUpdate(imod::IModel* modelPtr);
72  virtual void AfterUpdate(imod::IModel* modelPtr, const istd::IChangeable::ChangeSet& changeSet);
73 
74  // reimplemented (idoc::IDocumentStateComparator)
75  virtual bool HasStoredDocumentState() const;
76  virtual bool StoreDocumentState();
77  virtual bool RestoreDocumentState();
79 
80  // reimplemented (icomp::CComponentBase)
81  virtual void OnComponentDestroyed();
82 
83 private:
84  qint64 GetUsedMemorySize() const;
85 
86  UndoList m_undoList;
87  UndoList m_redoList;
88 
89  UndoArchivePtr m_beginStateArchivePtr;
90 
91  bool m_hasStoredDocumentState;
92  bool m_isBlocked;
93 
94  iser::CMemoryWriteArchive m_storedStateArchive;
95 
96  mutable DocumentChangeFlag m_stateChangedFlag;
97  mutable bool m_isStateChangedFlagValid;
98 
99  I_ATTR(int, m_maxBufferSizeAttrPtr);
100 };
101 
102 
103 } // namespace idoc
104 
105 
106 #endif // !idoc_CSerializedUndoManagerComp_included
107 
108 
virtual QString GetUndoLevelDescription(int stepIndex) const
Get description of single UNDO level.
virtual bool OnModelDetached(imod::IModel *modelPtr)
This call back function will be called, if an observable object is about to be detached.
virtual int GetAvailableRedoSteps() const
Get number of available REDO levels.
Implements multi level UNDO mechanism based on storing complete objects state at each step using seri...
bool DoListShift(int steps, UndoList &fromList, UndoList &toList)
Base class for component implementation.
virtual DocumentChangeFlag GetDocumentChangeFlag() const
Check if document state is the same as stored state.
Allows to store some document state used as reference for comarision.
virtual void AfterUpdate(imod::IModel *modelPtr, const istd::IChangeable::ChangeSet &changeSet)
This function will be called after update of the observer contents occures.
Common class for all classes which objects can be archived or restored from archive.
Definition: ISerializable.h:23
Basic implementation for a single model observer with binding to concrete data object interface...
virtual bool DoRedo(int steps=1)
Process REDO steps.
virtual void ResetUndo()
Reset all UNDO and REDO steps.
virtual bool StoreDocumentState()
Store state of some document.
virtual void BeforeUpdate(imod::IModel *modelPtr)
This function will be called before update of the observer contents occures.
virtual bool DoUndo(int steps=1)
Process UNDO steps.
virtual bool OnModelAttached(imod::IModel *modelPtr, istd::IChangeable::ChangeSet &changeMask)
This call back function will be called, if an observable object is about to be attached.
virtual int GetAvailableUndoSteps() const
Get number of available UNDO levels.
Common interface for all classes implementing the Observer functionality in the Model/Observer design...
Definition: IObserver.h:24
imod::TSingleModelObserverBase< iser::ISerializable > BaseClass2
istd::TDelPtr< iser::CMemoryWriteArchive > UndoArchivePtr
Common interface for model objects, that supports Model/Observer design pattern.
Definition: IModel.h:23
Set of change flags (its IDs).
Definition: IChangeable.h:30
Implementation of archive using memory buffer to store the persistent objects.
Interface providing UNDO/REDO functionality.
Definition: IUndoManager.h:16
virtual iser::ISerializable * CastFromModel(imod::IModel *modelPtr) const
virtual bool HasStoredDocumentState() const
Check if there is stored document available.
virtual QString GetRedoLevelDescription(int stepIndex) const
Get description of single UNDO level.
virtual bool RestoreDocumentState()
Restore last stored document state.

© 2007-2017 Witold Gantzke and Kirill Lepskiy