Commit d0a08508 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[ADD] - WPropertyBase now provides a new condition which is notified whenever...

[ADD] - WPropertyBase now provides a new condition which is notified whenever SOMETHING changes. This is especially useful if it is not necessary to know what changed (like in property widgets)
parent d5f8e631
......@@ -37,6 +37,7 @@ WProperties::WProperties( std::string name, std::string description ):
WPropertyBase( name, description ),
m_propAccess( m_properties.getAccessObject() )
{
m_updateCondition->add( m_properties.getChangeCondition() );
}
WProperties::~WProperties()
......
......@@ -36,7 +36,8 @@
WPropertyBase::WPropertyBase( std::string name, std::string description ):
m_name( name ),
m_description( description ),
m_hidden( false )
m_hidden( false ),
m_updateCondition( new WConditionSet() )
{
// check name validity
if ( ( m_name.find( std::string( "/" ) ) != std::string::npos ) || m_name.empty() )
......@@ -78,7 +79,11 @@ bool WPropertyBase::isHidden() const
void WPropertyBase::setHidden( bool hidden )
{
m_hidden = hidden;
if ( m_hidden != hidden )
{
m_hidden = hidden;
m_updateCondition->notify();
}
}
WPropInt WPropertyBase::toPropInt()
......@@ -126,3 +131,8 @@ WPropGroup WPropertyBase::toPropGroup()
return boost::shared_static_cast< WPVGroup >( shared_from_this() );
}
boost::shared_ptr< WCondition > WPropertyBase::getUpdateCondition() const
{
return m_updateCondition;
}
......@@ -34,6 +34,8 @@
#include <boost/enable_shared_from_this.hpp>
#include "WPropertyTypes.h"
#include "WCondition.h"
#include "WConditionSet.h"
/**
* Abstract base class for all properties. Simply provides name and type information.
......@@ -100,6 +102,22 @@ public:
*/
virtual bool setAsString( std::string value ) = 0;
/**
* This method returns a condition which gets fired whenever the property changes somehow. It is fired when:
* \li \ref setHidden is called and the hidden state changes
* \li \ref setAsString is called and the value changes
* \li WPropertyVariable::set is called and the value changes (regardless of suppression during set)
* \li WPropertyVariable::setMin/setMax is called and the value changes
* \li WPropertyVariable::addConstraint is called
* \li WPropertyVariable::removeConstraints is called
* \li WProperties::addProperty is called
* \li WProperties::addPropertyGroup is called
* This is especially useful if you simply want to know that something has happened.
*
* \return a condition notified whenever something changes.
*/
virtual boost::shared_ptr< WCondition > getUpdateCondition() const;
/////////////////////////////////////////////////////////////////////////////////////////////
// Helpers for easy conversion to the possible types
/////////////////////////////////////////////////////////////////////////////////////////////
......@@ -217,6 +235,12 @@ protected:
*/
PropertyChangeSignalType signal_PropertyChange;
/**
* Condition notified whenever something changes. See getUpdateCondition for more details.
* \see getUpdateCondition
*/
boost::shared_ptr< WConditionSet > m_updateCondition;
private:
};
......
......@@ -209,7 +209,15 @@ public:
*
* \return the constraint created and added.
*/
boost::shared_ptr< PropertyConstraint > addConstraint( PROPERTYCONSTRAINT_TYPE constraint );
boost::shared_ptr< PropertyConstraint > addConstraint( PROPERTYCONSTRAINT_TYPE constraint );
/**
* Gets the condition, which gets notified whenever the list of constraints changes. It is notified AFTER the write lock has been released so
* a read lock can be acquired in the callback.
*
* \return the condition.
*/
boost::shared_ptr< WCondition > getContraintsChangedCondition();
/**
* Creates a new WPropertyConstraintMin for this WPropertyVariable.
......@@ -329,33 +337,54 @@ protected:
*/
void propertyChangeNotifier();
/**
* this condition gets notified whenever the list of constraints changes.
* \note it gets AFTER the write lock has been released. So in callbacks, a read lock can be acquired.
*/
boost::shared_ptr< WCondition > m_constraintsChanged;
private:
};
template < typename T >
WPropertyVariable< T >::WPropertyVariable( std::string name, std::string description, const T& initial ):
WFlag< T >( new WCondition(), initial ),
WPropertyBase( name, description )
WPropertyBase( name, description ),
m_constraintsChanged( new WCondition() )
{
updateType();
// set constraint and change condition to update condition set of WPropertyBase
m_updateCondition->add( m_constraintsChanged );
m_updateCondition->add( WFlag< T >::getValueChangeCondition() );
}
template < typename T >
WPropertyVariable< T >::WPropertyVariable( std::string name, std::string description, const T& initial, boost::shared_ptr< WCondition > condition ):
WFlag< T >( condition, initial ),
WPropertyBase( name, description )
WPropertyBase( name, description ),
m_constraintsChanged( new WCondition() )
{
updateType();
// set constraint and change condition to update condition set of WPropertyBase
m_updateCondition->add( m_constraintsChanged );
m_updateCondition->add( WFlag< T >::getValueChangeCondition() );
}
template < typename T >
WPropertyVariable< T >::WPropertyVariable( std::string name, std::string description, const T& initial,
PropertyChangeNotifierType notifier ):
WFlag< T >( new WCondition(), initial ),
WPropertyBase( name, description )
WPropertyBase( name, description ),
m_constraintsChanged( new WCondition() )
{
updateType();
// set constraint and change condition to update condition set of WPropertyBase
m_updateCondition->add( m_constraintsChanged );
m_updateCondition->add( WFlag< T >::getValueChangeCondition() );
// set custom notifier
WFlag< T >::getCondition()->subscribeSignal( boost::bind( &WPropertyVariable< T >::propertyChangeNotifier, this ) );
signal_PropertyChange.connect( notifier );
......@@ -365,10 +394,15 @@ template < typename T >
WPropertyVariable< T >::WPropertyVariable( std::string name, std::string description, const T& initial, boost::shared_ptr< WCondition > condition,
PropertyChangeNotifierType notifier ):
WFlag< T >( condition, initial ),
WPropertyBase( name, description )
WPropertyBase( name, description ),
m_constraintsChanged( new WCondition() )
{
updateType();
// set constraint and change condition to update condition set of WPropertyBase
m_updateCondition->add( m_constraintsChanged );
m_updateCondition->add( WFlag< T >::getValueChangeCondition() );
// set custom notifier
WFlag< T >::getCondition()->subscribeSignal( boost::bind( &WPropertyVariable< T >::propertyChangeNotifier, this ) );
signal_PropertyChange.connect( notifier );
......@@ -439,6 +473,7 @@ void WPropertyVariable< T >::addConstraint( boost::shared_ptr< PropertyConstrain
boost::unique_lock< boost::shared_mutex > lock = boost::unique_lock< boost::shared_mutex >( m_constraintsLock );
m_constraints.insert( constraint );
lock.unlock();
m_constraintsChanged->notify();
}
template < typename T >
......@@ -450,6 +485,12 @@ WPropertyVariable< T >::addConstraint( PROPERTYCONSTRAINT_TYPE constraint )
return c;
}
template < typename T >
boost::shared_ptr< WCondition > WPropertyVariable< T >::getContraintsChangedCondition()
{
return m_constraintsChanged;
}
template < typename T >
void WPropertyVariable< T >::updateType()
{
......@@ -477,6 +518,7 @@ boost::shared_ptr< WPropertyConstraintMin< T > > WPropertyVariable< T >::setMin(
boost::unique_lock< boost::shared_mutex > lock = boost::unique_lock< boost::shared_mutex >( m_constraintsLock );
m_constraints.insert( c );
lock.unlock();
m_constraintsChanged->notify();
return c;
}
......@@ -488,6 +530,7 @@ boost::shared_ptr< WPropertyConstraintMax< T > > WPropertyVariable< T >::setMax(
boost::unique_lock< boost::shared_mutex > lock = boost::unique_lock< boost::shared_mutex >( m_constraintsLock );
m_constraints.insert( c );
lock.unlock();
m_constraintsChanged->notify();
return c;
}
......@@ -577,6 +620,7 @@ void WPropertyVariable< T >::removeConstraints( PROPERTYCONSTRAINT_TYPE type )
}
}
lock.unlock();
m_constraintsChanged->notify();
}
template < typename T >
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment