Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes

mitk::PropertyList Class Reference
[Data Management Classes]

Key-value list holding instances of BaseProperty. More...

#include <mitkPropertyList.h>

List of all members.

Public Types

typedef PropertyList Self
typedef itk::Object Superclass
typedef itk::SmartPointer< SelfPointer
typedef itk::SmartPointer
< const Self
ConstPointer
typedef std::map< std::string,
std::pair
< BaseProperty::Pointer, bool > > 
PropertyMap
typedef std::pair< std::string,
std::pair
< BaseProperty::Pointer, bool > > 
PropertyMapElementType

Public Member Functions

virtual const char * GetClassName () const
mitk::BasePropertyGetProperty (const std::string &propertyKey) const
 Get a property by its name.
void SetProperty (const std::string &propertyKey, BaseProperty *property)
 Set a property in the list/map by value.
void ReplaceProperty (const std::string &propertyKey, BaseProperty *property)
 Set a property object in the list/map by reference.
void ConcatenatePropertyList (PropertyList *pList, bool replace=false)
 Set a property object in the list/map by reference.
template<typename T >
bool GetPropertyValue (const char *propertyKey, T &value) const
 Convenience access method for GenericProperty<T> properties (T being the type of the second parameter)
bool GetBoolProperty (const char *propertyKey, bool &boolValue) const
 Convenience method to access the value of a BoolProperty.
void SetBoolProperty (const char *propertyKey, bool boolValue)
 Convenience method to set the value of a BoolProperty.
bool GetIntProperty (const char *propertyKey, int &intValue) const
 Convenience method to access the value of an IntProperty.
void SetIntProperty (const char *propertyKey, int intValue)
 Convenience method to set the value of an IntProperty.
bool GetFloatProperty (const char *propertyKey, float &floatValue) const
 Convenience method to access the value of a FloatProperty.
void SetFloatProperty (const char *propertyKey, float floatValue)
 Convenience method to set the value of a FloatProperty.
bool GetStringProperty (const char *propertyKey, std::string &stringValue) const
 Convenience method to access the value of a StringProperty.
void SetStringProperty (const char *propertyKey, const char *stringValue)
 Convenience method to set the value of a StringProperty.
virtual unsigned long GetMTime () const
 Get the timestamp of the last change of the map or the last change of one of the properties store in the list (whichever is later).
bool DeleteProperty (const std::string &propertyKey)
 Remove a property from the list/map.
const PropertyMapGetMap () const
bool IsEmpty () const
virtual Pointer Clone ()
virtual void Clear ()
virtual bool IsEnabled (const std::string &propertyKey)
virtual void SetEnabled (const std::string &propertyKey, bool enabled)

Static Public Member Functions

static Pointer New ()

Protected Member Functions

 PropertyList ()
virtual ~PropertyList ()

Protected Attributes

PropertyMap m_Properties
 Map of properties.

Detailed Description

Key-value list holding instances of BaseProperty.

This list is meant to hold an arbitrary list of "properties", which should describe the object associated with this list.

Usually you will use PropertyList as part of a DataNode object - in this context the properties describe the data object held by the DataNode (e.g. whether the object is rendered at all, which color is used for rendering, what name should be displayed for the object, etc.)

The values in the list are not fixed, you may introduce any kind of property that seems useful - all you have to do is inherit from BaseProperty.

The list is organized as a key-value pairs, i.e.

Please see the documentation of SetProperty and ReplaceProperty for two quite different semantics. Normally SetProperty is what you want - this method will try to change the value of an existing property and will not allow you to replace e.g. a ColorProperty with an IntProperty.

Definition at line 65 of file mitkPropertyList.h.


Member Typedef Documentation

typedef itk::SmartPointer<const Self> mitk::PropertyList::ConstPointer

Definition at line 70 of file mitkPropertyList.h.

typedef itk::SmartPointer<Self> mitk::PropertyList::Pointer

Definition at line 70 of file mitkPropertyList.h.

typedef std::map< std::string,std::pair<BaseProperty::Pointer,bool> > mitk::PropertyList::PropertyMap

Map structure to hold the properties: the map key is a string, the value consists of the actual property object (BaseProperty) and a bool flag (indicating whether a property is "enabled").

The "enabled" flag is there to "keep a property without showing it", i.e. GetProperty will not tell that there such a thing. Is there any real world use for this? (bug #1052)

Definition at line 75 of file mitkPropertyList.h.

typedef std::pair< std::string,std::pair<BaseProperty::Pointer,bool> > mitk::PropertyList::PropertyMapElementType

Definition at line 86 of file mitkPropertyList.h.

Definition at line 70 of file mitkPropertyList.h.

typedef itk::Object mitk::PropertyList::Superclass

Definition at line 70 of file mitkPropertyList.h.


Constructor & Destructor Documentation

mitk::PropertyList::PropertyList (  ) [protected]

Definition at line 119 of file mitkPropertyList.cpp.

{
}
mitk::PropertyList::~PropertyList (  ) [protected, virtual]

Definition at line 124 of file mitkPropertyList.cpp.

{
  Clear();
}

Member Function Documentation

void mitk::PropertyList::Clear (  ) [virtual]

Definition at line 182 of file mitkPropertyList.cpp.

Referenced by mitk::SceneReaderV1::DecorateNodeWithProperties().

{
  PropertyMap::iterator it = m_Properties.begin(), end = m_Properties.end();
  while(it!=end)
  {
    it->second.first = NULL;
    ++it;
  }
  m_Properties.clear();
}
mitk::PropertyList::Pointer mitk::PropertyList::Clone (  ) [virtual]

Definition at line 171 of file mitkPropertyList.cpp.

References New().

{
  mitk::PropertyList::Pointer newPropertyList = PropertyList::New();

  // copy the map
  newPropertyList->m_Properties = m_Properties;

  return newPropertyList.GetPointer();
}
void mitk::PropertyList::ConcatenatePropertyList ( PropertyList pList,
bool  replace = false 
)

Set a property object in the list/map by reference.

Definition at line 218 of file mitkPropertyList.cpp.

References GetMap().

{
  if (pList)
  {
    const PropertyMap* propertyMap = pList->GetMap();

    for ( PropertyMap::const_iterator iter = propertyMap->begin(); // m_PropertyList is created in the constructor, so we don't check it here
          iter != propertyMap->end();
          ++iter )
    {
      const std::string key = iter->first;
      BaseProperty* value = iter->second.first;
      if (replace)
      {
        ReplaceProperty( key.c_str(), value );
      }
      else
      {
        SetProperty( key.c_str(), value );
      }
    }
  }
}
bool mitk::PropertyList::DeleteProperty ( const std::string &  propertyKey )

Remove a property from the list/map.

Definition at line 155 of file mitkPropertyList.cpp.

{
  PropertyMap::iterator it;  
  it=m_Properties.find( propertyKey );

  if(it!=m_Properties.end())
  {
    it->second.first=NULL;
    m_Properties.erase(it);
    Modified();
    return true;
  }
  return false;
}
bool mitk::PropertyList::GetBoolProperty ( const char *  propertyKey,
bool &  boolValue 
) const

Convenience method to access the value of a BoolProperty.

Definition at line 242 of file mitkPropertyList.cpp.

References mitk::GenericProperty< T >::GetValue().

{
  BoolProperty *gp = dynamic_cast<BoolProperty*>( GetProperty(propertyKey) );
  if ( gp != NULL )
  {
    boolValue = gp->GetValue();
    return true;
  }
  return false;
  // Templated Method does not work on Macs
  //return GetPropertyValue<bool>(propertyKey, boolValue);
}
virtual const char* mitk::PropertyList::GetClassName (  ) const [virtual]
bool mitk::PropertyList::GetFloatProperty ( const char *  propertyKey,
float &  floatValue 
) const

Convenience method to access the value of a FloatProperty.

Definition at line 270 of file mitkPropertyList.cpp.

References mitk::GenericProperty< T >::GetValue().

{
  FloatProperty *gp = dynamic_cast<FloatProperty*>( GetProperty(propertyKey) );
  if ( gp != NULL )
  {
    floatValue = gp->GetValue();
    return true;
  }
  return false;
  // Templated Method does not work on Macs
  //return GetPropertyValue<float>(propertyKey, floatValue);
}
bool mitk::PropertyList::GetIntProperty ( const char *  propertyKey,
int &  intValue 
) const

Convenience method to access the value of an IntProperty.

Definition at line 256 of file mitkPropertyList.cpp.

References mitk::GenericProperty< T >::GetValue().

{
  IntProperty *gp = dynamic_cast<IntProperty*>( GetProperty(propertyKey) );
  if ( gp != NULL )
  {
    intValue = gp->GetValue();
    return true;
  }
  return false;
  // Templated Method does not work on Macs
  //return GetPropertyValue<int>(propertyKey, intValue);
}
const PropertyMap* mitk::PropertyList::GetMap (  ) const [inline]
unsigned long mitk::PropertyList::GetMTime (  ) const [virtual]

Get the timestamp of the last change of the map or the last change of one of the properties store in the list (whichever is later).

Consider the list as changed when any of the properties has changed recently.

Definition at line 133 of file mitkPropertyList.cpp.

Referenced by mitk::ImageMapperGL2D::Update().

{
  for ( PropertyMap::const_iterator it = m_Properties.begin() ;
        it != m_Properties.end();
        ++it )
  {
    if( it->second.first.IsNull() )
    {
      itkWarningMacro(<< "Property '" << it->first <<"' contains nothing (NULL).");
      continue;
    }
    if( Superclass::GetMTime() < it->second.first->GetMTime() )
    {
      Modified();
      break;
    }
  }
    
  return Superclass::GetMTime();
}
mitk::BaseProperty * mitk::PropertyList::GetProperty ( const std::string &  propertyKey ) const

Get a property by its name.

Definition at line 26 of file mitkPropertyList.cpp.

References m_Properties.

Referenced by mitk::NodePredicateProperty::CheckNode(), and mitk::PointSetGLMapper2D::Paint().

{
    PropertyMap::const_iterator it;
    
    it=m_Properties.find( propertyKey );
    if(it!=m_Properties.end() &&  it->second.second )
      return it->second.first;
    else 
        return NULL;
}
template<typename T >
bool mitk::PropertyList::GetPropertyValue ( const char *  propertyKey,
T &  value 
) const [inline]

Convenience access method for GenericProperty<T> properties (T being the type of the second parameter)

Returns:
true property was found

Definition at line 123 of file mitkPropertyList.h.

References mitk::GenericProperty< T >::GetValue().

Referenced by mitk::NavigationDataDisplacementFilter::SetParameters(), and mitk::CameraVisualization::SetParameters().

    {
      GenericProperty<T>* gp= dynamic_cast<GenericProperty<T>*>(GetProperty(propertyKey));
      if ( gp != NULL )
      {
        value = gp->GetValue();
        return true;
      }
      return false;
    }
bool mitk::PropertyList::GetStringProperty ( const char *  propertyKey,
std::string &  stringValue 
) const

Convenience method to access the value of a StringProperty.

Definition at line 284 of file mitkPropertyList.cpp.

References mitk::StringProperty::GetValue().

{
  StringProperty* sp= dynamic_cast<StringProperty*>(GetProperty(propertyKey));
  if ( sp != NULL )
  {
    stringValue = sp->GetValue();
    return true;
  }
  return false;
}
bool mitk::PropertyList::IsEmpty (  ) const [inline]

Definition at line 187 of file mitkPropertyList.h.

Referenced by mitk::SceneIO::SaveScene().

{ return m_Properties.empty(); }
bool mitk::PropertyList::IsEnabled ( const std::string &  propertyKey ) [virtual]

Definition at line 193 of file mitkPropertyList.cpp.

{
  PropertyMap::iterator it = m_Properties.find( propertyKey );
  if (it != m_Properties.end() && it->second.second) 
  {
   return true;
  } 
  else 
  {
    return false;
  }
}
static Pointer mitk::PropertyList::New (  ) [static]
void mitk::PropertyList::ReplaceProperty ( const std::string &  propertyKey,
BaseProperty property 
)

Set a property object in the list/map by reference.

The actual OBJECT holding the value of the property is replaced by this function. This is useful if you want to change the type of the property, like from BoolProperty to StringProperty. Another use is to share one and the same property object among several ProperyList/DataNode objects, which makes them appear synchronized.

Definition at line 97 of file mitkPropertyList.cpp.

{
  if (!property) return;

  PropertyMap::iterator it( m_Properties.find( propertyKey ) );
  
  // Is a property with key @a propertyKey contained in the list?
  if( it != m_Properties.end() )
  {
    it->second.first=NULL;
    m_Properties.erase(it);
  }

  //no? add/replace it.
  PropertyMapElementType newProp;
  newProp.first = propertyKey;
  newProp.second = std::pair<BaseProperty::Pointer,bool>(property,true);
  m_Properties.insert ( newProp );
  Modified();
}
void mitk::PropertyList::SetBoolProperty ( const char *  propertyKey,
bool  boolValue 
)

Convenience method to set the value of a BoolProperty.

Definition at line 302 of file mitkPropertyList.cpp.

References mitk::BoolProperty::New().

{
  SetProperty(propertyKey, mitk::BoolProperty::New(boolValue));
}
void mitk::PropertyList::SetEnabled ( const std::string &  propertyKey,
bool  enabled 
) [virtual]

Definition at line 207 of file mitkPropertyList.cpp.

{
  PropertyMap::iterator it = m_Properties.find( propertyKey );
  if (it != m_Properties.end() && it->second.second != enabled) 
  {
    it->second.second = enabled;
    this->Modified();
  }
}
void mitk::PropertyList::SetFloatProperty ( const char *  propertyKey,
float  floatValue 
)

Convenience method to set the value of a FloatProperty.

Definition at line 308 of file mitkPropertyList.cpp.

References mitk::FloatProperty::New().

{
  SetProperty(propertyKey, mitk::FloatProperty::New(floatValue));
}
void mitk::PropertyList::SetIntProperty ( const char *  propertyKey,
int  intValue 
)

Convenience method to set the value of an IntProperty.

Definition at line 296 of file mitkPropertyList.cpp.

References mitk::IntProperty::New().

{
  SetProperty(propertyKey, mitk::IntProperty::New(intValue));
}
void mitk::PropertyList::SetProperty ( const std::string &  propertyKey,
BaseProperty property 
)

Set a property in the list/map by value.

The actual OBJECT holding the value of the property is not replaced, but its value is modified to match that of property. To really replace the object holding the property - which would make sense if you want to change the type (bool, string) of the property

  • call ReplaceProperty.

Definition at line 38 of file mitkPropertyList.cpp.

References MITK_ERROR.

Referenced by QmitkBSplineRegistrationView::CalculateTransformation().

{
  if (!property) return;
  //make sure that BaseProperty*, which may have just been created and never been 
  //assigned to a SmartPointer, is registered/unregistered properly. If we do not
  //do that, it will a) not deleted in case it is identical to the old one or
  //b) possibly deleted when temporarily added to a smartpointer somewhere below.
  BaseProperty::Pointer tmpSmartPointerToProperty = property;

  PropertyMap::iterator it( m_Properties.find( propertyKey ) );
  
  // Is a property with key @a propertyKey contained in the list?
  if( it != m_Properties.end() )
  {
    // yes
    //is the property contained in the list identical to the new one?
    if( it->second.first == property) 
    {
      // yes? do nothing and return.
      return;
    }

    // compatible? then use operator= to assign value
    if (it->second.first->Assignable( *property ))
    {
      bool changed = (it->second.first->GetValueAsString() != property->GetValueAsString());
      *(static_cast<BaseProperty*>(it->second.first.GetPointer())) = *property;
      // muellerm,20.10: added modified event
      if(changed)
        this->Modified();
      return;
    }
    
    if ( typeid( *(it->second.first.GetPointer()) ) != typeid( *property ) )
    {
      // Accept only if the two types are matching. For replacing, use 
      // ReplaceProperty.
      MITK_ERROR << "In " __FILE__ ", l." << __LINE__ 
        << ": Trying to set existing property to a property with different type." 
        << " Use ReplaceProperty() instead."
        << std::endl;
      return;
    }

    // If types are identical, but the property has no operator= (s.a.),
    // overwrite the pointer.
    it->second.first = property;
    return;
  }

  //no? add/replace it.
  PropertyMapElementType newProp;
  newProp.first = propertyKey;
  newProp.second = std::pair<BaseProperty::Pointer,bool>(property,true);
  m_Properties.insert ( newProp );
  this->Modified();
}
void mitk::PropertyList::SetStringProperty ( const char *  propertyKey,
const char *  stringValue 
)

Convenience method to set the value of a StringProperty.

Definition at line 314 of file mitkPropertyList.cpp.

References mitk::StringProperty::New().

{
  SetProperty(propertyKey, mitk::StringProperty::New(stringValue));
}

Member Data Documentation

Map of properties.

Definition at line 207 of file mitkPropertyList.h.

Referenced by GetProperty().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines