Workspace 6.21.5
Public Member Functions | List of all members
SceneItemLibrary Class Reference

Library containing scene items, allowing scene item instances to be stored with identifiers, and be instanced elsewhere in a scene. More...

#include <Rendering/SceneComponents/sceneitemlibrary.h>

Public Member Functions

 SceneItemLibrary ()
 
 SceneItemLibrary (const SceneItemLibrary &)
 
virtual ~SceneItemLibrary ()
 
bool add (const QString &id, SceneItem &sceneItem)
 
bool add (SceneItemLibrary &library)
 
void clearSceneItems ()
 
void clearSubLibraries ()
 
SceneItemgetSceneItem (const QString &id)
 
SceneItemLibraryoperator= (const SceneItemLibrary &lib)
 
bool remove (const QString &id)
 
bool remove (SceneItem &sceneItem)
 
bool remove (SceneItemLibrary &library)
 

Detailed Description

The main purpose of this class is to provide a single place from which clients can retrieve a SceneItem with a given id. A SceneItemLibrary can hold other SceneItemLibrary instances, searching recursively (depth first) for a requested scene item id.

Constructor & Destructor Documentation

◆ SceneItemLibrary() [1/2]

Creates an empty library.

◆ SceneItemLibrary() [2/2]

Parameters
libThe library to make a copy of.

When lib is copied, the items it contains are not copied. Instead, the new SceneItemLibrary instance will hold references to the same things as lib. Therefore, the client needs to ensure that these contents remain valid for as long as the copy is in use. In particular, if lib is rebuilt as a result of a workspace operation's inputs being updated, the original copy of it should also be updated to prevent that copy from trying to use objects which might no longer exist.

◆ ~SceneItemLibrary()

~SceneItemLibrary ( )
virtual

The destructor destroys the library, but not the things it contains.

Member Function Documentation

◆ add() [1/2]

bool add ( const QString &  id,
SceneItem sceneItem 
)
Parameters
idThe id to assign to this sceneItem in the library.
sceneItemThe sceneItem to add to the library.

If a sceneItem with the same id as sceneItem is already present in the library, this function will not add sceneItem. Instead, the old sceneItem is retained and the function returns false. Note that this test is only performed for sceneItems held directly by this library, not for any of the sub-libraries it also might hold. This allows a library to provide sceneItems which override those specified in any sub-libraries.

Returns
True if sceneItem could be added.

◆ add() [2/2]

bool add ( SceneItemLibrary library)
Parameters
libraryThe sub-library to add to this library.
Returns
True if library could be added or false if it is already a direct sub-library of this one.

◆ clearSceneItems()

void clearSceneItems ( )

Clears all sceneItems from the library. Note that the sceneItems are not deleted. This function merely clears the list of sceneItems the library keeps internally.

◆ clearSubLibraries()

void clearSubLibraries ( )

Clears all sub-libraries from this library. Note that the sub-libraries are not deleted. This function merely clears the list of sub-libraries this library keeps internally.

◆ getSceneItem()

SceneItem * getSceneItem ( const QString &  id)
Parameters
idThe id of the sceneItem to retrieve.
Returns
The sceneItem corresponding to the specified id, or a null pointer if no such sceneItem could be found. Searches sub-libraries in a depth-first manner. The first sceneItem matching id is always returned whether or not the sceneItem is able to be used successfully.

◆ operator=()

SceneItemLibrary & operator= ( const SceneItemLibrary lib)
Parameters
libThe library to assign to this one.

See the comments for SceneItemLibrary(const SceneItemLibrary&), since they also apply here.

Returns
A reference to this object.

◆ remove() [1/3]

bool remove ( const QString &  id)
Parameters
idThe id of the sceneItem to remove from the library.
Returns
True if a sceneItem exists in the library with the specified id and it could be removed.

◆ remove() [2/3]

bool remove ( SceneItem sceneItem)
Parameters
sceneItemThe sceneItem to remove from the library.

Note that this function is slower than the remove(const String&) version due to how the data is stored internally. Access is optimized for lookups based on the id string, so searching for a particular sceneItem object is O(n) where n is the number of sceneItem this library holds directly (but is not affected by any sub-libraries).

Returns
True if sceneItem exists in the library and could be removed.

◆ remove() [3/3]

bool remove ( SceneItemLibrary library)
Parameters
libraryThe sub-library to remove from this library.
Returns
True if library is a sub-library directly held by this library and it could be removed. It will not be removed if it is not an immediate sub-library but is held more deeply in the sub-library hierachy.