ICF 3.0.5.47
Technical documentation of ICF Libraries
CMultiModelObserverBase.h
Go to the documentation of this file.
1/********************************************************************************
2** This file is part of the ICF Framework. Copyright (C) Witold Gantzke & Kirill Lepskiy
3** ICF Framework may be used under the terms of the LGPL License v. 2.1 by the Free Software Foundation.
4********************************************************************************/
5
6#ifndef imod_CMultiModelObserverBase_included
7#define imod_CMultiModelObserverBase_included
8
9
10// Qt includes
11#include <QtCore/QVector>
12#include <QtCore/QReadWriteLock>
13
14// ICF includes
15#include <imod/IModel.h>
16#include <imod/IObserver.h>
17
18
19namespace imod
20{
21
22
29{
30public:
33
37 int GetModelCount() const;
38
43 IModel* GetObservedModel(int modelIndex) const;
44
49 IModel* GetModelPtr(int modelIndex) const;
50
56
61
62 // reimplemented (imod::IObserver)
63 bool IsModelAttached(const IModel* modelPtr) const override;
64 bool OnModelAttached(IModel* modelPtr, istd::IChangeable::ChangeSet& changeMask) override;
65 bool OnModelDetached(IModel* modelPtr) override;
66 void BeforeModelChange(IModel* modelPtr) override;
67 void AfterModelChange(IModel* modelPtr, const istd::IChangeable::ChangeSet& changeSet) override;
68
69protected:
74 virtual void OnUpdate(IModel* modelPtr, const istd::IChangeable::ChangeSet& changeSet);
75
76private:
77 bool IsAttached(const imod::IModel* modelPtr) const;
78
79 typedef QVector<IModel*> Models;
80 Models m_models;
81
82 istd::IChangeable::ChangeSet m_observedIds;
83
84 mutable QReadWriteLock m_mutex;
85};
86
87
88} // namespace imod
89
90
91#endif // !imod_CMultiModelObserverBase_included
92
Basic implementation of a multiple model observer.
void BeforeModelChange(IModel *modelPtr) override
This function will be called before update of the observer contents occures.
void SetObservedIds(const istd::IChangeable::ChangeSet &changeMask)
Set list of ID's beeing observed.
void AfterModelChange(IModel *modelPtr, const istd::IChangeable::ChangeSet &changeSet) override
This function will be called after update of the observer contents occures.
virtual void OnUpdate(IModel *modelPtr, const istd::IChangeable::ChangeSet &changeSet)
Called on update of observed model.
bool OnModelAttached(IModel *modelPtr, istd::IChangeable::ChangeSet &changeMask) override
This call back function will be called, if an observable object is about to be attached.
int GetModelCount() const
Gets the number of connected models.
bool IsModelAttached(const IModel *modelPtr) const override
Check if specified model is attached.
void EnsureModelsDetached()
Ensure all attached models are detached.
IModel * GetObservedModel(int modelIndex) const
Get access to connected model with the index index.
bool OnModelDetached(IModel *modelPtr) override
This call back function will be called, if an observable object is about to be detached.
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:29
Common interface for all classes implementing the Observer functionality in the Model/Observer design...
Definition IObserver.h:30
Set of change flags (its IDs).
Definition IChangeable.h:38
This namespace containes basic implementation of Model/Observer design pattern This package is system...
Definition CModelBase.h:20

© Witold Gantzke and Kirill Lepskiy