LuciadCPillar 2023.1.04
luciad::FeatureStateManager Class Referenceabstract

Manages feature states. More...

#include <luciad/layers/features/FeatureStateManager.h>

Classes

class  Change
 This class is used to build feature state changes. More...
 

Public Member Functions

virtual ~FeatureStateManager ()=default
 
virtual void addObserver (std::shared_ptr< IFeatureStateObserver > observer, bool seedObserver=false)=0
 Adds an observer that allows to inspect feature state changes. More...
 
virtual void applyStateChange (const Change &featureStateChange)=0
 Applies the given state change. More...
 
virtual void clearEnabledStates (const LayerFeatureId &layerFeatureId)=0
 Clears (i.e. More...
 
virtual bool isStateEnabled (LayerFeatureId layerFeatureId, const FeatureState &featureState) const =0
 Checks if the given feature state is enabled for the given feature identifier. More...
 
virtual void removeObserver (const std::shared_ptr< IFeatureStateObserver > &observer)=0
 Removes the given observer. More...
 

Detailed Description

Manages feature states.

In essence, it keeps a mapping of enabled/disabled states for each feature for specific FeatureState instances. This class can for example manage which features are selected.

Example

// Create and add a selection observer that prints which feature is selected or deselected
auto selectionObserver = IFeatureStateObserver::create([](const FeatureStateEvent& changeEvent) {
for (auto changedFeature : changeEvent.getChangedFeatures(FeatureState::selected())) {
bool selected = changeEvent.getChange(FeatureState::selected(), changedFeature);
std::string selectedMessage = selected ? "Selected" : "Deselected";
std::cout << "Feature " << changedFeature.featureId << " => " << selectedMessage << std::endl;
}
});
featureStateManager->addObserver(selectionObserver);
// Apply a state change.
change->clearState(FeatureState::selected());
change->setState(feature1, FeatureState::selected(), true);
featureStateManager->applyStateChange(*change);
// Assuming that feature 2 was already selected before, the output will be:
// Feature 2 => Deselected
// Feature 1 => Selected
featureStateManager->removeObserver(selectionObserver);
This class is used by IFeatureStateObserver to pass information about FeatureState changes.
Definition: FeatureStateManager.h:19
std::vector< LayerFeatureId > getChangedFeatures(const FeatureState &featureState) const
Returns the list of features for which the given feature state has been changed.
static const FeatureState & selected()
A feature state representing an object that is selected.
static std::shared_ptr< FeatureStateManager::Change > create()
Returns a new, empty, FeatureStateManager::Change.
static std::shared_ptr< IFeatureStateObserver > create(std::function< void(const FeatureStateEvent &)> function)
Convenience method that can be used to construct a IFeatureStateObserver using a function (lambda).

Constructor & Destructor Documentation

◆ ~FeatureStateManager()

virtual luciad::FeatureStateManager::~FeatureStateManager ( )
virtualdefault

Member Function Documentation

◆ addObserver()

virtual void luciad::FeatureStateManager::addObserver ( std::shared_ptr< IFeatureStateObserver observer,
bool  seedObserver = false 
)
pure virtual

Adds an observer that allows to inspect feature state changes.

Note: this method should only be called on the UI thread

Parameters
observeran observer
seedObserverwhether to inform the observer about the features for which a FeatureState is currently enabled
Exceptions
InvalidArgumentExceptionif the observer is already added.
NullArgumentExceptionif observer is nullptr.

◆ applyStateChange()

virtual void luciad::FeatureStateManager::applyStateChange ( const Change featureStateChange)
pure virtual

Applies the given state change.

After this call, the FeatureStateManager::isStateEnabled method will reflect the given changes, and the registered observers will have been notified of the concrete changes for each feature.

Note: this method should only be called on the UI thread

Parameters
featureStateChangea feature state change

◆ clearEnabledStates()

virtual void luciad::FeatureStateManager::clearEnabledStates ( const LayerFeatureId layerFeatureId)
pure virtual

Clears (i.e.

sets to false) all enabled stated for the given feature.

Note: this method should only be called on the UI thread

Parameters
layerFeatureIdthe feature for which to clear all enabled states.

◆ isStateEnabled()

virtual bool luciad::FeatureStateManager::isStateEnabled ( LayerFeatureId  layerFeatureId,
const FeatureState featureState 
) const
pure virtual

Checks if the given feature state is enabled for the given feature identifier.

Note: this method can be called on any thread.

Parameters
layerFeatureIda feature identifier
featureStatea feature state
Returns
if the given feature state is enabled for the given feature identifier.

◆ removeObserver()

virtual void luciad::FeatureStateManager::removeObserver ( const std::shared_ptr< IFeatureStateObserver > &  observer)
pure virtual

Removes the given observer.

Note: this method should only be called on the UI thread

Parameters
observeran observer
Exceptions
InvalidArgumentExceptionif the observer was not added.
NullArgumentExceptionif observer is nullptr.