Removed GetViewsForModel.

This commit is contained in:
Leonardo Zide 2021-02-27 11:15:04 -08:00
parent 4b36b90f7c
commit 95fbc13247
4 changed files with 22 additions and 23 deletions

View file

@ -203,12 +203,6 @@ public:
return CurrentTab ? CurrentTab->GetModel() : nullptr;
}
const lcArray<lcView*>* GetViewsForModel(const lcModel* Model) const
{
const lcModelTabWidget* const TabWidget = GetTabWidgetForModel(Model);
return TabWidget ? TabWidget->GetViews() : nullptr;
}
lcModelTabWidget* GetTabForView(lcView* View) const
{
for (int TabIdx = 0; TabIdx < mModelTabWidget->count(); TabIdx++)

View file

@ -190,19 +190,15 @@ void lcModel::DeleteModel()
{
if (gMainWindow)
{
const lcArray<lcView*>* Views = gMainWindow->GetViewsForModel(this);
std::vector<lcView*> Views = lcView::GetModelViews(this);
// TODO: this is only needed to avoid a dangling pointer during undo/redo if a camera is set to a view but we should find a better solution instead
if (Views)
for (lcView* View : Views)
{
for (int ViewIdx = 0; ViewIdx < Views->GetSize(); ViewIdx++)
{
lcView* View = (*Views)[ViewIdx];
lcCamera* Camera = View->GetCamera();
lcCamera* Camera = View->GetCamera();
if (!Camera->IsSimple() && mCameras.FindIndex(Camera) != -1)
View->SetCamera(Camera, true);
}
if (!Camera->IsSimple() && mCameras.FindIndex(Camera) != -1)
View->SetCamera(Camera, true);
}
}
@ -2563,14 +2559,11 @@ bool lcModel::RemoveSelectedObjects()
if (Camera->IsSelected())
{
const lcArray<lcView*>* Views = gMainWindow->GetViewsForModel(this);
for (int ViewIdx = 0; ViewIdx < Views->GetSize(); ViewIdx++)
{
lcView* View = (*Views)[ViewIdx];
std::vector<lcView*> Views = lcView::GetModelViews(this);
for (lcView* View : Views)
if (Camera == View->GetCamera())
View->SetCamera(Camera, true);
}
RemovedCamera = true;
mCameras.RemoveIndex(CameraIdx);
@ -4103,10 +4096,10 @@ void lcModel::EraserToolClicked(lcObject* Object)
case lcObjectType::Camera:
{
const lcArray<lcView*>* Views = gMainWindow->GetViewsForModel(this);
for (int ViewIdx = 0; ViewIdx < Views->GetSize(); ViewIdx++)
std::vector<lcView*> Views = lcView::GetModelViews(this);
for (lcView* View : Views)
{
lcView* View = (*Views)[ViewIdx];
lcCamera* Camera = View->GetCamera();
if (Camera == Object)

View file

@ -62,6 +62,17 @@ lcView::~lcView()
delete mContext;
}
std::vector<lcView*> lcView::GetModelViews(const lcModel* Model)
{
std::vector<lcView*> Views;
for (lcView* View : mViews)
if (View->GetModel() == Model)
Views.push_back(View);
return Views;
}
void lcView::UpdateProjectViews(const Project* Project)
{
for (lcView* View : mViews)

View file

@ -188,6 +188,7 @@ public:
mBackgroundColor = BackgroundColor;
}
static std::vector<lcView*> GetModelViews(const lcModel* Model);
static void UpdateProjectViews(const Project* Project);
static void UpdateAllViews();