// Copyright Epic Games, Inc. All Rights Reserved. #include "MVVM/TrackRowModelStorageExtension.h" #include "HAL/PlatformCrt.h" #include "MVVM/ViewModels/SequenceModel.h" #include "MVVM/ViewModels/TrackRowModel.h" #include "MVVM/ViewModels/ViewModel.h" #include "MVVM/ViewModels/ViewModelHierarchy.h" #include "Misc/AssertionMacros.h" #include "Misc/Optional.h" #include "MovieSceneTrack.h" #include "Templates/TypeHash.h" namespace UE { namespace Sequencer { FTrackRowModelStorageExtension::FTrackRowModelStorageExtension() { } void FTrackRowModelStorageExtension::OnCreated(TSharedRef InWeakOwner) { OwnerModel = InWeakOwner->CastThis(); } void FTrackRowModelStorageExtension::OnReinitialize() { for (auto It = TrackToModel.CreateIterator(); It; ++It) { if (It.Key().Key.ResolveObjectPtr() == nullptr || It.Value().Pin().Get() == nullptr) { It.RemoveCurrent(); } } TrackToModel.Compact(); } TSharedPtr FTrackRowModelStorageExtension::CreateModelForTrackRow(UMovieSceneTrack* InTrack, int32 InRowIndex, TSharedPtr DesiredParent) { KeyType Key{ FObjectKey(InTrack), InRowIndex }; if (TSharedPtr Existing = TrackToModel.FindRef(Key).Pin()) { return Existing; } TSharedPtr NewModel = MakeShared(InTrack, InRowIndex); // IMPORTANT: We always add the model to the map before calling initialize // So that any code that runs inside Initialize is still able to find this TrackToModel.Add(Key, NewModel); if (!DesiredParent) { DesiredParent = OwnerModel->AsShared(); } TOptional Children = DesiredParent->GetChildList(EViewModelListType::Outliner); if (ensureMsgf(Children.IsSet(), TEXT("Attempting to create a folder within something that is not able to contain outliner items"))) { Children->AddChild(NewModel); } NewModel->Initialize(); return NewModel; } TSharedPtr FTrackRowModelStorageExtension::FindModelForTrackRow(UMovieSceneTrack* InTrack, int32 InRowIndex) const { KeyType Key{ FObjectKey(InTrack), InRowIndex }; return TrackToModel.FindRef(Key).Pin(); } } // namespace Sequencer } // namespace UE