ShapeCollection
Overview
ShapeCollection is a class in Aspose.Slides FOSS for C++.
Manages the collection of shapes on a slide. Operates in two modes: - Simple mode (default): shapes are managed in-memory only. - XML-backed mode (after init_internal): shapes are loaded from and persisted to the slide’s spTree XML, with lazy caching.
This class provides 49 methods for working with ShapeCollection objects in C++ programs.
Available methods include: ShapeCollection, Table, add_auto_shape, add_auto_shape_impl, add_connector, add_connector_impl, add_picture_frame, add_picture_frame_impl, add_table, add_table_impl, as_i_collection, as_i_enumerable, and 25 additional methods.
All public members are accessible to any C++ application after installing the Aspose.Slides FOSS for C++ package.
Properties: ShapeCollection, Table.
Properties
| Name | Type | Access | Description |
|---|---|---|---|
ShapeCollection | ShapeCollection | Read | Gets the shape collection. |
Table | Table | Read | Gets the table. |
Methods
| Signature | Description |
|---|---|
ShapeCollection() → ShapeCollection | Property gives access to the collection itself |
Table() → Table | Property provides access to the Table shape associated with the collection |
Table() → Table | |
ShapeCollection() | |
ShapeCollection() | |
init_internal(slide_part: Internal::pptx::SlidePart, parent_slide: IBaseSlide) | Initialize from a slide part, entering XML-backed mode. |
parent_group() → IGroupShape | Returns the parent group shape, or nullptr if top-level. |
as_i_collection() → IShapeCollection | Returns this collection as a generic collection interface. |
as_i_enumerable() → IShapeCollection | Returns this collection as a generic enumerable interface. |
size() → std::size_t | Returns the number of shapes. |
to_array() → std::vector<Shape*> | Returns all shapes as non-owning pointers. |
to_array(start_index: std::size_t, count: std::size_t) → std::vector<Shape*> | Returns all shapes as non-owning pointers. |
reorder(new_index: std::size_t, shape: Shape) | Moves a shape to the specified position (z-order). |
reorder(index: std::size_t, shapes: std::span<Shape*>) | Moves a shape to the specified position (z-order). |
add_auto_shape(type: ShapeType, x: double, y: double, width: double, height: double) → AutoShape | Adds an AutoShape to the collection. |
add_auto_shape(type: ShapeType, x: double, y: double, width: double, height: double, create_from_template: bool) → AutoShape | Adds an AutoShape to the collection. |
insert_auto_shape(index: std::size_t, type: ShapeType, x: double, y: double, width: double, height: double) → AutoShape | Inserts an AutoShape at the specified index. |
insert_auto_shape(index: std::size_t, type: ShapeType, x: double, y: double, width: double, height: double, create_from_template: bool) → AutoShape | Inserts an AutoShape at the specified index. |
add_connector(type: ShapeType, x: double, y: double, width: double, height: double) → Connector | Adds a Connector to the collection. |
add_connector(type: ShapeType, x: double, y: double, width: double, height: double, create_from_template: bool) → Connector | Adds a Connector to the collection. |
insert_connector(index: std::size_t, type: ShapeType, x: double, y: double, width: double, height: double) → Connector | Inserts a Connector at the specified index. |
insert_connector(index: std::size_t, type: ShapeType, x: double, y: double, width: double, height: double, create_from_template: bool) → Connector | Inserts a Connector at the specified index. |
index_of(shape: Shape) → std::ptrdiff_t | Returns the zero-based index of a shape, or -1 if not found. |
add_picture_frame(type: ShapeType, x: double, y: double, width: double, height: double, image: PPImage) → PictureFrame | Adds a PictureFrame to the collection. |
insert_picture_frame(index: std::size_t, type: ShapeType, x: double, y: double, width: double, height: double, image: PPImage) → PictureFrame | Inserts a PictureFrame at the specified index. |
add_table(x: double, y: double, column_widths: std::span<const double>, row_heights: std::span<const double>) → Table | Adds a Table to the collection. |
insert_table(index: std::size_t, x: double, y: double, column_widths: std::span<const double>, row_heights: std::span<const double>) → Table | Inserts a Table at the specified index. |
remove(shape: Shape) | Removes a shape from the collection by reference. |
remove_at(index: std::size_t) | Removes the shape at the given index. |
clear() | Removes all shapes. |
table_count() → std::size_t | Returns the number of tables in the collection. |
table_at(index: std::size_t) → Table | Returns the table at the given index. |
table_at(index: std::size_t) → Table | Returns the table at the given index. |
begin() → iterator | Returns an iterator to the first shape |
end() → iterator | Returns an iterator past the last shape |
begin() → const_iterator | |
end() → const_iterator | |
get_sp_tree() → pugi::xml_node | Get the spTree element from the slide XML. |
load_shapes() | Load all shapes from the XML, populating the internal cache. No-op if the cache is already valid. |
invalidate_cache() | Invalidate the shapes cache, forcing a reload on next access. |
save_to_part() | Save changes to the slide part. |
next_shape_id() → int | Find the next available shape ID in the spTree. |
build_auto_shape_xml(sp: pugi::xml_node, shape_id: int, name: std::string_view, type: ShapeType, x: double, y: double, w: double, h: double, create_from_template: bool) | Build XML content for a new AutoShape element. |
build_connector_xml(cxn_sp: pugi::xml_node, shape_id: int, name: std::string_view, type: ShapeType, x: double, y: double, w: double, h: double, create_from_template: bool) | Build XML content for a new connector (cxnSp) element. |
add_auto_shape_impl(index: std::optional<std::size_t>, type: ShapeType, x: double, y: double, w: double, h: double, create_from_template: bool) → AutoShape | Core implementation for add_auto_shape and insert_auto_shape. |
add_connector_impl(index: std::optional<std::size_t>, type: ShapeType, x: double, y: double, w: double, h: double, create_from_template: bool) → Connector | Core implementation for add_connector and insert_connector. |
add_picture_frame_impl(index: std::optional<std::size_t>, type: ShapeType, x: double, y: double, w: double, h: double, image: PPImage) → PictureFrame | Core implementation for add_picture_frame and insert_picture_frame. |
add_table_impl(index: std::optional<std::size_t>, x: double, y: double, column_widths: std::span<const double>, row_heights: std::span<const double>) → Table | Core implementation for add_table and insert_table. |
reorder_single(new_index: std::size_t, shape: Shape) | Reorder a single shape to a new position in XML and cache. |