diff --git a/GUI/Model/Mask/ProjectionItems.cpp b/GUI/Model/Mask/ProjectionItems.cpp index d8886031cab4129eefe46ae29b0ac1dc101abec9..1e9383b4de242beda3915df9911a592265c995a9 100644 --- a/GUI/Model/Mask/ProjectionItems.cpp +++ b/GUI/Model/Mask/ProjectionItems.cpp @@ -17,12 +17,11 @@ ProjectionContainerItem::ProjectionContainerItem() = default; -QVector<MaskItem*> -ProjectionContainerItem::projectionsOfType(GUI::ID::ProjectionType projectionType) +QVector<MaskItem*> ProjectionContainerItem::projectionsOfType(Qt::Orientation projectionType) { - if (projectionType == GUI::ID::ProjectionType::Horizontal) + if (projectionType == Qt::Horizontal) return projections<HorizontalLineItem>(); - else if (projectionType == GUI::ID::ProjectionType::Vertical) + else if (projectionType == Qt::Vertical) return projections<VerticalLineItem>(); else ASSERT_NEVER; diff --git a/GUI/Model/Mask/ProjectionItems.h b/GUI/Model/Mask/ProjectionItems.h index a5a4918f8a5b19c66a7e6cb7b2681f275cddf759..f75f79235a1c0e2cff37ce56d9d5e69402160900 100644 --- a/GUI/Model/Mask/ProjectionItems.h +++ b/GUI/Model/Mask/ProjectionItems.h @@ -24,7 +24,7 @@ class ProjectionContainerItem : public MaskContainerItem { public: ProjectionContainerItem(); - QVector<MaskItem*> projectionsOfType(GUI::ID::ProjectionType projectionType); + QVector<MaskItem*> projectionsOfType(Qt::Orientation projectionType); private: template <typename LineType> diff --git a/GUI/Support/Data/ID.h b/GUI/Support/Data/ID.h index 22be4c1c6bbcf8dea2926607c1b954216cfe04fe..ae70100c1cf1dca22e0f583306a4e4a23f396e79 100644 --- a/GUI/Support/Data/ID.h +++ b/GUI/Support/Data/ID.h @@ -17,9 +17,6 @@ namespace GUI::ID { -//! The possible states of a projection type. -enum ProjectionType { Horizontal, Vertical, Invalid }; - //! Which distributions should be available in the selector enum class Distributions { All, Symmetric }; diff --git a/GUI/View/Projection/ProjectionsPlot.cpp b/GUI/View/Projection/ProjectionsPlot.cpp index 46ea5f5ea841f4d1da0a3aaaeb77d8011333f608..3c52793dc6cac09e7e1b77736d8c6066ce1e65d4 100644 --- a/GUI/View/Projection/ProjectionsPlot.cpp +++ b/GUI/View/Projection/ProjectionsPlot.cpp @@ -24,15 +24,12 @@ #include "GUI/Support/Util/QCP_Util.h" #include "GUI/Support/Util/Style.h" #include "GUI/View/PlotScale/RangeUtil.h" -#include <boost/polymorphic_cast.hpp> #include <qcustomplot.h> #include <utility> -using boost::polymorphic_downcast; - -ProjectionsPlot::ProjectionsPlot(GUI::ID::ProjectionType projectionType, QWidget* parent) +ProjectionsPlot::ProjectionsPlot(Qt::Orientation orientation, QWidget* parent) : QWidget(parent) - , m_projectionType(projectionType) + , m_orientation(orientation) , m_plot(new QCustomPlot) { auto* vlayout = new QVBoxLayout(this); @@ -70,55 +67,55 @@ void ProjectionsPlot::onMarginsChanged(double left, double right) void ProjectionsPlot::connectItems() { - if (!data2DItem()) + if (!m_data2DItem) return; // Units changed - connect(data2DItem(), &Data2DItem::axesUnitsReplotRequested, this, + connect(m_data2DItem, &Data2DItem::axesUnitsReplotRequested, this, &ProjectionsPlot::updateProjections, Qt::UniqueConnection); // Update projection plot on new item appearance - connect(data2DItem(), &Data2DItem::projectionCreated, this, &ProjectionsPlot::updateProjections, + connect(m_data2DItem, &Data2DItem::projectionCreated, this, &ProjectionsPlot::updateProjections, Qt::UniqueConnection); // Update projection position - connect(data2DItem(), &Data2DItem::projectionPositionChanged, this, + connect(m_data2DItem, &Data2DItem::projectionPositionChanged, this, &ProjectionsPlot::onProjectionPropertyChanged, Qt::UniqueConnection); // Remove projection plot - connect(data2DItem(), &Data2DItem::projectionGone, this, &ProjectionsPlot::clearProjection, + connect(m_data2DItem, &Data2DItem::projectionGone, this, &ProjectionsPlot::clearProjection, Qt::UniqueConnection); // Values of intensity changed, regenerate everything. - connect(data2DItem(), &Data2DItem::datafieldChanged, this, + connect(m_data2DItem, &Data2DItem::datafieldChanged, this, &ProjectionsPlot::updateProjectionsData, Qt::UniqueConnection); // interpolation changed - connect(data2DItem(), &Data2DItem::interpolationChanged, this, &ProjectionsPlot::setInterpolate, + connect(m_data2DItem, &Data2DItem::interpolationChanged, this, &ProjectionsPlot::setInterpolate, Qt::UniqueConnection); // AXES // if the colormap is zoomed or dragged: - connect(data2DItem(), &Data2DItem::updateOtherPlots, this, &ProjectionsPlot::updateAxesRange, + connect(m_data2DItem, &Data2DItem::updateOtherPlots, this, &ProjectionsPlot::updateAxesRange, Qt::UniqueConnection); // if axes are changed externally, from the properties panel: // axes range - connect(data2DItem()->axItemX(), &BasicAxisItem::axisRangeChanged, this, + connect(m_data2DItem->axItemX(), &BasicAxisItem::axisRangeChanged, this, &ProjectionsPlot::updateAxesRange, Qt::UniqueConnection); - connect(data2DItem()->axItemY(), &BasicAxisItem::axisRangeChanged, this, + connect(m_data2DItem->axItemY(), &BasicAxisItem::axisRangeChanged, this, &ProjectionsPlot::updateAxesRange, Qt::UniqueConnection); - connect(data2DItem()->zAxisItem(), &BasicAxisItem::axisRangeChanged, this, + connect(m_data2DItem->zAxisItem(), &BasicAxisItem::axisRangeChanged, this, &ProjectionsPlot::updateAxesRange, Qt::UniqueConnection); // axes title - connect(data2DItem()->axItemX(), &BasicAxisItem::axisTitleChanged, this, + connect(m_data2DItem->axItemX(), &BasicAxisItem::axisTitleChanged, this, &ProjectionsPlot::updateAxesTitle, Qt::UniqueConnection); - connect(data2DItem()->axItemY(), &BasicAxisItem::axisTitleChanged, this, + connect(m_data2DItem->axItemY(), &BasicAxisItem::axisTitleChanged, this, &ProjectionsPlot::updateAxesTitle, Qt::UniqueConnection); // z log scale - connect(data2DItem()->zAxisItem(), &AmplitudeAxisItem::logScaleChanged, this, + connect(m_data2DItem->zAxisItem(), &AmplitudeAxisItem::logScaleChanged, this, &ProjectionsPlot::setLogz, Qt::UniqueConnection); updateProjectionsData(); @@ -126,46 +123,25 @@ void ProjectionsPlot::connectItems() void ProjectionsPlot::disconnectItems() { - if (!data2DItem()) + if (!m_data2DItem) return; - disconnect(data2DItem(), nullptr, this, nullptr); - disconnect(data2DItem()->axItemX(), nullptr, this, nullptr); - disconnect(data2DItem()->axItemY(), nullptr, this, nullptr); - disconnect(data2DItem()->zAxisItem(), nullptr, this, nullptr); -} - -Data2DItem* ProjectionsPlot::data2DItem() -{ - return m_data2DItem; -} - -ProjectionContainerItem* ProjectionsPlot::projectionContainerItem() -{ - ProjectionContainerItem* result = data2DItem()->projectionContainerItem(); - ASSERT(result); - return result; -} - -QVector<MaskItem*> ProjectionsPlot::projectionItems() -{ - return projectionContainerItem()->projectionsOfType(m_projectionType); + disconnect(m_data2DItem, nullptr, this, nullptr); + disconnect(m_data2DItem->axItemX(), nullptr, this, nullptr); + disconnect(m_data2DItem->axItemY(), nullptr, this, nullptr); + disconnect(m_data2DItem->zAxisItem(), nullptr, this, nullptr); } bool ProjectionsPlot::isCorrectProjectionType(MaskItem* item) { - if (isHorizontalType() && dynamic_cast<HorizontalLineItem*>(item)) - return true; - - if (!isHorizontalType() && dynamic_cast<VerticalLineItem*>(item)) - return true; - - return false; + if (m_orientation == Qt::Horizontal) + return dynamic_cast<HorizontalLineItem*>(item); + return dynamic_cast<VerticalLineItem*>(item); } QCPGraph* ProjectionsPlot::graphForItem(MaskRoot* item) { - if (!data2DItem()) + if (!m_data2DItem) return nullptr; QCPGraph* graph = m_item_to_graph[item]; @@ -173,7 +149,7 @@ QCPGraph* ProjectionsPlot::graphForItem(MaskRoot* item) graph = m_plot->addGraph(); QPen pen; pen.setColor(QColor(0, 0, 255, 200)); - graph->setLineStyle(data2DItem()->isInterpolated() ? QCPGraph::lsLine + graph->setLineStyle(m_data2DItem->isInterpolated() ? QCPGraph::lsLine : QCPGraph::lsStepCenter); graph->setPen(pen); m_item_to_graph[item] = graph; @@ -186,12 +162,12 @@ QCPGraph* ProjectionsPlot::graphForItem(MaskRoot* item) void ProjectionsPlot::updateProjectionsData() { - if (!data2DItem()) + if (!m_data2DItem) return; updateAxesRange(); updateAxesTitle(); - setLogz(data2DItem()->isLog()); + setLogz(m_data2DItem->isLog()); updateProjections(); } @@ -199,50 +175,52 @@ void ProjectionsPlot::updateProjectionsData() void ProjectionsPlot::updateProjections() { - for (auto* projItem : projectionItems()) { + ASSERT(m_data2DItem); + auto container_item = m_data2DItem->projectionContainerItem(); + if (!container_item) + return; + auto projn_items = container_item->projectionsOfType(m_orientation); + for (auto* projItem : projn_items) if (isCorrectProjectionType(projItem)) setGraphFromItem(graphForItem(projItem), projItem); - } replot(); } void ProjectionsPlot::onProjectionPropertyChanged(MaskRoot* item) { auto* projection = dynamic_cast<MaskItem*>(item); - ASSERT(projection); - if (isCorrectProjectionType(projection)) { + if (!projection) + return; + if (isCorrectProjectionType(projection)) if (auto* graph = graphForItem(projection)) setGraphFromItem(graph, projection); - } replot(); } -//! Updates canva's axes to match current zoom level of Data2DItem +//! Updates canvas axes to match current zoom level of Data2DItem void ProjectionsPlot::updateAxesRange() { - const Data2DItem* ii = data2DItem(); - if (!ii) + if (!m_data2DItem) return; - if (isHorizontalType()) - m_plot->xAxis->setRange(QCPRange(ii->lowerX(), ii->upperX())); + if (m_orientation == Qt::Horizontal) + m_plot->xAxis->setRange(QCPRange(m_data2DItem->lowerX(), m_data2DItem->upperX())); else - m_plot->xAxis->setRange(QCPRange(ii->lowerY(), ii->upperY())); + m_plot->xAxis->setRange(QCPRange(m_data2DItem->lowerY(), m_data2DItem->upperY())); - m_plot->yAxis->setRange(QCPRange(ii->lowerZ(), ii->upperZ())); + m_plot->yAxis->setRange(QCPRange(m_data2DItem->lowerZ(), m_data2DItem->upperZ())); } void ProjectionsPlot::updateAxesTitle() { - const Data2DItem* ii = data2DItem(); - if (!ii) + if (!m_data2DItem) return; - if (isHorizontalType()) - m_plot->xAxis->setLabel(ii->xAxisLabel()); + if (m_orientation == Qt::Horizontal) + m_plot->xAxis->setLabel(m_data2DItem->xAxisLabel()); else - m_plot->xAxis->setLabel(ii->yAxisLabel()); + m_plot->xAxis->setLabel(m_data2DItem->yAxisLabel()); } //! Removes plot corresponding to given projection item. @@ -258,7 +236,6 @@ void ProjectionsPlot::clearProjection(MaskRoot* item) void ProjectionsPlot::clearAll() { - // also removes projections from other intensity maps that are not in projectionItems() list m_plot->clearPlottables(); m_item_to_graph.clear(); replot(); @@ -268,17 +245,16 @@ void ProjectionsPlot::clearAll() void ProjectionsPlot::setGraphFromItem(QCPGraph* graph, MaskItem* item) { - const Data2DItem* ii = data2DItem(); - if (!ii || !ii->c_field()) + if (!m_data2DItem || !m_data2DItem->c_field()) return; std::unique_ptr<Datafield> field; // TODO: merge with very similar code in SaveProjectionsAssistant::projectionsData if (const auto* horLine = dynamic_cast<HorizontalLineItem*>(item)) - field.reset(ii->c_field()->xProjection(horLine->posY())); + field.reset(m_data2DItem->c_field()->xProjection(horLine->posY())); else if (const auto* verLine = dynamic_cast<VerticalLineItem*>(item)) - field.reset(ii->c_field()->yProjection(verLine->posX())); + field.reset(m_data2DItem->c_field()->yProjection(verLine->posX())); else ASSERT_NEVER; @@ -304,10 +280,3 @@ void ProjectionsPlot::replot() { m_plot->replot(); } - -//! Returns true, if widget is intended for horizontal projections. - -bool ProjectionsPlot::isHorizontalType() -{ - return m_projectionType == GUI::ID::ProjectionType::Horizontal; -} diff --git a/GUI/View/Projection/ProjectionsPlot.h b/GUI/View/Projection/ProjectionsPlot.h index 039b6b47332b7a48a9c5d81d2d7e630468e1a476..ea59994f26c887154ddd9efcb5f002c131792021 100644 --- a/GUI/View/Projection/ProjectionsPlot.h +++ b/GUI/View/Projection/ProjectionsPlot.h @@ -23,7 +23,6 @@ class Datafield; class Data2DItem; class MaskItem; class MaskRoot; -class ProjectionContainerItem; class QCPGraph; class QCustomPlot; @@ -32,7 +31,7 @@ class QCustomPlot; class ProjectionsPlot : public QWidget { Q_OBJECT public: - ProjectionsPlot(GUI::ID::ProjectionType projectionType, QWidget* parent = nullptr); + ProjectionsPlot(Qt::Orientation orientation, QWidget* parent = nullptr); void setData2DItem(Data2DItem* item); @@ -43,10 +42,7 @@ public slots: void onMarginsChanged(double left, double right); private: - Data2DItem* data2DItem(); - QVector<MaskItem*> projectionItems(); bool isCorrectProjectionType(MaskItem* item); - ProjectionContainerItem* projectionContainerItem(); QCPGraph* graphForItem(MaskRoot* item); void updateProjectionsData(); @@ -64,10 +60,8 @@ private: void replot(); - bool isHorizontalType(); - Data2DItem* m_data2DItem = nullptr; - GUI::ID::ProjectionType m_projectionType = GUI::ID::ProjectionType::Invalid; + const Qt::Orientation m_orientation; QCustomPlot* m_plot; QMap<MaskRoot*, QCPGraph*> m_item_to_graph; }; diff --git a/GUI/View/Projection/ProjectionsWidget.cpp b/GUI/View/Projection/ProjectionsWidget.cpp index 5aa4c22e74f50d2b133d5fe4eabd67ab2aba2f69..6616126475746b3336d36b18daf0144c2661a142 100644 --- a/GUI/View/Projection/ProjectionsWidget.cpp +++ b/GUI/View/Projection/ProjectionsWidget.cpp @@ -28,16 +28,16 @@ const int vertical_projection_tab = 1; ProjectionsWidget::ProjectionsWidget(QWidget* parent) : QWidget(parent) - , m_xProjection(new ProjectionsPlot(GUI::ID::ProjectionType::Horizontal)) - , m_yProjection(new ProjectionsPlot(GUI::ID::ProjectionType::Vertical)) + , m_xProjection(new ProjectionsPlot(Qt::Horizontal)) + , m_yProjection(new ProjectionsPlot(Qt::Vertical)) , m_tabWidget(new QTabWidget) { auto* layout = new QVBoxLayout; layout->setSpacing(0); m_tabWidget->setTabPosition(QTabWidget::North); - m_tabWidget->insertTab(GUI::ID::ProjectionType::Horizontal, m_xProjection, "Horizontal"); - m_tabWidget->insertTab(GUI::ID::ProjectionType::Vertical, m_yProjection, "Vertical"); + m_tabWidget->insertTab(Qt::Horizontal, m_xProjection, "Horizontal"); + m_tabWidget->insertTab(Qt::Vertical, m_yProjection, "Vertical"); layout->addWidget(m_tabWidget); setLayout(layout); diff --git a/GUI/View/Projection/SaveProjectionsAssistant.cpp b/GUI/View/Projection/SaveProjectionsAssistant.cpp index 8cafdb35e535b8c1cb920b07aa1f09acb9a8a1e7..b63b40a6bc03b76f90508f073a8e4c61810f8ceb 100644 --- a/GUI/View/Projection/SaveProjectionsAssistant.cpp +++ b/GUI/View/Projection/SaveProjectionsAssistant.cpp @@ -85,11 +85,11 @@ void SaveProjectionsAssistant::saveProjections(QWidget* parent, Data2DItem* data QTextStream out(&file); out << "# Projections along x-axis (horizontal projections) \n"; - out << projectionsToString(GUI::ID::ProjectionType::Horizontal, data2DItem); + out << projectionsToString(Qt::Horizontal, data2DItem); out << "\n"; out << "# Projections along y-axis (vertical projections) \n"; - out << projectionsToString(GUI::ID::ProjectionType::Vertical, data2DItem); + out << projectionsToString(Qt::Vertical, data2DItem); out << "\n"; file.close(); @@ -97,7 +97,7 @@ void SaveProjectionsAssistant::saveProjections(QWidget* parent, Data2DItem* data //! Generates multi-line string with projections data of given type (horizontal, vertical). -QString SaveProjectionsAssistant::projectionsToString(GUI::ID::ProjectionType projectionsType, +QString SaveProjectionsAssistant::projectionsToString(Qt::Orientation projectionsType, Data2DItem* data2DItem) { QString result; @@ -124,11 +124,10 @@ QString SaveProjectionsAssistant::projectionsToString(GUI::ID::ProjectionType pr //! Returns projections data for all projections of given type (horizontal, vertical). SaveProjectionsAssistant::ProjectionsData -SaveProjectionsAssistant::projectionsData(GUI::ID::ProjectionType projectionsType, - Data2DItem* data2DItem) +SaveProjectionsAssistant::projectionsData(Qt::Orientation projectionsType, Data2DItem* data2DItem) { ProjectionsData result; - result.is_horizontal = (projectionsType == GUI::ID::ProjectionType::Horizontal); + result.is_horizontal = (projectionsType == Qt::Horizontal); for (auto* item : projectionItems(projectionsType, data2DItem)) { std::unique_ptr<Datafield> field; @@ -155,14 +154,12 @@ SaveProjectionsAssistant::projectionsData(GUI::ID::ProjectionType projectionsTyp //! Returns vector of ProjectionItems sorted according to axis value. -QVector<MaskItem*> -SaveProjectionsAssistant::projectionItems(GUI::ID::ProjectionType projectionsType, - Data2DItem* data2DItem) +QVector<MaskItem*> SaveProjectionsAssistant::projectionItems(Qt::Orientation projectionsType, + Data2DItem* data2DItem) { auto result = data2DItem->projectionContainerItem()->projectionsOfType(projectionsType); std::sort(result.begin(), result.end(), - projectionsType == GUI::ID::ProjectionType::Horizontal ? horiz_less_posy - : vert_less_posx); + projectionsType == Qt::Horizontal ? horiz_less_posy : vert_less_posx); return result; } diff --git a/GUI/View/Projection/SaveProjectionsAssistant.h b/GUI/View/Projection/SaveProjectionsAssistant.h index b18a06e5f4653de48f643165ff728ac92bf281cc..60645ce44cf56260108ed4fcdc2b0edc17705b14 100644 --- a/GUI/View/Projection/SaveProjectionsAssistant.h +++ b/GUI/View/Projection/SaveProjectionsAssistant.h @@ -45,13 +45,11 @@ private: QVector<Projection> projections; }; - QString projectionsToString(GUI::ID::ProjectionType projectionsType, Data2DItem* data2DItem); + QString projectionsToString(Qt::Orientation projectionsType, Data2DItem* data2DItem); const Datafield* m_field; - ProjectionsData projectionsData(GUI::ID::ProjectionType projectionsType, - Data2DItem* data2DItem); - QVector<MaskItem*> projectionItems(GUI::ID::ProjectionType projectionsType, - Data2DItem* data2DItem); + ProjectionsData projectionsData(Qt::Orientation projectionsType, Data2DItem* data2DItem); + QVector<MaskItem*> projectionItems(Qt::Orientation projectionsType, Data2DItem* data2DItem); QString projectionFileHeader(ProjectionsData& projectionsData); };