From 7b18e0077e640963d8929dee8a79291bac60016f Mon Sep 17 00:00:00 2001
From: Joachim Wuttke <j.wuttke@fz-juelich.de>
Date: Fri, 9 Feb 2024 17:54:34 +0100
Subject: [PATCH] some direct access to OwningVector

---
 GUI/Model/Files/DatafilesSet.h              |  1 +
 GUI/Model/Project/LinkInstrumentManager.cpp | 30 ++++++++++-----------
 GUI/Model/Project/LinkInstrumentManager.h   |  4 +--
 3 files changed, 18 insertions(+), 17 deletions(-)

diff --git a/GUI/Model/Files/DatafilesSet.h b/GUI/Model/Files/DatafilesSet.h
index afdeb10412c..4dabd60092a 100644
--- a/GUI/Model/Files/DatafilesSet.h
+++ b/GUI/Model/Files/DatafilesSet.h
@@ -41,6 +41,7 @@ public:
     void writeTo(QXmlStreamWriter* w) const;
     void writeDatafiles(const QString& projectDir) const;
 
+    const OwningVector<DatafileItem>& dfileItems2() const { return m_dfile_items; }
     QVector<DatafileItem*> dfileItems() const;
     QStringList realItemNames() const;
     int currentIndex() const { return m_current_index; }
diff --git a/GUI/Model/Project/LinkInstrumentManager.cpp b/GUI/Model/Project/LinkInstrumentManager.cpp
index aa9dc779723..b199230ef60 100644
--- a/GUI/Model/Project/LinkInstrumentManager.cpp
+++ b/GUI/Model/Project/LinkInstrumentManager.cpp
@@ -86,7 +86,7 @@ LinkInstrumentManager::LinkInstrumentManager(ProjectDocument* document)
             &LinkInstrumentManager::onInstrumentChanged);
 }
 
-bool LinkInstrumentManager::canLinkDataToInstrument(const DatafileItem* dfile_item,
+bool LinkInstrumentManager::canLinkDataToInstrument(const DatafileItem* dfi,
                                                     const QString& identifier,
                                                     QWidget* parent) const
 {
@@ -96,23 +96,23 @@ bool LinkInstrumentManager::canLinkDataToInstrument(const DatafileItem* dfile_it
     if (!instrumentItem)
         return true;
 
-    if (instrumentItem->axdims().size() != dfile_item->axdims().size()) {
+    if (instrumentItem->axdims().size() != dfi->axdims().size()) {
         ::warn(parent, "Cannot link, data is incompatible with the instrument.");
         return false;
     }
 
-    if (instrumentItem->alignedWith(dfile_item))
+    if (instrumentItem->alignedWith(dfi))
         return true;
 
     ASSERT(parent);
     QString message =
-        dfile_item->holdsDimensionalData()
+        dfi->holdsDimensionalData()
             ? "Experimental data carries information on the range/points of measurement."
-            : printShapeMessage(instrumentItem->axdims(), dfile_item->axdims());
+            : printShapeMessage(instrumentItem->axdims(), dfi->axdims());
     if (!QuestionOnInstrumentReshaping(message))
         return false;
 
-    instrumentItem->updateToRealData(dfile_item);
+    instrumentItem->updateToRealData(dfi);
     emit m_doc->instruments()->instrumentChanged(instrumentItem);
     return true;
 }
@@ -121,20 +121,20 @@ void LinkInstrumentManager::onInstrumentChanged(const InstrumentItem* instrument
 {
     // Run through all DatafileItem and refresh linking to match possible change in detector
     // axes definition.
-    for (auto* dfile_item : m_doc->datafiles()->dfileItems())
-        if (dfile_item->instrumentId() == instrument->id()) {
-            if (!instrument->alignedWith(dfile_item)) {
-                dfile_item->unlinkFromInstrument();
-                emit linkToInstrumentChanged(dfile_item);
+    for (auto* dfi : m_doc->datafiles()->dfileItems2())
+        if (dfi->instrumentId() == instrument->id()) {
+            if (!instrument->alignedWith(dfi)) {
+                dfi->unlinkFromInstrument();
+                emit linkToInstrumentChanged(dfi);
             } else
-                dfile_item->linkToInstrument(instrument); // link stays same, only data is updated
+                dfi->linkToInstrument(instrument); // link stays same, only data is updated
         }
 }
 
 void LinkInstrumentManager::onInstrumentAddedOrRemoved()
 {
     // remove links in realItems (in case of a linked instrument was removed)
-    for (auto* dfile_item : m_doc->datafiles()->dfileItems())
-        if (!m_doc->instruments()->instrumentExists(dfile_item->instrumentId()))
-            dfile_item->unlinkFromInstrument();
+    for (auto* dfi : m_doc->datafiles()->dfileItems2())
+        if (!m_doc->instruments()->instrumentExists(dfi->instrumentId()))
+            dfi->unlinkFromInstrument();
 }
diff --git a/GUI/Model/Project/LinkInstrumentManager.h b/GUI/Model/Project/LinkInstrumentManager.h
index 87367c65415..7be979aecd0 100644
--- a/GUI/Model/Project/LinkInstrumentManager.h
+++ b/GUI/Model/Project/LinkInstrumentManager.h
@@ -35,11 +35,11 @@ public:
     //! quiet defines whether a "not possible" message box is shown if link is not possible. Use
     //! this e.g. for unit tests. The question for adjusting the instrument is not suppressed by
     //! this flag.
-    bool canLinkDataToInstrument(const DatafileItem* dfile_item, const QString& identifier,
+    bool canLinkDataToInstrument(const DatafileItem* dfi, const QString& identifier,
                                  QWidget* parent) const;
 
 signals:
-    void linkToInstrumentChanged(const DatafileItem* dfile_item);
+    void linkToInstrumentChanged(const DatafileItem* dfi);
 
 private:
     void onInstrumentChanged(const InstrumentItem* instrument);
-- 
GitLab