Commit 973fd2c9 authored by Mikhail Svechnikov's avatar Mikhail Svechnikov
Browse files

Data1DViewItem inherits SpecularDataItem

parent 9faa6513
Pipeline #67536 passed with stage
in 5 minutes and 28 seconds
......@@ -33,88 +33,17 @@ const double default_max = 1.0;
} // namespace
Data1DViewItem::Data1DViewItem()
: SessionItem(M_TYPE)
: SpecularDataItem(M_TYPE)
, m_job_item(nullptr)
{
addProperty(P_TITLE, QString());
auto* basicAxis = addProperty<BasicAxisItem>(P_XAXIS);
basicAxis->binsItem();
auto* amplitudeAxis = addProperty<AmplitudeAxisItem>(P_YAXIS);
amplitudeAxis->binsItem();
amplitudeAxis->titleItem();
amplitudeAxis->visibilityItem()->setValue(true);
amplitudeAxis->visibilityItem();
registerTag(T_DATA_PROPERTIES, 1, 1, {DataPropertyContainer::M_TYPE});
ComboProperty combo = ComboProperty() << "nbins";
addProperty(P_AXES_UNITS, combo.variant());
mapper()->setOnPropertyChange([this](const QString& name) {
if (name != P_AXES_UNITS)
if (!DataItem::isAxesUnitsPropertyName(name))
return;
setAxesRangeToData();
GUI::Model::DataViewUtils::updateAxesTitle(this);
});
setLowerX(default_min);
setUpperX(default_max);
setLowerY(default_min);
setUpperY(default_max);
setXaxisTitle(x_axis_default_name);
setYaxisTitle(y_axis_default_name);
}
int Data1DViewItem::getNbins() const
{
return xAxisItem()->binCount();
}
double Data1DViewItem::getLowerX() const
{
return xAxisItem()->min();
}
double Data1DViewItem::getUpperX() const
{
return xAxisItem()->max();
}
double Data1DViewItem::getLowerY() const
{
return yAxisItem()->min();
}
double Data1DViewItem::getUpperY() const
{
return yAxisItem()->max();
}
bool Data1DViewItem::isLog() const
{
return yAxisItem()->isLogScale();
}
QString Data1DViewItem::getXaxisTitle() const
{
return xAxisItem()->title();
}
QString Data1DViewItem::getYaxisTitle() const
{
return yAxisItem()->title();
}
void Data1DViewItem::setXaxisTitle(const QString& title)
{
xAxisItem()->setTitle(title);
}
void Data1DViewItem::setYaxisTitle(const QString& title)
{
yAxisItem()->setTitle(title);
}
//! set zoom range of x,y axes to axes of input data
......@@ -136,26 +65,6 @@ void Data1DViewItem::setAxesRangeToData()
setUpperY(data_range.second);
}
ComboProperty Data1DViewItem::axesUnits() const
{
return getItemValue(P_AXES_UNITS).value<ComboProperty>();
}
void Data1DViewItem::setAxesUnits(const ComboProperty& units)
{
setItemValue(Data1DViewItem::P_AXES_UNITS, units.variant());
}
SelectionDescriptor<QString> Data1DViewItem::axesUnitsDescriptor() const
{
return SelectionDescriptor<QString>(getItem(P_AXES_UNITS));
}
bool Data1DViewItem::isAxesUnitsPropertyName(const QString& name)
{
return name == P_AXES_UNITS;
}
void Data1DViewItem::resetToDefault()
{
// TODO: implement when applying DataITem1DView in ImportView
......@@ -194,31 +103,6 @@ JobItem* Data1DViewItem::jobItem()
throw Error("Error in DataItem1DView::jobItem: passed item is not owned by any job item");
}
void Data1DViewItem::setLowerX(double value)
{
xAxisItem()->setLowerBound(value);
}
void Data1DViewItem::setUpperX(double value)
{
xAxisItem()->setUpperBound(value);
}
void Data1DViewItem::setLowerY(double value)
{
yAxisItem()->setLowerBound(value);
}
void Data1DViewItem::setUpperY(double value)
{
yAxisItem()->setUpperBound(value);
}
void Data1DViewItem::setLog(bool log_flag)
{
yAxisItem()->setLogScale(log_flag);
}
DataPropertyContainer* Data1DViewItem::propertyContainerItem()
{
return item<DataPropertyContainer>(T_DATA_PROPERTIES);
......@@ -229,36 +113,6 @@ DataPropertyContainer* Data1DViewItem::createPropertyContainerItem()
return model()->insertItem<DataPropertyContainer>(this, -1, T_DATA_PROPERTIES);
}
const BasicAxisItem* Data1DViewItem::xAxisItem() const
{
return item<BasicAxisItem>(P_XAXIS);
}
BasicAxisItem* Data1DViewItem::xAxisItem()
{
return item<BasicAxisItem>(P_XAXIS);
}
const AmplitudeAxisItem* Data1DViewItem::yAxisItem() const
{
return item<AmplitudeAxisItem>(P_YAXIS);
}
AmplitudeAxisItem* Data1DViewItem::yAxisItem()
{
return item<AmplitudeAxisItem>(P_YAXIS);
}
bool Data1DViewItem::isXAxisPropertyName(const QString& name)
{
return name == P_XAXIS;
}
bool Data1DViewItem::isYAxisPropertyName(const QString& name)
{
return name == P_YAXIS;
}
//! Set axes viewport to original data.
void Data1DViewItem::resetView()
......
......@@ -18,6 +18,8 @@
#include "GUI/Model/BaseItem/SessionItem.h"
#include "GUI/Model/Descriptor/SelectionDescriptor.h"
#include "GUI/Model/Data/SpecularDataItem.h"
class AmplitudeAxisItem;
class BasicAxisItem;
class ComboProperty;
......@@ -27,16 +29,14 @@ class DataItem;
class JobItem;
class Datafield;
class SpecularDataItem;
//! View model for 1D DataItem. Can represent several items
//! at once. In current implementation the first of carried
//! items determines axes' limits.
class BA_CORE_API_ Data1DViewItem : public SessionItem {
class BA_CORE_API_ Data1DViewItem : public SpecularDataItem {
private:
static constexpr auto P_TITLE{"Title"};
static constexpr auto P_XAXIS{"x-axis"};
static constexpr auto P_YAXIS{"y-axis"};
static constexpr auto P_AXES_UNITS{"Axes Units"};
static constexpr auto T_DATA_PROPERTIES{"Data property container"};
public:
......@@ -44,40 +44,10 @@ public:
Data1DViewItem();
//! Number of bins in data
int getNbins() const;
//! Returns lower and upper zoom ranges of x-axis
double getLowerX() const;
double getUpperX() const;
//! Returns lower and upper zoom ranges of y-axis
double getLowerY() const;
double getUpperY() const;
bool isLog() const;
QString getXaxisTitle() const;
QString getYaxisTitle() const;
const BasicAxisItem* xAxisItem() const;
BasicAxisItem* xAxisItem();
const AmplitudeAxisItem* yAxisItem() const;
AmplitudeAxisItem* yAxisItem();
static bool isXAxisPropertyName(const QString& name);
static bool isYAxisPropertyName(const QString& name);
void resetView();
void setXaxisTitle(const QString& title);
void setYaxisTitle(const QString& title);
void setAxesRangeToData();
ComboProperty axesUnits() const;
void setAxesUnits(const ComboProperty& units);
SelectionDescriptor<QString> axesUnitsDescriptor() const;
static bool isAxesUnitsPropertyName(const QString& name);
//! Returns data view to default state (no dimensional units, default axes' names)
void resetToDefault();
......@@ -92,12 +62,6 @@ public:
//! job item set with DataItem1DView::setJobItem.
JobItem* jobItem();
void setLowerX(double value);
void setUpperX(double value);
void setLowerY(double value);
void setUpperY(double value);
void setLog(bool log_flag);
DataPropertyContainer* propertyContainerItem();
DataPropertyContainer* createPropertyContainerItem();
......
......@@ -32,7 +32,7 @@ ICoordSystem* getConverter(Data1DViewItem* view_item)
Coords selectedUnits(Data1DViewItem* view_item)
{
QString current_unit_name = view_item->axesUnits().getValue();
QString current_unit_name = view_item->axesUnits();
return GUI::Util::CoordName::coordFromName(current_unit_name);
}
......
......@@ -26,8 +26,8 @@ const QString y_axis_default_name = "Signal [a.u.]";
} // namespace
SpecularDataItem::SpecularDataItem()
: DataItem(M_TYPE)
SpecularDataItem::SpecularDataItem(const QString& modelType)
: DataItem(modelType)
{
addProperty(P_TITLE, QString());
......@@ -36,8 +36,13 @@ SpecularDataItem::SpecularDataItem()
auto* amplitudeAxis = addProperty<AmplitudeAxisItem>(P_YAXIS);
amplitudeAxis->visibilityItem()->setValue(true);
xAxisItem()->setTitle(x_axis_default_name);
yAxisItem()->setTitle(y_axis_default_name);
setXaxisTitle(x_axis_default_name);
setYaxisTitle(y_axis_default_name);
}
SpecularDataItem::SpecularDataItem()
: SpecularDataItem(M_TYPE)
{
}
void SpecularDataItem::setDatafield(Datafield* data)
......
......@@ -26,6 +26,9 @@ private:
static constexpr auto P_XAXIS{"x-axis"};
static constexpr auto P_YAXIS{"y-axis"};
protected:
SpecularDataItem(const QString& modelType);
public:
static constexpr auto M_TYPE{"SpecularData"};
......@@ -48,7 +51,7 @@ public:
double getLowerY() const;
double getUpperY() const;
//! Returns min and max range of y-axis as given by IntensityData
//! Returns min and max range of y-axis as given by data
double yMin() const;
double yMax() const;
......
......@@ -98,7 +98,8 @@ void FitComparison1DViewController::createDiffViewItem(JobItem* job_item)
m_diff_view_item->setJobItem(job_item);
auto* job_data_view = job_item->dataItemView();
ComboProperty units_value = job_data_view->axesUnits();
ComboProperty units_value = ComboProperty::fromList(job_data_view->axesUnits().options,
job_data_view->axesUnits());
m_diff_view_item->setAxesUnits(units_value);
}
......
......@@ -287,14 +287,14 @@ void Plot1D::modifyAxesProperties(const QString& axisName, const QString& proper
replot();
}
if (Data1DViewItem::isXAxisPropertyName(axisName)) {
if (SpecularDataItem::isXaxisPropertyName(axisName)) {
if (BasicAxisItem::isBoundsPropertiesName(propertyName)) {
setAxesRangeConnected(false);
m_custom_plot->xAxis->setRange(viewItem()->getLowerX(), viewItem()->getUpperX());
setAxesRangeConnected(true);
replot();
}
} else if (Data1DViewItem::isYAxisPropertyName(axisName)) {
} else if (SpecularDataItem::isYaxisPropertyName(axisName)) {
if (BasicAxisItem::isBoundsPropertiesName(propertyName)) {
setAxesRangeConnected(false);
m_custom_plot->yAxis->setRange(viewItem()->getLowerY(), viewItem()->getUpperY());
......
......@@ -61,7 +61,7 @@ const JobItem* SpecularDataPropertyWidget::jobItem() const
return dynamic_cast<JobItem*>(sessionItemWidget->currentItem());
}
void SpecularDataPropertyWidget::setCurrentItem(SessionItem* item)
void SpecularDataPropertyWidget::setCurrentItem(SpecularDataItem* item)
{
if (m_item)
m_item->mapper()->unsubscribe(this);
......@@ -72,20 +72,9 @@ void SpecularDataPropertyWidget::setCurrentItem(SessionItem* item)
if (!m_item)
return;
BasicAxisItem* xAxisItem = nullptr;
AmplitudeAxisItem* yAxisItem = nullptr;
SelectionDescriptor<QString> axesUnitsDescriptor;
if (auto* p = dynamic_cast<SpecularDataItem*>(m_item)) {
axesUnitsDescriptor = p->axesUnits();
xAxisItem = p->xAxisItem();
yAxisItem = p->yAxisItem();
} else if (auto* p = dynamic_cast<Data1DViewItem*>(m_item)) {
axesUnitsDescriptor = p->axesUnitsDescriptor();
xAxisItem = p->xAxisItem();
yAxisItem = p->yAxisItem();
} else
return;
BasicAxisItem* xAxisItem = m_item->xAxisItem();
AmplitudeAxisItem* yAxisItem = m_item->yAxisItem();
SelectionDescriptor<QString> axesUnitsDescriptor = m_item->axesUnits();
m_mainLayout->addRow("Axes units:", createComboBox(axesUnitsDescriptor));
......
......@@ -50,11 +50,11 @@ private:
QWidget* createComboBox(SelectionDescriptor<QString> d);
void updateUIValues();
void setCurrentItem(SessionItem* item);
void setCurrentItem(SpecularDataItem *item);
private:
QWidget* m_parent;
SessionItem* m_item;
SpecularDataItem* m_item;
QFormLayout* m_mainLayout;
QList<function<void()>> m_updaters;
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment