diff --git a/GUI/coregui/Views/IntensityDataWidgets/IntensityDataCanvas.cpp b/GUI/coregui/Views/IntensityDataWidgets/IntensityDataCanvas.cpp index 882c5ea0ec6a381ea98986de0dfadcda6c26fc95..5541eb343e0f92a34dee37d3ce0450497a6dba21 100644 --- a/GUI/coregui/Views/IntensityDataWidgets/IntensityDataCanvas.cpp +++ b/GUI/coregui/Views/IntensityDataWidgets/IntensityDataCanvas.cpp @@ -20,11 +20,11 @@ #include "SavePlotAssistant.h" #include "projectmanager.h" #include "ComboProperty.h" +#include "IntensityDataFFTPresenter.h" #include <QAction> #include <QVBoxLayout> #include <QMouseEvent> #include <QSettings> -#include "IntensityDataFunctions.h" namespace { @@ -99,20 +99,13 @@ void IntensityDataCanvas::onMousePress(QMouseEvent* event) void IntensityDataCanvas::onfftAction() { - auto dataItem = intensityDataItem(); - - if(m_backup) - { - dataItem->setOutputData(m_backup.release()); - } - - else - { - m_backup.reset(new OutputData<double>); - m_backup->copyFrom(*dataItem->getOutputData()); - - dataItem->setOutputData( - (IntensityDataFunctions::createFFT(*dataItem->getOutputData())).release()); + if(m_fftPresenter) { + // returning ColorMap to non-fft presentation + m_colorMap->setItem(intensityDataItem()); + m_fftPresenter.reset(); + } else { + m_fftPresenter.reset(new IntensityDataFFTPresenter); + m_colorMap->setItem(m_fftPresenter->fftItem(intensityDataItem())); } } @@ -126,6 +119,11 @@ void IntensityDataCanvas::subscribeToItem() } +void IntensityDataCanvas::unsubscribeFromItem() +{ + m_fftPresenter.reset(); +} + IntensityDataItem* IntensityDataCanvas::intensityDataItem() { IntensityDataItem* result = dynamic_cast<IntensityDataItem*>(currentItem()); diff --git a/GUI/coregui/Views/IntensityDataWidgets/IntensityDataCanvas.h b/GUI/coregui/Views/IntensityDataWidgets/IntensityDataCanvas.h index 8630d69c248d5d016e240d1b46843cc3a25acebd..0befc1bcc745b29035066397bc08bee59d7aaace 100644 --- a/GUI/coregui/Views/IntensityDataWidgets/IntensityDataCanvas.h +++ b/GUI/coregui/Views/IntensityDataWidgets/IntensityDataCanvas.h @@ -22,6 +22,7 @@ class SessionItem; class IntensityDataItem; class ColorMapCanvas; +class IntensityDataFFTPresenter; class QAction; //! The IntensityDataCanvas class represents IntensityDataItem as color map, @@ -48,7 +49,8 @@ public slots: void onfftAction(); protected: - virtual void subscribeToItem(); + void subscribeToItem(); + void unsubscribeFromItem(); private: IntensityDataItem* intensityDataItem(); @@ -61,7 +63,7 @@ private: QAction* m_savePlotAction; QAction* m_fftAction; - std::unique_ptr<OutputData<double>> m_backup; + std::unique_ptr<IntensityDataFFTPresenter> m_fftPresenter; }; diff --git a/GUI/coregui/Views/IntensityDataWidgets/IntensityDataFFTPresenter.cpp b/GUI/coregui/Views/IntensityDataWidgets/IntensityDataFFTPresenter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..628c07b0f2b8e128ddba49b15987b312b4dc3e01 --- /dev/null +++ b/GUI/coregui/Views/IntensityDataWidgets/IntensityDataFFTPresenter.cpp @@ -0,0 +1,40 @@ +// ************************************************************************** // +// +// BornAgain: simulate and fit scattering at grazing incidence +// +//! @file GUI/coregui/Views/IntensityDataWidgets/IntensityDataFFTPresenter.h +//! @brief Defines class IntensityDataFFTPresenter +//! +//! @homepage http://www.bornagainproject.org +//! @license GNU General Public License v3 or higher (see COPYING) +//! @copyright Forschungszentrum Jülich GmbH 2018 +//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS) +// +// ************************************************************************** // + +#include "IntensityDataFFTPresenter.h" +#include "IntensityDataFunctions.h" +#include "IntensityDataItem.h" +#include "SessionModel.h" +#include "GUIHelpers.h" +#include <QWidget> + +IntensityDataFFTPresenter::IntensityDataFFTPresenter(QWidget* parent) + : QObject(parent) + , m_fftModel(new SessionModel("TempFFTModel")) + , m_fftItem(nullptr) +{ + m_fftItem + = dynamic_cast<IntensityDataItem*>(m_fftModel->insertNewItem(Constants::IntensityDataType)); +} + +IntensityDataItem* IntensityDataFFTPresenter::fftItem(IntensityDataItem* origItem) +{ + if (!origItem) + throw GUIHelpers::Error("IntensityDataFFTPresenter::fftItem() -> Error. Empty item."); + + m_fftItem->setOutputData( + IntensityDataFunctions::createFFT(*origItem->getOutputData()).release()); + + return m_fftItem; +} diff --git a/GUI/coregui/Views/IntensityDataWidgets/IntensityDataFFTPresenter.h b/GUI/coregui/Views/IntensityDataWidgets/IntensityDataFFTPresenter.h new file mode 100644 index 0000000000000000000000000000000000000000..38dea903ec905c77b7714b8e2c4cf8497348b568 --- /dev/null +++ b/GUI/coregui/Views/IntensityDataWidgets/IntensityDataFFTPresenter.h @@ -0,0 +1,40 @@ +// ************************************************************************** // +// +// BornAgain: simulate and fit scattering at grazing incidence +// +//! @file GUI/coregui/Views/IntensityDataWidgets/IntensityDataFFTPresenter.h +//! @brief Defines class IntensityDataFFTPresenter +//! +//! @homepage http://www.bornagainproject.org +//! @license GNU General Public License v3 or higher (see COPYING) +//! @copyright Forschungszentrum Jülich GmbH 2018 +//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS) +// +// ************************************************************************** // + +#ifndef INTENSITYDATAFFTPRESENTER_H +#define INTENSITYDATAFFTPRESENTER_H + +#include "WinDllMacros.h" +#include <QObject> + +class SessionModel; +class IntensityDataItem; +class QWidget; + +//! Provides support in Fast Fourier transformation of IntensityDataItem. +//! Contains own model to hold IntensityDataItem with fft-transformed results. + +class BA_CORE_API_ IntensityDataFFTPresenter : public QObject { + Q_OBJECT +public: + IntensityDataFFTPresenter(QWidget* parent = nullptr); + + IntensityDataItem* fftItem(IntensityDataItem* origItem); + +private: + SessionModel *m_fftModel; + IntensityDataItem* m_fftItem; +}; + +#endif // INTENSITYDATAFFTPRESENTER_H