ImFusion SDK 4.3
Selection Class Referencefinal

#include <ImFusion/Base/Selection.h>

Utility class for describing a selection of elements out of a set. More...

+ Inheritance diagram for Selection:

Detailed Description

Utility class for describing a selection of elements out of a set.

Conceptually, a Selection pairs a range of indices that are selected with the index of a "focus" item and provides syntactic sugar on top. For instance, the set of selected items could define which ones to show in general while the focus item is additionally highlighted. The class is fully separate from the item set of which it describes the selection. This means for instance that it cannot know the actual number of items in the set and the user/parent class must manually make sure that they match. Also, a Selection only manages indices and offers no way of accessing the underlying elements.

In order to iterate over all selected indices, you can do for instance the following:

for (int index = selection.firstSelected(); index < selection.lastSelected(); ++index) {
if (selection.isSelected(index)) {
...
}
}

The same effect can also be achieved in a much more terse fashion:

for (int index : selection.selectedIndices()) {
...
}

Sometimes it can be more convenient to "thin out" a selection by only selecting every N-th element. You can use the fromFirstLastSkip() or setFirstLastSkip() helper functions for defining such selections.

Public Types

enum class  NonePolicy { Empty , Focus , All }
 Enumeration to specify what elements of the set to consider if the Selection is none (cf. isNone()) More...
 

Public Member Functions

 Selection ()
 A default-constructed selection is empty.
 
bool operator== (const Selection &other) const
 Tells if two selections are equal.
 
bool operator!= (const Selection &other) const
 Tells if two selections are different.
 
void configure (const Properties *p) override
 Configure this object instance by de-serializing the given Properties.
 
void configuration (Properties *p) const override
 Serialize the current object configuration into the given Properties object.
 
- Public Member Functions inherited from Configurable
virtual void configureDefaults ()
 Retrieve the properties of this object, replaces values with their defaults and sets it again.
 
void registerParameter (ParameterBase *param)
 Register the given Parameter or SubProperty, so that it will be configured during configure()/configuration().
 
void unregisterParameter (const ParameterBase *param)
 Remove the given Parameter or SubProperty from the list of registered parameters.
 
 Configurable (const Configurable &rhs)
 
 Configurable (Configurable &&rhs) noexcept
 
Configurableoperator= (const Configurable &)
 
Configurableoperator= (Configurable &&) noexcept
 

Helper functions

static Selection fromFirstLastSkip (int first, int last, int skip)
 Creates a Selection with first/last/skip convention (cf. setFirstLastSkip()).
 
static Selection fromAll (int range)
 Creates a Selection where all indices in the range [0, range) are selected.
 

Setting the selection

void setNone ()
 Select nothing.
 
void setAll (int range)
 Select all indices in the range [0, range).
 
void clamp (int range)
 Clamp the range of selected indices and the focus item to [0, range).
 
void setSingle (int index)
 Select a single element, all other indices will not be considered selected.
 
void setFirstLastSkip (int first, int last, int skip)
 Set the first and the total range of the selection together with a skip of the selection.
 
void setSelected (int index, bool isSelected)
 Set selected status of an individual element.
 
void setFocus (int index)
 Define a single focus item in addition to the selection.
 

Querying the selection

bool isSelected (int index, NonePolicy noneHandling=NonePolicy::Empty) const
 Return if a particular item is selected.
 
std::vector< int > selectedIndices () const
 Returns all selected indices.
 
bool isNone () const
 Return if none is selected, cf. setNone()
 
int range () const
 Return the total number of elements considered in the selection (both selected and non-selected)
 
int size () const
 Return the number of selected elements.
 
int firstSelected () const
 Return first selected element ( or -1 if the selection is None).
 
int lastSelected () const
 Return last selected element ( or -1 if the selection is None).
 
bool hasRegularSkip () const
 Returns true if there is an equidistant step between each selected element.
 
int skip () const
 Returns the smallest increment - 1 such that each selected element is visited when iterating from firstSelected to lastSelected I.e.
 
int focus () const
 Return the focus item.
 

Additional Inherited Members

- Public Attributes inherited from Configurable
Signal signalParametersChanged
 Emitted whenever one of the registered Parameters' or SubPropertys' signalValueChanged signal was emitted.
 
- Protected Attributes inherited from Configurable
std::vector< Paramm_params
 List of all registered Parameter and SubProperty instances.
 

Member Enumeration Documentation

◆ NonePolicy

enum class NonePolicy
strong

Enumeration to specify what elements of the set to consider if the Selection is none (cf. isNone())

Enumerator
Empty 

Consider no images being selected.

Focus 

Consider only the focus image being selected.

All 

Consider all images being selected.

Member Function Documentation

◆ setFirstLastSkip()

void setFirstLastSkip ( int first,
int last,
int skip )

Set the first and the total range of the selection together with a skip of the selection.

Afterwards only every N-th index in the range [first, last] is selected where N = skip+1. If last is smaller than first, the selection will be None

◆ isSelected()

bool isSelected ( int index,
NonePolicy noneHandling = NonePolicy::Empty ) const

Return if a particular item is selected.

The user can provide a NonePolicy to specify the return value in the case isNone() is true.

◆ hasRegularSkip()

bool hasRegularSkip ( ) const

Returns true if there is an equidistant step between each selected element.

The skip can be retrieved via skip().

◆ skip()

int skip ( ) const

Returns the smallest increment - 1 such that each selected element is visited when iterating from firstSelected to lastSelected I.e.

if there is a equidistant skip between selected elements, this skip is returned. Otherwise the method returns 0.

◆ configure()

void configure ( const Properties * p)
overridevirtual

Configure this object instance by de-serializing the given Properties.

The default implementation will do so automatically for all registered Parameter and SubProperty instances.

See also
configuration() for the inverse functionality

Reimplemented from Configurable.

◆ configuration()

void configuration ( Properties * p) const
overridevirtual

Serialize the current object configuration into the given Properties object.

The default implementation will do so automatically for all registered Parameter and SubProperty instances.

See also
configure() for the inverse functionality

Reimplemented from Configurable.


The documentation for this class was generated from the following file:
Search Tab / S to search, Esc to close