Code/Editor/Plugins/ComponentEntityEditorPlugin/UI/ComponentPalette/ComponentDataModel.cpp
AZ::EntityId CreateEntityFromSelection(const QModelIndexList& selection, QAbstractItemModel* model)
    {
        AZ::Vector3 position = AZ::Vector3::CreateZero();
        CViewport *view = GetIEditor()->GetViewManager()->GetGameViewport();
        int width, height;
        view->GetDimensions(&width, &height);
        position = LYVec3ToAZVec3(view->ViewToWorld(QPoint(width / 2, height / 2)));

        AZ::EntityId newEntityId;
        EBUS_EVENT_RESULT(newEntityId, AzToolsFramework::EditorRequests::Bus, CreateNewEntityAtPosition, position, AZ::EntityId());
        if (newEntityId.IsValid())
        {
            // Add all the selected components.
            AZ::ComponentTypeList componentsToAdd;
            for (auto index : selection)
            {
                // We only need to consider the first column, it's important that the data() function that 
                // returns ComponentDataModel::ClassDataRole also does so for the first column.
                if (index.column() != 0)
                {
                    continue;
                }

                QVariant classDataVariant = model->data(index, ComponentDataModel::ClassDataRole);
                if (classDataVariant.isValid())
                {
                    const AZ::SerializeContext::ClassData* classData = reinterpret_cast<const AZ::SerializeContext::ClassData*>(classDataVariant.value<void*>());
                    componentsToAdd.push_back(classData->m_typeId);
                }
            }

            AzToolsFramework::EntityCompositionRequestBus::Broadcast(&AzToolsFramework::EntityCompositionRequests::AddComponentsToEntities, AzToolsFramework::EntityIdList{ newEntityId }, componentsToAdd);

            return newEntityId;
        }

        return AZ::EntityId();
    }
// This is a helper function that given an object that derives from QAbstractItemModel, 
// it will request the model's "ClassDataRole" class data for an entry and use that 
// information to create a new entity with the selected components.
This is a helper function that given an object that derives from QAbstractItemModel,
it will request the model's "ClassDataRole" class data for an entry and use that
information to create a new entity with the selected components.
This is a helper function that given an object that derives from QAbstractItemModel it will request the model ' s " ClassDataRole " class data for an entry and use that information to create a new entity with the selected components .
AZ::EntityId CreateEntityFromSelection(const QModelIndexList& selection, QAbstractItemModel* model)
    {
        AZ::Vector3 position = AZ::Vector3::CreateZero();
        CViewport *view = GetIEditor()->GetViewManager()->GetGameViewport();
        int width, height;
        view->GetDimensions(&width, &height);
        position = LYVec3ToAZVec3(view->ViewToWorld(QPoint(width / 2, height / 2)));
        AZ::EntityId newEntityId;
        EBUS_EVENT_RESULT(newEntityId, AzToolsFramework::EditorRequests::Bus, CreateNewEntityAtPosition, position, AZ::EntityId());
        if (newEntityId.IsValid())
        {
            AZ::ComponentTypeList componentsToAdd;
            for (auto index : selection)
            {
                if (index.column() != 0)
                {
                    continue;
                }
                QVariant classDataVariant = model->data(index, ComponentDataModel::ClassDataRole);
                if (classDataVariant.isValid())
                {
                    const AZ::SerializeContext::ClassData* classData = reinterpret_cast<const AZ::SerializeContext::ClassData*>(classDataVariant.value<void*>());
                    componentsToAdd.push_back(classData->m_typeId);
                }
            }
            AzToolsFramework::EntityCompositionRequestBus::Broadcast(&AzToolsFramework::EntityCompositionRequests::AddComponentsToEntities, AzToolsFramework::EntityIdList{ newEntityId }, componentsToAdd);
            return newEntityId;
        }
        return AZ::EntityId();
    }
AZ :: EntityId CreateEntityFromSelection ( const QModelIndexList & selection , QAbstractItemModel * model ) { AZ :: Vector3 position = AZ :: Vector3 :: CreateZero ( ) ; CViewport * view = GetIEditor ( ) -> GetViewManager ( ) -> GetGameViewport ( ) ; int width , height ; view -> GetDimensions ( & width , & height ) ; position = LYVec3ToAZVec3 ( view -> ViewToWorld ( QPoint ( width / 2 , height / 2 ) ) ) ; AZ :: EntityId newEntityId ; EBUS_EVENT_RESULT ( newEntityId , AzToolsFramework :: EditorRequests :: Bus , CreateNewEntityAtPosition , position , AZ :: EntityId ( ) ) ; if ( newEntityId . IsValid ( ) ) { AZ :: ComponentTypeList componentsToAdd ; for ( auto index : selection ) { if ( index . column ( ) != 0 ) { continue ; } QVariant classDataVariant = model -> data ( index , ComponentDataModel :: ClassDataRole ) ; if ( classDataVariant . isValid ( ) ) { const AZ :: SerializeContext :: ClassData * classData = reinterpret_cast < const AZ :: SerializeContext :: ClassData * > ( classDataVariant . value < void * > ( ) ) ; componentsToAdd . push_back ( classData -> m_typeId ) ; } } AzToolsFramework :: EntityCompositionRequestBus :: Broadcast ( & AzToolsFramework :: EntityCompositionRequests :: AddComponentsToEntities , AzToolsFramework :: EntityIdList { newEntityId } , componentsToAdd ) ; return newEntityId ; } return AZ :: EntityId ( ) ; }
This is a helper function that given an object that derives from QAbstractItemModel,
it will request the model's "ClassDataRole" class data for an entry and use that
information to create a new entity with the selected components.
This is a helper function that given an object that derives from QAbstractItemModel it will request the model ' s " ClassDataRole " class data for an entry and use that information to create a new entity with the selected components .
// Add all the selected components. // We only need to consider the first column, it's important that the data() function that  // returns ComponentDataModel::ClassDataRole also does so for the first column.