Inviwo 0.9.12-pre
Inviwo documentation
Loading...
Searching...
No Matches
inviwo::OptionProperty< T > Class Template Reference

#include <inviwo/core/properties/optionproperty.h>

+ Inheritance diagram for inviwo::OptionProperty< T >:

Public Types

using value_type = T
 

Public Member Functions

OptionPropertyaddOption (std::string_view identifier, std::string_view displayName)
 
OptionPropertyaddOption (std::string_view identifier, std::string_view displayName, const T &value)
 Adds an option to the property.
 
OptionPropertyaddOption (std::string_view identifier, std::string_view displayName, std::string_view value)
 
OptionPropertyaddOption (T value)
 
virtual OptionPropertyclearOptions () override
 
virtual OptionProperty< T > * clone () const override
 
virtual void deserialize (Deserializer &d) override
 
const T & get () const
 
virtual std::string_view getClassIdentifier () const override
 
virtual std::string_view getClassIdentifierForWidget () const override
 Returns which property's widget should be used when the WidgetFactory tries to create a widget. Defaults to getClassIdentifier(), should only be overridden if a subclass want to reuse another property's widget.
 
virtual Document getDescription () const override
 
virtual std::vector< std::string > getDisplayNames () const override
 
virtual std::vector< std::string > getIdentifiers () const override
 
virtual const std::string & getOptionDisplayName (size_t index) const override
 
virtual const std::string & getOptionIdentifier (size_t index) const override
 
const std::vector< OptionPropertyOption< T > > & getOptions () const
 
const OptionPropertyOption< T > & getOptions (size_t index) const
 
const T & getOptionValue (size_t index) const
 
virtual const std::string & getSelectedDisplayName () const override
 
virtual const std::string & getSelectedIdentifier () const override
 
virtual size_t getSelectedIndex () const override
 
const T & getSelectedValue () const
 
std::vector< T > getValues () const
 
virtual bool isDefaultState () const override
 
virtual bool isSelectedDisplayName (std::string_view name) const override
 
virtual bool isSelectedIdentifier (std::string_view identifier) const override
 
virtual bool isSelectedIndex (size_t index) const override
 
bool isSelectedValue (const T &val) const
 
 operator const T & () const
 
 operator std::string_view () const
 
const T & operator* () const
 
const T * operator-> () const
 
 OptionProperty (const OptionProperty< T > &rhs)
 
 OptionProperty (std::string_view identifier, std::string_view displayName, const std::vector< OptionPropertyOption< T > > &options, size_t selectedIndex=0, InvalidationLevel invalidationLevel=InvalidationLevel::InvalidOutput, PropertySemantics semantics=PropertySemantics::Default)
 
template<typename U = T>
requires (fmt::is_formattable<U>::value || util::is_stream_insertable<U>::value)
 OptionProperty (std::string_view identifier, std::string_view displayName, const std::vector< U > &options, size_t selectedIndex=0, InvalidationLevel invalidationLevel=InvalidationLevel::InvalidOutput, PropertySemantics semantics=PropertySemantics::Default)
 
 OptionProperty (std::string_view identifier, std::string_view displayName, Document help, const std::vector< OptionPropertyOption< T > > &options, size_t selectedIndex=0, InvalidationLevel invalidationLevel=InvalidationLevel::InvalidOutput, PropertySemantics semantics=PropertySemantics::Default)
 
template<typename U = T>
requires (fmt::is_formattable<U>::value || util::is_stream_insertable<U>::value)
 OptionProperty (std::string_view identifier, std::string_view displayName, Document help, const std::vector< T > &options, size_t selectedIndex=0, InvalidationLevel invalidationLevel=InvalidationLevel::InvalidOutput, PropertySemantics semantics=PropertySemantics::Default)
 
 OptionProperty (std::string_view identifier, std::string_view displayName, Document help, InvalidationLevel invalidationLevel=InvalidationLevel::InvalidOutput, PropertySemantics semantics=PropertySemantics::Default)
 
 OptionProperty (std::string_view identifier, std::string_view displayName, InvalidationLevel invalidationLevel=InvalidationLevel::InvalidOutput, PropertySemantics semantics=PropertySemantics::Default)
 
 OptionProperty (std::string_view identifier, std::string_view displayName, OptionPropertyState< T > state)
 
virtual OptionPropertyremoveOption (size_t index)
 
virtual OptionPropertyremoveOption (std::string_view identifier)
 
virtual OptionPropertyreplaceOptions (const std::vector< std::string > &ids, const std::vector< std::string > &displayNames, const std::vector< T > &values)
 
OptionPropertyreplaceOptions (const std::vector< T > &values)
 
virtual OptionPropertyreplaceOptions (std::vector< OptionPropertyOption< T > > options)
 
virtual OptionPropertyresetToDefaultState () override
 
virtual void serialize (Serializer &s) const override
 
void set (const OptionProperty *srcProperty)
 
virtual void set (const Property *srcProperty) override
 
bool set (const T &value)
 Set the selected index to that of the value provided if found in the list of options.
 
template<typename U = T, class = std::enable_if_t<std::is_same_v<U, std::string>, void>>
bool set (std::string_view value)
 Set the selected index to that of the value provided if found in the list of options.
 
virtual OptionPropertysetCurrentStateAsDefault () override
 
OptionProperty< T > & setDefault (const T &value)
 
OptionProperty< T > & setDefaultSelectedIndex (size_t index)
 
virtual bool setSelectedDisplayName (std::string_view name) override
 
virtual bool setSelectedIdentifier (std::string_view identifier) override
 
virtual bool setSelectedIndex (size_t index) override
 
bool setSelectedValue (const T &val)
 Set the selected index to that of the value provided if found in the list of options.
 
bool setSelectedValue (std::string_view value)
 Set the selected index to that of the value provided if found in the list of options.
 
virtual size_t size () const override
 
template<typename Func >
requires (std::is_invocable_r_v<bool, Func, std::vector<OptionPropertyOption<T>>&>)
OptionPropertyupdateOptions (Func &&updater)
 
template<typename Func >
requires (std::is_invocable_r_v<bool, Func, std::vector<OptionPropertyOption<T>>&>)
OptionProperty< T > & updateOptions (Func &&updater)
 
- Public Member Functions inherited from inviwo::BaseOptionProperty
 BaseOptionProperty (const BaseOptionProperty &rhs)
 
 BaseOptionProperty (std::string_view identifier, std::string_view displayName, Document help, InvalidationLevel invalidationLevel=InvalidationLevel::InvalidOutput, PropertySemantics semantics=PropertySemantics::Default)
 
bool empty () const
 
void set (const BaseOptionProperty *srcProperty)
 
- Public Member Functions inherited from inviwo::Property
virtual void accept (NetworkVisitor &visitor)
 Accept a NetworkVisitor, the visitor will visit this Property.
 
template<typename P >
PropertyautoLinkToProperty (std::string_view propertyPath)
 
void clearInitiatingWidget ()
 
void deregisterWidget (PropertyWidget *propertyWidget)
 
const std::vector< std::pair< std::string, std::string > > & getAutoLinkToProperty () const
 
virtual std::string_view getDisplayName () const
 
DocumentgetHelp ()
 
const DocumentgetHelp () const
 
virtual std::string_view getIdentifier () const
 
virtual InvalidationLevel getInvalidationLevel () const
 
PropertyOwnergetOwner ()
 
const PropertyOwnergetOwner () const
 
std::string_view getPath () const
 Get the property path as string.
 
void getPath (std::pmr::string &out) const
 
virtual bool getReadOnly () const
 
virtual PropertySemantics getSemantics () const
 
virtual PropertySerializationMode getSerializationMode () const
 
virtual bool getVisible () const
 
const std::vector< PropertyWidget * > & getWidgets () const
 
bool hasWidgets () const
 
virtual bool isModified () const
 
virtual bool needsSerialization () const
 
const BaseCallBack * onChange (std::function< void()> callback)
 
std::shared_ptr< std::function< void()> > onChangeScoped (std::function< void()> callback)
 
 Property (std::string_view identifier, std::string_view displayName, InvalidationLevel invalidationLevel, PropertySemantics semantics=PropertySemantics::Default)
 
 Property (std::string_view identifier="", std::string_view displayName="", Document help={}, InvalidationLevel invalidationLevel=InvalidationLevel::InvalidOutput, PropertySemantics semantics=PropertySemantics::Default, ReadOnly readOnly=ReadOnly::No)
 
virtual PropertypropertyModified ()
 
template<typename P , typename DecisionFunc >
PropertyreadonlyDependsOn (P &prop, DecisionFunc callback)
 
void registerWidget (PropertyWidget *propertyWidget)
 
void removeOnChange (const BaseCallBack *callback)
 
virtual PropertysetDisplayName (std::string_view displayName)
 A property's name displayed to the user.
 
PropertysetHelp (Document help)
 
virtual PropertysetIdentifier (std::string_view identifier)
 
void setInitiatingWidget (PropertyWidget *propertyWidget)
 
virtual PropertysetInvalidationLevel (InvalidationLevel invalidationLevel)
 
virtual PropertysetModified ()
 
virtual void setOwner (PropertyOwner *owner)
 
virtual PropertysetReadOnly (bool value)
 Enable or disable editing of property.
 
virtual PropertysetSemantics (const PropertySemantics &semantics)
 
virtual PropertysetSerializationMode (PropertySerializationMode mode)
 
virtual void setValid ()
 
virtual PropertysetVisible (bool val)
 
void updateWidgets ()
 
template<typename P , typename DecisionFunc >
PropertyvisibilityDependsOn (P &prop, DecisionFunc callback)
 
virtual ~Property ()
 Removes itself from its PropertyOwner.
 
- Public Member Functions inherited from inviwo::Observable< PropertyObserver >
void addObserver (PropertyObserver *observer)
 
bool isObservedBy (PropertyObserver *observer) const
 
 Observable (const Observable< PropertyObserver > &other)
 
 Observable (Observable< PropertyObserver > &&other) noexcept
 
Observable< PropertyObserver > & operator= (const Observable< PropertyObserver > &other)
 
Observable< PropertyObserver > & operator= (Observable< PropertyObserver > &&other) noexcept
 
void removeObserver (PropertyObserver *observer)
 
virtual void startBlockingNotifications () override final
 
virtual void stopBlockingNotifications () override final
 
- Public Member Functions inherited from inviwo::MetaDataOwner
void copyMetaDataFrom (const MetaDataOwner &src)
 
void copyMetaDataTo (MetaDataOwner &dst)
 
template<typename T >
requires std::derived_from<T, MetaData>
T * createMetaData (std::string_view key)
 
void deserialize (Deserializer &d)
 
template<typename T >
requires std::derived_from<T, MetaData>
T * getMetaData (std::string_view key)
 
template<typename T >
requires std::derived_from<T, MetaData>
const T * getMetaData (std::string_view key) const
 
template<typename T , typename U >
requires std::derived_from<T, MetaData> && Gettable<T, U>
getMetaData (std::string_view key, U val) const
 
MetaDataMapgetMetaDataMap ()
 
const MetaDataMapgetMetaDataMap () const
 
bool hasMetaData (std::string_view key) const
 
template<typename T >
requires std::derived_from<T, MetaData>
bool hasMetaData (std::string_view key) const
 
 MetaDataOwner (const MetaDataOwner &rhs)=default
 
 MetaDataOwner (MetaDataOwner &rhs)=default
 
MetaDataOwneroperator= (const MetaDataOwner &rhs)=default
 
MetaDataOwneroperator= (MetaDataOwner &)=default
 
void serialize (Serializer &s) const
 
template<typename T , typename U >
requires std::derived_from<T, MetaData> && Settable<T, U>
void setMetaData (std::string_view key, U value)
 
template<typename T >
requires std::derived_from<T, MetaData>
bool unsetMetaData (std::string_view key)
 unset, i.e. remove the metadata entry matching the given key and type
 

Protected Member Functions

std::optional< size_t > findId (std::string_view id)
 
const OptionPropertyOption< T > & opt (size_t index) const
 
const std::vector< OptionPropertyOption< T > > & opts () const
 
std::vector< OptionPropertyOption< T > > & optsMut ()
 
- Protected Member Functions inherited from inviwo::Property
void notifyAboutChange ()
 
Propertyoperator= (const Property &that)=delete
 
Propertyoperator= (Property &&that)
 
 Property (const Property &rhs)
 
 Property (Property &&rhs)
 
- Protected Member Functions inherited from inviwo::PropertyObservable
void notifyObserversOnSetDisplayName (Property *property, const std::string &displayName)
 
void notifyObserversOnSetIdentifier (Property *property, const std::string &identifier)
 
void notifyObserversOnSetReadOnly (Property *property, bool readonly)
 
void notifyObserversOnSetSemantics (Property *property, const PropertySemantics &semantics)
 
void notifyObserversOnSetVisible (Property *property, bool visible)
 
- Protected Member Functions inherited from inviwo::Observable< PropertyObserver >
void forEachObserver (C callback)
 
- Protected Member Functions inherited from inviwo::ObservableInterface
void addObservationHelper (Observer *observer)
 
void removeObservationHelper (Observer *observer)
 

Protected Attributes

size_t selectedIndex_ {}
 
- Protected Attributes inherited from inviwo::Property
CallBackList onChangeCallback_
 
PropertySerializationMode serializationMode_
 
- Protected Attributes inherited from inviwo::MetaDataOwner
MetaDataMap metaData_
 

Additional Inherited Members

- Static Public Member Functions inherited from inviwo::Property
template<typename T , typename U >
static void setStateAsDefault (T &property, const U &state)
 

Detailed Description

template<typename T>
class inviwo::OptionProperty< T >

OptionProperty with a custom type T.

For dynamic template option properties, T needs to have some traits defining the class identifier. Default identifiers are provided for the standard types defined in defaultvalues.h. If the template parameter T is a custom enum class, there needs to be a EnumTraits<T> struct defining the name of the enum. This enum name then becomes part of the property identifier.

#include <inviwo/core/util/enumtraits.h>
enum class MyEnum { Value1, Value2, Value3 };
template <>
struct EnumTraits<MyEnum> {
static std::string_view name() { return "MyEnum"; }
};
registerProperty<OptionProperty<MyEnum>>();
Definition enumtraits.h:40

For other data types, the class identifier must be provided using PropertyTraits.

template <>
static constexpr std::string_view classIdentifier() {
return "org.inviwo.OptionPropertyMyType";
}
};
Definition optionproperty.h:204
STL namespace.
A traits class for getting the class identifier from a Property. This provides a customization point ...
Definition property.h:72
Template Parameters
Tinternal value type of the option property
See also
defaultvalues.h enumtraits.h propertytraits.h

Member Function Documentation

◆ addOption()

template<typename T >
OptionProperty< T > & inviwo::OptionProperty< T >::addOption ( std::string_view identifier,
std::string_view displayName,
const T & value )

Adds an option to the property.

Adds a option to the property and stores it as a struct in the options_ The option name is the name of the option that will be displayed in the widget.

◆ clearOptions()

template<typename T >
OptionProperty< T > & inviwo::OptionProperty< T >::clearOptions ( )
overridevirtual

◆ clone()

template<typename T >
OptionProperty< T > * inviwo::OptionProperty< T >::clone ( ) const
overridevirtual

Creates a clone of this property. The clone will have the same identifier, hence the identifier must be changed if the clone should be added to the same owner as this. The new clone does not have any owner set.

Implements inviwo::Property.

Reimplemented in inviwo::ColumnOptionProperty, and inviwo::FontFaceOptionProperty.

◆ deserialize()

template<typename T >
void inviwo::OptionProperty< T >::deserialize ( Deserializer & d)
overridevirtual

Reimplemented from inviwo::Property.

◆ getClassIdentifier()

template<typename T >
std::string_view inviwo::OptionProperty< T >::getClassIdentifier ( ) const
overridevirtual

◆ getClassIdentifierForWidget()

template<typename T >
std::string_view inviwo::OptionProperty< T >::getClassIdentifierForWidget ( ) const
overridevirtual

Returns which property's widget should be used when the WidgetFactory tries to create a widget. Defaults to getClassIdentifier(), should only be overridden if a subclass want to reuse another property's widget.

Reimplemented from inviwo::Property.

◆ getDescription()

template<typename T >
Document inviwo::OptionProperty< T >::getDescription ( ) const
overridevirtual

This function should describe the state of the property By default this will return a document describing all the state. i.e. Identifier, DisplayName, Help, InvalidationLevel, PropertySemantics, etc. Derived properties should extend this function and add their state, usually values etc. The description is usually shown as a tooltip in the GUI.

Reimplemented from inviwo::Property.

◆ getDisplayNames()

template<typename T >
std::vector< std::string > inviwo::OptionProperty< T >::getDisplayNames ( ) const
overridevirtual

◆ getIdentifiers()

template<typename T >
std::vector< std::string > inviwo::OptionProperty< T >::getIdentifiers ( ) const
overridevirtual

◆ getOptionDisplayName()

template<typename T >
const std::string & inviwo::OptionProperty< T >::getOptionDisplayName ( size_t index) const
overridevirtual

◆ getOptionIdentifier()

template<typename T >
const std::string & inviwo::OptionProperty< T >::getOptionIdentifier ( size_t index) const
overridevirtual

◆ getSelectedDisplayName()

template<typename T >
const std::string & inviwo::OptionProperty< T >::getSelectedDisplayName ( ) const
overridevirtual

◆ getSelectedIdentifier()

template<typename T >
const std::string & inviwo::OptionProperty< T >::getSelectedIdentifier ( ) const
overridevirtual

◆ getSelectedIndex()

template<typename T >
size_t inviwo::OptionProperty< T >::getSelectedIndex ( ) const
overridevirtual

◆ isDefaultState()

template<typename T >
bool inviwo::OptionProperty< T >::isDefaultState ( ) const
overridevirtual

Check if the property is in it's default state, i.e. resetToDefaultState would do nothing

See also
setCurrentStateAsDefault
resetToDefaultState

Reimplemented from inviwo::Property.

◆ isSelectedDisplayName()

template<typename T >
bool inviwo::OptionProperty< T >::isSelectedDisplayName ( std::string_view name) const
overridevirtual

◆ isSelectedIdentifier()

template<typename T >
bool inviwo::OptionProperty< T >::isSelectedIdentifier ( std::string_view identifier) const
overridevirtual

◆ isSelectedIndex()

template<typename T >
bool inviwo::OptionProperty< T >::isSelectedIndex ( size_t index) const
overridevirtual

◆ operator const T &()

template<typename T >
inviwo::OptionProperty< T >::operator const T & ( ) const

Implicit conversion operator. The OptionProperty will implicitly be converted to T when possible.

◆ resetToDefaultState()

template<typename T >
OptionProperty< T > & inviwo::OptionProperty< T >::resetToDefaultState ( )
overridevirtual

Reset the state of the property back to it's default value. It is important that all overriding properties make sure to call the base class implementation.

Reimplemented from inviwo::Property.

◆ serialize()

template<typename T >
void inviwo::OptionProperty< T >::serialize ( Serializer & s) const
overridevirtual

Reimplemented from inviwo::Property.

◆ set() [1/3]

template<typename T >
void inviwo::OptionProperty< T >::set ( const Property * src)
overridevirtual

Set the value of this to that of src. The "value" is in this case considered to be for example the string in a StringProperty or the float value in a FloatProperty. But not things like the identifier of display name.

Reimplemented from inviwo::BaseOptionProperty.

Reimplemented in inviwo::ColumnOptionProperty.

◆ set() [2/3]

template<typename T >
bool inviwo::OptionProperty< T >::set ( const T & value)

Set the selected index to that of the value provided if found in the list of options.

Parameters
valueto set
Returns
True if the value was found in the list of options else false.

◆ set() [3/3]

template<typename T >
template<typename U , class >
bool inviwo::OptionProperty< T >::set ( std::string_view value)

Set the selected index to that of the value provided if found in the list of options.

Parameters
valueto set
Returns
True if the value was found in the list of options else false.

◆ setCurrentStateAsDefault()

template<typename T >
OptionProperty< T > & inviwo::OptionProperty< T >::setCurrentStateAsDefault ( )
overridevirtual

Sets the default state, since the constructor can't add any default state, you must call this function after adding all the default options, usually in the processor constructor.

See also
Property::setCurrentStateAsDefault()

Reimplemented from inviwo::Property.

◆ setSelectedDisplayName()

template<typename T >
bool inviwo::OptionProperty< T >::setSelectedDisplayName ( std::string_view name)
overridevirtual

◆ setSelectedIdentifier()

template<typename T >
bool inviwo::OptionProperty< T >::setSelectedIdentifier ( std::string_view identifier)
overridevirtual

◆ setSelectedIndex()

template<typename T >
bool inviwo::OptionProperty< T >::setSelectedIndex ( size_t index)
overridevirtual

◆ setSelectedValue() [1/2]

template<typename T >
bool inviwo::OptionProperty< T >::setSelectedValue ( const T & val)

Set the selected index to that of the value provided if found in the list of options.

Parameters
valto set
Returns
True if the value was found in the list of options else false.

◆ setSelectedValue() [2/2]

template<typename T >
requires std::is_same_v<T, std::string>
bool inviwo::OptionProperty< T >::setSelectedValue ( std::string_view value)

Set the selected index to that of the value provided if found in the list of options.

Parameters
valueto set
Returns
True if the value was found in the list of options else false.

◆ size()

template<typename T >
size_t inviwo::OptionProperty< T >::size ( ) const
overridevirtual

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