BlendSplitter  3.0.0
A Blender-like Qt Widget management library
WidgetRegistry Class Reference

A registry of all widgets that can be displayed in a SwitchingWidget. More...

#include <WidgetRegistry.hpp>

Inheritance diagram for WidgetRegistry:
Collaboration diagram for WidgetRegistry:

Signals

void registryChanged ()
 Signal emited when WidgetRegistry changes its contents. More...
 

Public Member Functions

RegistryItemitem (int i) const
 Get the item at position i. More...
 
int indexOf (RegistryItem *item) const
 Get the position of an item in WidgetRegistry. More...
 
RegistryItemgetDefault ()
 Get the default RegistryItem. More...
 
void setDefault (RegistryItem *item)
 Set the default RegistryItem. More...
 
void setDefault (int index=0)
 Set the default RegistryItem. More...
 
void addItem (RegistryItem *item)
 Add an item to WidgetRegistry. More...
 
void addItem (QString name="Default", QWidget *(*widget)()=[]() ->QWidget *{return new QLabel{"Default widget"};}, void(*populateBar)(SwitchingBar *, QWidget *)=[](SwitchingBar *, QWidget *) ->void {})
 Add an item to WidgetRegistry. More...
 
void insertItem (int index, RegistryItem *item)
 Insert an item into WidgetRegistry. More...
 
void insertItem (int index, QString name="Default", QWidget *(*widget)()=[]() ->QWidget *{return new QLabel{"Default widget"};}, void(*populateBar)(SwitchingBar *, QWidget *)=[](SwitchingBar *, QWidget *) ->void {})
 Insert an item into widgetRegistry. More...
 
void removeItem (RegistryItem *item)
 Remove a RegistryItem from WidgetRegistry. More...
 
void removeItem (int index)
 Remove a RegistryItem from WidgetRegistry. More...
 
int size () const
 Get the size of WidgetRegistry. More...
 

Static Public Member Functions

static WidgetRegistrygetRegistry ()
 Registry getter. More...
 

Detailed Description

A registry of all widgets that can be displayed in a SwitchingWidget.

This singleton-class acts as a registry of widgets that can be displayed in a SwitchingWidget by selecting from a combo box in the SwitchingBar. Each item is represented as one RegistryItem. The Registry also contains a pointer to the default RegistryItem, which is shown when a new SwitchingWidget is created.

Definition at line 18 of file WidgetRegistry.hpp.

Member Function Documentation

§ addItem() [1/2]

void WidgetRegistry::addItem ( RegistryItem item)

Add an item to WidgetRegistry.

Adds a given RegistryItem at the end of WidgetRegistry.

Parameters
itemA pointer to the RegistryItem to be added

§ addItem() [2/2]

void WidgetRegistry::addItem ( QString  name = "Default",
QWidget *(*)()  widget = []() ->QWidget *{return new QLabel{"Default widget"};},
void(*)(SwitchingBar *, QWidget *)  populateBar = [](SwitchingBar *, QWidget *) ->void {} 
)

Add an item to WidgetRegistry.

Adds a RegistryItem constructed with the given parameters at the end of WidgetRegistry. This is equal to calling addItem(new RegistryItem{name, widget, populateBar}).

Parameters
nameThe name of the widget, used in the SwitchingBar combo box
widgetA pointer to a function constructing the widget
populateBarA pointer to a function populating the SwitchingBar

§ getDefault()

RegistryItem* WidgetRegistry::getDefault ( )

Get the default RegistryItem.

This function gives you the default RegistryItem. Note that if no item was set as default, the currently first item is set as default by this function. If the registry is empty, a RegistryItem is added to the registry (using the default constructor) and set as default.

Returns
A pointer to the default RegistryItem

§ getRegistry()

static WidgetRegistry* WidgetRegistry::getRegistry ( )
static

Registry getter.

This is a singleton class, i. e. you can't construct any object yourself. To get the one-and-only instance of this class, you need to call WidgetRegistry::getRegistry(). The function will create the object if neccessary (= when called for the first time) and return a pointer to it.

Returns
A pointer to the one-and-only instance of WidgetRegistry

§ indexOf()

int WidgetRegistry::indexOf ( RegistryItem item) const

Get the position of an item in WidgetRegistry.

Get the index (counting starts at 0) of an item. Often used together with item(int i) const.

Parameters
itemA pointer to the item whose index is to be returned
Returns
Index of the item

§ insertItem() [1/2]

void WidgetRegistry::insertItem ( int  index,
RegistryItem item 
)

Insert an item into WidgetRegistry.

Inserts a given RegistryItem into WidgetRegistry at a given index.

Parameters
indexThe desired index of the inserted RegistryItem (counting starts at 0)
itemA pointer to the RegistryItem to be added

§ insertItem() [2/2]

void WidgetRegistry::insertItem ( int  index,
QString  name = "Default",
QWidget *(*)()  widget = []() ->QWidget *{return new QLabel{"Default widget"};},
void(*)(SwitchingBar *, QWidget *)  populateBar = [](SwitchingBar *, QWidget *) ->void {} 
)

Insert an item into widgetRegistry.

Inserts a RegistryItem constructed with the given parameters into WidgetRegistry at a given index. This is equal to calling insertItem(index, new RegistryItem{name, widget, populateBar}).

Parameters
indexThe desired index of the inserted RegistryItem (counting starts at 0)
nameThe name of the widget, used in the SwitchingBar combo box
widgetA pointer to a function constructing the widget
populateBarA pointer to a function populating the SwitchingBar

§ item()

RegistryItem* WidgetRegistry::item ( int  i) const

Get the item at position i.

This function gives you the item at position i (counting starts at 0).

Parameters
iIndex of the item to be returned
Returns
A pointer to the RegistryItem at position i

§ registryChanged

void WidgetRegistry::registryChanged ( )
signal

Signal emited when WidgetRegistry changes its contents.

This signal is emited when a RegistryItem is added, inserted or removed from WidgetRegistry. It is NOT emited when the default item is changed unless this change requires adding a RegistryItem.

§ removeItem() [1/2]

void WidgetRegistry::removeItem ( RegistryItem item)

Remove a RegistryItem from WidgetRegistry.

Removes a given RegistryItem from WidgetRegistry. If this is also the default RegistryItem, the first RegistryItem is set as default if it exists. This is equal to calling removeItem(indexOf(item)).

Parameters
item

§ removeItem() [2/2]

void WidgetRegistry::removeItem ( int  index)

Remove a RegistryItem from WidgetRegistry.

Removes the RegistryItem at position index (counting starts at 0) from WidgetRegistry. If this is also the default RegistryItem, the first RegistryItem is set as default if it exists.

Parameters
indexIndex of the RegistryItem to be removed

§ setDefault() [1/2]

void WidgetRegistry::setDefault ( RegistryItem item)

Set the default RegistryItem.

This function sets the default RegistryItem. Note that if the item is not in WidgetRegistry, it is added as the last entry. The default item is used when a new SwitchingWidget is created as the displayed widget.

Parameters
itemA pointer to the RegistryItem to be set as default

§ setDefault() [2/2]

void WidgetRegistry::setDefault ( int  index = 0)

Set the default RegistryItem.

This function sets the default RegistryItem to be the RegistryItem at given index. This is equal to calling setDefault(item(index)).

Parameters
indexIndex of the RegistryItem to be set as default (counting starts at 0)

§ size()

int WidgetRegistry::size ( ) const

Get the size of WidgetRegistry.

This function returns the number of RegistryItems currently in WidgetRegistry. Note that these are indexed as 0, ..., (size() - 1).

Returns
Number of RegistryItems in WidgetRegistry

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