diff --git a/GUI/coregui/Views/IntensityDataWidgets/SpecularPlotWithDataView.cpp b/GUI/coregui/Views/IntensityDataWidgets/Plot1D.cpp similarity index 78% rename from GUI/coregui/Views/IntensityDataWidgets/SpecularPlotWithDataView.cpp rename to GUI/coregui/Views/IntensityDataWidgets/Plot1D.cpp index cd4bb463e3d2d9a346f9944c6b6bbe52880c000c..40249401067dfc3a3981524db4df4cb95eb46e12 100644 --- a/GUI/coregui/Views/IntensityDataWidgets/SpecularPlotWithDataView.cpp +++ b/GUI/coregui/Views/IntensityDataWidgets/Plot1D.cpp @@ -2,8 +2,8 @@ // // BornAgain: simulate and fit scattering at grazing incidence // -//! @file GUI/coregui/Views/SpecularDataWidgets/SpecularPlotWithDataView.cpp -//! @brief Implements class SpecularPlotWithDataView +//! @file GUI/coregui/Views/SpecularDataWidgets/Plot1D.cpp +//! @brief Implements class Plot1D //! //! @homepage http://www.bornagainproject.org //! @license GNU General Public License v3 or higher (see COPYING) @@ -12,7 +12,7 @@ // // ************************************************************************** // -#include "SpecularPlotWithDataView.h" +#include "Plot1D.h" #include "AxesItems.h" #include "ColorMapUtils.h" #include "DataItem.h" @@ -30,7 +30,7 @@ const int replot_update_interval = 10; int getBin(double x, const QCPGraph* graph); } -SpecularPlotWithDataView::SpecularPlotWithDataView(QWidget* parent) +Plot1D::Plot1D(QWidget* parent) : ScientificPlot(parent, PLOT_TYPE::Plot1D), m_custom_plot(new QCustomPlot), m_update_timer(new UpdateTimer(replot_update_interval, this)), m_block_update(true) { @@ -48,7 +48,7 @@ SpecularPlotWithDataView::SpecularPlotWithDataView(QWidget* parent) setMouseTrackingEnabled(true); } -PlotEventInfo SpecularPlotWithDataView::eventInfo(double xpos, double ypos) const +PlotEventInfo Plot1D::eventInfo(double xpos, double ypos) const { PlotEventInfo result(plotType()); if (!viewItem()) @@ -63,18 +63,18 @@ PlotEventInfo SpecularPlotWithDataView::eventInfo(double xpos, double ypos) cons return result; } -void SpecularPlotWithDataView::setLog(bool log) +void Plot1D::setLog(bool log) { ColorMapUtils::setLogz(m_custom_plot->yAxis, log); ColorMapUtils::setLogz(m_custom_plot->yAxis2, log); } -void SpecularPlotWithDataView::resetView() +void Plot1D::resetView() { viewItem()->resetView(); } -void SpecularPlotWithDataView::onPropertyChanged(const QString& property_name) +void Plot1D::onPropertyChanged(const QString& property_name) { if (m_block_update) return; @@ -85,7 +85,7 @@ void SpecularPlotWithDataView::onPropertyChanged(const QString& property_name) } } -void SpecularPlotWithDataView::onXaxisRangeChanged(QCPRange newRange) +void Plot1D::onXaxisRangeChanged(QCPRange newRange) { m_block_update = true; viewItem()->setLowerX(newRange.lower); @@ -93,7 +93,7 @@ void SpecularPlotWithDataView::onXaxisRangeChanged(QCPRange newRange) m_block_update = false; } -void SpecularPlotWithDataView::onYaxisRangeChanged(QCPRange newRange) +void Plot1D::onYaxisRangeChanged(QCPRange newRange) { m_block_update = true; viewItem()->setLowerY(newRange.lower); @@ -101,12 +101,12 @@ void SpecularPlotWithDataView::onYaxisRangeChanged(QCPRange newRange) m_block_update = false; } -void SpecularPlotWithDataView::onTimeToReplot() +void Plot1D::onTimeToReplot() { m_custom_plot->replot(); } -void SpecularPlotWithDataView::subscribeToItem() +void Plot1D::subscribeToItem() { initPlots(); refreshPlotData(); @@ -127,14 +127,14 @@ void SpecularPlotWithDataView::subscribeToItem() setConnected(true); } -void SpecularPlotWithDataView::unsubscribeFromItem() +void Plot1D::unsubscribeFromItem() { m_custom_plot->clearGraphs(); m_graph_map.clear(); setConnected(false); } -void SpecularPlotWithDataView::initPlots() +void Plot1D::initPlots() { auto property_items = viewItem()->propertyItems<Data1DProperties>(); std::for_each( @@ -146,45 +146,45 @@ void SpecularPlotWithDataView::initPlots() }); } -void SpecularPlotWithDataView::setConnected(bool isConnected) +void Plot1D::setConnected(bool isConnected) { setAxesRangeConnected(isConnected); setUpdateTimerConnected(isConnected); } -void SpecularPlotWithDataView::setAxesRangeConnected(bool isConnected) +void Plot1D::setAxesRangeConnected(bool isConnected) { if (isConnected) { connect(m_custom_plot->xAxis, static_cast<void (QCPAxis::*)(const QCPRange&)>(&QCPAxis::rangeChanged), this, - &SpecularPlotWithDataView::onXaxisRangeChanged, Qt::UniqueConnection); + &Plot1D::onXaxisRangeChanged, Qt::UniqueConnection); connect(m_custom_plot->yAxis, static_cast<void (QCPAxis::*)(const QCPRange&)>(&QCPAxis::rangeChanged), this, - &SpecularPlotWithDataView::onYaxisRangeChanged, Qt::UniqueConnection); + &Plot1D::onYaxisRangeChanged, Qt::UniqueConnection); } else { disconnect(m_custom_plot->xAxis, static_cast<void (QCPAxis::*)(const QCPRange&)>(&QCPAxis::rangeChanged), this, - &SpecularPlotWithDataView::onXaxisRangeChanged); + &Plot1D::onXaxisRangeChanged); disconnect(m_custom_plot->yAxis, static_cast<void (QCPAxis::*)(const QCPRange&)>(&QCPAxis::rangeChanged), this, - &SpecularPlotWithDataView::onYaxisRangeChanged); + &Plot1D::onYaxisRangeChanged); } } -void SpecularPlotWithDataView::setUpdateTimerConnected(bool isConnected) +void Plot1D::setUpdateTimerConnected(bool isConnected) { if (isConnected) connect(m_update_timer, &UpdateTimer::timeToUpdate, this, - &SpecularPlotWithDataView::onTimeToReplot, Qt::UniqueConnection); + &Plot1D::onTimeToReplot, Qt::UniqueConnection); else disconnect(m_update_timer, &UpdateTimer::timeToUpdate, this, - &SpecularPlotWithDataView::onTimeToReplot); + &Plot1D::onTimeToReplot); } -void SpecularPlotWithDataView::refreshPlotData() +void Plot1D::refreshPlotData() { auto view_item = viewItem(); assert(view_item); @@ -201,7 +201,7 @@ void SpecularPlotWithDataView::refreshPlotData() m_block_update = false; } -void SpecularPlotWithDataView::setAxesRangeFromItem(DataItem1DView* item) +void Plot1D::setAxesRangeFromItem(DataItem1DView* item) { m_custom_plot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); m_custom_plot->axisRect()->setupFullAxesBox(true); @@ -213,13 +213,13 @@ void SpecularPlotWithDataView::setAxesRangeFromItem(DataItem1DView* item) setAxesRangeConnected(true); } -void SpecularPlotWithDataView::setAxesLabelsFromItem(DataItem1DView* item) +void Plot1D::setAxesLabelsFromItem(DataItem1DView* item) { setLabel(item->xAxisItem(), m_custom_plot->xAxis, item->getXaxisTitle()); setLabel(item->yAxisItem(), m_custom_plot->yAxis, item->getYaxisTitle()); } -void SpecularPlotWithDataView::setLabel(const BasicAxisItem* item, QCPAxis* axis, QString label) +void Plot1D::setLabel(const BasicAxisItem* item, QCPAxis* axis, QString label) { assert(item && axis); if (item->getItemValue(BasicAxisItem::P_TITLE_IS_VISIBLE).toBool()) @@ -228,7 +228,7 @@ void SpecularPlotWithDataView::setLabel(const BasicAxisItem* item, QCPAxis* axis axis->setLabel(QString()); } -void SpecularPlotWithDataView::setDataFromItem(DataItem1DView* item) +void Plot1D::setDataFromItem(DataItem1DView* item) { assert(item); auto property_items = item->propertyItems<Data1DProperties>(); @@ -247,20 +247,20 @@ void SpecularPlotWithDataView::setDataFromItem(DataItem1DView* item) }); } -DataItem1DView* SpecularPlotWithDataView::viewItem() +DataItem1DView* Plot1D::viewItem() { return const_cast<DataItem1DView*>( - static_cast<const SpecularPlotWithDataView*>(this)->viewItem()); + static_cast<const Plot1D*>(this)->viewItem()); } -const DataItem1DView* SpecularPlotWithDataView::viewItem() const +const DataItem1DView* Plot1D::viewItem() const { const auto result = dynamic_cast<const DataItem1DView*>(currentItem()); Q_ASSERT(result); return result; } -void SpecularPlotWithDataView::modifyAxesProperties(const QString& axisName, +void Plot1D::modifyAxesProperties(const QString& axisName, const QString& propertyName) { if (m_block_update) @@ -292,7 +292,7 @@ void SpecularPlotWithDataView::modifyAxesProperties(const QString& axisName, } } -void SpecularPlotWithDataView::replot() +void Plot1D::replot() { m_update_timer->scheduleUpdate(); } diff --git a/GUI/coregui/Views/IntensityDataWidgets/SpecularPlotWithDataView.h b/GUI/coregui/Views/IntensityDataWidgets/Plot1D.h similarity index 90% rename from GUI/coregui/Views/IntensityDataWidgets/SpecularPlotWithDataView.h rename to GUI/coregui/Views/IntensityDataWidgets/Plot1D.h index fa718ba66f52d6ae50f623de8406930139da83ec..1942c81e1c54673467a85535c8dfd7bf5dc3c688 100644 --- a/GUI/coregui/Views/IntensityDataWidgets/SpecularPlotWithDataView.h +++ b/GUI/coregui/Views/IntensityDataWidgets/Plot1D.h @@ -2,8 +2,8 @@ // // BornAgain: simulate and fit scattering at grazing incidence // -//! @file GUI/coregui/Views/SpecularDataWidgets/SpecularPlotWithDataView.h -//! @brief Defines class SpecularPlotWithDataView +//! @file GUI/coregui/Views/SpecularDataWidgets/Plot1D.h +//! @brief Defines class Plot1D //! //! @homepage http://www.bornagainproject.org //! @license GNU General Public License v3 or higher (see COPYING) @@ -12,8 +12,8 @@ // // ************************************************************************** // -#ifndef SPECULARPLOTWITHDATAVIEW_H -#define SPECULARPLOTWITHDATAVIEW_H +#ifndef PLOT1D_H +#define PLOT1D_H #include "ScientificPlot.h" #include "qcustomplot.h" @@ -29,12 +29,12 @@ class UpdateTimer; //! DataItem1DView. Provides minimal functionality for data plotting and axes interaction. Should be //! a component for more complicated plotting widgets. -class SpecularPlotWithDataView : public ScientificPlot +class Plot1D : public ScientificPlot { Q_OBJECT public: - explicit SpecularPlotWithDataView(QWidget* parent = nullptr); + explicit Plot1D(QWidget* parent = nullptr); QSize sizeHint() const override { return QSize(500, 400); } QSize minimumSizeHint() const override { return QSize(128, 128); } @@ -110,4 +110,4 @@ private: bool m_block_update; }; -#endif // SPECULARPLOTWITHDATAVIEW_H +#endif // PLOT1D_H diff --git a/GUI/coregui/Views/TestView.cpp b/GUI/coregui/Views/TestView.cpp index 4cc14d3d96f0c0afdeada71f42549ba30023a616..57ffdfe8d6fcfd9ae44f829c9891f741897cb323 100644 --- a/GUI/coregui/Views/TestView.cpp +++ b/GUI/coregui/Views/TestView.cpp @@ -14,6 +14,7 @@ #include "TestView.h" #include "AccordionWidget.h" +#include "ApplicationModels.h" #include "DataItem1DView.h" #include "JobModel.h" #include "JobItem.h" @@ -21,11 +22,10 @@ #include "MaterialEditor.h" #include "MinimizerItem.h" #include "MinimizerSettingsWidget.h" -#include "ApplicationModels.h" +#include "Plot1D.h" #include "RealDataItem.h" #include "SampleModel.h" #include "SpecularDataItem.h" -#include "SpecularPlotWithDataView.h" #include "TestComponentView.h" #include "mainwindow.h" #include <QTreeView> @@ -215,7 +215,7 @@ void TestView::test_specular_data_widget() QVBoxLayout* layout = new QVBoxLayout; layout->setMargin(0); layout->setSpacing(0); - auto widget = new SpecularPlotWithDataView(this); + auto widget = new Plot1D(this); widget->setItem(job_item->dataItemView()); layout->addWidget(widget); setLayout(layout);