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; ...@@ -33,88 +33,17 @@ const double default_max = 1.0;
} // namespace } // namespace
Data1DViewItem::Data1DViewItem() Data1DViewItem::Data1DViewItem()
: SessionItem(M_TYPE) : SpecularDataItem(M_TYPE)
, m_job_item(nullptr) , 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}); 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) { mapper()->setOnPropertyChange([this](const QString& name) {
if (name != P_AXES_UNITS) if (!DataItem::isAxesUnitsPropertyName(name))
return; return;
setAxesRangeToData(); setAxesRangeToData();
GUI::Model::DataViewUtils::updateAxesTitle(this); 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 //! set zoom range of x,y axes to axes of input data
...@@ -136,26 +65,6 @@ void Data1DViewItem::setAxesRangeToData() ...@@ -136,26 +65,6 @@ void Data1DViewItem::setAxesRangeToData()
setUpperY(data_range.second); 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() void Data1DViewItem::resetToDefault()
{ {
// TODO: implement when applying DataITem1DView in ImportView // TODO: implement when applying DataITem1DView in ImportView
...@@ -194,31 +103,6 @@ JobItem* Data1DViewItem::jobItem() ...@@ -194,31 +103,6 @@ JobItem* Data1DViewItem::jobItem()
throw Error("Error in DataItem1DView::jobItem: passed item is not owned by any job item"); 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() DataPropertyContainer* Data1DViewItem::propertyContainerItem()
{ {
return item<DataPropertyContainer>(T_DATA_PROPERTIES); return item<DataPropertyContainer>(T_DATA_PROPERTIES);
...@@ -229,36 +113,6 @@ DataPropertyContainer* Data1DViewItem::createPropertyContainerItem() ...@@ -229,36 +113,6 @@ DataPropertyContainer* Data1DViewItem::createPropertyContainerItem()
return model()->insertItem<DataPropertyContainer>(this, -1, T_DATA_PROPERTIES); 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. //! Set axes viewport to original data.
void Data1DViewItem::resetView() void Data1DViewItem::resetView()
......
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
#include "GUI/Model/BaseItem/SessionItem.h" #include "GUI/Model/BaseItem/SessionItem.h"
#include "GUI/Model/Descriptor/SelectionDescriptor.h" #include "GUI/Model/Descriptor/SelectionDescriptor.h"
#include "GUI/Model/Data/SpecularDataItem.h"
class AmplitudeAxisItem; class AmplitudeAxisItem;
class BasicAxisItem; class BasicAxisItem;
class ComboProperty; class ComboProperty;
...@@ -27,16 +29,14 @@ class DataItem; ...@@ -27,16 +29,14 @@ class DataItem;
class JobItem; class JobItem;
class Datafield; class Datafield;
class SpecularDataItem;
//! View model for 1D DataItem. Can represent several items //! View model for 1D DataItem. Can represent several items
//! at once. In current implementation the first of carried //! at once. In current implementation the first of carried
//! items determines axes' limits. //! items determines axes' limits.
class BA_CORE_API_ Data1DViewItem : public SessionItem { class BA_CORE_API_ Data1DViewItem : public SpecularDataItem {
private: 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"}; static constexpr auto T_DATA_PROPERTIES{"Data property container"};
public: public:
...@@ -44,40 +44,10 @@ public: ...@@ -44,40 +44,10 @@ public:
Data1DViewItem(); 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 resetView();
void setXaxisTitle(const QString& title);
void setYaxisTitle(const QString& title);
void setAxesRangeToData(); 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) //! Returns data view to default state (no dimensional units, default axes' names)
void resetToDefault(); void resetToDefault();
...@@ -92,12 +62,6 @@ public: ...@@ -92,12 +62,6 @@ public:
//! job item set with DataItem1DView::setJobItem. //! job item set with DataItem1DView::setJobItem.
JobItem* jobItem(); 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* propertyContainerItem();
DataPropertyContainer* createPropertyContainerItem(); DataPropertyContainer* createPropertyContainerItem();
......
...@@ -32,7 +32,7 @@ ICoordSystem* getConverter(Data1DViewItem* view_item) ...@@ -32,7 +32,7 @@ ICoordSystem* getConverter(Data1DViewItem* view_item)
Coords selectedUnits(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); return GUI::Util::CoordName::coordFromName(current_unit_name);
} }
......
...@@ -26,8 +26,8 @@ const QString y_axis_default_name = "Signal [a.u.]"; ...@@ -26,8 +26,8 @@ const QString y_axis_default_name = "Signal [a.u.]";
} // namespace } // namespace
SpecularDataItem::SpecularDataItem() SpecularDataItem::SpecularDataItem(const QString& modelType)
: DataItem(M_TYPE) : DataItem(modelType)
{ {
addProperty(P_TITLE, QString()); addProperty(P_TITLE, QString());
...@@ -36,8 +36,13 @@ SpecularDataItem::SpecularDataItem() ...@@ -36,8 +36,13 @@ SpecularDataItem::SpecularDataItem()
auto* amplitudeAxis = addProperty<AmplitudeAxisItem>(P_YAXIS); auto* amplitudeAxis = addProperty<AmplitudeAxisItem>(P_YAXIS);
amplitudeAxis->visibilityItem()->setValue(true); amplitudeAxis->visibilityItem()->setValue(true);
xAxisItem()->setTitle(x_axis_default_name); setXaxisTitle(x_axis_default_name);
yAxisItem()->setTitle(y_axis_default_name); setYaxisTitle(y_axis_default_name);
}
SpecularDataItem::SpecularDataItem()
: SpecularDataItem(M_TYPE)
{
} }
void SpecularDataItem::setDatafield(Datafield* data) void SpecularDataItem::setDatafield(Datafield* data)
......
...@@ -26,6 +26,9 @@ private: ...@@ -26,6 +26,9 @@ private:
static constexpr auto P_XAXIS{"x-axis"}; static constexpr auto P_XAXIS{"x-axis"};
static constexpr auto P_YAXIS{"y-axis"}; static constexpr auto P_YAXIS{"y-axis"};
protected:
SpecularDataItem(const QString& modelType);
public: public:
static constexpr auto M_TYPE{"SpecularData"}; static constexpr auto M_TYPE{"SpecularData"};
...@@ -48,7 +51,7 @@ public: ...@@ -48,7 +51,7 @@ public:
double getLowerY() const; double getLowerY() const;
double getUpperY() 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 yMin() const;
double yMax() const; double yMax() const;
......
...@@ -98,7 +98,8 @@ void FitComparison1DViewController::createDiffViewItem(JobItem* job_item) ...@@ -98,7 +98,8 @@ void FitComparison1DViewController::createDiffViewItem(JobItem* job_item)
m_diff_view_item->setJobItem(job_item); m_diff_view_item->setJobItem(job_item);
auto* job_data_view = job_item->dataItemView(); 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); m_diff_view_item->setAxesUnits(units_value);
} }
......
...@@ -287,14 +287,14 @@ void Plot1D::modifyAxesProperties(const QString& axisName, const QString& proper ...@@ -287,14 +287,14 @@ void Plot1D::modifyAxesProperties(const QString& axisName, const QString& proper
replot(); replot();
} }
if (Data1DViewItem::isXAxisPropertyName(axisName)) { if (SpecularDataItem::isXaxisPropertyName(axisName)) {
if (BasicAxisItem::isBoundsPropertiesName(propertyName)) { if (BasicAxisItem::isBoundsPropertiesName(propertyName)) {
setAxesRangeConnected(false); setAxesRangeConnected(false);
m_custom_plot->xAxis->setRange(viewItem()->getLowerX(), viewItem()->getUpperX()); m_custom_plot->xAxis->setRange(viewItem()->getLowerX(), viewItem()->getUpperX());
setAxesRangeConnected(true); setAxesRangeConnected(true);
replot(); replot();
} }
} else if (Data1DViewItem::isYAxisPropertyName(axisName)) { } else if (SpecularDataItem::isYaxisPropertyName(axisName)) {
if (BasicAxisItem::isBoundsPropertiesName(propertyName)) { if (BasicAxisItem::isBoundsPropertiesName(propertyName)) {
setAxesRangeConnected(false); setAxesRangeConnected(false);
m_custom_plot->yAxis->setRange(viewItem()->getLowerY(), viewItem()->getUpperY()); m_custom_plot->yAxis->setRange(viewItem()->getLowerY(), viewItem()->getUpperY());
......
...@@ -61,7 +61,7 @@ const JobItem* SpecularDataPropertyWidget::jobItem() const ...@@ -61,7 +61,7 @@ const JobItem* SpecularDataPropertyWidget::jobItem() const
return dynamic_cast<JobItem*>(sessionItemWidget->currentItem()); return dynamic_cast<JobItem*>(sessionItemWidget->currentItem());
} }
void SpecularDataPropertyWidget::setCurrentItem(SessionItem* item) void SpecularDataPropertyWidget::setCurrentItem(SpecularDataItem* item)
{ {
if (m_item) if (m_item)
m_item->mapper()->unsubscribe(this); m_item->mapper()->unsubscribe(this);
...@@ -72,20 +72,9 @@ void SpecularDataPropertyWidget::setCurrentItem(SessionItem* item) ...@@ -72,20 +72,9 @@ void SpecularDataPropertyWidget::setCurrentItem(SessionItem* item)
if (!m_item) if (!m_item)
return; return;
BasicAxisItem* xAxisItem = nullptr; BasicAxisItem* xAxisItem = m_item->xAxisItem();
AmplitudeAxisItem* yAxisItem = nullptr; AmplitudeAxisItem* yAxisItem = m_item->yAxisItem();
SelectionDescriptor<QString> axesUnitsDescriptor; SelectionDescriptor<QString> axesUnitsDescriptor = m_item->axesUnits();
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;
m_mainLayout->addRow("Axes units:", createComboBox(axesUnitsDescriptor)); m_mainLayout->addRow("Axes units:", createComboBox(axesUnitsDescriptor));
......
...@@ -50,11 +50,11 @@ private: ...@@ -50,11 +50,11 @@ private:
QWidget* createComboBox(SelectionDescriptor<QString> d); QWidget* createComboBox(SelectionDescriptor<QString> d);
void updateUIValues(); void updateUIValues();
void setCurrentItem(SessionItem* item); void setCurrentItem(SpecularDataItem *item);
private: private:
QWidget* m_parent; QWidget* m_parent;
SessionItem* m_item; SpecularDataItem* m_item;
QFormLayout* m_mainLayout; QFormLayout* m_mainLayout;
QList<function<void()>> m_updaters; 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