From 406776fbd30d1b1b0365ca2f0bb8ca9e9cd5d8a7 Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de>
Date: Thu, 9 Nov 2023 17:26:10 +0100
Subject: [PATCH] mv fct updateSize from view to scene

---
 GUI/View/Mask/MaskEditorCanvas.cpp             |  2 +-
 GUI/View/Mask/MaskGraphicsScene.cpp            | 11 +++++++++++
 GUI/View/Mask/MaskGraphicsScene.h              |  2 ++
 GUI/View/Mask/MaskGraphicsView.cpp             | 18 +++---------------
 GUI/View/Mask/MaskGraphicsView.h               |  6 +++---
 .../Projection/ProjectionsEditorCanvas.cpp     |  2 +-
 6 files changed, 21 insertions(+), 20 deletions(-)

diff --git a/GUI/View/Mask/MaskEditorCanvas.cpp b/GUI/View/Mask/MaskEditorCanvas.cpp
index 28815c11ae1..48f79cf4b78 100644
--- a/GUI/View/Mask/MaskEditorCanvas.cpp
+++ b/GUI/View/Mask/MaskEditorCanvas.cpp
@@ -53,7 +53,7 @@ void MaskEditorCanvas::setContextMEC(Data2DItem* data2DItem)
 
     m_scene->setAssociatedItems(data2DItem, data2DItem->maskContainerItem());
     m_resultsPresenter->setContextMRP(data2DItem);
-    m_view->updateSize(m_view->size());
+    m_scene->updateSize(m_view->size());
 
     m_statusLabel->addPlot(m_scene->colorMap());
 }
diff --git a/GUI/View/Mask/MaskGraphicsScene.cpp b/GUI/View/Mask/MaskGraphicsScene.cpp
index 06c59fa63b3..0fbe467db14 100644
--- a/GUI/View/Mask/MaskGraphicsScene.cpp
+++ b/GUI/View/Mask/MaskGraphicsScene.cpp
@@ -769,3 +769,14 @@ PolygonDisplay* MaskGraphicsScene::currentPolygon() const
         return dynamic_cast<PolygonDisplay*>(m_ItemToView[m_currentItem]);
     return nullptr;
 }
+
+void MaskGraphicsScene::updateSize(const QSize& newSize)
+{
+    for (QGraphicsItem* graphicsItem : items()) {
+        if (auto* proxy = dynamic_cast<MaskGraphicsProxy*>(graphicsItem)) {
+            proxy->resize(newSize);
+            setSceneRect(0, 0, newSize.width(), newSize.height());
+            proxy->setPos(0, 0);
+        }
+    }
+}
diff --git a/GUI/View/Mask/MaskGraphicsScene.h b/GUI/View/Mask/MaskGraphicsScene.h
index 233a4445d06..dfe810653fa 100644
--- a/GUI/View/Mask/MaskGraphicsScene.h
+++ b/GUI/View/Mask/MaskGraphicsScene.h
@@ -49,6 +49,8 @@ public:
 
     ColorMap* colorMap();
 
+    void updateSize(const QSize& newSize);
+
 signals:
     void itemContextMenuRequest(const QPoint& point);
     void lineItemProcessed();
diff --git a/GUI/View/Mask/MaskGraphicsView.cpp b/GUI/View/Mask/MaskGraphicsView.cpp
index 343e7ea8b45..3b2f2fb3091 100644
--- a/GUI/View/Mask/MaskGraphicsView.cpp
+++ b/GUI/View/Mask/MaskGraphicsView.cpp
@@ -13,9 +13,7 @@
 //  ************************************************************************************************
 
 #include "GUI/View/Mask/MaskGraphicsView.h"
-#include "GUI/View/Mask/MaskGraphicsProxy.h"
 #include "GUI/View/Mask/MaskGraphicsScene.h"
-#include <QGraphicsScene>
 #include <QScrollBar>
 #include <QTransform>
 #include <QWheelEvent>
@@ -29,8 +27,9 @@ const double zoom_step = 0.05;
 } // namespace
 
 
-MaskGraphicsView::MaskGraphicsView(QGraphicsScene* scene, QWidget* parent)
+MaskGraphicsView::MaskGraphicsView(MaskGraphicsScene* scene, QWidget* parent)
     : QGraphicsView(scene, parent)
+    , m_scene(scene)
     , m_current_zoom_value(1.0)
 {
     setObjectName("MaskGraphicsView");
@@ -67,7 +66,7 @@ void MaskGraphicsView::wheelEvent(QWheelEvent* event)
 void MaskGraphicsView::resizeEvent(QResizeEvent* event)
 {
     QWidget::resizeEvent(event);
-    updateSize(event->size());
+    m_scene->updateSize(event->size());
 }
 
 void MaskGraphicsView::keyPressEvent(QKeyEvent* event)
@@ -140,14 +139,3 @@ void MaskGraphicsView::increaseZoomValue()
         zoom_value = max_zoom_value;
     setZoomValue(zoom_value);
 }
-
-void MaskGraphicsView::updateSize(const QSize& newSize)
-{
-    for (QGraphicsItem* graphicsItem : scene()->items()) {
-        if (auto* proxy = dynamic_cast<MaskGraphicsProxy*>(graphicsItem)) {
-            proxy->resize(newSize);
-            scene()->setSceneRect(0, 0, newSize.width(), newSize.height());
-            proxy->setPos(0, 0);
-        }
-    }
-}
diff --git a/GUI/View/Mask/MaskGraphicsView.h b/GUI/View/Mask/MaskGraphicsView.h
index 555f4b92cd6..b8a3be11999 100644
--- a/GUI/View/Mask/MaskGraphicsView.h
+++ b/GUI/View/Mask/MaskGraphicsView.h
@@ -18,6 +18,7 @@
 #include "GUI/Model/Data/MaskEditorFlags.h"
 #include <QGraphicsView>
 
+class MaskGraphicsScene;
 class QWheelEvent;
 
 //! Graphics view for MaskEditorCanvas
@@ -25,12 +26,10 @@ class QWheelEvent;
 class MaskGraphicsView : public QGraphicsView {
     Q_OBJECT
 public:
-    MaskGraphicsView(QGraphicsScene* scene, QWidget* parent = nullptr);
+    MaskGraphicsView(MaskGraphicsScene* scene, QWidget* parent = nullptr);
     QSize sizeHint() const override { return QSize(512, 512); }
     QSize minimumSizeHint() const override { return QSize(128, 128); }
 
-    void updateSize(const QSize& newSize);
-
 public slots:
     void onResetViewRequest();
 
@@ -51,6 +50,7 @@ private:
     void decreaseZoomValue();
     void increaseZoomValue();
 
+    MaskGraphicsScene* m_scene;
     double m_current_zoom_value;
 };
 
diff --git a/GUI/View/Projection/ProjectionsEditorCanvas.cpp b/GUI/View/Projection/ProjectionsEditorCanvas.cpp
index b0107d28e53..3c500f37655 100644
--- a/GUI/View/Projection/ProjectionsEditorCanvas.cpp
+++ b/GUI/View/Projection/ProjectionsEditorCanvas.cpp
@@ -67,7 +67,7 @@ void ProjectionsEditorCanvas::setContextPC(Data2DItem* data2DItem)
     connect(m_scene, &MaskGraphicsScene::lineItemDeleted, data2DItem, &Data2DItem::projectionGone,
             Qt::UniqueConnection);
 
-    m_view->updateSize(m_view->size());
+    m_scene->updateSize(m_view->size());
 
     m_data2DItem = data2DItem;
 
-- 
GitLab