From 5174055a89fe99f7b4361e1c8fe1bfb8e4fc1e01 Mon Sep 17 00:00:00 2001
From: Mikhail Svechnikov <m.svechnikov@fz-juelich.de>
Date: Wed, 5 Jul 2023 12:14:44 +0200
Subject: [PATCH] ProjectionsEditorActions: pick up selection model from
 container

---
 .../IntensityDataProjectionsWidget.cpp         | 14 ++------------
 .../IntensityDataProjectionsWidget.h           |  2 --
 .../Projection/ProjectionsEditorActions.cpp    | 18 ++++++++++--------
 GUI/View/Projection/ProjectionsEditorActions.h |  5 ++---
 4 files changed, 14 insertions(+), 25 deletions(-)

diff --git a/GUI/View/Projection/IntensityDataProjectionsWidget.cpp b/GUI/View/Projection/IntensityDataProjectionsWidget.cpp
index 3b625c8d3d2..2a7d227b398 100644
--- a/GUI/View/Projection/IntensityDataProjectionsWidget.cpp
+++ b/GUI/View/Projection/IntensityDataProjectionsWidget.cpp
@@ -63,16 +63,7 @@ void IntensityDataProjectionsWidget::setContext()
 {
     ASSERT(currentIntensityDataItem());
 
-    ProjectionContainerItem* containerItem =
-        currentIntensityDataItem()->getOrCreateProjectionContainerItem();
-    ASSERT(containerItem);
-
-    MaskContainerModel* containerModel = containerItem->model();
-    ASSERT(containerModel);
-
-    m_selectionModel.reset(new QItemSelectionModel(containerModel));
-
-    m_projectionsCanvas->setSelectionModel(m_selectionModel.get());
+//    m_projectionsCanvas->setSelectionModel(m_selectionModel.get());
 
     // The following line must come before 'm_projectionsCanvas->setContext()'!
     // It prevents problem with switching between datasets in projection mode.
@@ -81,8 +72,7 @@ void IntensityDataProjectionsWidget::setContext()
     m_projectionsCanvas->setContext(currentIntensityDataItem());
     m_projectionsWidget->setIntensityItem(currentIntensityDataItem());
 
-    m_editorActions->setContext(currentIntensityDataItem(), containerModel);
-    m_editorActions->setSelectionModel(m_selectionModel.get());
+    m_editorActions->setContext(currentIntensityDataItem());
 }
 
 void IntensityDataProjectionsWidget::resetContext()
diff --git a/GUI/View/Projection/IntensityDataProjectionsWidget.h b/GUI/View/Projection/IntensityDataProjectionsWidget.h
index 7144d6d5e59..1636eb4d24e 100644
--- a/GUI/View/Projection/IntensityDataProjectionsWidget.h
+++ b/GUI/View/Projection/IntensityDataProjectionsWidget.h
@@ -22,7 +22,6 @@ class ProjectionsEditorActions;
 class ProjectionsEditorCanvas;
 class ProjectionsToolbar;
 class ProjectionsWidget;
-class QItemSelectionModel;
 
 //! Main widget to embed projections editor for IntensityDataItem.
 //! Part of RealDataPresenter and JobResultsPresenter.
@@ -47,7 +46,6 @@ private:
     ProjectionsEditorCanvas* m_projectionsCanvas; //! canvas with color map at the top
     ProjectionsWidget* m_projectionsWidget;       //! bottom widget to draw projections plot
     IntensityDataPropertyWidget* m_propertyPanel; //! panel at the right with properties
-    std::unique_ptr<QItemSelectionModel> m_selectionModel;
 };
 
 #endif // BORNAGAIN_GUI_VIEW_PROJECTION_INTENSITYDATAPROJECTIONSWIDGET_H
diff --git a/GUI/View/Projection/ProjectionsEditorActions.cpp b/GUI/View/Projection/ProjectionsEditorActions.cpp
index 07cec543aa8..797a382ba90 100644
--- a/GUI/View/Projection/ProjectionsEditorActions.cpp
+++ b/GUI/View/Projection/ProjectionsEditorActions.cpp
@@ -50,17 +50,19 @@ ProjectionsEditorActions::ProjectionsEditorActions(QWidget* parent)
     connect(m_deleteAction, &QAction::triggered, this, &ProjectionsEditorActions::onDeleteAction);
 }
 
-void ProjectionsEditorActions::setContext(IntensityDataItem* intensityItem,
-                                          MaskContainerModel* maskContainerModel)
+void ProjectionsEditorActions::setContext(IntensityDataItem* intensityItem)
 {
-    ASSERT(maskContainerModel);
-    m_maskContainerModel = maskContainerModel;
+    ASSERT(intensityItem);
     m_intensityDataItem = intensityItem;
-}
 
-void ProjectionsEditorActions::setSelectionModel(QItemSelectionModel* selectionModel)
-{
-    m_selectionModel = selectionModel;
+    ProjectionContainerItem* containerItem = intensityItem->getOrCreateProjectionContainerItem();
+    ASSERT(containerItem);
+
+    m_maskContainerModel = containerItem->model();
+    ASSERT(m_maskContainerModel);
+
+    m_selectionModel = containerItem->selectionModel();
+    ASSERT(m_selectionModel);
 }
 
 QList<QAction*> ProjectionsEditorActions::topToolbarActions()
diff --git a/GUI/View/Projection/ProjectionsEditorActions.h b/GUI/View/Projection/ProjectionsEditorActions.h
index 0f5d2e0d19c..73ff062fbb7 100644
--- a/GUI/View/Projection/ProjectionsEditorActions.h
+++ b/GUI/View/Projection/ProjectionsEditorActions.h
@@ -20,6 +20,7 @@
 
 class IntensityDataItem;
 class MaskContainerModel;
+class ProjectionContainerItem;
 
 //! Provides various actions for ProjectionsEditor.
 
@@ -29,9 +30,7 @@ class ProjectionsEditorActions : public QObject {
 public:
     ProjectionsEditorActions(QWidget* parent = nullptr);
 
-    void setContext(IntensityDataItem* intensityItem, MaskContainerModel* maskContainerModel);
-
-    void setSelectionModel(QItemSelectionModel* selectionModel);
+    void setContext(IntensityDataItem* intensityItem);
 
     QList<QAction*> topToolbarActions();
 
-- 
GitLab