Files

103 lines
3.5 KiB
C++
Raw Permalink Normal View History

2015-07-29 14:19:43 +02:00
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2014 Ceetron Solutions AS
2020-06-19 07:53:59 +02:00
//
2015-07-29 14:19:43 +02:00
// <APPLICATION_NAME> is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
2020-06-19 07:53:59 +02:00
//
2015-07-29 14:19:43 +02:00
// <APPLICATION_NAME> is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
2020-06-19 07:53:59 +02:00
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
2015-07-29 14:19:43 +02:00
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "cafNotificationCenter.h"
#include "cafAssert.h"
2015-07-29 14:19:43 +02:00
#include <QtGlobal>
#include <algorithm>
namespace caf
{
//--------------------------------------------------------------------------------------------------
2020-06-19 07:53:59 +02:00
///
2015-07-29 14:19:43 +02:00
//--------------------------------------------------------------------------------------------------
NotificationCenter::NotificationCenter()
{
}
//--------------------------------------------------------------------------------------------------
2020-06-19 07:53:59 +02:00
///
2015-07-29 14:19:43 +02:00
//--------------------------------------------------------------------------------------------------
NotificationCenter::~NotificationCenter()
{
CAF_ASSERT( m_observers.empty() );
2015-07-29 14:19:43 +02:00
}
//--------------------------------------------------------------------------------------------------
2020-06-19 07:53:59 +02:00
///
2015-07-29 14:19:43 +02:00
//--------------------------------------------------------------------------------------------------
2020-06-19 07:53:59 +02:00
void NotificationCenter::registerObserver( DataModelObserver* observer )
2015-07-29 14:19:43 +02:00
{
2020-06-19 07:53:59 +02:00
std::vector<DataModelObserver*>::iterator it = std::find( m_observers.begin(), m_observers.end(), observer );
if ( it == m_observers.end() )
2015-07-29 14:19:43 +02:00
{
2020-06-19 07:53:59 +02:00
m_observers.push_back( observer );
2015-07-29 14:19:43 +02:00
}
}
//--------------------------------------------------------------------------------------------------
2020-06-19 07:53:59 +02:00
///
2015-07-29 14:19:43 +02:00
//--------------------------------------------------------------------------------------------------
2020-06-19 07:53:59 +02:00
void NotificationCenter::removeObserver( DataModelObserver* observer )
2015-07-29 14:19:43 +02:00
{
2020-06-19 07:53:59 +02:00
std::vector<DataModelObserver*>::iterator it = std::find( m_observers.begin(), m_observers.end(), observer );
if ( it != m_observers.end() )
2015-07-29 14:19:43 +02:00
{
2020-06-19 07:53:59 +02:00
m_observers.erase( it );
2015-07-29 14:19:43 +02:00
}
}
//--------------------------------------------------------------------------------------------------
2020-06-19 07:53:59 +02:00
///
2015-07-29 14:19:43 +02:00
//--------------------------------------------------------------------------------------------------
2020-06-19 07:53:59 +02:00
void NotificationCenter::notifyObserversOfDataChange( caf::PdmObjectHandle* itemThatChanged )
2015-07-29 14:19:43 +02:00
{
2020-06-19 07:53:59 +02:00
CAF_ASSERT( itemThatChanged );
2015-07-29 14:19:43 +02:00
2024-10-28 13:09:18 +01:00
for ( DataModelObserver* o : m_observers )
2015-07-29 14:19:43 +02:00
{
2020-06-19 07:53:59 +02:00
o->handleModelNotification( itemThatChanged );
2015-07-29 14:19:43 +02:00
}
}
//--------------------------------------------------------------------------------------------------
2020-06-19 07:53:59 +02:00
///
2015-07-29 14:19:43 +02:00
//--------------------------------------------------------------------------------------------------
void NotificationCenter::notifyObservers()
{
2024-10-28 13:09:18 +01:00
for ( DataModelObserver* o : m_observers )
2015-07-29 14:19:43 +02:00
{
2020-06-19 07:53:59 +02:00
o->handleModelNotification( nullptr );
2015-07-29 14:19:43 +02:00
}
}
//--------------------------------------------------------------------------------------------------
2020-06-19 07:53:59 +02:00
///
2015-07-29 14:19:43 +02:00
//--------------------------------------------------------------------------------------------------
void NotificationCenter::notifyObserversOfSelectionChange()
{
2024-10-28 13:09:18 +01:00
for ( DataModelObserver* o : m_observers )
2015-07-29 14:19:43 +02:00
{
o->handleModelSelectionChange();
}
}
} // end namespace caf