ACF $AcfVersion:0$
CMultiModelDispatcherBase.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later OR GPL-2.0-or-later OR GPL-3.0-or-later OR LicenseRef-ACF-Commercial
2#pragma once
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
15namespace imod
16{
17
18
31{
32public:
41 bool RegisterModel(IModel* modelPtr, int modelId = 0, const istd::IChangeable::ChangeSet& relevantFlags = istd::IChangeable::GetAllChanges());
42
48 void UnregisterModel(int modelId = 0);
49
54
58 template <class Object>
59 Object* GetObjectAt(int modelId) const;
60
61protected:
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) override;
71
72 private:
74 int m_modelId;
75 };
76
77 // abstract methods
81 virtual void OnModelChanged(int modelId, const istd::IChangeable::ChangeSet& changeSet) = 0;
82
83private:
85 typedef QMap<int, ObserverProxyPtr> ModelMap;
86
87 ModelMap m_modelMap;
88};
89
90
91// public template methods
92
93template <class Object>
95{
96 typename ModelMap::ConstIterator foundIter = m_modelMap.constFind(modelId);
97 if ((foundIter != m_modelMap.constEnd()) && foundIter.value().IsValid()){
98 return dynamic_cast<Object*>(foundIter.value()->GetObservedModel());
99 }
100
101 return NULL;
102}
103
104
105} // namespace imod
106
107
108
109
ObserverProxy(CMultiModelDispatcherBase *parentPtr, int modelId, const istd::IChangeable::ChangeSet &relevantFlags)
virtual void OnUpdate(const istd::IChangeable::ChangeSet &changeSet) override
Called on update of observed model.
Generic implementation of a data model changes notifier.
Object * GetObjectAt(int modelId) const
Get concrete object instance of the obsered model.
bool RegisterModel(IModel *modelPtr, int modelId=0, const istd::IChangeable::ChangeSet &relevantFlags=istd::IChangeable::GetAllChanges())
Register the data model to be observed.
void UnregisterAllModels()
Unregister all observed data objects.
virtual void OnModelChanged(int modelId, const istd::IChangeable::ChangeSet &changeSet)=0
Called when some model observed by dispatcher will be changed.
void UnregisterModel(int modelId=0)
Unregister the data model object.
Basic implementation for a single model observer.
Common interface for model objects, that supports Model/Observer design pattern.
Definition IModel.h:25
Set of change flags (its IDs).
Definition IChangeable.h:36
static const ChangeSet & GetAllChanges()
Get anonymous change set.
Base interface for all used interfaces and implementations.
Pointer wrapper providing automatic deleting pointed object during destruction.
Definition TDelPtr.h:21
#define NULL
Definition istd.h:74
This namespace containes basic implementation of Model/Observer design pattern This package is system...
Definition CModelBase.h:16