Commit e7257e5a authored by Mikhail Svechnikov's avatar Mikhail Svechnikov Committed by Mikhail Svechnikov
Browse files

add mappers in parallel

parent ea7a3b04
...@@ -200,6 +200,7 @@ class GroupInfo; ...@@ -200,6 +200,7 @@ class GroupInfo;
//! \endcode //! \endcode
//! //!
//! 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
#include <QDebug> #include <QDebug>
class BA_CORE_API_ SessionItem { class BA_CORE_API_ SessionItem {
friend class SessionModel; friend class SessionModel;
......
...@@ -24,6 +24,9 @@ void DataItem::setDatafield(Datafield* data) ...@@ -24,6 +24,9 @@ void DataItem::setDatafield(Datafield* data)
setLastModified(QDateTime::currentDateTime()); setLastModified(QDateTime::currentDateTime());
emit datafieldChanged(data); emit datafieldChanged(data);
#ifdef USE_MAPPERS
emitDataChanged();
#endif
} }
void DataItem::setRawDataVector(const std::vector<double>& data) void DataItem::setRawDataVector(const std::vector<double>& data)
...@@ -36,6 +39,9 @@ void DataItem::setRawDataVector(const std::vector<double>& data) ...@@ -36,6 +39,9 @@ void DataItem::setRawDataVector(const std::vector<double>& data)
setLastModified(QDateTime::currentDateTime()); setLastModified(QDateTime::currentDateTime());
emit rawDataVectorChanged(data); emit rawDataVectorChanged(data);
#ifdef USE_MAPPERS
emitDataChanged();
#endif
} }
QString DataItem::fileName() const QString DataItem::fileName() const
...@@ -105,21 +111,26 @@ SessionItem* DataItem::getAxesUnitsItem() const ...@@ -105,21 +111,26 @@ SessionItem* DataItem::getAxesUnitsItem() const
return getItem(P_AXES_UNITS); return getItem(P_AXES_UNITS);
} }
SelectionDescriptor<QString> DataItem::axesUnits() const void DataItem::createAxesUnitsDescriptor()
{ {
SessionItem* item = getAxesUnitsItem(); SessionItem* item = getAxesUnitsItem();
qInfo() << item << "createAxesUnitsDescriptor" << endl;
SelectionDescriptor<QString> d = SelectionDescriptor<QString>(item); m_axes_units = SelectionDescriptor<QString>(item);
#ifndef USE_MAPPERS
d.currentIndexSetter = [=](int index) { m_axes_units.currentIndexSetter = [=](int index) {
ComboProperty comboProperty = item->value().value<ComboProperty>(); ComboProperty comboProperty = item->value().value<ComboProperty>();
if (comboProperty.currentIndex() != index) { if (comboProperty.currentIndex() != index) {
comboProperty.setCurrentIndex(index); comboProperty.setCurrentIndex(index);
qInfo() << "new setter : DataItem" << endl; qInfo() << "new setter" << endl;
const_cast<DataItem*>(this)->setAxesUnits(comboProperty); const_cast<DataItem*>(this)->setAxesUnits(comboProperty);
} }
}; };
return d; #endif
}
SelectionDescriptor<QString> DataItem::axesUnits() const
{
return m_axes_units;
} }
bool DataItem::isAxesUnitsPropertyName(const QString& name) bool DataItem::isAxesUnitsPropertyName(const QString& name)
...@@ -142,5 +153,5 @@ DataItem::DataItem(const QString& modelType) ...@@ -142,5 +153,5 @@ DataItem::DataItem(const QString& modelType)
// name of the file used to serialize given IntensityDataItem // name of the file used to serialize given IntensityDataItem
addProperty(P_FILE_NAME, "undefined"); addProperty(P_FILE_NAME, "undefined");
addProperty(P_AXES_UNITS, ComboProperty::fromList({"nbins"}).variant()); addProperty(P_AXES_UNITS, ComboProperty::fromList({"nbins"}).variant());
} }
...@@ -62,6 +62,7 @@ public: ...@@ -62,6 +62,7 @@ public:
void setAxesUnits(const ComboProperty& units); void setAxesUnits(const ComboProperty& units);
SessionItem* getAxesUnitsItem() const; SessionItem* getAxesUnitsItem() const;
void createAxesUnitsDescriptor();
SelectionDescriptor<QString> axesUnits() const; SelectionDescriptor<QString> axesUnits() const;
static bool isAxesUnitsPropertyName(const QString& name); static bool isAxesUnitsPropertyName(const QString& name);
static void updateAxesUnits(SessionItem* item, const QString& name, static void updateAxesUnits(SessionItem* item, const QString& name,
...@@ -81,11 +82,12 @@ signals: ...@@ -81,11 +82,12 @@ signals:
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(const ComboProperty& units); void axesUnitsChanged(const ComboProperty& units);
void axesUnitsReplotRequested(); void replotRequested();
protected: protected:
explicit DataItem(const QString& modelType); explicit DataItem(const QString& modelType);
SelectionDescriptor<QString> m_axes_units;
std::unique_ptr<Datafield> m_data; //!< simulation results std::unique_ptr<Datafield> m_data; //!< simulation results
QDateTime m_last_modified; QDateTime m_last_modified;
std::mutex m_update_data_mutex; std::mutex m_update_data_mutex;
......
...@@ -79,9 +79,9 @@ void IntensityDataItem::setDatafield(Datafield* data) ...@@ -79,9 +79,9 @@ void IntensityDataItem::setDatafield(Datafield* data)
updateAxesZoomLevel(); updateAxesZoomLevel();
updateAxesLabels(); updateAxesLabels();
updateDataRange(); updateDataRange();
#ifdef USE_MAPPERS
// qInfo() << "setDatafield\n------------------------\n" << endl;
emitDataChanged(); emitDataChanged();
#endif
} }
int IntensityDataItem::xSize() const int IntensityDataItem::xSize() const
......
...@@ -45,15 +45,11 @@ void GUI::Model::JobItemUtils::updateDataAxes(DataItem* intensityItem, ...@@ -45,15 +45,11 @@ void GUI::Model::JobItemUtils::updateDataAxes(DataItem* intensityItem,
return; return;
} }
qInfo() << "a" << intensityItem << intensityItem->getDatafield() << endl;
if (!intensityItem->getDatafield()) if (!intensityItem->getDatafield())
return; return;
qInfo() << "b" << endl;
Coords requested_units = GUI::Util::CoordName::coordFromName(intensityItem->selectedCoords()); Coords requested_units = GUI::Util::CoordName::coordFromName(intensityItem->selectedCoords());
qInfo() << "selected" << intensityItem->selectedCoords() << endl;
auto* const converter = instrumentItem->createCoordSystem(); auto* const converter = instrumentItem->createCoordSystem();
auto newData = std::make_unique<Datafield>(converter->convertedAxes(requested_units)); auto newData = std::make_unique<Datafield>(converter->convertedAxes(requested_units));
......
...@@ -88,6 +88,7 @@ public: ...@@ -88,6 +88,7 @@ public:
if (comboProperty.currentIndex() != index) { if (comboProperty.currentIndex() != index) {
comboProperty.setCurrentIndex(index); comboProperty.setCurrentIndex(index);
item->setValue(QVariant::fromValue<ComboProperty>(comboProperty)); item->setValue(QVariant::fromValue<ComboProperty>(comboProperty));
qInfo() << item << "old setter" << endl;
} }
}; };
currentIndexGetter = [=] { return item->value().value<ComboProperty>().currentIndex(); }; currentIndexGetter = [=] { return item->value().value<ComboProperty>().currentIndex(); };
......
...@@ -58,13 +58,14 @@ void IntensityDataWidget::setItem(SessionItem* job_Item) ...@@ -58,13 +58,14 @@ void IntensityDataWidget::setItem(SessionItem* job_Item)
SessionItemWidget::setItem(job_Item); SessionItemWidget::setItem(job_Item);
// now we can access to JobItem // now we can access to JobItem
// m_intensityCanvas->setItem(intensityDataItem());
// m_propertyWidget->setItem({intensityDataItem(),
// realIntensityDataItem(),
// diffIntensityDataItem()});
m_intensityCanvas->setItem(intensityDataItem()); m_intensityCanvas->setItem(intensityDataItem());
#ifdef USE_MAPPERS
m_propertyWidget->setItem({intensityDataItem()}); m_propertyWidget->setItem({intensityDataItem()});
#else
m_propertyWidget->setItem({intensityDataItem(),
realIntensityDataItem(),
diffIntensityDataItem()});
#endif
m_fftPresenter->reset(); m_fftPresenter->reset();
} }
...@@ -75,7 +76,7 @@ JobItem* IntensityDataWidget::jobItem() ...@@ -75,7 +76,7 @@ JobItem* IntensityDataWidget::jobItem()
IntensityDataItem* IntensityDataWidget::realIntensityDataItem() IntensityDataItem* IntensityDataWidget::realIntensityDataItem()
{ {
if(jobItem()) if(jobItem() && jobItem()->realDataItem())
return jobItem()->realDataItem()->intensityDataItem(); return jobItem()->realDataItem()->intensityDataItem();
else else
return nullptr; return nullptr;
......
...@@ -178,14 +178,27 @@ void DiffItemController::subscribe() ...@@ -178,14 +178,27 @@ void DiffItemController::subscribe()
return; return;
} }
// on simulation data change // on simulation data change
#ifdef USE_MAPPERS
m_current_item->dataItem()->mapper()->setOnValueChange([this]() { updateDiffData(); }, this);
#else
connect(m_current_item->dataItem(), &DataItem::datafieldChanged, this, connect(m_current_item->dataItem(), &DataItem::datafieldChanged, this,
[=](Datafield*) { updateDiffData(); }); [=](Datafield*) { updateDiffData(); });
#endif
// on diff item units change // on diff item units change
#ifdef USE_MAPPERS
m_diff_item->mapper()->setOnPropertyChange(
[this](const QString& name) {
if (DataItem::isAxesUnitsPropertyName(name))
m_diff_item->updateCoords(m_current_item->instrumentItem());
},
this);
#else
connect(m_diff_item, &DataItem::axesUnitsChanged, this, [=](const ComboProperty&) { connect(m_diff_item, &DataItem::axesUnitsChanged, this, [=](const ComboProperty&) {
m_diff_item->updateCoords(m_current_item->instrumentItem()); m_diff_item->updateCoords(m_current_item->instrumentItem());
}); });
#endif
} }
void DiffItemController::unsubscribe() void DiffItemController::unsubscribe()
...@@ -193,7 +206,12 @@ void DiffItemController::unsubscribe() ...@@ -193,7 +206,12 @@ void DiffItemController::unsubscribe()
if (!m_current_item) if (!m_current_item)
return; 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_current_item->dataItem(), nullptr, this, nullptr);
disconnect(m_diff_item, nullptr, this, nullptr); disconnect(m_diff_item, nullptr, this, nullptr);
#endif
m_current_item = nullptr; m_current_item = nullptr;
} }
...@@ -164,14 +164,27 @@ void DiffItemController::subscribe() ...@@ -164,14 +164,27 @@ void DiffItemController::subscribe()
} }
// on simulation data change // on simulation data change
#ifdef USE_MAPPERS
m_current_item->dataItem()->mapper()->setOnValueChange([this]() { updateDiffData(); }, this);
#else
connect(m_current_item->dataItem(), &DataItem::datafieldChanged, this, connect(m_current_item->dataItem(), &DataItem::datafieldChanged, this,
[=](Datafield*) { updateDiffData(); }); [=](Datafield*) { updateDiffData(); });
#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
m_current_item->dataItem()->mapper()->unsubscribe(this);
#else
disconnect(m_current_item->dataItem(), nullptr, this, nullptr); disconnect(m_current_item->dataItem(), nullptr, this, nullptr);
#endif
m_current_item = nullptr; m_current_item = nullptr;
} }
...@@ -103,7 +103,12 @@ void FitComparisonWidget::subscribeToItem() ...@@ -103,7 +103,12 @@ void FitComparisonWidget::subscribeToItem()
m_statusLabel->addPlot(m_simulatedDataPlot->colorMap()); m_statusLabel->addPlot(m_simulatedDataPlot->colorMap());
m_statusLabel->addPlot(m_relativeDiffPlot->colorMap()); m_statusLabel->addPlot(m_relativeDiffPlot->colorMap());
m_propertyWidget->setItem({simulatedDataItem()/*, realDataItem(), diffItem()*/}); #ifdef USE_MAPPERS
m_propertyWidget->setItem({simulatedDataItem()});
#else
qInfo() << simulatedDataItem() << realDataItem() << diffItem() << endl;
m_propertyWidget->setItem({simulatedDataItem(), realDataItem(), diffItem()});
#endif
} }
void FitComparisonWidget::unsubscribeFromItem() void FitComparisonWidget::unsubscribeFromItem()
......
...@@ -127,11 +127,16 @@ void Plot1D::subscribeToItem() ...@@ -127,11 +127,16 @@ void Plot1D::subscribeToItem()
this); this);
std::for_each(m_graph_map.begin(), m_graph_map.end(), [caller = this](auto pair) { std::for_each(m_graph_map.begin(), m_graph_map.end(), [caller = this](auto pair) {
#ifdef USE_MAPPERS
auto property_item = pair.first;
property_item->dataItem()->mapper()->setOnValueChange(
[caller]() { caller->refreshPlotData(); }, caller);
#else
DataItem* dataItem = pair.first->dataItem(); DataItem* dataItem = pair.first->dataItem();
connect(dataItem, &DataItem::datafieldChanged, caller, connect(dataItem, &DataItem::datafieldChanged, caller,
[=](Datafield*) { caller->refreshPlotData(); }); [caller](Datafield*) { caller->refreshPlotData(); });
#endif
}); });
setConnected(true); setConnected(true);
} }
...@@ -139,7 +144,11 @@ void Plot1D::unsubscribeFromItem() ...@@ -139,7 +144,11 @@ void Plot1D::unsubscribeFromItem()
{ {
m_custom_plot->clearGraphs(); m_custom_plot->clearGraphs();
std::for_each(m_graph_map.begin(), m_graph_map.end(), [caller = this](auto pair) { std::for_each(m_graph_map.begin(), m_graph_map.end(), [caller = this](auto pair) {
#ifdef USE_MAPPERS
pair.first->dataItem()->mapper()->unsubscribe(caller);
#else
disconnect(pair.first->dataItem(), nullptr, caller, nullptr); disconnect(pair.first->dataItem(), nullptr, caller, nullptr);
#endif
}); });
m_graph_map.clear(); m_graph_map.clear();
setConnected(false); setConnected(false);
......
...@@ -206,21 +206,8 @@ void ColorMap::onTimeToReplot() ...@@ -206,21 +206,8 @@ void ColorMap::onTimeToReplot()
void ColorMap::subscribeToItem() void ColorMap::subscribeToItem()
{ {
// qInfo() << "ColorMap" << intensityItem() << endl;
setColorMapFromItem(intensityItem()); setColorMapFromItem(intensityItem());
#ifdef USE_MAPPERS
// connect(intensityItem(), &IntensityDataItem::axesUnitsReplotRequested, this, [=]() {
// setAxesRangeConnected(false);
// m_customPlot->xAxis->setRange(GUI::View::RangeUtils::itemZoomX(intensityItem()));
// m_customPlot->yAxis->setRange(GUI::View::RangeUtils::itemZoomY(intensityItem()));
// setAxesRangeConnected(true);
// setAxesRangeFromItem(intensityItem());
// setDataFromItem(intensityItem());
// replot();
// });
intensityItem()->mapper()->setOnPropertyChange( intensityItem()->mapper()->setOnPropertyChange(
[this](const QString& name) { onPropertyChanged(name); }, this); [this](const QString& name) { onPropertyChanged(name); }, this);
...@@ -233,7 +220,18 @@ void ColorMap::subscribeToItem() ...@@ -233,7 +220,18 @@ void ColorMap::subscribeToItem()
this); this);
intensityItem()->mapper()->setOnValueChange([this]() { onIntensityModified(); }, this); intensityItem()->mapper()->setOnValueChange([this]() { onIntensityModified(); }, this);
#else
connect(intensityItem(), &IntensityDataItem::replotRequested, this, [=]() {
setAxesRangeConnected(false);
m_customPlot->xAxis->setRange(GUI::View::RangeUtils::itemZoomX(intensityItem()));
m_customPlot->yAxis->setRange(GUI::View::RangeUtils::itemZoomY(intensityItem()));
setAxesRangeConnected(true);
setAxesRangeFromItem(intensityItem());
setDataFromItem(intensityItem());
replot();
});
#endif
setConnected(true); setConnected(true);
} }
......
...@@ -49,7 +49,11 @@ void IntensityDataPropertyWidget::unsubscribe() ...@@ -49,7 +49,11 @@ void IntensityDataPropertyWidget::unsubscribe()
{ {
for(IntensityDataItem* item : m_items_vec) for(IntensityDataItem* item : m_items_vec)
if (item) if (item)
#ifdef USE_MAPPERS
item->mapper()->unsubscribe(this);
#else
disconnect(item, nullptr, this, nullptr); disconnect(item, nullptr, this, nullptr);
#endif
} }
void IntensityDataPropertyWidget::setItem(QVector<IntensityDataItem*> itemsVec) void IntensityDataPropertyWidget::setItem(QVector<IntensityDataItem*> itemsVec)
...@@ -61,14 +65,18 @@ void IntensityDataPropertyWidget::setItem(QVector<IntensityDataItem*> itemsVec) ...@@ -61,14 +65,18 @@ void IntensityDataPropertyWidget::setItem(QVector<IntensityDataItem*> itemsVec)
m_updaters.clear(); m_updaters.clear();
m_items_vec = itemsVec; m_items_vec = itemsVec;
IntensityDataItem*& first_item = itemsVec.first(); IntensityDataItem* first_item = itemsVec.first();
if (!first_item) if (!first_item)
return; return;
for(IntensityDataItem* item : m_items_vec)
if(item)
item->createAxesUnitsDescriptor();
m_mainLayout->addRow("Axes units:", createComboBox(first_item->axesUnits(), m_mainLayout->addRow("Axes units:", createComboBox(first_item->axesUnits(),
[=](int newIndex){ [=](int newIndex){
for(IntensityDataItem* item : m_items_vec) for(IntensityDataItem* item : m_items_vec)
if(item) { if(item) {
qInfo() << "axesUnits" << item << endl;
item->axesUnits().setCurrentIndex(newIndex); item->axesUnits().setCurrentIndex(newIndex);
} }
})); }));
...@@ -131,28 +139,35 @@ void IntensityDataPropertyWidget::setItem(QVector<IntensityDataItem*> itemsVec) ...@@ -131,28 +139,35 @@ void IntensityDataPropertyWidget::setItem(QVector<IntensityDataItem*> itemsVec)
[=](SessionItem*, const QString&) { updateUIValues(); }, this); [=](SessionItem*, const QString&) { updateUIValues(); }, this);
// update coordinates on axes units change // update coordinates on axes units change
// connect(first_item, &IntensityDataItem::axesUnitsChanged, this, [=](const ComboProperty&){ #ifdef USE_MAPPERS
// if(jobItem()) {
// for(IntensityDataItem* item : m_items_vec)
// if(item) {
// item->blockSignals(true);
// item->updateCoords(jobItem()->instrumentItem());
// item->blockSignals(false);
// emit item->axesUnitsReplotRequested();
// }
// qInfo() << ".-.-.-.-.-.-.-.-.-.-.-.-.-.-." << endl;
// }
// });
first_item->mapper()->setOnPropertyChange( first_item->mapper()->setOnPropertyChange(
[this](SessionItem* item, const QString& name) { [this](SessionItem* item, const QString& name) {
if(jobItem()) if(jobItem())
DataItem::updateAxesUnits(item, name, jobItem()->instrumentItem()); DataItem::updateAxesUnits(item, name, jobItem()->instrumentItem());
}, },
this); this);
#else
for(IntensityDataItem* item : m_items_vec)
if(item)
connect(item, &IntensityDataItem::axesUnitsChanged, this, [=](const ComboProperty&){
if(jobItem()) {
item->blockSignals(true);
item->updateCoords(jobItem()->instrumentItem());
item->blockSignals(false);
qInfo() << item << "replotRequested" << endl;
emit item->replotRequested();
}
});
#endif
for(int i=0; i<itemsVec.size(); i++) for(int i=0; i<itemsVec.size(); i++)
connect(itemsVec[i], &IntensityDataItem::destroyed, this, [=](){ m_items_vec[i] = nullptr; }); if(itemsVec[i])
#ifdef USE_MAPPERS
itemsVec[i]->mapper()->setOnItemDestroy([this](SessionItem*) { m_items_vec[i] = nullptr; }, this);
#else
connect(itemsVec[i], &IntensityDataItem::destroyed, this, [=](){ m_items_vec[i] = nullptr; });
#endif
} }
const JobItem* IntensityDataPropertyWidget::jobItem() const const JobItem* IntensityDataPropertyWidget::jobItem() const
......
...@@ -28,6 +28,9 @@ public: ...@@ -28,6 +28,9 @@ public:
QTest::qSleep(nap_time); QTest::qSleep(nap_time);
// changing item (Datafield) // changing item (Datafield)
#ifdef USE_MAPPERS
emitDataChanged();
#else
if (typeid(T) == typeid(SpecularDataItem)) { if (typeid(T) == typeid(SpecularDataItem)) {
std::vector<double> data = {1, 2, 3}; std::vector<double> data = {1, 2, 3};
item->setDatafield(DataUtils::Array::createPField1D(data).release()); item->setDatafield(DataUtils::Array::createPField1D(data).release());
...@@ -38,6 +41,7 @@ public: ...@@ -38,6 +41,7 @@ public:
data.push_back(std::vector<double>({1, 2, 3})); data.push_back(std::vector<double>({1, 2, 3}));
item->setDatafield(DataUtils::Array::createPField2D(data).release()); item->setDatafield(DataUtils::Array::createPField2D(data).release());
} }
#endif
QDateTime time3 = item->lastModified(); QDateTime time3 = item->lastModified();
EXPECT_TRUE(time2.msecsTo(time3) > nap_time / 2); EXPECT_TRUE(time2.msecsTo(time3) > nap_time / 2);
} }
......
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