6#include <QtCore/QtGlobal>
9#include <imod/CMultiModelDispatcherBase.h>
58template <
typename ModelInterface,
typename Parent>
62 typedef void (Parent::*CallbackMethod)(
const istd::IChangeable::ChangeSet& changeSet,
const ModelInterface* objectPtr);
63 typedef imod::CMultiModelDispatcherBase BaseClass;
67 bool RegisterObject(
const ModelInterface* dataPtr, CallbackMethod callbackMethod,
int modelId = 0);
68 bool RegisterObject(ModelInterface* dataPtr, CallbackMethod callbackMethod,
int modelId = 0);
69 void UnregisterObject(
int modelId);
70 void UnregisterAllObjects();
72 ModelInterface* GetObjectAt(
int modelId)
const;
75 virtual void OnModelChanged(
int modelId,
const istd::IChangeable::ChangeSet& changeSet)
override;
80 typedef QMap<int, CallbackMethod> CallbackMap;
81 CallbackMap m_callbackMap;
85template <
typename ModelInterface,
typename Parent>
92template <
typename ModelInterface,
typename Parent>
93bool TModelUpdateBinder<ModelInterface, Parent>::RegisterObject(
const ModelInterface* dataPtr, CallbackMethod callbackMethod,
int modelId)
95 return RegisterObject(
const_cast<ModelInterface*
>(dataPtr), callbackMethod, modelId);
99template <
typename ModelInterface,
typename Parent>
100bool TModelUpdateBinder<ModelInterface, Parent>::RegisterObject(ModelInterface* dataPtr, CallbackMethod callbackMethod,
int modelId)
102 auto modelPtr =
dynamic_cast<imod::IModel*
>(dataPtr);
103 if (modelPtr !=
nullptr){
104 m_callbackMap[modelId] = callbackMethod;
105 if (BaseClass::RegisterModel(modelPtr, modelId)){
109 m_callbackMap.remove(modelId);
116template<
typename ModelInterface,
typename Parent>
117void TModelUpdateBinder<ModelInterface, Parent>::UnregisterObject(
int modelId)
119 BaseClass::UnregisterModel(modelId);
121 m_callbackMap.remove(modelId);
125template<
typename ModelInterface,
typename Parent>
126void TModelUpdateBinder<ModelInterface, Parent>::UnregisterAllObjects()
128 BaseClass::UnregisterAllModels();
130 m_callbackMap.clear();
134template<
typename ModelInterface,
typename Parent>
135ModelInterface* TModelUpdateBinder<ModelInterface, Parent>::GetObjectAt(
int modelId)
const
137 return BaseClass::GetObjectAt<ModelInterface>(modelId);
143template <
typename ModelInterface,
typename Parent>
144void TModelUpdateBinder<ModelInterface, Parent>::OnModelChanged(
int modelId,
const istd::IChangeable::ChangeSet& changeSet)
146 if (m_callbackMap.contains(modelId)){
147 const CallbackMethod& method = m_callbackMap[modelId];
149 (m_parent.*method)(changeSet, GetObjectAt(modelId));