ShapeCollection

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

NameTypeAccessDescription
ShapeCollectionShapeCollectionReadGets the shape collection.
TableTableReadGets the table.

Methods

SignatureDescription
ShapeCollection()ShapeCollectionProperty gives access to the collection itself
Table()TableProperty 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()IGroupShapeReturns the parent group shape, or nullptr if top-level.
as_i_collection()IShapeCollectionReturns this collection as a generic collection interface.
as_i_enumerable()IShapeCollectionReturns this collection as a generic enumerable interface.
size()std::size_tReturns 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)AutoShapeAdds an AutoShape to the collection.
add_auto_shape(type: ShapeType, x: double, y: double, width: double, height: double, create_from_template: bool)AutoShapeAdds an AutoShape to the collection.
insert_auto_shape(index: std::size_t, type: ShapeType, x: double, y: double, width: double, height: double)AutoShapeInserts 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)AutoShapeInserts an AutoShape at the specified index.
add_connector(type: ShapeType, x: double, y: double, width: double, height: double)ConnectorAdds a Connector to the collection.
add_connector(type: ShapeType, x: double, y: double, width: double, height: double, create_from_template: bool)ConnectorAdds a Connector to the collection.
insert_connector(index: std::size_t, type: ShapeType, x: double, y: double, width: double, height: double)ConnectorInserts 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)ConnectorInserts a Connector at the specified index.
index_of(shape: Shape)std::ptrdiff_tReturns 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)PictureFrameAdds a PictureFrame to the collection.
insert_picture_frame(index: std::size_t, type: ShapeType, x: double, y: double, width: double, height: double, image: PPImage)PictureFrameInserts a PictureFrame at the specified index.
add_table(x: double, y: double, column_widths: std::span<const double>, row_heights: std::span<const double>)TableAdds 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>)TableInserts 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_tReturns the number of tables in the collection.
table_at(index: std::size_t)TableReturns the table at the given index.
table_at(index: std::size_t)TableReturns the table at the given index.
begin()iteratorReturns an iterator to the first shape
end()iteratorReturns an iterator past the last shape
begin()const_iterator
end()const_iterator
get_sp_tree()pugi::xml_nodeGet 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()intFind 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)AutoShapeCore 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)ConnectorCore 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)PictureFrameCore 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>)TableCore 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.

See Also