openshot-audio  0.1.7
Classes | Public Member Functions | Public Attributes | Static Public Attributes | List of all members
ComponentBuilder Class Reference

#include <juce_ComponentBuilder.h>

Inheritance diagram for ComponentBuilder:
ValueTree::Listener

Classes

class  ImageProvider
 
class  TypeHandler
 

Public Member Functions

 ComponentBuilder (const ValueTree &state)
 
 ComponentBuilder ()
 
 ~ComponentBuilder ()
 
ComponentgetManagedComponent ()
 
ComponentcreateComponent ()
 
void registerTypeHandler (TypeHandler *type)
 
TypeHandlergetHandlerForState (const ValueTree &state) const
 
int getNumHandlers () const noexcept
 
TypeHandlergetHandler (int index) const noexcept
 
void registerStandardComponentTypes ()
 
void setImageProvider (ImageProvider *newImageProvider) noexcept
 
ImageProvidergetImageProvider () const noexcept
 
void updateChildComponents (Component &parent, const ValueTree &children)
 

Public Attributes

ValueTree state
 

Static Public Attributes

static const Identifier idProperty
 

Detailed Description

Loads and maintains a tree of Components from a ValueTree that represents them.

To allow the state of a tree of components to be saved as a ValueTree and re-loaded, this class lets you register a set of type-handlers for the different components that are involved, and then uses these types to re-create a set of components from its stored state.

Essentially, to use this, you need to create a ComponentBuilder with your ValueTree, then use registerTypeHandler() to give it a set of type handlers that can cope with all the items in your tree. Then you can call getComponent() to build the component. Once you've got the component you can either take it and delete the ComponentBuilder object, or if you keep the ComponentBuilder around, it'll monitor any changes in the ValueTree and automatically update the component to reflect these changes.

Constructor & Destructor Documentation

◆ ComponentBuilder() [1/2]

ComponentBuilder::ComponentBuilder ( const ValueTree state)
explicit

Creates a ComponentBuilder that will use the given state. Once you've created your builder, you should use registerTypeHandler() to register some type handlers for it, and then you can call createComponent() or getManagedComponent() to get the actual component.

◆ ComponentBuilder() [2/2]

ComponentBuilder::ComponentBuilder ( )

Creates a builder that doesn't have a state object.

◆ ~ComponentBuilder()

ComponentBuilder::~ComponentBuilder ( )

Destructor.

Member Function Documentation

◆ createComponent()

Component * ComponentBuilder::createComponent ( )

Creates and returns a new instance of the component that the ValueTree represents. The caller is responsible for using and deleting the object that is returned. Unlike getManagedComponent(), the component that is returned will not be updated by the builder.

◆ getHandler()

ComponentBuilder::TypeHandler * ComponentBuilder::getHandler ( int  index) const
noexcept

Returns one of the registered type handlers.

See also
getNumHandlers, registerTypeHandler

◆ getHandlerForState()

ComponentBuilder::TypeHandler * ComponentBuilder::getHandlerForState ( const ValueTree state) const

Tries to find a registered type handler that can load a component from the given ValueTree.

◆ getImageProvider()

ComponentBuilder::ImageProvider * ComponentBuilder::getImageProvider ( ) const
noexcept

Returns the current image provider that this builder is using, or nullptr if none has been set.

◆ getManagedComponent()

Component * ComponentBuilder::getManagedComponent ( )

Returns the builder's component (creating it if necessary).

The first time that this method is called, the builder will attempt to create a component from the ValueTree, so you must have registered some suitable type handlers before calling this. If there's a problem and the component can't be created, this method returns nullptr.

The component that is returned is owned by this ComponentBuilder, so you can put it inside your own parent components, but don't delete it! The ComponentBuilder will delete it automatically when the builder is destroyed. If you want to get a component that you can delete yourself, call createComponent() instead.

The ComponentBuilder will update this component if any changes are made to the ValueTree, so if there's a chance that the tree might change, be careful not to keep any pointers to sub-components, as they may be changed or removed.

◆ getNumHandlers()

int ComponentBuilder::getNumHandlers ( ) const
noexcept

Returns the number of registered type handlers.

See also
getHandler, registerTypeHandler

◆ registerStandardComponentTypes()

void ComponentBuilder::registerStandardComponentTypes ( )

Registers handlers for various standard juce components.

◆ registerTypeHandler()

void ComponentBuilder::registerTypeHandler ( TypeHandler type)

Adds a type handler that the builder can use when trying to load components.

See also
Drawable::registerDrawableTypeHandlers()

◆ setImageProvider()

void ComponentBuilder::setImageProvider ( ImageProvider newImageProvider)
noexcept

Gives the builder an ImageProvider object that the type handlers can use when loading images from stored references.

The object that is passed in is not owned by the builder, so the caller must delete it when it is no longer needed, but not while the builder may still be using it. To clear the image provider, just call setImageProvider (nullptr).

◆ updateChildComponents()

void ComponentBuilder::updateChildComponents ( Component parent,
const ValueTree children 
)

Updates the children of a parent component by updating them from the children of a given ValueTree.

Member Data Documentation

◆ idProperty

const Identifier ComponentBuilder::idProperty
static

An identifier for the property of the ValueTrees that is used to store a unique ID for that component.

◆ state

ValueTree ComponentBuilder::state

This is the ValueTree data object that the builder is working with.


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