From 7ce2377b8a0f8ddaf66d2ed92f8d4005697aa2e4 Mon Sep 17 00:00:00 2001
From: Mikhail Svechnikov <svechnikovmv@gmail.com>
Date: Fri, 17 Feb 2023 16:49:55 +0100
Subject: [PATCH] pass InstrumentModel to RealModel and RealItems

---
 GUI/Model/Model/RealModel.cpp         | 4 +++-
 GUI/Model/Model/RealModel.h           | 6 ++++--
 GUI/Model/Project/ProjectDocument.cpp | 1 +
 3 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/GUI/Model/Model/RealModel.cpp b/GUI/Model/Model/RealModel.cpp
index 66386bcac57..0f2681c6d26 100644
--- a/GUI/Model/Model/RealModel.cpp
+++ b/GUI/Model/Model/RealModel.cpp
@@ -28,8 +28,9 @@ const QString SelectedRank("SelectedRank");
 } // namespace Tag
 } // namespace
 
-RealModel::RealModel(QObject* parent)
+RealModel::RealModel(InstrumentModel *instrumentModel, QObject* parent)
     : QObject(parent)
+    , m_instrumentModel(instrumentModel)
 {
     setObjectName("RealModel");
 }
@@ -118,6 +119,7 @@ void RealModel::readFrom(QXmlStreamReader* r, const QString& projectDir,
 RealItem* RealModel::createRealItem()
 {
     auto realItem = std::make_unique<RealItem>();
+    realItem->setInstrumentModel(m_instrumentModel);
     m_realItems.push_back(std::move(realItem));
     emit realDataAddedOrRemoved();
     return m_realItems.back().get();
diff --git a/GUI/Model/Model/RealModel.h b/GUI/Model/Model/RealModel.h
index 5cc11d2141e..082bc34bfda 100644
--- a/GUI/Model/Model/RealModel.h
+++ b/GUI/Model/Model/RealModel.h
@@ -19,16 +19,17 @@
 #include <QObject>
 #include <QXmlStreamWriter>
 
-class RealItem;
 class DataItem;
+class InstrumentModel;
 class MessageService;
+class RealItem;
 
 //! The RealModel class is a model to store all imported RealItem's.
 class RealModel : public QObject {
     Q_OBJECT
 
 public:
-    explicit RealModel(QObject* parent = nullptr);
+    explicit RealModel(InstrumentModel* instrumentModel = nullptr, QObject* parent = nullptr);
     ~RealModel();
 
     QVector<DataItem*> dataItems() const;
@@ -63,6 +64,7 @@ signals:
 
 private:
     DataFilesCleaner dataFilesCleaner;
+    InstrumentModel* m_instrumentModel;
     std::vector<std::unique_ptr<RealItem>> m_realItems;
     int m_selectedIndex = -1;
     int m_selectedRank = -1;
diff --git a/GUI/Model/Project/ProjectDocument.cpp b/GUI/Model/Project/ProjectDocument.cpp
index 5a641111125..62dcf818f29 100644
--- a/GUI/Model/Project/ProjectDocument.cpp
+++ b/GUI/Model/Project/ProjectDocument.cpp
@@ -54,6 +54,7 @@ ProjectDocument::ProjectDocument()
     , m_singleSampleMode(false)
     , m_functionalities(All)
     , m_instrumentEditController(&m_instrumentModel)
+    , m_realModel(&m_instrumentModel)
     , m_lastViewActive(GUI::ID::ViewId::Instrument)
 {
     connect(&m_instrumentEditController, &InstrumentsEditController::instrumentAddedOrRemoved, this,
-- 
GitLab