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

[i311] GUI: fix for a simulation with specular data (Closes #311)

Merging branch 'i311'  into 'main'.

See merge request !957
parents d95dd39c 8b402654
Pipeline #67491 failed with stage
in 5 minutes and 35 seconds
...@@ -201,6 +201,7 @@ class GroupInfo; ...@@ -201,6 +201,7 @@ class GroupInfo;
//! //!
//! This code part again shows the (highly error-prone) string-based type checking. //! This code part again shows the (highly error-prone) string-based type checking.
//#define USE_MAPPERS //#define USE_MAPPERS
#include <QDebug>
class BA_CORE_API_ SessionItem { class BA_CORE_API_ SessionItem {
friend class SessionModel; friend class SessionModel;
......
...@@ -23,7 +23,7 @@ void DataItem::setDatafield(Datafield* data) ...@@ -23,7 +23,7 @@ void DataItem::setDatafield(Datafield* data)
m_data.reset(data); m_data.reset(data);
setLastModified(QDateTime::currentDateTime()); setLastModified(QDateTime::currentDateTime());
emit datafieldChanged(data); emit datafieldChanged();
#ifdef USE_MAPPERS #ifdef USE_MAPPERS
emitDataChanged(); emitDataChanged();
#endif #endif
......
...@@ -76,7 +76,7 @@ public: ...@@ -76,7 +76,7 @@ public:
virtual void reset(ImportDataInfo data) = 0; virtual void reset(ImportDataInfo data) = 0;
signals: signals:
void datafieldChanged(Datafield* data); void datafieldChanged();
void rawDataVectorChanged(const std::vector<double>& data); void rawDataVectorChanged(const std::vector<double>& data);
void fileNameChanged(const QString& filename); void fileNameChanged(const QString& filename);
void axesUnitsChanged(); void axesUnitsChanged();
......
...@@ -331,7 +331,7 @@ void IntensityDataItem::setLogz(bool logz) ...@@ -331,7 +331,7 @@ void IntensityDataItem::setLogz(bool logz)
void IntensityDataItem::setInterpolated(bool interp) void IntensityDataItem::setInterpolated(bool interp)
{ {
setItemValue(P_IS_INTERPOLATED, interp); setItemValue(P_IS_INTERPOLATED, interp);
emit interpolationChanged(); emit interpolationChanged(interp);
} }
//! Sets zoom range of X,Y axes, if it was not yet defined. //! Sets zoom range of X,Y axes, if it was not yet defined.
......
...@@ -26,6 +26,7 @@ class ProjectionContainerItem; ...@@ -26,6 +26,7 @@ class ProjectionContainerItem;
class BA_CORE_API_ IntensityDataItem : public DataItem { class BA_CORE_API_ IntensityDataItem : public DataItem {
Q_OBJECT Q_OBJECT
private: private:
// using DataItem::mapper;
static constexpr auto P_PROJECTIONS{"Projections"}; static constexpr auto P_PROJECTIONS{"Projections"};
static constexpr auto P_TITLE{"Title"}; static constexpr auto P_TITLE{"Title"};
static constexpr auto P_IS_INTERPOLATED{"Interpolation"}; static constexpr auto P_IS_INTERPOLATED{"Interpolation"};
...@@ -123,7 +124,7 @@ public: ...@@ -123,7 +124,7 @@ public:
signals: signals:
void gradientChanged(); void gradientChanged();
void interpolationChanged(); void interpolationChanged(bool isInterpol);
void axesRangeChangedFromPlot(); void axesRangeChangedFromPlot();
void updateOtherPlots(); void updateOtherPlots();
void updateThisPlot(); void updateThisPlot();
......
...@@ -195,7 +195,7 @@ bool AmplitudeAxisItem::isLogScale() const ...@@ -195,7 +195,7 @@ bool AmplitudeAxisItem::isLogScale() const
void AmplitudeAxisItem::setLogScale(bool value) void AmplitudeAxisItem::setLogScale(bool value)
{ {
setItemValue(P_IS_LOGSCALE, value); setItemValue(P_IS_LOGSCALE, value);
emit logScaleChanged(); emit logScaleChanged(value);
} }
SessionItem* AmplitudeAxisItem::logScaleItem() const SessionItem* AmplitudeAxisItem::logScaleItem() const
......
...@@ -99,7 +99,7 @@ public: ...@@ -99,7 +99,7 @@ public:
void setLocked(bool locked); void setLocked(bool locked);
signals: signals:
void logScaleChanged(); void logScaleChanged(bool isLog);
}; };
......
...@@ -112,6 +112,7 @@ void GUI::Model::JobFunctions::initDataView(JobItem* job_item) ...@@ -112,6 +112,7 @@ void GUI::Model::JobFunctions::initDataView(JobItem* job_item)
// also triggers Data1DViewItem::setAxesRangeToData and // also triggers Data1DViewItem::setAxesRangeToData and
// GUI::Model::DataViewUtils::updateAxesTitle by setting new value of P_AXES_UNITS. // GUI::Model::DataViewUtils::updateAxesTitle by setting new value of P_AXES_UNITS.
auto* converter = job_item->instrumentItem()->createCoordSystem(); auto* converter = job_item->instrumentItem()->createCoordSystem();
view_item->setAxesUnits(GUI::Model::JobItemUtils::availableUnits(*converter)); view_item->setAxesUnits(GUI::Model::JobItemUtils::availableUnits(*converter));
} }
......
...@@ -55,7 +55,8 @@ JobItem* JobModel::addJob(const MultiLayerItem* sampleItem, const InstrumentItem ...@@ -55,7 +55,8 @@ JobItem* JobModel::addJob(const MultiLayerItem* sampleItem, const InstrumentItem
ASSERT(sampleItem); ASSERT(sampleItem);
ASSERT(instrumentItem); ASSERT(instrumentItem);
auto* jobItem = insertItem<JobItem>(); JobItem* jobItem = insertItem<JobItem>();
emit jobAdded();
jobItem->setItemName(generateJobName()); jobItem->setItemName(generateJobName());
jobItem->setIdentifier(QUuid::createUuid().toString()); jobItem->setIdentifier(QUuid::createUuid().toString());
......
...@@ -53,6 +53,7 @@ public: ...@@ -53,6 +53,7 @@ public:
signals: signals:
void focusRequest(JobItem* item); void focusRequest(JobItem* item);
void globalProgress(int); void globalProgress(int);
void jobAdded();
private: private:
//! generates numbered job name with new/unused number //! generates numbered job name with new/unused number
......
...@@ -28,19 +28,16 @@ JobListModel::JobListModel(JobModel* jobs, QObject* parent) ...@@ -28,19 +28,16 @@ JobListModel::JobListModel(JobModel* jobs, QObject* parent)
: QAbstractListModel(parent) : QAbstractListModel(parent)
, m_jobs(jobs) , m_jobs(jobs)
{ {
for (JobItem* job : m_jobs->jobItems()) for (JobItem* job : m_jobs->jobItems()) {
enableJobNotification(job); enableJobNotification(job);
}
connect(jobs, &QAbstractItemModel::rowsAboutToBeInserted, this, connect(jobs, &JobModel::jobAdded, this, &JobListModel::onJobAdded, Qt::UniqueConnection);
&JobListModel::onRowsAboutToBeInserted);
connect(jobs, &QAbstractItemModel::rowsInserted, this, &JobListModel::onRowsInserted);
} }
JobListModel::~JobListModel() JobListModel::~JobListModel()
{ {
for (JobItem* job : m_jobs->jobItems()) { for (JobItem* job : m_jobs->jobItems())
disableJobNotification(job); disableJobNotification(job);
}
} }
int JobListModel::rowCount(const QModelIndex&) const int JobListModel::rowCount(const QModelIndex&) const
...@@ -111,20 +108,10 @@ void JobListModel::emitJobListModelChanged(JobItem* job) ...@@ -111,20 +108,10 @@ void JobListModel::emitJobListModelChanged(JobItem* job)
// private slots // private slots
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void JobListModel::onRowsAboutToBeInserted(const QModelIndex& parent, int start, int end) void JobListModel::onJobAdded()
{ {
if (!parent.isValid()) for (JobItem* job : m_jobs->jobItems())
beginInsertRows(QModelIndex(), start, end); enableJobNotification(job);
}
void JobListModel::onRowsInserted(const QModelIndex& parent, int start, int end)
{
if (!parent.isValid()) {
endInsertRows();
QVector<JobItem*> jobs = m_jobs->jobItems();
for (int i = start; i <= end; i++)
enableJobNotification(jobs.at(i));
}
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
...@@ -134,15 +121,13 @@ void JobListModel::onRowsInserted(const QModelIndex& parent, int start, int end) ...@@ -134,15 +121,13 @@ void JobListModel::onRowsInserted(const QModelIndex& parent, int start, int end)
void JobListModel::enableJobNotification(JobItem* job) void JobListModel::enableJobNotification(JobItem* job)
{ {
// name // name
connect(job, &JobItem::jobNameChanged, this, connect(job, &JobItem::jobNameChanged, this, [=]() { emitJobListModelChanged(job); });
[=](const QString&) { emitJobListModelChanged(job); });
// status // status
connect(job, &JobItem::jobStatusChanged, this, connect(job, &JobItem::jobStatusChanged, this, [=]() { emitJobListModelChanged(job); });
[=](const JobStatus) { emitJobListModelChanged(job); });
// progress // progress
connect(job, &JobItem::jobProgressChanged, this, [=](int) { emitJobListModelChanged(job); }); connect(job, &JobItem::jobProgressChanged, this, [=]() { emitJobListModelChanged(job); });
} }
void JobListModel::disableJobNotification(JobItem* job) void JobListModel::disableJobNotification(JobItem* job)
......
...@@ -40,8 +40,7 @@ public: ...@@ -40,8 +40,7 @@ public:
private slots: private slots:
void emitJobListModelChanged(JobItem* job); void emitJobListModelChanged(JobItem* job);
void onRowsAboutToBeInserted(const QModelIndex& parent, int start, int end); void onJobAdded();
void onRowsInserted(const QModelIndex& parent, int start, int end);
private: private:
void enableJobNotification(JobItem* job); void enableJobNotification(JobItem* job);
......
...@@ -177,7 +177,7 @@ void DiffItemController::subscribe() ...@@ -177,7 +177,7 @@ void DiffItemController::subscribe()
m_current_item->dataItem()->mapper()->setOnValueChange([this]() { updateDiffData(); }, this); m_current_item->dataItem()->mapper()->setOnValueChange([this]() { updateDiffData(); }, this);
#else #else
connect(m_current_item->dataItem(), &DataItem::datafieldChanged, this, connect(m_current_item->dataItem(), &DataItem::datafieldChanged, this,
[=](Datafield*) { updateDiffData(); }); &DiffItemController::updateDiffData, Qt::UniqueConnection);
#endif #endif
// on diff item units change // on diff item units change
......
...@@ -168,23 +168,20 @@ void DiffItemController::subscribe() ...@@ -168,23 +168,20 @@ void DiffItemController::subscribe()
m_current_item->dataItem()->mapper()->setOnValueChange([this]() { updateDiffData(); }, this); m_current_item->dataItem()->mapper()->setOnValueChange([this]() { updateDiffData(); }, this);
#else #else
connect(m_current_item->dataItem(), &DataItem::datafieldChanged, this, connect(m_current_item->dataItem(), &DataItem::datafieldChanged, this,
[=](Datafield*) { updateDiffData(); }); &DiffItemController::updateDiffData, Qt::UniqueConnection);
#endif #endif
} }
void DiffItemController::unsubscribe() void DiffItemController::unsubscribe()
{ {
#ifdef USE_MAPPERS
m_diff_item->mapper()->unsubscribe(this);
#else
disconnect(m_diff_item, nullptr, this, nullptr);
#endif
if (!m_current_item) if (!m_current_item)
return; return;
#ifdef USE_MAPPERS #ifdef USE_MAPPERS
m_current_item->dataItem()->mapper()->unsubscribe(this); m_current_item->dataItem()->mapper()->unsubscribe(this);
m_diff_item->mapper()->unsubscribe(this);
#else #else
disconnect(m_current_item->dataItem(), nullptr, this, nullptr); disconnect(m_current_item->dataItem(), nullptr, this, nullptr);
disconnect(m_diff_item, nullptr, this, nullptr);
#endif #endif
m_current_item = nullptr; m_current_item = nullptr;
} }
...@@ -134,7 +134,7 @@ void Plot1D::subscribeToItem() ...@@ -134,7 +134,7 @@ void Plot1D::subscribeToItem()
#else #else
DataItem* dataItem = pair.first->dataItem(); DataItem* dataItem = pair.first->dataItem();
connect(dataItem, &DataItem::datafieldChanged, caller, connect(dataItem, &DataItem::datafieldChanged, caller,
[caller](Datafield*) { caller->refreshPlotData(); }); [caller]() { caller->refreshPlotData(); });
#endif #endif
}); });
setConnected(true); setConnected(true);
......
...@@ -225,9 +225,8 @@ void ColorMap::subscribeToItem() ...@@ -225,9 +225,8 @@ void ColorMap::subscribeToItem()
intensityItem()->mapper()->setOnValueChange([this]() { onIntensityModified(); }, this); intensityItem()->mapper()->setOnValueChange([this]() { onIntensityModified(); }, this);
#else #else
// datafield // datafield
connect(intensityItem(), &IntensityDataItem::datafieldChanged, this, [=]() { connect(intensityItem(), &IntensityDataItem::datafieldChanged, this,
onIntensityModified(); &ColorMap::onIntensityModified, Qt::UniqueConnection);
});
// units // units
connect(intensityItem(), &IntensityDataItem::axesUnitsReplotRequested, this, [=]() { connect(intensityItem(), &IntensityDataItem::axesUnitsReplotRequested, this, [=]() {
setAxesRangeFromItem(intensityItem()); setAxesRangeFromItem(intensityItem());
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
#include <QLineEdit> #include <QLineEdit>
#define FOR_EACH_ITEM \ #define FOR_EACH_ITEM \
for(IntensityDataItem* item : m_items_vec) \ for(IntensityDataItem*& item : m_items_vec) \
if(item) if(item)
IntensityDataPropertyWidget::IntensityDataPropertyWidget(QWidget* parent) IntensityDataPropertyWidget::IntensityDataPropertyWidget(QWidget* parent)
...@@ -141,14 +141,12 @@ void IntensityDataPropertyWidget::setItem(QVector<IntensityDataItem*> itemsVec) ...@@ -141,14 +141,12 @@ void IntensityDataPropertyWidget::setItem(QVector<IntensityDataItem*> itemsVec)
updateUIValues(); updateUIValues();
// react on external changes (e.g. zooming in customplot shall update the axis values)
// update coordinates on axes units change
#ifdef USE_MAPPERS #ifdef USE_MAPPERS
// react on external changes (e.g. zooming in customplot shall update the axis values)
first_item->mapper()->setOnChildPropertyChange( first_item->mapper()->setOnChildPropertyChange(
[=](SessionItem*, const QString&) { updateUIValues(); }, this); [=](SessionItem*, const QString&) { updateUIValues(); }, this);
// update coordinates on axes units change
first_item->mapper()->setOnPropertyChange( first_item->mapper()->setOnPropertyChange(
[this](SessionItem* item, const QString& name) { [this](SessionItem* item, const QString& name) {
if(jobItem()) if(jobItem())
...@@ -160,7 +158,7 @@ void IntensityDataPropertyWidget::setItem(QVector<IntensityDataItem*> itemsVec) ...@@ -160,7 +158,7 @@ void IntensityDataPropertyWidget::setItem(QVector<IntensityDataItem*> itemsVec)
[&](SessionItem*) { item = nullptr; }, this); [&](SessionItem*) { item = nullptr; }, this);
#else #else
// update values on panel // react on external changes (e.g. zooming in customplot shall update the axis values)
FOR_EACH_ITEM FOR_EACH_ITEM
connect(item, &IntensityDataItem::axesRangeChangedFromPlot, this, [=](){ connect(item, &IntensityDataItem::axesRangeChangedFromPlot, this, [=](){
updateUIValues(); updateUIValues();
......
...@@ -101,7 +101,10 @@ JobItem* ProjectionsEditor::jobItem() ...@@ -101,7 +101,10 @@ JobItem* ProjectionsEditor::jobItem()
IntensityDataItem* ProjectionsEditor::simulatedIntensity() IntensityDataItem* ProjectionsEditor::simulatedIntensity()
{ {
return dynamic_cast<IntensityDataItem*>(jobItem()->dataItem()); if(jobItem())
return dynamic_cast<IntensityDataItem*>(jobItem()->dataItem());
else
return nullptr;
} }
IntensityDataItem* ProjectionsEditor::realIntensityDataItem() IntensityDataItem* ProjectionsEditor::realIntensityDataItem()
......
...@@ -81,25 +81,63 @@ void ProjectionsPlot::subscribeToItem() ...@@ -81,25 +81,63 @@ void ProjectionsPlot::subscribeToItem()
this); this);
// Values of intensity changed, regenerate everything. // Values of intensity changed, regenerate everything.
intensityItem()->mapper()->setOnValueChange( #ifdef USE_MAPPERS
[this]() { // intensityItem()->mapper()->setOnValueChange(
// [this]() {
// updateProjectionsData();
// updateProjections();
// },
// this);
#else
connect(intensityItem(), &IntensityDataItem::datafieldChanged, this, [=]() {
updateProjectionsData(); updateProjectionsData();
updateProjections(); updateProjections();
}, });
this); #endif
// IntensityItem property (e.g. interpolation changed) // interpolation changed
#ifdef USE_MAPPERS
intensityItem()->mapper()->setOnPropertyChange( intensityItem()->mapper()->setOnPropertyChange(
[this](const QString& name) { onIntensityItemPropertyChanged(name); }, this); [this](const QString& name) { onIntensityItemPropertyChanged(name); }, this);
#else
connect(intensityItem(), &IntensityDataItem::interpolationChanged, this,
&ProjectionsPlot::setInterpolate, Qt::UniqueConnection);
#endif
// Update to changed IntensityDataItem axes // AXES
#ifdef USE_MAPPERS
intensityItem()->mapper()->setOnChildPropertyChange( intensityItem()->mapper()->setOnChildPropertyChange(
[this](SessionItem* item, const QString name) { [this](SessionItem* item, const QString name) {
if (item->modelType() == BasicAxisItem::M_TYPE if (item->modelType() == BasicAxisItem::M_TYPE
|| item->modelType() == AmplitudeAxisItem::M_TYPE) || item->modelType() == AmplitudeAxisItem::M_TYPE) {
onAxisPropertyChanged(item->itemName(), name); onAxisPropertyChanged(item->itemName(), name);
}
}, },
this); this);
#else
// if the colormap is zoomed or dragged:
connect(intensityItem(), &IntensityDataItem::updateOtherPlots, this,
&ProjectionsPlot::updateAxesRange, Qt::UniqueConnection);
// if axes are changed externally, from the properties panel:
// axes range
connect(intensityItem()->xAxisItem(), &BasicAxisItem::axisRangeChanged, this,
&ProjectionsPlot::updateAxesRange, Qt::UniqueConnection);
connect(intensityItem()->yAxisItem(), &BasicAxisItem::axisRangeChanged, this,
&ProjectionsPlot::updateAxesRange, Qt::UniqueConnection);
connect(intensityItem()->zAxisItem(), &BasicAxisItem::axisRangeChanged, this,
&ProjectionsPlot::updateAxesRange, Qt::UniqueConnection);
// axes title
connect(intensityItem()->xAxisItem(), &BasicAxisItem::axisTitleChanged, this,
&ProjectionsPlot::updateAxesTitle, Qt::UniqueConnection);
connect(intensityItem()->yAxisItem(), &BasicAxisItem::axisTitleChanged, this,
&ProjectionsPlot::updateAxesTitle, Qt::UniqueConnection);
// z log scale
connect(intensityItem()->zAxisItem(), &AmplitudeAxisItem::logScaleChanged, this,
&ProjectionsPlot::setLogz, Qt::UniqueConnection);
#endif
updateProjectionsData(); updateProjectionsData();
updateProjections(); updateProjections();
......
...@@ -194,7 +194,8 @@ void SimulationView::updateSelection(QComboBox* comboBox, QStringList itemList, ...@@ -194,7 +194,8 @@ void SimulationView::updateSelection(QComboBox* comboBox, QStringList itemList,
} }
if (allowNone) if (allowNone)
itemList.insert(-1, "None"); itemList.prepend("None");
comboBox->addItems(itemList); comboBox->addItems(itemList);
if (itemList.contains(previousItem)) if (itemList.contains(previousItem))
comboBox->setCurrentIndex(itemList.indexOf(previousItem)); comboBox->setCurrentIndex(itemList.indexOf(previousItem));
......
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