// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only

/*!
    \page studio-3d-repeater-3d.html

    \title 3D Repeater

    The \uicontrol {3D Repeater} component is used to create multiple
    similar items in a 3D scene. Like other view types, \uicontrol {3D Repeater}
    needs a model and a delegate. The delegate sets the item to use and the
    model sets the structure of the items in the \uicontrol {3D Repeater}
    component.

    The model can be any of the supported \l{Qt QML Models QML Types}
    {data models}. Additionally, like delegates for other views, a delegate for
    the \uicontrol {3D Repeater} can access its index within the repeater, as
    well as the model data relevant to the delegate.

    \note \uicontrol {3D Repeater} owns all items it instantiates. Removing or
    dynamically deleting an item created by \uicontrol {3D Repeater} results in
    unpredictable behavior.

    \note \uicontrol {3D Repeater} can only repeat objects derived from
    \uicontrol Nodes.

    For more information, see \l{Repeater3D} in the
    \uicontrol {Qt Quick 3D} documentation.

    \section1 3D Repeater properties

    You can specify the \uicontrol Model and the \uicontrol Delegate property for
    a \uicontrol {3D Repeater}

    \section2 Model

    The \uicontrol Model property specifies the model providing data for the
    repeater. You can only use the \uicontrol Model property in the
    \uicontrol Properties view to set a numeric model or to bind to QML based
    models. You can use the \l {Code} view to define any of the supported
    data models as the value of the \uicontrol Model property:
        \list
            \li A number that indicates the number of delegates to be created by
                the repeater.
            \li A model, such as a \uicontrol ListModel component, or a
                QAbstractItemModel subclass.
            \li A string list.
            \li An object list.
        \endlist

    The type of model affects the properties that are exposed to the delegate.

    \section2 Delegate

    The \uicontrol Delegate property specifies a template defining each object
    instantiated by the repeater. Currently, the \uicontrol Delegate property
    needs to be defined in code using the \uicontrol Edit mode or
    the \uicontrol {Code} view. Delegates are exposed to a read-only index
    property that indicates the index of the delegate within the repeater. For
    more information, see \l{https://doc.qt.io/qt/qml-qtquick3d-repeater3d.html#delegate-prop}
    {Delegate} in the \uicontrol {Qt Quick 3D} documentation.

    If the model is a model object, such as a \uicontrol ListModel, the delegate
    can access all model roles as named properties, in the same way that delegates
    do for view classes like \uicontrol ListView.

    \section1 Adding a 3D Repeater component with a numeric model

    This section explains how to add a \uicontrol {3D Repeater} component with
    a numeric model to your \QDS project. For an example, you will add a
    \uicontrol {3D Repeater} component and a numeric model to draw four cubes.

    To add a \uicontrol {3D Repeater} component:

    \list 1
      \li Drag a \uicontrol {3D Repeater} component from \uicontrol Components to
      \e scene in \uicontrol Navigator.
      \li Select \e {3D Repeater} in \uicontrol Navigator and in
      \uicontrol Properties, set \uicontrol Model to, for example, 4.
      \image {repeater3d-model-property.png} {The Repeater Model property set to 4 in the Properties view.}
    \endlist
    Now, you have set up the \uicontrol {3D Repeater} component to use a numeric
    model that draws four instances of the same item. Next, you need to add the
    item to draw. In this example we are using a \uicontrol Cube:
    \list 1
      \li From \uicontrol Components, drag a \uicontrol Cube to \e _Repeater3D in
      \uicontrol Navigator.
      Now, four cubes are drawn to the scene, but they are drawn to the exact same
      place. Next, use \uicontrol {Binding Editor} to create a binding that sets the
      location to increase by, for example, 150 for each of the cubes.
      \li Select \e cube in \uicontrol Navigator and in \uicontrol Properties
      select \imageactionicon
      next to \uicontrol Translation > \uicontrol X.
      \li Select \uicontrol {Set Binding} to open \uicontrol {Binding Editor}.
      \li In \uicontrol {Binding Editor}, enter \c{index * 150}.
      \image {repeater3d-index-binding.png} {index * 150 set in Bindings Editor.}
      \li Select \uicontrol OK and go to the \uicontrol{3D} view to see the
      result.
    \image {repeater3d-numeric-model.webp} {Four cubes rendered with the Repeater component in the 3D view.}
    \endlist

    \section1 Adding a 3D Repeater component with a List Model

    This section explains how to add a \uicontrol {3D Repeater} component with
    a list model to your \QDS project. For an example, you will add a
    \uicontrol {3D Repeater} component and a list model to draw three spheres
    of different size.

    To add a \uicontrol 3D Repeater component:

    \list 1
        \li Drag a \uicontrol {3D Repeater} component from \uicontrol Components
            to \e scene in \uicontrol Navigator.
        \li You need to enter the QML code for the \uicontrol ListModel manually.
            Go to the \uicontrol {Code} view, and enter the following code inside
            the root object:
            \code qml
                ListModel {
                    id: planetModel
                    ListElement {
                        name: "Mars"
                        radius: 3.39
                    }
                    ListElement {
                        name: "Earth"
                        radius: 6.37
                    }
                    ListElement {
                        name: "Venus"
                        radius: 6.05
                    }
                }
            \endcode
            The default root object for a \QDS project is \c Rectangle. Paste
            the \uicontrol ListModel code inside \c Rectangle, for example,
            like this:
            \code qml
            Rectangle {
                width: Constants.width
                height: Constants.height
                color: Constants.backgroundColor

                ListModel {
                    id: planetModel
                    ListElement {
                        name: "Mars"
                        radius: 3.39
                    }
                    ListElement {
                        name: "Earth"
                        radius: 6.37
                    }
                    ListElement {
                        name: "Venus"
                        radius: 6.05
                    }
                }
                View3D {
                    id: view3D
                    anchors.fill: parent
                    ...
            \endcode
        \li In the \uicontrol {Code} view, add \c {model: planetModel} to the
            \c Repeater3D object to determine that you want to use the
            \c ListModel as the model for \uicontrol {3D Repeater}:
            \code qml
            Repeater3D {
                id: repeater3D
                model: planetModel
            }
            \endcode
    \endlist

    Now, you have set up the \uicontrol {3D Repeater} component to use a
    \uicontrol ListModel to draw the items. Next, you need to add the
    item to draw. In this example, you are using a \uicontrol Sphere:

    \list 1
      \li From \uicontrol Components, drag a \uicontrol Sphere to \e _Repeater3D
      in \uicontrol Navigator.
      \image {repeater3d-listmodel-navigator.png} {The Sphere component in the Navigator view.}
      \li Select \e sphere in \uicontrol Navigator and in the \uicontrol Properties view, select
      \imageactionicon
      next to \uicontrol Scale > \uicontrol X.
      \li Select \uicontrol {Set Binding} to open \uicontrol {Binding Editor}.
      \li In \uicontrol {Binding Editor}, enter \c{radius}. This sets the X
      scale to the radius value defined in the list model for each of the spheres
      that are drawn.
      \image {repeater3d-radius-binding.png} {radius set in Binding Editor.}
      \li Select \uicontrol OK.
      \li Repeat steps 2 to 5 for \uicontrol Scale > \uicontrol Y and
      \uicontrol Scale > \uicontrol Z.
    \endlist

    Now, three spheres of different size are drawn but they are drawn in the same
    position so you need to change the position to see all the spheres:

    \list 1
      \li Select \e sphere in \uicontrol Navigator and in the \uicontrol Properties view, select
      \imageactionicon
      next to \uicontrol Translation > \uicontrol X.
      \li Select \uicontrol {Set Binding} to open \uicontrol {Binding Editor}.
      \li In \uicontrol {Binding Editor}, enter \c{index * 1000}. This sets the X
      location to increase by 1000 for each of the spheres that are drawn.
      \image {repeater3d-location-binding.png} {index * 1000 set in Binding Editor.}
      \li Select \uicontrol OK and go to the \uicontrol{3D} view to see the
      result. You need to zoom out to see all the spheres.
      \image {repeater3d-list-model.webp} {Spheres drawn with a 3D Repeater and a ListModel.}
    \endlist

*/
