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

changing signaling in IntensityDataPropertyWidget almost done

parent e7afdc40
......@@ -203,19 +203,16 @@ bool IntensityDataItem::isZAxisLocked() const
void IntensityDataItem::setZAxisLocked(bool state)
{
item<AmplitudeAxisItem>(P_ZAXIS)->setLocked(state);
emit zAxisLockChanged(state);
}
void IntensityDataItem::setXaxisTitle(const QString& title)
{
xAxisItem()->setTitle(title);
emit xAxisTitleChanged(title);
}
void IntensityDataItem::setYaxisTitle(const QString& title)
{
yAxisItem()->setTitle(title);
emit yAxisTitleChanged(title);
}
//! set zoom range of x,y axes to axes of input data
......@@ -284,25 +281,21 @@ bool IntensityDataItem::isZaxisPropertyName(const QString& name)
void IntensityDataItem::setLowerX(double value)
{
xAxisItem()->setLowerBound(value);
emit xAxisLowerChanged(value);
}
void IntensityDataItem::setUpperX(double value)
{
xAxisItem()->setUpperBound(value);
emit xAxisUpperChanged(value);
}
void IntensityDataItem::setLowerY(double value)
{
yAxisItem()->setLowerBound(value);
emit yAxisLowerChanged(value);
}
void IntensityDataItem::setUpperY(double value)
{
yAxisItem()->setUpperBound(value);
emit yAxisUpperChanged(value);
}
void IntensityDataItem::setLowerAndUpperZ(double zmin, double zmax)
......@@ -317,19 +310,17 @@ void IntensityDataItem::setLowerAndUpperZ(double zmin, double zmax)
void IntensityDataItem::setLowerZ(double zmin)
{
zAxisItem()->setLowerBound(zmin);
emit zAxisLowerChanged(zmin);
}
void IntensityDataItem::setUpperZ(double zmax)
{
zAxisItem()->setUpperBound(zmax);
emit zAxisUpperChanged(zmax);
}
void IntensityDataItem::setLogz(bool logz)
{
zAxisItem()->setLogScale(logz);
emit zLogChanged(logz);
emit zLogChanged();
}
void IntensityDataItem::setInterpolated(bool interp)
......
......@@ -123,17 +123,8 @@ public:
signals:
void gradientChanged();
void zAxisLockChanged(bool isLocked);
void xAxisTitleChanged(const QString& title);
void yAxisTitleChanged(const QString& title);
void xAxisLowerChanged(double value);
void xAxisUpperChanged(double value);
void yAxisLowerChanged(double value);
void yAxisUpperChanged(double value);
void zAxisLowerChanged(double value);
void zAxisUpperChanged(double value);
void zLogChanged(bool isLog);
void zAxisLockChanged();
void zLogChanged();
void interpolationChanged();
public slots:
......
......@@ -64,6 +64,11 @@ DoubleDescriptor BasicAxisItem::max(const QString& unit) const
{
DoubleDescriptor d(getItem(P_MAX_DEG), unit);
d.label = "Max";
// temp setter with signal
d.set = [=](double v) {
d.set(v);
emit const_cast<BasicAxisItem*>(this)->axisRangeChanged();
};
return d;
}
......@@ -90,6 +95,7 @@ QString BasicAxisItem::title() const
void BasicAxisItem::setTitle(const QString& title)
{
setItemValue(P_TITLE, title);
emit axisTitleChanged();
}
SessionItem* BasicAxisItem::titleItem() const
......@@ -123,7 +129,7 @@ SessionItem* BasicAxisItem::visibilityItem() const
return getItem(P_IS_VISIBLE);
}
bool BasicAxisItem::visibilityValue() const
bool BasicAxisItem::isVisible() const
{
return visibilityItem()->value().toBool();
}
......@@ -131,6 +137,7 @@ bool BasicAxisItem::visibilityValue() const
void BasicAxisItem::setVisibilityValue(bool b)
{
setItemValue(P_IS_VISIBLE, b);
emit axisVisibilityChanged();
}
bool BasicAxisItem::isVisibilityPropertyName(const QString& name)
......@@ -188,6 +195,7 @@ bool AmplitudeAxisItem::isLogScale() const
void AmplitudeAxisItem::setLogScale(bool value)
{
setItemValue(P_IS_LOGSCALE, value);
emit logScaleChanged();
}
SessionItem* AmplitudeAxisItem::logScaleItem() const
......
......@@ -65,18 +65,21 @@ public:
virtual std::unique_ptr<IAxis> createAxis(double scale) const;
SessionItem* visibilityItem() const;
bool visibilityValue() const;
bool isVisible() const;
void setVisibilityValue(bool b);
static bool isVisibilityPropertyName(const QString& name);
signals:
void axisRangeChanged();
void axisTitleChanged();
void axisVisibilityChanged();
protected:
explicit BasicAxisItem(const QString& type);
};
class AmplitudeAxisItem : public BasicAxisItem {
Q_OBJECT
private:
static constexpr auto P_IS_LOGSCALE{"log10"};
static constexpr auto P_LOCK_MIN_MAX{"Lock (min, max)"};
......@@ -94,6 +97,10 @@ public:
bool isLocked() const;
void setLocked(bool locked);
signals:
void logScaleChanged();
};
#endif // BORNAGAIN_GUI_MODEL_DEVICE_AXESITEMS_H
......@@ -158,7 +158,7 @@ void ColorMap::onAxisPropertyChanged(const QString& axisName, const QString& pro
setLogz(intensityItem()->isLogz());
replot();
} else if (BasicAxisItem::isVisibilityPropertyName(propertyName)) {
setColorScaleVisible(intensityItem()->zAxisItem()->visibilityValue());
setColorScaleVisible(intensityItem()->zAxisItem()->isVisible());
replot();
}
}
......@@ -221,7 +221,7 @@ void ColorMap::subscribeToItem()
intensityItem()->mapper()->setOnValueChange([this]() { onIntensityModified(); }, this);
#else
// axes units
// units
connect(intensityItem(), &IntensityDataItem::axesUnitsReplotRequested, this, [=]() {
setAxesRangeFromItem(intensityItem());
setAxesZoomFromItem(intensityItem());
......@@ -239,13 +239,44 @@ void ColorMap::subscribeToItem()
replot();
});
// axes
// x axis
connect(intensityItem()->xAxisItem(), &BasicAxisItem::axisRangeChanged, this, [=]() {
setAxesRangeConnected(false);
m_customPlot->xAxis->setRange(GUI::View::RangeUtils::itemZoomX(intensityItem()));
setAxesRangeConnected(true);
replot();
});
connect(intensityItem()->xAxisItem(), &BasicAxisItem::axisTitleChanged, this, [=]() {
setAxesLabelsFromItem(intensityItem());
replot();
});
// y axis
connect(intensityItem()->yAxisItem(), &BasicAxisItem::axisRangeChanged, this, [=]() {
setAxesRangeConnected(false);
m_customPlot->yAxis->setRange(GUI::View::RangeUtils::itemZoomY(intensityItem()));
setAxesRangeConnected(true);
replot();
});
connect(intensityItem()->yAxisItem(), &BasicAxisItem::axisTitleChanged, this, [=]() {
setAxesLabelsFromItem(intensityItem());
replot();
});
// z axis
connect(intensityItem()->zAxisItem(), &BasicAxisItem::axisRangeChanged, this, [=]() {
setDataRangeFromItem(intensityItem());
replot();
});
connect(intensityItem()->zAxisItem(), &AmplitudeAxisItem::logScaleChanged, this, [=]() {
setLogz(intensityItem()->isLogz());
replot();
});
connect(intensityItem()->zAxisItem(), &BasicAxisItem::axisVisibilityChanged, this, [=]() {
setColorScaleVisible(intensityItem()->zAxisItem()->isVisible());
replot();
});
#endif
setConnected(true);
}
......@@ -418,7 +449,7 @@ void ColorMap::setDataFromItem(IntensityDataItem* item)
void ColorMap::setColorScaleAppearanceFromItem(IntensityDataItem* item)
{
setColorScaleVisible(item->zAxisItem()->visibilityValue());
setColorScaleVisible(item->zAxisItem()->isVisible());
m_colorMap->setGradient(GUI::View::RangeUtils::itemGradient(intensityItem()));
m_colorMap->setInterpolate(intensityItem()->isInterpolated());
// make sure the axis rect and color scale synchronize their bottom and top margins (so they
......
......@@ -27,8 +27,8 @@
#include <QGroupBox>
#include <QLineEdit>
#define FOR_EACH_ITEM \
for(IntensityDataItem* item : m_items_vec) \
#define FOR_EACH_ITEM \
for(IntensityDataItem* item : m_items_vec) \
if(item)
IntensityDataPropertyWidget::IntensityDataPropertyWidget(QWidget* parent)
......@@ -51,12 +51,10 @@ IntensityDataPropertyWidget::~IntensityDataPropertyWidget()
void IntensityDataPropertyWidget::unsubscribe()
{
for(IntensityDataItem* item : m_items_vec)
if (item)
#ifdef USE_MAPPERS
item->mapper()->unsubscribe(this);
FOR_EACH_ITEM item->mapper()->unsubscribe(this);
#else
disconnect(item, nullptr, this, nullptr);
FOR_EACH_ITEM disconnect(item, nullptr, this, nullptr);
#endif
}
......@@ -75,25 +73,14 @@ void IntensityDataPropertyWidget::setItem(QVector<IntensityDataItem*> itemsVec)
return;
m_mainLayout->addRow("Axes units:", createComboBox(first_item->axesUnits(),
[=](int newIndex){
for(IntensityDataItem* item : m_items_vec)
if(item)
item->axesUnits().setCurrentIndex(newIndex);
}));
[=](int newIndex) { FOR_EACH_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);
}));
[=](int newIndex) { FOR_EACH_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);
}));
[=](bool b) { FOR_EACH_ITEM item->setInterpolated(b); }));
// -- x-axis
auto* xGroup = new QGroupBox("X axis", this);
......@@ -102,13 +89,13 @@ void IntensityDataPropertyWidget::setItem(QVector<IntensityDataItem*> itemsVec)
xFormLayout->setSpacing(5);
xFormLayout->addRow("Min:", createDoubleSpinbox(first_item->xAxisItem()->min(),
[=](double newValue){
for(IntensityDataItem* item : m_items_vec)
if(item)
item->xAxisItem()->min().set(newValue);
}));
// xFormLayout->addRow("Max:", createDoubleSpinbox(first_item->xAxisItem()->max()));
// xFormLayout->addRow("Title:", createTextEdit(first_item->xAxisItem()->titleItem()));
[=](double newValue) { FOR_EACH_ITEM item->xAxisItem()->min().set(newValue); }));
xFormLayout->addRow("Max:", createDoubleSpinbox(first_item->xAxisItem()->max(),
[=](double newValue) { FOR_EACH_ITEM item->xAxisItem()->max().set(newValue); }));
xFormLayout->addRow("Title:", createTextEdit(first_item->xAxisItem()->titleItem(),
[=](QString newText) { FOR_EACH_ITEM item->xAxisItem()->setTitle(newText); }));
m_mainLayout->addRow(xGroup);
......@@ -118,9 +105,14 @@ void IntensityDataPropertyWidget::setItem(QVector<IntensityDataItem*> itemsVec)
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()));
yFormLayout->addRow("Min:", createDoubleSpinbox(first_item->yAxisItem()->min(),
[=](double newValue) { FOR_EACH_ITEM item->yAxisItem()->min().set(newValue); }));
yFormLayout->addRow("Max:", createDoubleSpinbox(first_item->yAxisItem()->max(),
[=](double newValue) { FOR_EACH_ITEM item->yAxisItem()->max().set(newValue); }));
yFormLayout->addRow("Title:", createTextEdit(first_item->yAxisItem()->titleItem(),
[=](QString newText) { FOR_EACH_ITEM item->yAxisItem()->setTitle(newText); }));
m_mainLayout->addRow(yGroup);
......@@ -130,10 +122,19 @@ void IntensityDataPropertyWidget::setItem(QVector<IntensityDataItem*> itemsVec)
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()));
zFormLayout->addRow("Min:", createDoubleSpinbox(first_item->zAxisItem()->min(),
[=](double newValue) { FOR_EACH_ITEM item->zAxisItem()->min().set(newValue); }));
zFormLayout->addRow("Max:", createDoubleSpinbox(first_item->zAxisItem()->max(),
[=](double newValue) { FOR_EACH_ITEM item->zAxisItem()->max().set(newValue); }));
zFormLayout->addRow(createCheckBox("log10",
[=]() { return first_item->zAxisItem()->isLogScale(); },
[=](bool b) { FOR_EACH_ITEM item->zAxisItem()->setLogScale(b); }));
zFormLayout->addRow(createCheckBox("Visible",
[=]() { return first_item->zAxisItem()->isVisible(); },
[=](bool b) { FOR_EACH_ITEM item->zAxisItem()->setVisibilityValue(b); }));
m_mainLayout->addRow(zGroup);
......@@ -151,9 +152,13 @@ void IntensityDataPropertyWidget::setItem(QVector<IntensityDataItem*> itemsVec)
DataItem::updateAxesUnits(item, name, jobItem()->instrumentItem());
},
this);
FOR_EACH_ITEM
itemsVec[i]->mapper()->setOnItemDestroy(
[this, i](SessionItem*) { m_items_vec[i] = nullptr; }, this);
#else
for(IntensityDataItem* item : m_items_vec)
if(item)
FOR_EACH_ITEM
connect(item, &IntensityDataItem::axesUnitsChanged, this, [=](){
if(jobItem()) {
item->blockSignals(true);
......@@ -163,14 +168,6 @@ void IntensityDataPropertyWidget::setItem(QVector<IntensityDataItem*> itemsVec)
}
});
#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
......@@ -182,7 +179,8 @@ const JobItem* IntensityDataPropertyWidget::jobItem() const
return dynamic_cast<JobItem*>(sessionItemWidget->currentItem());
}
QWidget* IntensityDataPropertyWidget::createDoubleSpinbox(DoubleDescriptor d, function<void(double)> slot)
QWidget* IntensityDataPropertyWidget::createDoubleSpinbox(DoubleDescriptor d,
function<void(double)> slot)
{
auto* spinBox = new DoubleSpinBox(this, d);
spinBox->setToolTip(d.tooltip);
......@@ -196,22 +194,20 @@ QWidget* IntensityDataPropertyWidget::createDoubleSpinbox(DoubleDescriptor d, fu
return spinBox;
}
QWidget* IntensityDataPropertyWidget::createTextEdit(SessionItem* item)
QWidget* IntensityDataPropertyWidget::createTextEdit(SessionItem* item,
function<void(QString)> slot)
{
auto* edit = new QLineEdit(this);
connect(edit, &QLineEdit::textEdited, [=](const QString& t) { item->setValue(t); });
connect(edit, &QLineEdit::textEdited, [=](const QString& newText) {
if(slot)
slot(newText);
});
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)
{
......
......@@ -41,8 +41,7 @@ public:
private:
QWidget* createDoubleSpinbox(DoubleDescriptor d, function<void(double)> slot);
QWidget* createTextEdit(SessionItem* item);
QWidget* createCheckBox(const QString& title, SessionItem* item);
QWidget* createTextEdit(SessionItem* item, function<void(QString)> slot);
QWidget* createCheckBox(const QString& title, function<bool()> getter,
function<void(bool)> setter);
QWidget* createComboBox(SelectionDescriptor<QString> d,
......
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