CModelBase.h
Go to the documentation of this file.
1 #ifndef imod_CModelBase_included
2 #define imod_CModelBase_included
3 
4 
5 // Qt includes
6 #include <QtCore/QMap>
7 
8 // ACF includes
9 #include <imod/imod.h>
10 #include <imod/IModel.h>
11 #include <imod/IObserver.h>
12 
13 
14 namespace imod
15 {
16 
17 
23 class CModelBase: virtual public imod::IModel
24 {
25 public:
26  typedef QSet<IObserver*> Observers;
27 
28  CModelBase();
29  virtual ~CModelBase();
30 
34  virtual int GetObserverCount() const;
35 
39  virtual Observers GetObservers() const;
40 
42 
43  // reimplemented (imod::IModel)
44  virtual bool AttachObserver(imod::IObserver* observerPtr);
45  virtual void DetachObserver(imod::IObserver* observerPtr);
46  virtual void DetachAllObservers();
47  virtual bool IsAttached(const imod::IObserver* observerPtr) const;
48 
49 protected:
54  void NotifyBeforeChange(const istd::IChangeable::ChangeSet& changeSet, bool isGroup);
59  void NotifyAfterChange(const istd::IChangeable::ChangeSet& changeSet);
60 
64  virtual void OnBeginGlobalChanges() = 0;
68  virtual void OnEndGlobalChanges(const istd::IChangeable::ChangeSet& changeSet) = 0;
69 
70 private:
71  Q_DISABLE_COPY(CModelBase);
72 
73  void CleanupObserverState();
74 
75 private:
79  enum AttachingState
80  {
84  AS_ATTACHING,
85 
89  AS_ATTACHED,
93  AS_ATTACHED_UPDATING,
97  AS_DETACHING,
98 
102  AS_DETACHED
103  };
104 
105  struct ObserverInfo
106  {
107  AttachingState state;
109  };
110 
111  typedef QMap<IObserver*, ObserverInfo> ObserversMap;
112  ObserversMap m_observers;
113 
114  int m_blockCounter;
115  bool m_isDuringChanges;
116  istd::IChangeable::ChangeSet m_cumulatedChangeIds;
117 };
118 
119 
120 // public inline methods
121 
123 {
124  return m_cumulatedChangeIds;
125 }
126 
127 
128 } // namespace imod
129 
130 
131 #endif // !imod_CModelBase_included
132 
void NotifyBeforeChange(const istd::IChangeable::ChangeSet &changeSet, bool isGroup)
Called before each change.
QSet< IObserver * > Observers
Definition: CModelBase.h:26
const istd::IChangeable::ChangeSet & GetCumulatedChanges() const
Definition: CModelBase.h:122
virtual Observers GetObservers() const
Returns set of all observers.
Basic implementation of a model.
Definition: CModelBase.h:23
virtual bool AttachObserver(imod::IObserver *observerPtr)
Attaches model object to observer observerPtr.
virtual int GetObserverCount() const
Returns count of connected observers.
virtual bool IsAttached(const imod::IObserver *observerPtr) const
Returns true if observer observer is attached to this model object.
void NotifyAfterChange(const istd::IChangeable::ChangeSet &changeSet)
Called after each change.
virtual void DetachObserver(imod::IObserver *observerPtr)
Detaches model object from observer observerPtr.
virtual void DetachAllObservers()
Detaches all attached observers.
virtual void OnEndGlobalChanges(const istd::IChangeable::ChangeSet &changeSet)=0
Called after global changes are finished.
virtual ~CModelBase()
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
virtual void OnBeginGlobalChanges()=0
Called before global changes will be started.

© 2007-2017 Witold Gantzke and Kirill Lepskiy