BlendSplitter
3.0.0
A Blender-like Qt Widget management library
|
A registry of all widgets that can be displayed in a SwitchingWidget. More...
#include <WidgetRegistry.hpp>
Signals | |
void | registryChanged () |
Signal emited when WidgetRegistry changes its contents. More... | |
Public Member Functions | |
RegistryItem * | item (int i) const |
Get the item at position i. More... | |
int | indexOf (RegistryItem *item) const |
Get the position of an item in WidgetRegistry. More... | |
RegistryItem * | getDefault () |
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 WidgetRegistry * | getRegistry () |
Registry getter. More... | |
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.
void WidgetRegistry::addItem | ( | RegistryItem * | item | ) |
Add an item to WidgetRegistry.
Adds a given RegistryItem at the end of WidgetRegistry.
item | A pointer to the RegistryItem to be added |
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}).
name | The name of the widget, used in the SwitchingBar combo box |
widget | A pointer to a function constructing the widget |
populateBar | A pointer to a function populating the SwitchingBar |
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.
|
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.
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.
item | A pointer to the item whose index is to be returned |
void WidgetRegistry::insertItem | ( | int | index, |
RegistryItem * | item | ||
) |
Insert an item into WidgetRegistry.
Inserts a given RegistryItem into WidgetRegistry at a given index.
index | The desired index of the inserted RegistryItem (counting starts at 0) |
item | A pointer to the RegistryItem to be added |
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}).
index | The desired index of the inserted RegistryItem (counting starts at 0) |
name | The name of the widget, used in the SwitchingBar combo box |
widget | A pointer to a function constructing the widget |
populateBar | A pointer to a function populating the SwitchingBar |
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).
i | Index of the item to be returned |
|
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.
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)).
item |
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.
index | Index of the RegistryItem to be removed |
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.
item | A pointer to the RegistryItem to be set as default |
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)).
index | Index of the RegistryItem to be set as default (counting starts at 0) |
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).