From ee1a944256cc01d71f47e9ef7254167dc8c862fc Mon Sep 17 00:00:00 2001
From: Matthias Puchner <github@mpuchner.de>
Date: Mon, 23 Aug 2021 11:50:28 +0200
Subject: [PATCH] use current project for SessionModelView to access models

...instead of access via mainWindow
---
 GUI/Views/SessionModelView.cpp     | 12 +++++++-----
 GUI/mainwindow/mainwindow.cpp      | 10 ----------
 GUI/mainwindow/mainwindow.h        |  2 --
 GUI/mainwindow/projectdocument.cpp | 10 ++++++++++
 GUI/mainwindow/projectdocument.h   |  5 +++++
 5 files changed, 22 insertions(+), 17 deletions(-)

diff --git a/GUI/Views/SessionModelView.cpp b/GUI/Views/SessionModelView.cpp
index 1685c3f67ca..edc3b642a02 100644
--- a/GUI/Views/SessionModelView.cpp
+++ b/GUI/Views/SessionModelView.cpp
@@ -22,6 +22,7 @@
 #include "GUI/Views/SessionModelDelegate.h"
 #include "GUI/Views/TestView.h"
 #include "GUI/mainwindow/mainwindow.h"
+#include "GUI/mainwindow/projectmanager.h"
 #include <QToolBar>
 #include <QToolButton>
 #include <QVBoxLayout>
@@ -83,11 +84,12 @@ void SessionModelView::init_tabs()
 
 QList<SessionModel*> SessionModelView::modelsForTabs()
 {
-    QList<SessionModel*> result = QList<SessionModel*>()
-                                  << m_mainWindow->instrumentModel() << m_mainWindow->sampleModel()
-                                  << m_mainWindow->realDataModel() << m_mainWindow->materialModel()
-                                  << m_mainWindow->jobModel();
-    return result;
+    auto doc = ProjectManager::instance()->document();
+    if (!doc)
+        return {};
+
+    return {doc->instrumentModel(), doc->sampleModel(), doc->realDataModel(), doc->materialModel(),
+            doc->jobModel()};
 }
 
 void SessionModelView::init_test_view()
diff --git a/GUI/mainwindow/mainwindow.cpp b/GUI/mainwindow/mainwindow.cpp
index 31f60fd659f..bb02ee956a1 100644
--- a/GUI/mainwindow/mainwindow.cpp
+++ b/GUI/mainwindow/mainwindow.cpp
@@ -137,21 +137,11 @@ MainWindow* MainWindow::instance()
     return s_instance;
 }
 
-MaterialModel* MainWindow::materialModel()
-{
-    return models()->materialModel();
-}
-
 InstrumentModel* MainWindow::instrumentModel()
 {
     return models()->instrumentModel();
 }
 
-SampleModel* MainWindow::sampleModel()
-{
-    return models()->sampleModel();
-}
-
 RealDataModel* MainWindow::realDataModel()
 {
     return models()->realDataModel();
diff --git a/GUI/mainwindow/mainwindow.h b/GUI/mainwindow/mainwindow.h
index 01567edc6cc..71ff463dea3 100644
--- a/GUI/mainwindow/mainwindow.h
+++ b/GUI/mainwindow/mainwindow.h
@@ -55,9 +55,7 @@ public:
     //! Returns the one and only instance of this class
     static MainWindow* instance();
 
-    MaterialModel* materialModel();
     InstrumentModel* instrumentModel();
-    SampleModel* sampleModel();
     RealDataModel* realDataModel();
     JobModel* jobModel();
     ApplicationModels* models();
diff --git a/GUI/mainwindow/projectdocument.cpp b/GUI/mainwindow/projectdocument.cpp
index b8d3a46c6c4..7735bca1545 100644
--- a/GUI/mainwindow/projectdocument.cpp
+++ b/GUI/mainwindow/projectdocument.cpp
@@ -115,6 +115,16 @@ MaterialModel* ProjectDocument::materialModel() const
     return m_applicationModels != nullptr ? m_applicationModels->materialModel() : nullptr;
 }
 
+RealDataModel* ProjectDocument::realDataModel() const
+{
+    return m_applicationModels != nullptr ? m_applicationModels->realDataModel() : nullptr;
+}
+
+JobModel* ProjectDocument::jobModel() const
+{
+    return m_applicationModels != nullptr ? m_applicationModels->jobModel() : nullptr;
+}
+
 void ProjectDocument::save(const QString& project_file_name, bool autoSave)
 {
     saveProjectData(project_file_name);
diff --git a/GUI/mainwindow/projectdocument.h b/GUI/mainwindow/projectdocument.h
index 727aeba832b..34a43c0c147 100644
--- a/GUI/mainwindow/projectdocument.h
+++ b/GUI/mainwindow/projectdocument.h
@@ -24,6 +24,8 @@ class OutputDataIOService;
 class InstrumentModel;
 class SampleModel;
 class MaterialModel;
+class RealDataModel;
+class JobModel;
 
 //! Project document class handles all data related to the opened project
 //! (sample, jobModel, project specific windows settings)
@@ -56,6 +58,9 @@ public:
     InstrumentModel* instrumentModel() const;
     SampleModel* sampleModel() const;
     MaterialModel* materialModel() const;
+    RealDataModel* realDataModel() const;
+    JobModel* jobModel() const;
+
 
     void save(const QString& project_file_name, bool autoSave = false);
 
-- 
GitLab