ACF $AcfVersion:0$
CMultiModelObserverBase.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/QMutex>
8
9// ACF includes
10#include <imod/IModel.h>
11#include <imod/IObserver.h>
12
13
14namespace imod
15{
16
17
24{
25public:
28
32 int GetModelCount() const;
33
38 IModel* GetObservedModel(int modelIndex) const;
39
44 IModel* GetModelPtr(int modelIndex) const;
45
51
56
57 // reimplemented (imod::IObserver)
58 virtual bool IsModelAttached(const IModel* modelPtr) const override;
59 virtual bool OnModelAttached(IModel* modelPtr, istd::IChangeable::ChangeSet& changeMask) override;
60 virtual bool OnModelDetached(IModel* modelPtr) override;
61 virtual void BeforeUpdate(IModel* modelPtr) override;
62 virtual void AfterUpdate(IModel* modelPtr, const istd::IChangeable::ChangeSet& changeSet) override;
63
64protected:
69 virtual void OnUpdate(IModel* modelPtr, const istd::IChangeable::ChangeSet& changeSet);
70
71private:
72 bool IsAttached(const imod::IModel* modelPtr) const;
73
74 typedef QVector<IModel*> Models;
75 Models m_models;
76
77 istd::IChangeable::ChangeSet m_observedIds;
78
79#if QT_VERSION >= 0x060000
80 mutable QRecursiveMutex m_mutex;
81#else
82 mutable QMutex m_mutex;
83#endif
84};
85
86
87} // namespace imod
88
89
90
Basic implementation of a multiple model observer.
virtual void BeforeUpdate(IModel *modelPtr) override
Callback invoked before an update of the observer's content occurs.
virtual bool IsModelAttached(const IModel *modelPtr) const override
Checks if the specified model is currently attached to this observer.
void SetObservedIds(const istd::IChangeable::ChangeSet &changeMask)
Set list of ID's beeing observed.
virtual void OnUpdate(IModel *modelPtr, const istd::IChangeable::ChangeSet &changeSet)
Called on update of observed model.
int GetModelCount() const
Gets the number of connected models.
void EnsureModelsDetached()
Ensure all attached models are detached.
virtual void AfterUpdate(IModel *modelPtr, const istd::IChangeable::ChangeSet &changeSet) override
Callback invoked after an update of the observer's content occurs.
virtual bool OnModelAttached(IModel *modelPtr, istd::IChangeable::ChangeSet &changeMask) override
Callback invoked when an observable model is about to be attached to this observer.
virtual bool OnModelDetached(IModel *modelPtr) override
Callback invoked when an observable model is about to be detached from this observer.
IModel * GetObservedModel(int modelIndex) const
Get access to connected model with the index index.
IModel * GetModelPtr(int modelIndex) const
Get access to connected model with the index index.
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
This namespace containes basic implementation of Model/Observer design pattern This package is system...
Definition CModelBase.h:16