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