MT Showcase SDK
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
Showcase::UIComponent Class Reference

This is a base class for components that provide UI functionality. More...

#include <UIComponent.hpp>

Inheritance diagram for Showcase::UIComponent:
Showcase::Component Showcase::OperatorComponent Showcase::ScheduleComponent Showcase::WidgetComponent Showcase::CustomWidgetInstanceComponent

Public Member Functions

 UIComponent (CachedGraphPtr uiGraph=nullptr)
 Create a new UIComponent. More...
 
std::vector< std::shared_ptr
< UIComponent > > 
assignments (const QByteArray &slot) const
 List of components assigned to slot. More...
 
const Slots & componentSlots () const
 Slots of this component. More...
 
const std::unordered_set
< QByteArray > & 
roles () const
 Roles that this component will implement. More...
 
QByteArray subtype () const
 The subtype of this component. More...
 
UIComponentInstancePtr createInstance (const QByteArray &role)
 Create a new instance of this component with the given role. More...
 
void assignToSlot (const QByteArray &slotName, std::shared_ptr< UIComponent > comp)
 Add the given component to this component's slot. More...
 
void componentAddedToSlot (const QByteArray &slotName, std::shared_ptr< UIComponent > comp)
 Callback, that is called when one of the child components has finished. More...
 
void componentRemovedFromSlot (const QByteArray &slotName, std::shared_ptr< UIComponent > comp)
 Callback, that is called when one of the child components has been removed. More...
 
bool slotsFulfilled (const std::unique_lock< std::mutex > &lock=std::unique_lock< std::mutex >()) const
 Checks if the component is ready to be instanced (it has all the slots in place) More...
 
void setOnSlotsFulfilled (std::function< void(void)> &&f)
 Set component to execute lambda when slots are fulfilled. More...
 
void setOnSlotsUnfulfilled (std::function< void(void)> &&f)
 Set component to execute lambda when slots were previously fulfilled and become unfulfilled. More...
 
void removeFromSlots (const NodeId &id)
 Remove all instances of the given node id from this component's slots. More...
 
void initializeContentSlot (const Slot &slot, const Property &property)
 Initialize a new content slot. More...
 
void removeContentSlot (const Slot &slot)
 Remove content from given slot. More...
 
bool enabled () const
 Components are enabled by default, but they can be disabled in certain circumstances. More...
 
void setEnabled (bool enabled)
 Set component enabled or disabled. More...
 
- Public Member Functions inherited from Showcase::Component
 Component (CachedGraphPtr uiGraph=nullptr)
 Create a new component. More...
 
void setCachedGraph (CachedGraphPtr uiGraph)
 Showcase nodes are stored in cached graphs. More...
 
void init (const GraphNode &confNode)
 Initializes the component and links it to the given graph node. More...
 
const QString & name () const
 Each component has a unique name that identifies it. More...
 
void setComponentName (const QString &name)
 Set a new name for this coomponent. More...
 
void setSchema (const Schema &schema)
 Schema holds the definition of the component. More...
 
const Schemaschema () const
 Get the schema of this component. More...
 
ComponentInstancePtr createInstance ()
 A single component can have multiple instances, each instance behaves independently from one another, but is tied to the creator component. More...
 
void instanceDestroyed (ComponentInstanceKey key)
 Component keeps track of its instances, and must be notified when an instance is destroyed. More...
 
size_t numInstances () const
 Returns the current number of alive instances created from this component. More...
 
CachedGraphPtr cachedGraph () const
 Returns the cached graph that this component is part of. More...
 
CachedNodePtr cachedNode () const
 Returns the cached graph node that links to this component. More...
 
const NodeIdnodeId () const
 Returns the node id of this component's cached node. More...
 
const std::list
< ComponentInstancePtr > & 
instances () const
 Returns all current instances of this component. More...
 

Protected Member Functions

bool acceptContentProperty (const PropertyKey &key) const
 Filters non relevant content properties away.
 
virtual void placeholderStatusChanged (const NodeId &id) override
 
virtual void propertyReceived (const Property &property) override
 Need to override because some 'slots' (content), may hide in attributes. More...
 
virtual void contentNodeReceivedProperty (std::shared_ptr< ContentNode > node, const Property &prop, bool eventWasPending=false)
 These just passes the correspongind callbacks to instances. More...
 
virtual void contentNodeLostProperty (std::shared_ptr< ContentNode > node, const Property &prop, bool eventWasPending=false)
 
virtual void contentNodeFound (std::shared_ptr< ContentNode > node, std::shared_ptr< ContentNode > parent=nullptr, bool eventWasPending=false)
 These just passes the correspongind callbacks to instances, When this is called, it must be that found node is 'complete'. More...
 
virtual void contentNodeLost (std::shared_ptr< ContentNode > node, std::shared_ptr< ContentNode > parent=nullptr, bool eventWasPending=false)
 
- Protected Member Functions inherited from Showcase::Component
void applyForInstances (std::function< void(ComponentInstancePtr)> &&f)
 Calls f for each instance.
 

Detailed Description

This is a base class for components that provide UI functionality.

Constructor & Destructor Documentation

Showcase::UIComponent::UIComponent ( CachedGraphPtr  uiGraph = nullptr)

Create a new UIComponent.

Parameters
uiGraphthe cached graph for the component

Member Function Documentation

std::vector< UIComponentPtr > Showcase::UIComponent::assignments ( const QByteArray &  slot) const

List of components assigned to slot.

Parameters
slotname of the slot
Returns
all components assigned to the given slot
void Showcase::UIComponent::assignToSlot ( const QByteArray &  slotName,
std::shared_ptr< UIComponent comp 
)

Add the given component to this component's slot.

Parameters
slotNamename of the slot
compcomponent to add

Error! what to do?

void Showcase::UIComponent::componentAddedToSlot ( const QByteArray &  slotName,
std::shared_ptr< UIComponent comp 
)

Callback, that is called when one of the child components has finished.

By default just propagates event to instances

Parameters
slotNamename of the slot
compcomponent that was added
void Showcase::UIComponent::componentRemovedFromSlot ( const QByteArray &  slotName,
std::shared_ptr< UIComponent comp 
)

Callback, that is called when one of the child components has been removed.

By default just propagates event to instances

Parameters
slotNamename of the slot
compcomponent that was removed
const Slots & Showcase::UIComponent::componentSlots ( ) const

Slots of this component.

This will specify what roles this component will accept.

Returns
slots of the component
void Showcase::UIComponent::contentNodeFound ( std::shared_ptr< ContentNode node,
std::shared_ptr< ContentNode parent = nullptr,
bool  eventWasPending = false 
)
protectedvirtual

These just passes the correspongind callbacks to instances, When this is called, it must be that found node is 'complete'.

If we're currently setting content to an instance, don't handle new events yet, queue them and handle later

void Showcase::UIComponent::contentNodeLost ( std::shared_ptr< ContentNode node,
std::shared_ptr< ContentNode parent = nullptr,
bool  eventWasPending = false 
)
protectedvirtual

If we're currently setting content to an instance, don't handle new events yet, queue them and handle later

void Showcase::UIComponent::contentNodeLostProperty ( std::shared_ptr< ContentNode node,
const Property &  prop,
bool  eventWasPending = false 
)
protectedvirtual

If we're currently setting content to an instance, don't handle new events yet, queue them and handle later

void Showcase::UIComponent::contentNodeReceivedProperty ( std::shared_ptr< ContentNode node,
const Property &  prop,
bool  eventWasPending = false 
)
protectedvirtual

These just passes the correspongind callbacks to instances.

If we're currently setting content to an instance, don't handle new events yet, queue them and handle later

UIComponentInstancePtr Showcase::UIComponent::createInstance ( const QByteArray &  role)

Create a new instance of this component with the given role.

Parameters
whichrole the component is created into
Returns
new instance of the component
bool Showcase::UIComponent::enabled ( ) const

Components are enabled by default, but they can be disabled in certain circumstances.

Returns
is the component enabled
void Showcase::UIComponent::initializeContentSlot ( const Slot slot,
const Property &  property 
)

Initialize a new content slot.

below content stuff

Parameters
slotslot the content set is assigned to
propertyproperty that holds the data for creating content root node
void Showcase::UIComponent::placeholderStatusChanged ( const NodeId id)
overrideprotectedvirtual

Not ready or no placeholder, either way destroy the subcomponent

Implements Showcase::Component.

void Showcase::UIComponent::propertyReceived ( const Property &  property)
overrideprotectedvirtual

Need to override because some 'slots' (content), may hide in attributes.

If any children were already attached to this slot, remove them first. Make sure that LOST events are sent before FOUND event.

Reimplemented from Showcase::Component.

void Showcase::UIComponent::removeContentSlot ( const Slot slot)

Remove content from given slot.

Parameters
slotslot the content set is removed from
void Showcase::UIComponent::removeFromSlots ( const NodeId id)

Remove all instances of the given node id from this component's slots.

Parameters
idnode id to remove

A somewhat unefficient way

const std::unordered_set< QByteArray > & Showcase::UIComponent::roles ( ) const

Roles that this component will implement.

This determines the slots this component can be added to

Returns
roles of the component
void Showcase::UIComponent::setEnabled ( bool  enabled)

Set component enabled or disabled.

If component is disabled, all its instances are removed

void Showcase::UIComponent::setOnSlotsFulfilled ( std::function< void(void)> &&  f)

Set component to execute lambda when slots are fulfilled.

This is needed to propagate 'slots fulfilled' -event in the ui component hierarchy

Parameters
flambda to execute
void Showcase::UIComponent::setOnSlotsUnfulfilled ( std::function< void(void)> &&  f)

Set component to execute lambda when slots were previously fulfilled and become unfulfilled.

Parameters
flambda to execute
bool Showcase::UIComponent::slotsFulfilled ( const std::unique_lock< std::mutex > &  lock = std::unique_lock<std::mutex>()) const

Checks if the component is ready to be instanced (it has all the slots in place)

Parameters
lockmutex used to lock the component tree while checking
Returns
true if this component is ready
QByteArray Showcase::UIComponent::subtype ( ) const

The subtype of this component.

Will be empty if component has no subtype

Returns
subtype of the component or empty string