ACF $AcfVersion:0$
Public Types | Public Member Functions | Protected Member Functions | List of all members
imod::TSingleModelObserverBase< ModelInterface > Class Template Reference

Basic implementation for a single model observer with binding to concrete data object interface. More...

#include <TSingleModelObserverBase.h>

Inheritance diagram for imod::TSingleModelObserverBase< ModelInterface >:
imod::CSingleModelObserverBase imod::IObserver istd::IPolymorphic

Public Types

typedef CSingleModelObserverBase BaseClass
 
typedef ModelInterface ModelType
 
- Public Types inherited from imod::CSingleModelObserverBase
typedef imod::IModel ModelType
 

Public Member Functions

 TSingleModelObserverBase ()
 
ModelInterface * GetObservedObject () const
 Get instance of observed object.
 
ModelInterface * GetObjectPtr () const
 Get instance of observed object.
 
bool AttachOrSetObject (ModelInterface *objectPtr)
 Attach to model of object or set object pointer, if no connection is possible.
 
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 OnModelDetached (imod::IModel *modelPtr) override
 Callback invoked when an observable model is about to be detached from this observer.
 
- Public Member Functions inherited from imod::CSingleModelObserverBase
 CSingleModelObserverBase ()
 
virtual ~CSingleModelObserverBase ()
 
imod::IModelGetObservedModel () const
 Get access to observed model.
 
imod::IModelGetModelPtr () const
 Get access to observed model.
 
void EnsureModelDetached ()
 Make sure this observer is detached.
 
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.
 
virtual void BeforeUpdate (imod::IModel *modelPtr) override
 Callback invoked before an update of the observer's content occurs.
 
virtual void AfterUpdate (imod::IModel *modelPtr, const istd::IChangeable::ChangeSet &changeSet) override
 Callback invoked after an update of the observer's content occurs.
 
- Public Member Functions inherited from istd::IPolymorphic
virtual ~IPolymorphic ()
 

Protected Member Functions

virtual ModelInterface * CastFromModel (imod::IModel *modelPtr) const
 
- Protected Member Functions inherited from imod::CSingleModelObserverBase
void SetModelPtr (imod::IModel *modelPtr)
 Set internal model pointer to specified value.
 
virtual void OnUpdate (const istd::IChangeable::ChangeSet &changeSet)
 Called on update of observed model.
 

Additional Inherited Members

- Static Protected Attributes inherited from imod::CSingleModelObserverBase
static const istd::IChangeable::ChangeSet s_undoChanges
 

Detailed Description

template<class ModelInterface>
class imod::TSingleModelObserverBase< ModelInterface >

Basic implementation for a single model observer with binding to concrete data object interface.

Definition at line 27 of file TSingleModelObserverBase.h.

Member Typedef Documentation

◆ BaseClass

template<class ModelInterface >
typedef CSingleModelObserverBase imod::TSingleModelObserverBase< ModelInterface >::BaseClass

Definition at line 30 of file TSingleModelObserverBase.h.

◆ ModelType

template<class ModelInterface >
typedef ModelInterface imod::TSingleModelObserverBase< ModelInterface >::ModelType

Definition at line 31 of file TSingleModelObserverBase.h.

Constructor & Destructor Documentation

◆ TSingleModelObserverBase()

template<class ModelInterface >
imod::TSingleModelObserverBase< ModelInterface >::TSingleModelObserverBase ( )

Definition at line 65 of file TSingleModelObserverBase.h.

References NULL.

Member Function Documentation

◆ AttachOrSetObject()

template<class ModelInterface >
bool imod::TSingleModelObserverBase< ModelInterface >::AttachOrSetObject ( ModelInterface *  objectPtr)

Attach to model of object or set object pointer, if no connection is possible.

Definition at line 86 of file TSingleModelObserverBase.h.

References imod::IModel::AttachObserver(), and NULL.

◆ CastFromModel()

template<class ModelInterface >
ModelInterface * imod::TSingleModelObserverBase< ModelInterface >::CastFromModel ( imod::IModel modelPtr) const
protectedvirtual

Reimplemented in idoc::CSerializedUndoManagerComp.

Definition at line 147 of file TSingleModelObserverBase.h.

◆ GetObjectPtr()

template<class ModelInterface >
ModelInterface * imod::TSingleModelObserverBase< ModelInterface >::GetObjectPtr ( ) const

Get instance of observed object.

Deprecated:
use GetObservedObject instead.

Definition at line 79 of file TSingleModelObserverBase.h.

◆ GetObservedObject()

template<class ModelInterface >
ModelInterface * imod::TSingleModelObserverBase< ModelInterface >::GetObservedObject ( ) const

Get instance of observed object.

Definition at line 72 of file TSingleModelObserverBase.h.

◆ OnModelAttached()

template<class ModelInterface >
bool imod::TSingleModelObserverBase< ModelInterface >::OnModelAttached ( imod::IModel modelPtr,
istd::IChangeable::ChangeSet changeMask 
)
overridevirtual

Callback invoked when an observable model is about to be attached to this observer.

This method is called by the model when attempting to establish an observer relationship. The implementation should:

  1. Validate that the model is of an acceptable type
  2. Set the changeMask to specify which changes to monitor
  3. Return true to accept the attachment, or false to reject it
Parameters
modelPtrPointer to the model object being attached. Never nullptr.
changeMaskOutput parameter where the observer specifies which change types it wants to be notified about. Set the appropriate change flags using changeMask.Set(changeId). An empty mask means the observer wants all changes.
Returns
true if the model is accepted and attachment succeeds, false to reject the attachment (e.g., if the model is of incompatible type).
Note
After successful attachment, the observer should initialize its state based on the current model data.
The changeMask allows filtering notifications for better performance. Only changes matching the mask will trigger AfterUpdate() calls.
virtual bool OnModelAttached(IModel* modelPtr,
{
// Type check
CMyModel* model = dynamic_cast<CMyModel*>(modelPtr);
if (!model) return false;
// Set up change filtering
changeMask.Set(CMyModel::CF_DATA_CHANGED);
changeMask.Set(CMyModel::CF_STATUS_CHANGED);
// Don't set CF_INTERNAL_CHANGED - we don't care about those
// Initialize view from current model state
UpdateViewFromModel(model);
return true;
}
Common interface for model objects, that supports Model/Observer design pattern.
Definition IModel.h:25
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.
Set of change flags (its IDs).
Definition IChangeable.h:36
See also
OnModelDetached(), IsModelAttached(), AfterUpdate()

Reimplemented from imod::CSingleModelObserverBase.

Reimplemented in idoc::CSerializedUndoManagerComp, iqt2d::CSelectableSceneExtenderComp, iqtdoc::CMainWindowGuiComp, iqtgui::TGuiObserverWrap< iqtgui::CComposedGuiComp, imod::TSingleModelObserverBase< iprm::IParamsSet > >, iqtgui::TGuiObserverWrap< iqtgui::TDesignerGuiCompBase< UI, QWidget >, imod::TSingleModelObserverBase< Model > >, iqtgui::TGuiObserverWrap< iqtgui::TGuiComponentBase< QLabel >, imod::TSingleModelObserverBase< istd::IInformationProvider > >, iqtgui::TGuiObserverWrap< iqtgui::TGuiComponentBase< QTextEdit >, imod::TSingleModelObserverBase< idoc::ITextDocument > >, iqtgui::TGuiObserverWrap< iqtgui::TGuiComponentBase< QWidget >, imod::TSingleModelObserverBase< idoc::IDocumentMetaInfo > >, iqtgui::TGuiObserverWrap< iqtgui::TGuiComponentBase< QWidget >, imod::TSingleModelObserverBase< iimg::IMultiBitmapProvider > >, iqtgui::TGuiObserverWrap< TGuiComponentBase< ItemWidgetClass >, imod::TSingleModelObserverBase< ibase::IQtItemModelProvider > >, and iqtgui::TGuiObserverWrap< TGuiComponentBase< QTableView >, imod::TSingleModelObserverBase< ibase::IQtItemModelProvider > >.

Definition at line 106 of file TSingleModelObserverBase.h.

References I_IF_DEBUG, and NULL.

◆ OnModelDetached()

template<class ModelInterface >
bool imod::TSingleModelObserverBase< ModelInterface >::OnModelDetached ( imod::IModel modelPtr)
overridevirtual

Callback invoked when an observable model is about to be detached from this observer.

This method is called when the observer-model relationship is being terminated, either explicitly or because the model is being destroyed. The implementation should clean up any state or resources related to this model.

Parameters
modelPtrPointer to the model object being detached
Returns
true if the detachment was handled successfully, false otherwise
Note
After this call, the observer should not access the model pointer anymore.
This method may be called even if OnModelAttached() previously returned false.
Clean up any cached data or references to this model.
virtual bool OnModelDetached(IModel* modelPtr)
{
if (m_currentModel == modelPtr) {
// Clear any cached data
m_cachedData.clear();
m_currentModel = nullptr;
// Update UI to show no model is attached
ClearDisplay();
return true;
}
return false;
}
virtual bool OnModelDetached(imod::IModel *modelPtr) override
Callback invoked when an observable model is about to be detached from this observer.
See also
OnModelAttached(), IsModelAttached()

Reimplemented from imod::CSingleModelObserverBase.

Reimplemented in idoc::CSerializedUndoManagerComp, iqt2d::CSelectableSceneExtenderComp, iqtdoc::CMainWindowGuiComp, iqtgui::TGuiObserverWrap< iqtgui::CComposedGuiComp, imod::TSingleModelObserverBase< iprm::IParamsSet > >, iqtgui::TGuiObserverWrap< iqtgui::TDesignerGuiCompBase< UI, QWidget >, imod::TSingleModelObserverBase< Model > >, iqtgui::TGuiObserverWrap< iqtgui::TGuiComponentBase< QLabel >, imod::TSingleModelObserverBase< istd::IInformationProvider > >, iqtgui::TGuiObserverWrap< iqtgui::TGuiComponentBase< QTextEdit >, imod::TSingleModelObserverBase< idoc::ITextDocument > >, iqtgui::TGuiObserverWrap< iqtgui::TGuiComponentBase< QWidget >, imod::TSingleModelObserverBase< idoc::IDocumentMetaInfo > >, iqtgui::TGuiObserverWrap< iqtgui::TGuiComponentBase< QWidget >, imod::TSingleModelObserverBase< iimg::IMultiBitmapProvider > >, iqtgui::TGuiObserverWrap< TGuiComponentBase< ItemWidgetClass >, imod::TSingleModelObserverBase< ibase::IQtItemModelProvider > >, and iqtgui::TGuiObserverWrap< TGuiComponentBase< QTableView >, imod::TSingleModelObserverBase< ibase::IQtItemModelProvider > >.

Definition at line 129 of file TSingleModelObserverBase.h.

References NULL.


The documentation for this class was generated from the following file: