CSingleModelObserverBase.h
Go to the documentation of this file.
1 #ifndef imod_CSingleModelObserverBase_included
2 #define imod_CSingleModelObserverBase_included
3 
4 
5 // ACF includes
6 #include <imod/IObserver.h>
7 
8 
9 namespace imod
10 {
11 
12 
13 class IModel;
14 
15 
22 class CSingleModelObserverBase: virtual public IObserver
23 {
24 public:
26 
28  virtual ~CSingleModelObserverBase();
29 
40  imod::IModel* GetModelPtr() const;
45  void EnsureModelDetached();
46 
50  void SetObservedIds(const istd::IChangeable::ChangeSet& changeMask);
51 
52  // reimplemented (imod::IObserver)
53  virtual bool IsModelAttached(const imod::IModel* modelPtr = NULL) const;
54  virtual bool OnModelAttached(imod::IModel* modelPtr, istd::IChangeable::ChangeSet& changeMask);
55  virtual bool OnModelDetached(imod::IModel* modelPtr);
56  virtual void BeforeUpdate(imod::IModel* modelPtr);
57  virtual void AfterUpdate(imod::IModel* modelPtr, const istd::IChangeable::ChangeSet& changeSet);
58 
59 protected:
63  void SetModelPtr(imod::IModel* modelPtr);
64 
69  virtual void OnUpdate(const istd::IChangeable::ChangeSet& changeSet);
70 
71 protected:
73 
74 private:
75  Q_DISABLE_COPY(CSingleModelObserverBase)
76 
77  imod::IModel* m_modelPtr;
78 
79  istd::IChangeable::ChangeSet m_observedIds;
80 };
81 
82 
83 // inline methods
84 
86 {
87  return m_modelPtr;
88 }
89 
90 
92 {
93  return m_modelPtr;
94 }
95 
96 
97 // reimplemented (imod::IObserver)
98 
99 inline bool CSingleModelObserverBase::IsModelAttached(const imod::IModel* modelPtr) const
100 {
101  if (modelPtr == NULL){
102  return m_modelPtr != NULL;
103  }
104 
105  return m_modelPtr == modelPtr;
106 }
107 
108 
109 // protected inline methods
110 
112 {
113  m_modelPtr = modelPtr;
114 }
115 
116 
117 } // namespace imod
118 
119 
120 #endif // !imod_CSingleModelObserverBase_included
121 
122 
Basic implementation for a single model observer.
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.
void SetObservedIds(const istd::IChangeable::ChangeSet &changeMask)
Set list of ID's beeing observed.
virtual void BeforeUpdate(imod::IModel *modelPtr)
This function will be called before update of the observer contents occures.
imod::IModel * GetObservedModel() const
Get access to observed model.
static const istd::IChangeable::ChangeSet s_undoChanges
virtual void AfterUpdate(imod::IModel *modelPtr, const istd::IChangeable::ChangeSet &changeSet)
This function will be called after update of the observer contents occures.
virtual bool OnModelDetached(imod::IModel *modelPtr)
This call back function will be called, if an observable object is about to be detached.
virtual void OnUpdate(const istd::IChangeable::ChangeSet &changeSet)
Called on update of observed model.
virtual bool IsModelAttached(const imod::IModel *modelPtr=NULL) const
Check if specified model is attached.
#define NULL
Definition: istd.h:64
Common interface for all classes implementing the Observer functionality in the Model/Observer design...
Definition: IObserver.h:24
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
void SetModelPtr(imod::IModel *modelPtr)
Set internal model pointer to specified value.
imod::IModel * GetModelPtr() const
Get access to observed model.
void EnsureModelDetached()
Make sure this observer is detached.

© 2007-2017 Witold Gantzke and Kirill Lepskiy