Skip to content
Snippets Groups Projects
Commit bd02ef57 authored by Mikhail Svechnikov's avatar Mikhail Svechnikov
Browse files

[i72] GUI: 1D data importer: show data points instead of line (Closes #72)

Merging branch 'i72'  into 'main'.

See merge request !877
parents c663892e 5a93aac0
No related branches found
No related tags found
1 merge request!877GUI: 1D data importer: show data points instead of line
Pipeline #64869 passed
......@@ -31,6 +31,26 @@ const std::vector<std::pair<QString, Qt::GlobalColor>> color_queue = {
{"Red", Qt::GlobalColor::darkRed}, {"Cyan", Qt::GlobalColor::darkCyan},
{"Gray", Qt::GlobalColor::darkGray}, {"Magenta", Qt::GlobalColor::darkMagenta}};
// scatters for representation of 1D graphs
const QMap<QString, QCPScatterStyle::ScatterShape> scatter_map = {
{"None", QCPScatterStyle::ScatterShape::ssNone},
{"Disc", QCPScatterStyle::ScatterShape::ssDisc},
{"Circle", QCPScatterStyle::ScatterShape::ssCircle},
{"Cross", QCPScatterStyle::ScatterShape::ssCross},
{"Diamond", QCPScatterStyle::ScatterShape::ssDiamond},
{"Star", QCPScatterStyle::ScatterShape::ssStar}
};
// connection lines for representation of 1D graphs
const QMap<QString, QCPGraph::LineStyle> line_map = {
{"None", QCPGraph::LineStyle::lsNone},
{"Line", QCPGraph::LineStyle::lsLine},
{"StepLeft", QCPGraph::LineStyle::lsStepLeft},
{"StepRight", QCPGraph::LineStyle::lsStepRight},
{"StepCenter", QCPGraph::LineStyle::lsStepCenter},
{"Impulse", QCPGraph::LineStyle::lsImpulse}
};
struct ColorNameComparator {
ColorNameComparator(QString value_to_comp)
: m_value_to_comp(std::move(value_to_comp))
......@@ -53,6 +73,24 @@ ComboProperty defaultColorCombo()
return result;
}
ComboProperty defaultScatterCombo()
{
ComboProperty result;
for (const auto& scatter : scatter_map.keys())
result << scatter;
result.setValue(scatter_map.keys().first());
return result;
}
ComboProperty defaultLineCombo()
{
ComboProperty result;
for (const auto& line : line_map.keys())
result << line;
result.setValue(line_map.keys().first());
return result;
}
// TODO cover with unit tests and simplify
QModelIndex getIndexFromPath(const SessionModel* model, const QString& path)
......@@ -102,6 +140,8 @@ Data1DProperties::Data1DProperties()
: DataProperties(M_TYPE)
{
addProperty(P_COLOR, defaultColorCombo().variant());
addProperty(P_SCATTER, defaultScatterCombo().variant());
addProperty(P_LINE, defaultLineCombo().variant());
}
QColor Data1DProperties::color()
......@@ -136,3 +176,33 @@ void Data1DProperties::setColorProperty(const QString& color_name)
color_combo.setValue(color_name);
setItemValue(P_COLOR, color_combo.variant());
}
QCPScatterStyle::ScatterShape Data1DProperties::scatter()
{
const QString& scatter_name = getItemValue(P_SCATTER).value<ComboProperty>().getValue();
bool contains = scatter_map.contains(scatter_name);
ASSERT(contains);
return QCPScatterStyle::ScatterShape(scatter_map.value(scatter_name));
}
QCPGraph::LineStyle Data1DProperties::line()
{
const QString& line_name = getItemValue(P_LINE).value<ComboProperty>().getValue();
bool contains = line_map.contains(line_name);
ASSERT(contains);
return QCPGraph::LineStyle(line_map.value(line_name));
}
void Data1DProperties::setScatterProperty(const QString& scatter_name)
{
auto scatter_combo = defaultScatterCombo();
scatter_combo.setValue(scatter_name);
setItemValue(P_SCATTER, scatter_combo.variant());
}
void Data1DProperties::setLineProperty(const QString& line_name)
{
auto line_combo = defaultLineCombo();
line_combo.setValue(line_name);
setItemValue(P_LINE, line_combo.variant());
}
......@@ -16,6 +16,7 @@
#define BORNAGAIN_GUI_MODEL_DATA_DATAPROPERTIES_H
#include "GUI/Model/BaseItem/SessionItem.h"
#include "3rdparty/GUI/qcustomplot/qcustomplot.h"
class DataItem;
......@@ -38,13 +39,15 @@ protected:
class Data1DProperties : public DataProperties {
private:
static constexpr auto P_COLOR{"Color"};
static constexpr auto P_SCATTER{"Scatter"};
static constexpr auto P_LINE{"Line"};
public:
static constexpr auto M_TYPE{"DataItem1DProperties"};
Data1DProperties();
//! Creates and returns a color object from color name in Data1DPresentationProperties
//! Creates and returns a color object from color name
QColor color();
//! Returns the name of the color
......@@ -53,6 +56,18 @@ public:
//! Returns set up color ComboProperty.
void setColorProperty(const QString& color_name);
//! Returns a QCP scatter object from its name
QCPScatterStyle::ScatterShape scatter();
//! Returns a QCP line object from its name
QCPGraph::LineStyle line();
//! Set up scatter for qcustomplot.
void setScatterProperty(const QString& scatter_name);
//! Set up line for qcustomplot.
void setLineProperty(const QString& line_name);
//! Returns the name of the color, which follows the color of passes property
//! container. If the container is nullptr or has the last-in-queue color,
//! Returns default color.
......
......@@ -14,6 +14,7 @@
#include "GUI/Model/Data/DataPropertyContainer.h"
#include "GUI/Model/Data/DataItem.h"
#include "GUI/Model/Data/RealDataItem.h"
#include "GUI/Model/Data/DataProperties.h"
#include "GUI/Util/Error.h"
......@@ -56,7 +57,6 @@ void DataPropertyContainer::addItem(DataItem* data_item)
if (this->model() != data_item->model())
throw Error("Error in DataPropertyContainer::addItem: hosting models are different");
auto property_items = propertyItems();
Data1DProperties* previous_item = nullptr;
if (!propertyItems().empty())
previous_item = dynamic_cast<Data1DProperties*>(propertyItems().back());
......@@ -65,6 +65,14 @@ void DataPropertyContainer::addItem(DataItem* data_item)
insertChild(-1, property_item);
property_item->setDataItem(data_item);
property_item->setColorProperty(Data1DProperties::nextColorName(previous_item));
if(dynamic_cast<RealDataItem*>(data_item->parent())) {
property_item->setScatterProperty("Disc");
property_item->setLineProperty("None");
} else {
property_item->setScatterProperty("None");
property_item->setLineProperty("Line");
}
}
std::vector<DataItem*> DataPropertyContainer::dataItems()
......
......@@ -148,10 +148,12 @@ void Plot1D::unsubscribeFromItem()
void Plot1D::initPlots()
{
auto property_items = viewItem()->propertyContainerItem()->propertyItems();
std::for_each(property_items.begin(), property_items.end(), [this](Data1DProperties* item) {
auto* graph = m_custom_plot->addGraph();
graph->setLineStyle(QCPGraph::lsLine);
graph->setLineStyle(item->line());
graph->setPen(QPen(item->color()));
graph->setScatterStyle(item->scatter());
m_graph_map[item] = graph;
});
}
......
......@@ -77,6 +77,11 @@ void SpecularDataCanvas::enableDeprecatedOnMousePress(bool b)
&SpecularDataCanvas::onMousePress);
}
void SpecularDataCanvas::initScatter()
{
m_plot_canvas->initScatter();
}
void SpecularDataCanvas::onResetViewAction()
{
specularDataItem()->resetView();
......
......@@ -43,6 +43,7 @@ public:
//! context menu for axis configuration)
void enableDeprecatedOnMousePress(bool b);
void initScatter();
public slots:
void onResetViewAction();
void onSavePlotAction();
......
......@@ -49,6 +49,8 @@ void SpecularDataWidget::setItem(SessionItem* jobItem)
SessionItemWidget::setItem(jobItem);
m_intensity_canvas->setItem(specularDataItem());
m_propertyWidget->setItem(specularDataItem());
m_intensity_canvas->initScatter();
}
QList<QAction*> SpecularDataWidget::actionList()
......
......@@ -12,9 +12,10 @@
//
// ************************************************************************************************
#include "GUI/View/PlotSpecular/SpecularPlot.h"
#include "GUI/Model/Data/SpecularDataItem.h"
#include "GUI/Model/Device/AxesItems.h"
#include "GUI/Model/Data/RealDataItem.h"
#include "GUI/View/PlotSpecular/SpecularPlot.h"
#include "GUI/View/PlotUtil/PlotConstants.h"
#include "GUI/View/PlotUtil/PlotEventInfo.h"
#include "GUI/View/PlotUtil/RangeUtils.h"
......@@ -141,7 +142,17 @@ void SpecularPlot::initPlot()
m_custom_plot->xAxis->setTickLabelFont(
QFont(QFont().family(), GUI::Constants::plot_tick_label_size()));
m_custom_plot->yAxis->setTickLabelFont(
QFont(QFont().family(), GUI::Constants::plot_tick_label_size()));
QFont(QFont().family(), GUI::Constants::plot_tick_label_size()));
}
void SpecularPlot::initScatter()
{
if(dynamic_cast<RealDataItem*>(specularItem()->parent())) {
m_custom_plot->graph()->setScatterStyle(QCPScatterStyle::ssDisc);
} else {
m_custom_plot->graph()->setScatterStyle(QCPScatterStyle::ssNone);
}
m_custom_plot->replot();
}
void SpecularPlot::setConnected(bool isConnected)
......
......@@ -50,6 +50,9 @@ public:
//! reset all axes min,max to initial value
void resetView();
//! Adds scatter ro real data plot
void initScatter();
private slots:
//! updates plot depending on IntensityDataItem properties
void onPropertyChanged(const QString& property_name);
......
......@@ -54,6 +54,11 @@ QCustomPlot* SpecularPlotCanvas::customPlot()
return m_plot->customPlot();
}
void SpecularPlotCanvas::initScatter()
{
m_plot->initScatter();
}
void SpecularPlotCanvas::setStatusLabelEnabled(bool flag)
{
m_statusLabel->setLabelEnabled(flag);
......
......@@ -35,6 +35,7 @@ public:
SpecularPlot* specularPlot();
QCustomPlot* customPlot();
void initScatter();
void setStatusLabelEnabled(bool flag);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment