ACF $AcfVersion:0$
CModelUpdateBridge.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/QVector>
7#include <QtCore/QReadWriteLock>
8
9// ACF includes
10#include <istd/IChangeable.h>
11#include <imod/IModel.h>
12#include <imod/IObserver.h>
13
14
15namespace imod
16{
17
18
27class CModelUpdateBridge: virtual public IObserver
28{
29public:
34 {
39
43 UF_SOURCE = 0x2
44 };
45
46 explicit CModelUpdateBridge(istd::IChangeable* changeablePtr, int updateFlags = UF_DELEGATED);
47
49
53 imod::IModel* GetObservedModel(int modelIndex) const;
54
58 int GetModelCount() const;
59
64
65 // reimplemented (imod::IObserver)
66 virtual bool IsModelAttached(const imod::IModel* modelPtr) const override;
67 virtual bool OnModelAttached(imod::IModel* modelPtr, istd::IChangeable::ChangeSet& changeMask) override;
68 virtual bool OnModelDetached(imod::IModel* modelPtr) override;
69 virtual void BeforeUpdate(imod::IModel* modelPtr) override;
70 virtual void AfterUpdate(imod::IModel* modelPtr, const istd::IChangeable::ChangeSet& changeSet) override;
71
72private:
73 bool IsAttached(const imod::IModel* modelPtr) const;
74
75private:
76 typedef QVector<imod::IModel*> Models;
77 Models m_models;
78
79 istd::IChangeable* m_changeablePtr;
80
81 int m_updateFlags;
82
83 mutable QReadWriteLock m_modelListMutex;
84};
85
86
87} // namespace imod
88
89
90
Reflects the changes of observed objects as changes of some other object (over istd::IChangeable),...
virtual void BeforeUpdate(imod::IModel *modelPtr) override
Callback invoked before an update of the observer's content occurs.
CModelUpdateBridge(istd::IChangeable *changeablePtr, int updateFlags=UF_DELEGATED)
virtual bool OnModelDetached(imod::IModel *modelPtr) override
Callback invoked when an observable model is about to be detached from this observer.
virtual void AfterUpdate(imod::IModel *modelPtr, const istd::IChangeable::ChangeSet &changeSet) override
Callback invoked after an update of the observer's content occurs.
void EnsureModelsDetached()
Remove all observed models from this bridge.
UpdateFlags
Flags to control the change set using for the change notification of the target object.
@ UF_DELEGATED
Change notification of the target object will be done using change set containing CF_DELEGATED flag o...
@ UF_SOURCE
Change notification of the target object will be done using change set of observered object.
imod::IModel * GetObservedModel(int modelIndex) const
Get access to connected model with the index index.
int GetModelCount() const
Gets the number of connected models.
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.
virtual bool IsModelAttached(const imod::IModel *modelPtr) const override
Checks if the specified model is currently attached to this observer.
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
Common interface for data model objects, which can be changed.
Definition IChangeable.h:28
This namespace containes basic implementation of Model/Observer design pattern This package is system...
Definition CModelBase.h:16