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

setter with signal

parent acfe07ad
......@@ -106,7 +106,14 @@ void DataItem::setAxesUnits(const ComboProperty& 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)
......
......@@ -165,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
......
......@@ -61,10 +61,6 @@ void IntensityDataWidget::setItem(SessionItem* job_Item)
#ifdef USE_MAPPERS
m_propertyWidget->setItem({intensityDataItem()});
#else
qInfo() << endl
<< "simu" << intensityDataItem() << endl
<< "real" << realIntensityDataItem() << endl
<< "diff" << diffIntensityDataItem() << endl;
m_propertyWidget->setItem({intensityDataItem(),
realIntensityDataItem(),
diffIntensityDataItem()});
......
......@@ -106,10 +106,6 @@ void FitComparisonWidget::subscribeToItem()
#ifdef USE_MAPPERS
m_propertyWidget->setItem({simulatedDataItem()});
#else
qInfo() << endl
<< "simu" << simulatedDataItem() << endl
<< "real" << realDataItem() << endl
<< "diff" << diffItem() << endl;
m_propertyWidget->setItem({simulatedDataItem(), realDataItem(), diffItem()});
#endif
}
......
......@@ -72,18 +72,14 @@ void IntensityDataPropertyWidget::setItem(QVector<IntensityDataItem*> itemsVec)
m_mainLayout->addRow("Axes units:", createComboBox(first_item->axesUnits(),
[=](int newIndex){
for(IntensityDataItem* item : m_items_vec)
if(item) {
if(item)
item->axesUnits().setCurrentIndex(newIndex);
emit item->axesUnitsChanged();
}
}));
m_mainLayout->addRow("Color scheme:", createComboBox(first_item->gradient(),
[=](int newIndex){
for(IntensityDataItem* item : m_items_vec)
if(item) {
if(item)
item->gradient().setCurrentIndex(newIndex);
emit item->gradientChanged();
}
}));
m_mainLayout->addRow(createCheckBox("Interpolate",
......
// ************************************************************************************************
//
// BornAgain: simulate and fit reflection and scattering
//
//! @file GUI/View/PlotUtil/IntensityDataPropertyWidget.cpp
//! @brief Implements class IntensityDataPropertyWidget
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2018
//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
// ************************************************************************************************
#include "GUI/View/PlotUtil/IntensityDataPropertyWidget.h"
#include "GUI/Model/Data/IntensityDataItem.h"
#include "GUI/Model/Device/AxesItems.h"
#include "GUI/Model/Job/JobItem.h"
#include "GUI/Util/ComboProperty.h"
#include "GUI/View/Common/DoubleSpinBox.h"
#include "GUI/View/Common/SessionItemWidget.h"
#include "GUI/View/Tool/LayoutUtils.h"
#include <QAction>
#include <QCheckBox>
#include <QComboBox>
#include <QFormLayout>
#include <QGroupBox>
#include <QLineEdit>
IntensityDataPropertyWidget::IntensityDataPropertyWidget(QWidget* parent)
: QWidget(parent)
, parent(parent)
{
setWindowTitle("Properties");
setAttribute(Qt::WA_StyledBackground, true);
setProperty("stylable", true); // for stylesheet addressing
m_mainLayout = new QFormLayout(this);
m_mainLayout->setContentsMargins(8, 8, 8, 8);
m_mainLayout->setSpacing(5);
}
IntensityDataPropertyWidget::~IntensityDataPropertyWidget()
{
unsubscribe();
}
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)
{
if(itemsVec.size() == 0)
return;
unsubscribe();
GUI::Util::Layout::clearLayout(m_mainLayout);
m_updaters.clear();
m_items_vec = itemsVec;
IntensityDataItem* first_item = itemsVec.first();
if (!first_item)
return;
m_mainLayout->addRow("Axes units:", createComboBox(first_item->axesUnits(),
[=](int newIndex){
for(IntensityDataItem* item : m_items_vec)
if(item)
item->axesUnits().setCurrentIndex(newIndex);
}));
m_mainLayout->addRow("Color scheme:", createComboBox(first_item->gradient(),
[=](int newIndex){
for(IntensityDataItem* item : m_items_vec)
if(item)
item->gradient().setCurrentIndex(newIndex);
}));
m_mainLayout->addRow(createCheckBox("Interpolate",
[=]() { return first_item->isInterpolated(); },
[=](bool b) {
for(IntensityDataItem* item : m_items_vec)
if(item)
item->setInterpolated(b);
}));
// -- x-axis
auto* xGroup = new QGroupBox("X axis", this);
auto* xFormLayout = new QFormLayout(xGroup);
xFormLayout->setContentsMargins(0, 0, 0, 0);
xFormLayout->setSpacing(5);
xFormLayout->addRow("Min:", createDoubleSpinbox(first_item->xAxisItem()->min()));
xFormLayout->addRow("Max:", createDoubleSpinbox(first_item->xAxisItem()->max()));
xFormLayout->addRow("Title:", createTextEdit(first_item->xAxisItem()->titleItem()));
m_mainLayout->addRow(xGroup);
// -- y-axis
auto* yGroup = new QGroupBox("Y axis", this);
auto* yFormLayout = new QFormLayout(yGroup);
yFormLayout->setContentsMargins(0, 0, 0, 0);
yFormLayout->setSpacing(5);
yFormLayout->addRow("Min:", createDoubleSpinbox(first_item->yAxisItem()->min()));
yFormLayout->addRow("Max:", createDoubleSpinbox(first_item->yAxisItem()->max()));
yFormLayout->addRow("Title:", createTextEdit(first_item->yAxisItem()->titleItem()));
m_mainLayout->addRow(yGroup);
// -- color-axis
auto* zGroup = new QGroupBox("Color legend", this);
auto* zFormLayout = new QFormLayout(zGroup);
zFormLayout->setContentsMargins(0, 0, 0, 0);
zFormLayout->setSpacing(5);
zFormLayout->addRow("Min:", createDoubleSpinbox(first_item->zAxisItem()->min()));
zFormLayout->addRow("Max:", createDoubleSpinbox(first_item->zAxisItem()->max()));
zFormLayout->addRow(createCheckBox("log10", first_item->zAxisItem()->logScaleItem()));
zFormLayout->addRow(createCheckBox("Visible", first_item->zAxisItem()->visibilityItem()));
m_mainLayout->addRow(zGroup);
updateUIValues();
// 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
#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, [=](){
if(jobItem()) {
item->blockSignals(true);
item->updateCoords(jobItem()->instrumentItem());
item->blockSignals(false);
emit item->axesUnitsReplotRequested();
}
});
#endif
for(int i=0; i<itemsVec.size(); i++)
if(itemsVec[i])
#ifdef USE_MAPPERS
itemsVec[i]->mapper()->setOnItemDestroy([this, i](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
{
SessionItemWidget* sessionItemWidget = dynamic_cast<SessionItemWidget*>(parent);
if (!sessionItemWidget)
return nullptr;
return dynamic_cast<JobItem*>(sessionItemWidget->currentItem());
}
QWidget* IntensityDataPropertyWidget::createDoubleSpinbox(DoubleDescriptor d)
{
auto* spinBox = new DoubleSpinBox(this, d);
spinBox->setToolTip(d.tooltip);
QObject::connect(spinBox, &DoubleSpinBox::baseValueChanged,
[=](double newValue) { d.set(newValue); });
m_updaters << [=]() { spinBox->updateValue(); };
return spinBox;
}
QWidget* IntensityDataPropertyWidget::createTextEdit(SessionItem* item)
{
auto* edit = new QLineEdit(this);
connect(edit, &QLineEdit::textEdited, [=](const QString& t) { item->setValue(t); });
m_updaters << [=]() { edit->setText(item->value().toString()); };
return edit;
}
QWidget* IntensityDataPropertyWidget::createCheckBox(const QString& title, SessionItem* item)
{
return createCheckBox(
title, [=]() { return item->value().toBool(); }, [=](bool b) { item->setValue(b); });
}
QWidget* IntensityDataPropertyWidget::createCheckBox(const QString& title, function<bool()> getter,
function<void(bool)> setter)
{
auto* checkBox = new QCheckBox(title, this);
connect(checkBox, &QCheckBox::stateChanged, [=]() { setter(checkBox->isChecked()); });
m_updaters << [=]() {
QSignalBlocker b(checkBox);
checkBox->setChecked(getter());
};
return checkBox;
}
QWidget* IntensityDataPropertyWidget::createComboBox(SelectionDescriptor<QString> d,
function<void(int)> slot)
{
auto* combo = new QComboBox(this);
combo->addItems(d.options);
combo->setMaxCount(d.options.size());
connect(combo, qOverload<int>(&QComboBox::currentIndexChanged),[=] (int newIndex) {
if(slot)
slot(newIndex);
});
m_updaters << [=]() {
QSignalBlocker b(combo);
combo->setCurrentIndex(d.currentIndex());
};
return combo;
}
void IntensityDataPropertyWidget::updateUIValues()
{
for (const auto& updater : m_updaters)
updater();
}
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