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;
//! \endcode
//!
//! 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;
......
......@@ -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
......@@ -105,21 +111,26 @@ SessionItem* DataItem::getAxesUnitsItem() const
return getItem(P_AXES_UNITS);
}
SelectionDescriptor<QString> DataItem::axesUnits() const
void DataItem::createAxesUnitsDescriptor()
{
SessionItem* item = getAxesUnitsItem();
SelectionDescriptor<QString> d = SelectionDescriptor<QString>(item);
d.currentIndexSetter = [=](int index) {
qInfo() << item << "createAxesUnitsDescriptor" << endl;
m_axes_units = SelectionDescriptor<QString>(item);
#ifndef USE_MAPPERS
m_axes_units.currentIndexSetter = [=](int index) {
ComboProperty comboProperty = item->value().value<ComboProperty>();
if (comboProperty.currentIndex() != index) {
comboProperty.setCurrentIndex(index);
qInfo() << "new setter : DataItem" << endl;
qInfo() << "new setter" << endl;
const_cast<DataItem*>(this)->setAxesUnits(comboProperty);
}
};
return d;
#endif
}
SelectionDescriptor<QString> DataItem::axesUnits() const
{
return m_axes_units;
}
bool DataItem::isAxesUnitsPropertyName(const QString& name)
......
......@@ -62,6 +62,7 @@ public:
void setAxesUnits(const ComboProperty& units);
SessionItem* getAxesUnitsItem() const;
void createAxesUnitsDescriptor();
SelectionDescriptor<QString> axesUnits() const;
static bool isAxesUnitsPropertyName(const QString& name);
static void updateAxesUnits(SessionItem* item, const QString& name,
......@@ -81,11 +82,12 @@ signals:
void rawDataVectorChanged(const std::vector<double>& data);
void fileNameChanged(const QString& filename);
void axesUnitsChanged(const ComboProperty& units);
void axesUnitsReplotRequested();
void replotRequested();
protected:
explicit DataItem(const QString& modelType);
SelectionDescriptor<QString> m_axes_units;
std::unique_ptr<Datafield> m_data; //!< simulation results
QDateTime m_last_modified;
std::mutex m_update_data_mutex;
......
......@@ -79,9 +79,9 @@ void IntensityDataItem::setDatafield(Datafield* data)
updateAxesZoomLevel();
updateAxesLabels();
updateDataRange();
// qInfo() << "setDatafield\n------------------------\n" << endl;
#ifdef USE_MAPPERS
emitDataChanged();
#endif
}
int IntensityDataItem::xSize() const
......
......@@ -45,15 +45,11 @@ void GUI::Model::JobItemUtils::updateDataAxes(DataItem* intensityItem,
return;
}
qInfo() << "a" << intensityItem << intensityItem->getDatafield() << endl;
if (!intensityItem->getDatafield())
return;
qInfo() << "b" << endl;
Coords requested_units = GUI::Util::CoordName::coordFromName(intensityItem->selectedCoords());
qInfo() << "selected" << intensityItem->selectedCoords() << endl;
auto* const converter = instrumentItem->createCoordSystem();
auto newData = std::make_unique<Datafield>(converter->convertedAxes(requested_units));
......
......@@ -88,6 +88,7 @@ public:
if (comboProperty.currentIndex() != index) {
comboProperty.setCurrentIndex(index);
item->setValue(QVariant::fromValue<ComboProperty>(comboProperty));
qInfo() << item << "old setter" << endl;
}
};
currentIndexGetter = [=] { return item->value().value<ComboProperty>().currentIndex(); };
......
......@@ -58,13 +58,14 @@ void IntensityDataWidget::setItem(SessionItem* job_Item)
SessionItemWidget::setItem(job_Item);
// now we can access to JobItem
// m_intensityCanvas->setItem(intensityDataItem());
// m_propertyWidget->setItem({intensityDataItem(),
// realIntensityDataItem(),
// diffIntensityDataItem()});
m_intensityCanvas->setItem(intensityDataItem());
#ifdef USE_MAPPERS
m_propertyWidget->setItem({intensityDataItem()});
#else
m_propertyWidget->setItem({intensityDataItem(),
realIntensityDataItem(),
diffIntensityDataItem()});
#endif
m_fftPresenter->reset();
}
......@@ -75,7 +76,7 @@ JobItem* IntensityDataWidget::jobItem()
IntensityDataItem* IntensityDataWidget::realIntensityDataItem()
{
if(jobItem())
if(jobItem() && jobItem()->realDataItem())
return jobItem()->realDataItem()->intensityDataItem();
else
return nullptr;
......
......@@ -179,13 +179,26 @@ void DiffItemController::subscribe()
}
// 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,
[=](Datafield*) { updateDiffData(); });
#endif
// 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&) {
m_diff_item->updateCoords(m_current_item->instrumentItem());
});
#endif
}
void DiffItemController::unsubscribe()
......@@ -193,7 +206,12 @@ void DiffItemController::unsubscribe()
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;
}
......@@ -164,14 +164,27 @@ void DiffItemController::subscribe()
}
// 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,
[=](Datafield*) { updateDiffData(); });
#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);
#else
disconnect(m_current_item->dataItem(), nullptr, this, nullptr);
#endif
m_current_item = nullptr;
}
......@@ -103,7 +103,12 @@ void FitComparisonWidget::subscribeToItem()
m_statusLabel->addPlot(m_simulatedDataPlot->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()
......
......@@ -127,11 +127,16 @@ void Plot1D::subscribeToItem()
this);
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();
connect(dataItem, &DataItem::datafieldChanged, caller,
[=](Datafield*) { caller->refreshPlotData(); });
[caller](Datafield*) { caller->refreshPlotData(); });
#endif
});
setConnected(true);
}
......@@ -139,7 +144,11 @@ void Plot1D::unsubscribeFromItem()
{
m_custom_plot->clearGraphs();
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);
#endif
});
m_graph_map.clear();
setConnected(false);
......
......@@ -206,21 +206,8 @@ void ColorMap::onTimeToReplot()
void ColorMap::subscribeToItem()
{
// qInfo() << "ColorMap" << intensityItem() << endl;
setColorMapFromItem(intensityItem());
// 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();
// });
#ifdef USE_MAPPERS
intensityItem()->mapper()->setOnPropertyChange(
[this](const QString& name) { onPropertyChanged(name); }, this);
......@@ -233,7 +220,18 @@ void ColorMap::subscribeToItem()
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);
}
......
......@@ -49,7 +49,11 @@ void IntensityDataPropertyWidget::unsubscribe()
{
for(IntensityDataItem* item : m_items_vec)
if (item)
#ifdef USE_MAPPERS
item->mapper()->unsubscribe(this);
#else
disconnect(item, nullptr, this, nullptr);
#endif
}
void IntensityDataPropertyWidget::setItem(QVector<IntensityDataItem*> itemsVec)
......@@ -61,14 +65,18 @@ void IntensityDataPropertyWidget::setItem(QVector<IntensityDataItem*> itemsVec)
m_updaters.clear();
m_items_vec = itemsVec;
IntensityDataItem*& first_item = itemsVec.first();
IntensityDataItem* first_item = itemsVec.first();
if (!first_item)
return;
for(IntensityDataItem* item : m_items_vec)
if(item)
item->createAxesUnitsDescriptor();
m_mainLayout->addRow("Axes units:", createComboBox(first_item->axesUnits(),
[=](int newIndex){
for(IntensityDataItem* item : m_items_vec)
if(item) {
qInfo() << "axesUnits" << item << endl;
item->axesUnits().setCurrentIndex(newIndex);
}
}));
......@@ -131,28 +139,35 @@ void IntensityDataPropertyWidget::setItem(QVector<IntensityDataItem*> itemsVec)
[=](SessionItem*, const QString&) { updateUIValues(); }, this);
// update coordinates on axes units change
// connect(first_item, &IntensityDataItem::axesUnitsChanged, this, [=](const ComboProperty&){
// 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;
// }
// });
#ifdef USE_MAPPERS
first_item->mapper()->setOnPropertyChange(
[this](SessionItem* item, const QString& name) {
if(jobItem())
DataItem::updateAxesUnits(item, name, jobItem()->instrumentItem());
},
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++)
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
......
......@@ -28,6 +28,9 @@ public:
QTest::qSleep(nap_time);
// changing item (Datafield)
#ifdef USE_MAPPERS
emitDataChanged();
#else
if (typeid(T) == typeid(SpecularDataItem)) {
std::vector<double> data = {1, 2, 3};
item->setDatafield(DataUtils::Array::createPField1D(data).release());
......@@ -38,6 +41,7 @@ public:
data.push_back(std::vector<double>({1, 2, 3}));
item->setDatafield(DataUtils::Array::createPField2D(data).release());
}
#endif
QDateTime time3 = item->lastModified();
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