CMultiModelDispatcherBase.h
Go to the documentation of this file.
1 #ifndef imod_CMultiModelDispatcherBase_included
2 #define imod_CMultiModelDispatcherBase_included
3 
4 
5 // Qt includes
6 #include <QtCore/QMap>
7 
8 // ACF includes
9 #include <istd/IChangeable.h>
10 #include <istd/TDelPtr.h>
11 #include <imod/IModel.h>
13 
14 
15 namespace imod
16 {
17 
18 
31 {
32 public:
41  bool RegisterModel(IModel* modelPtr, int modelId = 0, const istd::IChangeable::ChangeSet& relevantFlags = istd::IChangeable::GetAllChanges());
42 
48  void UnregisterModel(int modelId = 0);
49 
53  void UnregisterAllModels();
54 
58  template <class Object>
59  Object* GetObjectAt(int modelId) const;
60 
61 protected:
63  {
64  public:
66 
67  ObserverProxy(CMultiModelDispatcherBase* parentPtr, int modelId, const istd::IChangeable::ChangeSet& relevantFlags);
68 
69  // reimplemented (imod::CSingleModelObserverBase)
70  virtual void OnUpdate(const istd::IChangeable::ChangeSet& changeSet);
71 
72  private:
73  CMultiModelDispatcherBase& m_parent;
74  int m_modelId;
75  };
76 
77  // abstract methods
78  virtual void OnModelChanged(int modelId, const istd::IChangeable::ChangeSet& changeSet) = 0;
79 
80 private:
82  typedef QMap<int, ObserverProxyPtr> ModelMap;
83 
84  ModelMap m_modelMap;
85 };
86 
87 
88 // public template methods
89 
90 template <class Object>
91 Object* CMultiModelDispatcherBase::GetObjectAt(int modelId) const
92 {
93  typename ModelMap::ConstIterator foundIter = m_modelMap.constFind(modelId);
94  if ((foundIter != m_modelMap.constEnd()) && foundIter.value().IsValid()){
95  return dynamic_cast<Object*>(foundIter.value()->GetObservedModel());
96  }
97 
98  return NULL;
99 }
100 
101 
102 } // namespace imod
103 
104 
105 #endif // !imod_CMultiModelDispatcherBase_included
106 
107 
Basic implementation for a single model observer.
virtual void OnUpdate(const istd::IChangeable::ChangeSet &changeSet)
Called on update of observed model.
void UnregisterModel(int modelId=0)
Unregister the data model object.
void UnregisterAllModels()
Unregister all observed data objects.
Generic implementation of a data model changes notifier.
virtual void OnModelChanged(int modelId, const istd::IChangeable::ChangeSet &changeSet)=0
Object * GetObjectAt(int modelId) const
Get concrete object instance of the obsered model.
ObserverProxy(CMultiModelDispatcherBase *parentPtr, int modelId, const istd::IChangeable::ChangeSet &relevantFlags)
Base interface for all used interfaces and implementations.
Definition: IPolymorphic.h:17
bool RegisterModel(IModel *modelPtr, int modelId=0, const istd::IChangeable::ChangeSet &relevantFlags=istd::IChangeable::GetAllChanges())
Register the data model to be observed.
#define NULL
Definition: istd.h:64
static const ChangeSet & GetAllChanges()
Get anonymous change set.
Definition: IChangeable.h:387
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
Pointer wrapper providing automatic deleting pointed object during destruction.
Definition: TDelPtr.h:20

© 2007-2017 Witold Gantzke and Kirill Lepskiy