Commit d95dd39c authored by Mikhail Svechnikov's avatar Mikhail Svechnikov
Browse files

[i88g] GUI: change data items signaling in IntensityDataPropertyWidget ()

Merging branch 'i88g'  into 'main'.

See merge request !955
parents 18aca57d 89b869aa
Pipeline #67482 failed with stage
in 5 minutes and 48 seconds
......@@ -158,6 +158,7 @@ double SphericalCoords::calculateValue(size_t i_axis, Coords units, double value
return (k_f - k_i).z();
}
ASSERT(0);
return 0;
}
case Coords::QXQY: {
const R3 k_i = vecOfLambdaAlphaPhi(m_wavelength, m_alpha_i, m_phi_i);
......@@ -170,6 +171,7 @@ double SphericalCoords::calculateValue(size_t i_axis, Coords units, double value
return (k_f - k_i).x();
}
ASSERT(0);
return 0;
}
default:
ASSERT(0);
......
......@@ -200,7 +200,7 @@ class GroupInfo;
//! \endcode
//!
//! This code part again shows the (highly error-prone) string-based type checking.
//#define USE_MAPPERS
class BA_CORE_API_ SessionItem {
friend class SessionModel;
......
......@@ -24,6 +24,9 @@ void DataItem::setDatafield(Datafield* data)
setLastModified(QDateTime::currentDateTime());
emit datafieldChanged(data);
#ifdef USE_MAPPERS
emitDataChanged();
#endif
}
void DataItem::setRawDataVector(const std::vector<double>& data)
......@@ -36,6 +39,9 @@ void DataItem::setRawDataVector(const std::vector<double>& data)
setLastModified(QDateTime::currentDateTime());
emit rawDataVectorChanged(data);
#ifdef USE_MAPPERS
emitDataChanged();
#endif
}
QString DataItem::fileName() const
......@@ -96,18 +102,18 @@ QString DataItem::selectedCoords() const
void DataItem::setAxesUnits(const ComboProperty& units)
{
setItemValue(P_AXES_UNITS, units.variant());
emit axesUnitsChanged(units);
}
SessionItem* DataItem::getAxesUnitsItem() const
{
return getItem(P_AXES_UNITS);
}
SelectionDescriptor<QString> DataItem::axesUnits() const
{
return SelectionDescriptor<QString>(getItem(P_AXES_UNITS));
SelectionDescriptor<QString> d = SelectionDescriptor<QString>(getItem(P_AXES_UNITS));
// temporary setter with signal
d.currentIndexSetter = [=](int index) {
d.currentIndexSetter(index);
emit const_cast<DataItem*>(this)->axesUnitsChanged();
};
return d;
}
bool DataItem::isAxesUnitsPropertyName(const QString& name)
......
......@@ -61,7 +61,6 @@ public:
QString selectedCoords() const;
void setAxesUnits(const ComboProperty& units);
SessionItem* getAxesUnitsItem() const;
SelectionDescriptor<QString> axesUnits() const;
static bool isAxesUnitsPropertyName(const QString& name);
static void updateAxesUnits(SessionItem* item, const QString& name,
......@@ -80,7 +79,8 @@ signals:
void datafieldChanged(Datafield* data);
void rawDataVectorChanged(const std::vector<double>& data);
void fileNameChanged(const QString& filename);
void axesUnitsChanged(const ComboProperty& units);
void axesUnitsChanged();
void axesUnitsReplotRequested();
protected:
explicit DataItem(const QString& modelType);
......
......@@ -79,8 +79,9 @@ void IntensityDataItem::setDatafield(Datafield* data)
updateAxesZoomLevel();
updateAxesLabels();
updateDataRange();
#ifdef USE_MAPPERS
emitDataChanged();
#endif
}
int IntensityDataItem::xSize() const
......@@ -164,7 +165,14 @@ void IntensityDataItem::setGradient(const ComboProperty& gradient)
SelectionDescriptor<QString> IntensityDataItem::gradient() const
{
return SelectionDescriptor<QString>(getItem(P_GRADIENT));
SelectionDescriptor<QString> d = SelectionDescriptor<QString>(getItem(P_GRADIENT));
// temporary setter with signal
d.currentIndexSetter = [=](int index) {
d.currentIndexSetter(index);
emit const_cast<IntensityDataItem*>(this)->gradientChanged();
};
return d;
}
bool IntensityDataItem::isLogz() const
......@@ -273,21 +281,25 @@ bool IntensityDataItem::isZaxisPropertyName(const QString& name)
void IntensityDataItem::setLowerX(double value)
{
xAxisItem()->setLowerBound(value);
emit axesRangeChangedFromPlot();
}
void IntensityDataItem::setUpperX(double value)
{
xAxisItem()->setUpperBound(value);
emit axesRangeChangedFromPlot();
}
void IntensityDataItem::setLowerY(double value)
{
yAxisItem()->setLowerBound(value);
emit axesRangeChangedFromPlot();
}
void IntensityDataItem::setUpperY(double value)
{
yAxisItem()->setUpperBound(value);
emit axesRangeChangedFromPlot();
}
void IntensityDataItem::setLowerAndUpperZ(double zmin, double zmax)
......@@ -302,11 +314,13 @@ void IntensityDataItem::setLowerAndUpperZ(double zmin, double zmax)
void IntensityDataItem::setLowerZ(double zmin)
{
zAxisItem()->setLowerBound(zmin);
emit axesRangeChangedFromPlot();
}
void IntensityDataItem::setUpperZ(double zmax)
{
zAxisItem()->setUpperBound(zmax);
emit axesRangeChangedFromPlot();
}
void IntensityDataItem::setLogz(bool logz)
......@@ -317,6 +331,7 @@ void IntensityDataItem::setLogz(bool logz)
void IntensityDataItem::setInterpolated(bool interp)
{
setItemValue(P_IS_INTERPOLATED, interp);
emit interpolationChanged();
}
//! Sets zoom range of X,Y axes, if it was not yet defined.
......
......@@ -24,6 +24,7 @@ class MaskContainerItem;
class ProjectionContainerItem;
class BA_CORE_API_ IntensityDataItem : public DataItem {
Q_OBJECT
private:
static constexpr auto P_PROJECTIONS{"Projections"};
static constexpr auto P_TITLE{"Title"};
......@@ -120,6 +121,13 @@ public:
static bool isYaxisPropertyName(const QString& name);
static bool isZaxisPropertyName(const QString& name);
signals:
void gradientChanged();
void interpolationChanged();
void axesRangeChangedFromPlot();
void updateOtherPlots();
void updateThisPlot();
public slots:
void setLowerX(double value);
void setUpperX(double value);
......
......@@ -42,6 +42,11 @@ DoubleDescriptor BasicAxisItem::min(const QString& unit) const
{
DoubleDescriptor d(getItem(P_MIN_DEG), unit);
d.label = "Min";
// temp setter with signal
d.set = [=](double v) {
d.set(v);
emit const_cast<BasicAxisItem*>(this)->axisRangeChanged();
};
return d;
}
......@@ -59,6 +64,11 @@ DoubleDescriptor BasicAxisItem::max(const QString& unit) const
{
DoubleDescriptor d(getItem(P_MAX_DEG), unit);
d.label = "Max";
// temp setter with signal
d.set = [=](double v) {
d.set(v);
emit const_cast<BasicAxisItem*>(this)->axisRangeChanged();
};
return d;
}
......@@ -85,6 +95,7 @@ QString BasicAxisItem::title() const
void BasicAxisItem::setTitle(const QString& title)
{
setItemValue(P_TITLE, title);
emit axisTitleChanged();
}
SessionItem* BasicAxisItem::titleItem() const
......@@ -118,7 +129,7 @@ SessionItem* BasicAxisItem::visibilityItem() const
return getItem(P_IS_VISIBLE);
}
bool BasicAxisItem::visibilityValue() const
bool BasicAxisItem::isVisible() const
{
return visibilityItem()->value().toBool();
}
......@@ -126,6 +137,7 @@ bool BasicAxisItem::visibilityValue() const
void BasicAxisItem::setVisibilityValue(bool b)
{
setItemValue(P_IS_VISIBLE, b);
emit axisVisibilityChanged();
}
bool BasicAxisItem::isVisibilityPropertyName(const QString& name)
......@@ -183,6 +195,7 @@ bool AmplitudeAxisItem::isLogScale() const
void AmplitudeAxisItem::setLogScale(bool value)
{
setItemValue(P_IS_LOGSCALE, value);
emit logScaleChanged();
}
SessionItem* AmplitudeAxisItem::logScaleItem() const
......
......@@ -22,7 +22,8 @@
class IAxis;
class Streamer;
class BasicAxisItem : public SessionItem {
class BasicAxisItem : public QObject, public SessionItem {
Q_OBJECT
private:
static constexpr auto P_IS_VISIBLE{"Visibility"};
static constexpr auto P_NBINS{"Nbins"};
......@@ -64,15 +65,21 @@ public:
virtual std::unique_ptr<IAxis> createAxis(double scale) const;
SessionItem* visibilityItem() const;
bool visibilityValue() const;
bool isVisible() const;
void setVisibilityValue(bool b);
static bool isVisibilityPropertyName(const QString& name);
signals:
void axisRangeChanged();
void axisTitleChanged();
void axisVisibilityChanged();
protected:
explicit BasicAxisItem(const QString& type);
};
class AmplitudeAxisItem : public BasicAxisItem {
Q_OBJECT
private:
static constexpr auto P_IS_LOGSCALE{"log10"};
static constexpr auto P_LOCK_MIN_MAX{"Lock (min, max)"};
......@@ -90,6 +97,10 @@ public:
bool isLocked() const;
void setLocked(bool locked);
signals:
void logScaleChanged();
};
#endif // BORNAGAIN_GUI_MODEL_DEVICE_AXESITEMS_H
......@@ -59,17 +59,13 @@ JobItem::JobItem()
addProperty(P_PRESENTATION_TYPE, QVariant::Type::Invalid);
registerTag(T_OUTPUT, 1, 1, {IntensityDataItem::M_TYPE, SpecularDataItem::M_TYPE});
registerTag(T_DIFF, 1, 1, {IntensityDataItem::M_TYPE, SpecularDataItem::M_TYPE});
registerTag(T_REALDATA, 1, 1, {RealDataItem::M_TYPE});
registerTag(T_DATAVIEW, 1, 1, {Data1DViewItem::M_TYPE});
registerTag(T_FIT_SUITE, 1, 1, {FitSuiteItem::M_TYPE});
}
JobItem::~JobItem()
{
emit jobDestroyed();
}
QString JobItem::getIdentifier() const
{
return getItemValue(P_IDENTIFIER).toString();
......@@ -294,7 +290,26 @@ RealDataItem* JobItem::realDataItem()
RealDataItem* JobItem::copyRealDataIntoJob(const RealDataItem* real_data)
{
return model()->copyItem(real_data, this, T_REALDATA);
// create diffDataItem together with realDataItem
if(!diffDataItem()) {
if(real_data->isIntensityData())
model()->insertItem<IntensityDataItem>(this, -1, T_DIFF);
else if(real_data->isSpecularData())
model()->insertItem<SpecularDataItem>(this, -1, T_DIFF);
else
ASSERT(0)
// immediately create coordinate system and axes units
if (instrumentItem()) {
GUI::Model::JobItemUtils::setIntensityItemCoords(diffDataItem(), instrumentItem());
diffDataItem()->updateCoords(instrumentItem());
}
}
RealDataItem* realDataCopy = model()->copyItem(real_data, this, T_REALDATA);
if(!isSpecularJob()) {
realDataCopy->intensityDataItem()->setGradient(intensityDataItem()->getGradient());
}
return realDataCopy;
}
RealDataItem* JobItem::createRealDataItem()
......@@ -302,14 +317,14 @@ RealDataItem* JobItem::createRealDataItem()
return model()->insertItem<RealDataItem>(this, -1, T_REALDATA);
}
Data1DViewItem* JobItem::dataItemView()
DataItem* JobItem::diffDataItem()
{
return dynamic_cast<Data1DViewItem*>(getItem(JobItem::T_DATAVIEW));
return dynamic_cast<DataItem*>(getItem(T_DIFF));
}
void JobItem::addDataViewItem(Data1DViewItem* data_view)
Data1DViewItem* JobItem::dataItemView()
{
insertChild(-1, data_view, T_DATAVIEW);
return dynamic_cast<Data1DViewItem*>(getItem(JobItem::T_DATAVIEW));
}
Data1DViewItem* JobItem::createDataViewItem()
......
......@@ -54,6 +54,7 @@ private:
static constexpr auto P_PRESENTATION_TYPE{"Presentation type"};
static constexpr auto T_MATERIAL_CONTAINER{"Material container tag"};
static constexpr auto T_OUTPUT{"Output tag"};
static constexpr auto T_DIFF{"Diff tag"};
static constexpr auto T_REALDATA{"Real Data tag"};
static constexpr auto T_DATAVIEW{"Data View tag"};
static constexpr auto T_FIT_SUITE{"Fit suite tag"};
......@@ -62,7 +63,6 @@ public:
static constexpr auto M_TYPE{"JobItem"};
JobItem();
~JobItem();
QString getIdentifier() const;
void setIdentifier(const QString& identifier);
......@@ -127,8 +127,8 @@ public:
RealDataItem* copyRealDataIntoJob(const RealDataItem* real_data);
RealDataItem* createRealDataItem();
DataItem* diffDataItem();
Data1DViewItem* dataItemView();
void addDataViewItem(Data1DViewItem* data_view);
Data1DViewItem* createDataViewItem();
QString sampleName() const;
......@@ -147,7 +147,6 @@ public:
friend class JobModel;
signals:
void jobDestroyed();
void jobNameChanged(const QString& name);
void jobStatusChanged(const JobStatus status);
void jobBeginTimeChanged(const QDateTime& begin_time);
......
......@@ -49,8 +49,7 @@ FitSessionController* FitSessionManager::sessionController(JobItem* jobItem)
FitSessionController* FitSessionManager::createController(JobItem* jobItem)
{
// job destruction
connect(jobItem, &JobItem::jobDestroyed, this, [=]() { removeController(jobItem); });
connect(jobItem, &JobItem::destroyed, this, [=]() { removeController(jobItem); });
auto* result = new FitSessionController(this);
result->setItem(jobItem);
......
......@@ -107,7 +107,7 @@ void MaskEditorPropertyPanel::setMaskContext(SessionModel* model,
connect(m_listView->selectionModel(), &QItemSelectionModel::selectionChanged, this,
&MaskEditorPropertyPanel::onSelectionChanged, Qt::UniqueConnection);
m_plotPropertyEditor->setItem(m_intensityDataItem);
m_plotPropertyEditor->setItem({m_intensityDataItem});
}
void MaskEditorPropertyPanel::resetContext()
......@@ -117,7 +117,7 @@ void MaskEditorPropertyPanel::resetContext()
m_intensityDataItem = nullptr;
m_listView->setModel(nullptr);
setCurrentMaskItem(nullptr);
m_plotPropertyEditor->setItem(nullptr);
m_plotPropertyEditor->setItem({nullptr});
}
QItemSelectionModel* MaskEditorPropertyPanel::selectionModel()
......@@ -136,13 +136,13 @@ void MaskEditorPropertyPanel::setPanelHidden(bool hidden)
if (hidden) {
setCurrentMaskItem(nullptr);
m_plotPropertyEditor->setItem(nullptr);
m_plotPropertyEditor->setItem({nullptr});
} else {
QModelIndexList indexes = selectionModel()->selectedIndexes();
if (!indexes.empty())
setCurrentMaskItem(maskItemForIndex(indexes.front()));
m_plotPropertyEditor->setItem(m_intensityDataItem);
m_plotPropertyEditor->setItem({m_intensityDataItem});
}
}
......
......@@ -66,7 +66,6 @@ void IntensityDataCanvas::setItem(SessionItem* intensityItem)
SessionItemWidget::setItem(intensityItem);
m_colorMap->setItem(intensityDataItem());
applyPersistentSettings();
if (!m_rotateDataAction)
initRotation();
}
......@@ -106,12 +105,6 @@ void IntensityDataCanvas::onMousePress(QMouseEvent* event)
emit customContextMenuRequested(event->globalPos());
}
void IntensityDataCanvas::subscribeToItem()
{
intensityDataItem()->mapper()->setOnPropertyChange(
[this](const QString& name) { onPropertyChanged(name); }, this);
}
void IntensityDataCanvas::rotateData()
{
auto* realDataItem = dynamic_cast<RealDataItem*>(intensityDataItem()->parentItem());
......@@ -169,38 +162,3 @@ void IntensityDataCanvas::initRotation()
connect(m_rotateDataAction, &QAction::triggered, this, &IntensityDataCanvas::rotateData);
}
}
//! Reads gradient/ interpolation settings from IntensityDataItem and writes to persistant
//! project settings.
void IntensityDataCanvas::onPropertyChanged(const QString& name)
{
if (IntensityDataItem::isGradientPropertyName(name)) {
QSettings settings;
settings.setValue(SettingsKeyGradient, intensityDataItem()->getGradientValue());
} else if (IntensityDataItem::isInterpolatedPropertyName(name)) {
QSettings settings;
settings.setValue(SettingsKeyInterpolation, intensityDataItem()->isInterpolated());
}
}
//! Apply persistent settings (gradient, interpolation) to IntensityDataItem.
void IntensityDataCanvas::applyPersistentSettings()
{
QSettings settings;
if (settings.contains(SettingsKeyGradient)) {
ComboProperty combo = intensityDataItem()->getGradient();
QString persistentGradient = settings.value(SettingsKeyGradient).toString();
if (combo.getValue() != persistentGradient) {
combo.setValue(persistentGradient);
intensityDataItem()->setGradient(combo);
}
}
if (settings.contains(SettingsKeyInterpolation)) {
bool value = settings.value(SettingsKeyInterpolation).toBool();
intensityDataItem()->setInterpolated(value);
}
}
......@@ -45,15 +45,12 @@ public slots:
void onMousePress(QMouseEvent* event);
protected:
void subscribeToItem() override;
void rotateData();
private:
IntensityDataItem* intensityDataItem();
void initActions();
void initRotation();
void onPropertyChanged(const QString& name);
void applyPersistentSettings();
ColorMapCanvas* m_colorMap;
QAction* m_resetViewAction;
......
......@@ -53,14 +53,42 @@ IntensityDataWidget::IntensityDataWidget(QWidget* parent)
m_propertyWidget->setVisible(false);
}
void IntensityDataWidget::setItem(SessionItem* jobItem)
void IntensityDataWidget::setItem(SessionItem* job_Item)
{
SessionItemWidget::setItem(jobItem);
SessionItemWidget::setItem(job_Item); // now we can access to jobItem()
m_intensityCanvas->setItem(intensityDataItem());
m_propertyWidget->setItem(intensityDataItem());
#ifdef USE_MAPPERS
m_propertyWidget->setItem({intensityDataItem()});
#else
m_propertyWidget->setItem({intensityDataItem(),
realIntensityDataItem(),
diffIntensityDataItem()});
#endif
m_fftPresenter->reset();
}
JobItem* IntensityDataWidget::jobItem()
{
return dynamic_cast<JobItem*>(currentItem());
}
IntensityDataItem* IntensityDataWidget::realIntensityDataItem()
{
if(jobItem() && jobItem()->realDataItem())
return jobItem()->realDataItem()->intensityDataItem();
else
return nullptr;
}
IntensityDataItem* IntensityDataWidget::diffIntensityDataItem()
{
if(jobItem())
return dynamic_cast<IntensityDataItem*>(jobItem()->diffDataItem());
else
return nullptr;
}
QList<QAction*> IntensityDataWidget::actionList()
{
return m_intensityCanvas->actionList() + m_fftPresenter->actionList()
......@@ -83,11 +111,11 @@ void IntensityDataWidget::onFFTAction()
if (m_fftPresenter->inFFTMode()) {
auto* fftItem = m_fftPresenter->fftItem(intensityDataItem());
m_intensityCanvas->setItem(fftItem);
m_propertyWidget->setItem(fftItem);
m_propertyWidget->setItem({fftItem});
} else {
// returning ColorMap to non-fft presentation
m_intensityCanvas->setItem(intensityDataItem());
m_propertyWidget->setItem(intensityDataItem());
m_propertyWidget->setItem({intensityDataItem()});
}
}
......
......@@ -25,6 +25,7 @@ class IntensityDataItem;
class QAction;
class QContextMenuEvent;
class IntensityDataFFTPresenter;
class JobItem;
//! A common widget to display color map (IntensityDataCanvas) and properties
//! (ItemPropertyWidget) of intensity data item.
......@@ -35,7 +36,10 @@ class IntensityDataWidget : public SessionItemWidget {
public:
IntensityDataWidget(QWidget* parent = nullptr);
void setItem(SessionItem* jobItem) override;
void setItem(SessionItem* job_Item) override;
JobItem* jobItem();
IntensityDataItem* realIntensityDataItem();
IntensityDataItem* diffIntensityDataItem();
QList<QAction*> actionList() override;
......
......@@ -32,7 +32,7 @@ const double relative_diff_max_2d = 1.0;
class FitComparisonController2D::DiffItemController : public QObject {
public:
DiffItemController(const QString& data_type, QObject* parent);
DiffItemController(QObject* parent);
~DiffItemController() override;
void setItem(JobItem* job_item);
void updateDiffData();
......@@ -42,7 +42,6 @@ public:
private:
JobItem* m_current_item;
SessionModel* m_tempIntensityDataModel;
DataItem* m_diff_item;
};
......@@ -50,7 +49,7 @@ using DiffItemController = FitComparisonController2D::DiffItemController;
FitComparisonController2D::FitComparisonController2D(QObject* parent)
: QObject(parent)
, m_diff_item_controller(new DiffItemController(IntensityDataItem::M_TYPE, this))
, m_diff_item_controller(new DiffItemController(this))
, m_appearanceRepeater(new PropertyRepeater(this))
, m_xAxisRepeater(new PropertyRepeater(this))
, m_yAxisRepeater(new PropertyRepeater(this))
......@@ -120,13 +119,11 @@ void FitComparisonController2D::clear()