From b8ac5a823390b19a594472f6c1972576bbfdaf85 Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (o)" <j.wuttke@fz-juelich.de> Date: Tue, 12 Mar 2024 15:49:01 +0100 Subject: [PATCH] Plot2DFram w/o data member and w/o ctor arg --- GUI/View/Frame/Plot2DFrame.cpp | 26 ++++++++++++++------------ GUI/View/Frame/Plot2DFrame.h | 4 ++-- GUI/View/Frame/StackedFrames.cpp | 8 ++++---- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/GUI/View/Frame/Plot2DFrame.cpp b/GUI/View/Frame/Plot2DFrame.cpp index 4da738293bc..ece6761e3bd 100644 --- a/GUI/View/Frame/Plot2DFrame.cpp +++ b/GUI/View/Frame/Plot2DFrame.cpp @@ -29,14 +29,11 @@ #include <QSplitter> #include <QStackedWidget> -Plot2DFrame::Plot2DFrame(Data2DItem* item) +Plot2DFrame::Plot2DFrame() : m_canvas2D(new MaskEditorCanvas) , m_canvas1D(new ProjectedGraphsCanvas) , m_masks_panel(new MasksPanel) - , m_data_item(item) { - ASSERT(item); - auto* layout = new QHBoxLayout; setLayout(layout); layout->setContentsMargins(0, 0, 0, 0); @@ -71,7 +68,7 @@ Plot2DFrame::Plot2DFrame(Data2DItem* item) [panels] { panels->setHidden(!panels->isHidden()); }); connect(gActions->save_projections, &QAction::triggered, - [this] { GUI::IO::saveProjections(m_data_item); }); + [this] { GUI::IO::saveProjections(dataItem()); }); connect(gActions->delete_projection, &QAction::triggered, [this] { removeProjection(); }); @@ -97,10 +94,15 @@ Plot2DFrame::Plot2DFrame(Data2DItem* item) showEvent(nullptr); } +Data2DItem* Plot2DFrame::dataItem() +{ + return m_data_source->realData2DItem(); +} + void Plot2DFrame::updateFrame() { - ASSERT(m_data_item); - MasksQModel* masks_qmodel = m_data_item->getOrCreateModel(); + ASSERT(dataItem()); + MasksQModel* masks_qmodel = dataItem()->getOrCreateModel(); ASSERT(masks_qmodel); m_masks_panel->updateMasksPanel(masks_qmodel); @@ -108,22 +110,22 @@ void Plot2DFrame::updateFrame() // It prevents problem with switching between datasets in projection mode. m_canvas1D->disconnectItem(); - m_canvas2D->updateCanvas(m_data_item); - m_canvas1D->setData2DItem(m_data_item); + m_canvas2D->updateCanvas(dataItem()); + m_canvas1D->setData2DItem(dataItem()); } void Plot2DFrame::showEvent(QShowEvent*) { - ASSERT(m_data_item); + ASSERT(dataItem()); updateFrame(); } void Plot2DFrame::removeProjection() { - if (!m_data_item) + if (!dataItem()) return; - MasksQModel* masks_qmodel = m_data_item->getOrCreateProjectionModel(); + MasksQModel* masks_qmodel = dataItem()->getOrCreateProjectionModel(); ASSERT(masks_qmodel); masks_qmodel->deleteItem(); gDoc->setModified(); diff --git a/GUI/View/Frame/Plot2DFrame.h b/GUI/View/Frame/Plot2DFrame.h index 5dd4872685f..a97e129099d 100644 --- a/GUI/View/Frame/Plot2DFrame.h +++ b/GUI/View/Frame/Plot2DFrame.h @@ -27,18 +27,18 @@ class ProjectedGraphsCanvas; class Plot2DFrame : public QWidget { public: - Plot2DFrame(Data2DItem* item); + Plot2DFrame(); private: void updateFrame(); void showEvent(QShowEvent*) override; void removeProjection(); + Data2DItem* dataItem(); MaskEditorCanvas* m_canvas2D; //!< canvas with color map at the top ProjectedGraphsCanvas* m_canvas1D; //!< bottom widget to draw projections plot MasksPanel* m_masks_panel; //!< panel with mask list and properties of one mask - Data2DItem* m_data_item; std::unique_ptr<DataSource> m_data_source; }; diff --git a/GUI/View/Frame/StackedFrames.cpp b/GUI/View/Frame/StackedFrames.cpp index 46a2e7aa2bc..ed28b79c84c 100644 --- a/GUI/View/Frame/StackedFrames.cpp +++ b/GUI/View/Frame/StackedFrames.cpp @@ -73,8 +73,8 @@ QWidget* StackedDataFrames::newFrame(QObject* obj) const { if (auto* item = dynamic_cast<Data1DItem*>(obj)) return new SpecularFrame(item); - if (auto* item = dynamic_cast<Data2DItem*>(obj)) - return new Plot2DFrame(item); + if (dynamic_cast<Data2DItem*>(obj)) + return new Plot2DFrame; ASSERT_NEVER; } @@ -108,8 +108,8 @@ QWidget* StackedJobFrames::newFrame(QObject* obj) const { if (auto* item = dynamic_cast<Data1DItem*>(obj)) return new SpecularFrame(item); - if (auto* item = dynamic_cast<Data2DItem*>(obj)) - return new Plot2DFrame(item); + if (dynamic_cast<Data2DItem*>(obj)) + return new Plot2DFrame; if (auto* item = dynamic_cast<JobItem*>(obj)) { if (item->rank() == 1) return new Fit1DFrame(item); -- GitLab