Public Functions
LThemeItem(const LString& name, const LAttributeMap& attributes, bool is_overridable, const LString& file_name, LThemeItem* parent = nullptr) | |
void | append_child(LThemeItem* child) |
std::vector<LString> | attribute_group_names() const |
LAttributeMap | attributes(int type_index = -1) |
LThemeItem* | child(int index) const |
size_t | child_count() const |
std::map<LString, LThemeItem*>& | children() |
LThemeItem* | find_item(const LString& path) |
LThemeItem* | find_item(std::deque<LString> name_list) |
int | index() const |
bool | is_overridable() const |
LString | path() const |
LJsonObject | to_json_object() const |
Detailed Description
An LThemeItem is an LObject that handles the hierarchical structure of LTheme objects. A theme-item can store a set of LAttribute objects, which are referred to as theme attributes, as well as child LThemeItem objects.
A theme-item has a name which typically matches the name of the widget it represents.
Storing File Names
When a theme's implementation sets are loaded, their theme-item hierarchies are merged. To ensure that the data is separated back correctly, theme-items store the name of the file that their data originated from.
The file name should be provided during initialization.
JSON Data Format
The JSON data for a theme-item is formatted as follows:
{ // Beginning of item's object
"attributes": { // The item's attributes (if any)
<attr_name>: <attr_object>, // First attribute
... // Any other attributes follow (if any)
},
"children": { // The item's children (if any)
<item_name>: <item_object>, // First child
... // Any other children follow (if any)
},
"is_overridable": <bool> // True if attributes are overridable (optional)
}
If the is_overridable value is not present, it is assumed to be false.
For information on how an attribute's JSON object is formatted, see LAttribute.
In a theme file (see LTheme), a top-level item-object is stored in the file's root object with the item's name as its key. The following is an example:
{ // Beginning of file's root object
<top_level_item1>: <item_object>, // First top-level item
... // Any other top-level items follow (if any)
}
Member Function Documentation
LThemeItem(const LString& name, const LAttributeMap& attributes, bool is_overridable, const LString& file_name, LThemeItem* parent = nullptr)
Constructs a theme-item.
void append_child(LThemeItem* child)
Adds child to the list of child items.
std::vector<LString> attribute_group_names() const
Returns a list of group names determined from the item's child attributes.
LAttributeMap attributes(int type_index = -1)
Returns the item's child attributes.
If a valid variant index (see LVariant) is provided as the argument for type_index, then the returned map of attributes will only contain attributes whose values' types match the type-index.
LThemeItem* child(int index) const
Returns a pointer to the theme-item at the given index.
If the argument provided for the index parameter does not exist, then nullptr is returned.
size_t child_count() const
Returns the number of child items that this theme-item has.
std::map<LString, LThemeItem*>& children()
Returns a reference to the map containing the child theme-items.
LThemeItem* find_item(const LString& path)
Returns the child item identified by path.
This function operates recursively down the item's hierarchy. If no item is found, then nullptr is returned.
LThemeItem* find_item(std::deque<LString> name_list)
Returns the child item identified by name_list.
This function operates recursively down the item's hierarchy. If no item is found, then nullptr is returned.
int index() const
Returns the index of this item as it appears in the parent's list of child items.
bool is_overridable() const
Returns a boolean value indicating whether or not the item's attributes are overridable.
LString path() const
Returns the item's path.
An item path is a string composed of the names in the item's hierarchy leading down to the item. The names are separated with forward-slash (/) characters.
LJsonObject to_json_object() const
Returns a JSON-object that contains a copy of the item's data.