ACF $AcfVersion:0$
CSingleModelObserverBase.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// ACF includes
6#include <imod/IObserver.h>
7
8
9namespace imod
10{
11
12
13class IModel;
14
15
22class CSingleModelObserverBase: virtual public IObserver
23{
24public:
26
29
46
51
52 // reimplemented (imod::IObserver)
53 virtual bool IsModelAttached(const imod::IModel* modelPtr = NULL) const override;
54 virtual bool OnModelAttached(imod::IModel* modelPtr, istd::IChangeable::ChangeSet& changeMask) override;
55 virtual bool OnModelDetached(imod::IModel* modelPtr) override;
56 virtual void BeforeUpdate(imod::IModel* modelPtr) override;
57 virtual void AfterUpdate(imod::IModel* modelPtr, const istd::IChangeable::ChangeSet& changeSet) override;
58
59protected:
63 void SetModelPtr(imod::IModel* modelPtr);
64
69 virtual void OnUpdate(const istd::IChangeable::ChangeSet& changeSet);
70
71protected:
73
74private:
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
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
121
Basic implementation for a single model observer.
imod::IModel * GetModelPtr() const
Get access to observed model.
virtual void AfterUpdate(imod::IModel *modelPtr, const istd::IChangeable::ChangeSet &changeSet) override
Callback invoked after an update of the observer's content occurs.
virtual void OnUpdate(const istd::IChangeable::ChangeSet &changeSet)
Called on update of observed model.
virtual bool OnModelAttached(imod::IModel *modelPtr, istd::IChangeable::ChangeSet &changeMask) override
Callback invoked when an observable model is about to be attached to this observer.
static const istd::IChangeable::ChangeSet s_undoChanges
virtual void BeforeUpdate(imod::IModel *modelPtr) override
Callback invoked before an update of the observer's content occurs.
void SetObservedIds(const istd::IChangeable::ChangeSet &changeMask)
Set list of ID's beeing observed.
virtual bool IsModelAttached(const imod::IModel *modelPtr=NULL) const override
Checks if the specified model is currently attached to this observer.
void EnsureModelDetached()
Make sure this observer is detached.
void SetModelPtr(imod::IModel *modelPtr)
Set internal model pointer to specified value.
virtual bool OnModelDetached(imod::IModel *modelPtr) override
Callback invoked when an observable model is about to be detached from this observer.
imod::IModel * GetObservedModel() const
Get access to observed model.
Common interface for model objects, that supports Model/Observer design pattern.
Definition IModel.h:25
Common interface for all classes implementing the Observer functionality in the Model/Observer design...
Definition IObserver.h:156
Set of change flags (its IDs).
Definition IChangeable.h:36
#define NULL
Definition istd.h:74
This namespace containes basic implementation of Model/Observer design pattern This package is system...
Definition CModelBase.h:16