Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mlz
BornAgain
Commits
e7afdc40
Commit
e7afdc40
authored
Jun 10, 2022
by
Mikhail Svechnikov
Committed by
Mikhail Svechnikov
Jun 13, 2022
Browse files
double property signal started
parent
ce755230
Changes
6
Hide whitespace changes
Inline
Side-by-side
GUI/Model/Device/AxesItems.cpp
View file @
e7afdc40
...
...
@@ -42,6 +42,11 @@ DoubleDescriptor BasicAxisItem::min(const QString& unit) const
{
DoubleDescriptor
d
(
getItem
(
P_MIN_DEG
),
unit
);
d
.
label
=
"Min"
;
// temp setter with signal
d
.
set
=
[
=
](
double
v
)
{
d
.
set
(
v
);
emit
const_cast
<
BasicAxisItem
*>
(
this
)
->
axisRangeChanged
();
};
return
d
;
}
...
...
GUI/Model/Device/AxesItems.h
View file @
e7afdc40
...
...
@@ -22,7 +22,8 @@
class
IAxis
;
class
Streamer
;
class
BasicAxisItem
:
public
SessionItem
{
class
BasicAxisItem
:
public
QObject
,
public
SessionItem
{
Q_OBJECT
private:
static
constexpr
auto
P_IS_VISIBLE
{
"Visibility"
};
static
constexpr
auto
P_NBINS
{
"Nbins"
};
...
...
@@ -68,6 +69,9 @@ public:
void
setVisibilityValue
(
bool
b
);
static
bool
isVisibilityPropertyName
(
const
QString
&
name
);
signals:
void
axisRangeChanged
();
protected:
explicit
BasicAxisItem
(
const
QString
&
type
);
};
...
...
GUI/View/PlotUtil/ColorMap.cpp
View file @
e7afdc40
...
...
@@ -221,20 +221,31 @@ void ColorMap::subscribeToItem()
intensityItem
()
->
mapper
()
->
setOnValueChange
([
this
]()
{
onIntensityModified
();
},
this
);
#else
// axes units
connect
(
intensityItem
(),
&
IntensityDataItem
::
axesUnitsReplotRequested
,
this
,
[
=
]()
{
setAxesRangeFromItem
(
intensityItem
());
setAxesZoomFromItem
(
intensityItem
());
setAxesLabelsFromItem
(
intensityItem
());
replot
();
});
// color scheme
connect
(
intensityItem
(),
&
IntensityDataItem
::
gradientChanged
,
this
,
[
=
]()
{
m_colorMap
->
setGradient
(
GUI
::
View
::
RangeUtils
::
itemGradient
(
intensityItem
()));
replot
();
});
// interpolation
connect
(
intensityItem
(),
&
IntensityDataItem
::
interpolationChanged
,
this
,
[
=
]()
{
m_colorMap
->
setInterpolate
(
intensityItem
()
->
isInterpolated
());
replot
();
});
// axes
connect
(
intensityItem
()
->
xAxisItem
(),
&
BasicAxisItem
::
axisRangeChanged
,
this
,
[
=
]()
{
setAxesRangeConnected
(
false
);
m_customPlot
->
xAxis
->
setRange
(
GUI
::
View
::
RangeUtils
::
itemZoomX
(
intensityItem
()));
setAxesRangeConnected
(
true
);
replot
();
});
#endif
setConnected
(
true
);
}
...
...
GUI/View/PlotUtil/IntensityDataPropertyWidget.cpp
View file @
e7afdc40
...
...
@@ -27,6 +27,10 @@
#include
<QGroupBox>
#include
<QLineEdit>
#define FOR_EACH_ITEM \
for(IntensityDataItem* item : m_items_vec) \
if(item)
IntensityDataPropertyWidget
::
IntensityDataPropertyWidget
(
QWidget
*
parent
)
:
QWidget
(
parent
)
,
parent
(
parent
)
...
...
@@ -56,6 +60,7 @@ void IntensityDataPropertyWidget::unsubscribe()
#endif
}
void
IntensityDataPropertyWidget
::
setItem
(
QVector
<
IntensityDataItem
*>
itemsVec
)
{
if
(
itemsVec
.
size
()
==
0
)
...
...
@@ -96,9 +101,14 @@ void IntensityDataPropertyWidget::setItem(QVector<IntensityDataItem*> itemsVec)
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
()));
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()));
m_mainLayout
->
addRow
(
xGroup
);
...
...
@@ -108,8 +118,8 @@ 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("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
);
...
...
@@ -120,8 +130,8 @@ 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("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
()));
...
...
@@ -143,7 +153,7 @@ void IntensityDataPropertyWidget::setItem(QVector<IntensityDataItem*> itemsVec)
this
);
#else
for
(
IntensityDataItem
*
item
:
m_items_vec
)
if
(
item
)
{
if
(
item
)
connect
(
item
,
&
IntensityDataItem
::
axesUnitsChanged
,
this
,
[
=
](){
if
(
jobItem
())
{
item
->
blockSignals
(
true
);
...
...
@@ -152,7 +162,6 @@ void IntensityDataPropertyWidget::setItem(QVector<IntensityDataItem*> itemsVec)
emit
item
->
axesUnitsReplotRequested
();
}
});
}
#endif
for
(
int
i
=
0
;
i
<
itemsVec
.
size
();
i
++
)
...
...
@@ -173,12 +182,14 @@ const JobItem* IntensityDataPropertyWidget::jobItem() const
return
dynamic_cast
<
JobItem
*>
(
sessionItemWidget
->
currentItem
());
}
QWidget
*
IntensityDataPropertyWidget
::
createDoubleSpinbox
(
DoubleDescriptor
d
)
QWidget
*
IntensityDataPropertyWidget
::
createDoubleSpinbox
(
DoubleDescriptor
d
,
function
<
void
(
double
)
>
slot
)
{
auto
*
spinBox
=
new
DoubleSpinBox
(
this
,
d
);
spinBox
->
setToolTip
(
d
.
tooltip
);
QObject
::
connect
(
spinBox
,
&
DoubleSpinBox
::
baseValueChanged
,
[
=
](
double
newValue
)
{
d
.
set
(
newValue
);
});
QObject
::
connect
(
spinBox
,
&
DoubleSpinBox
::
baseValueChanged
,
[
=
](
double
newValue
)
{
if
(
slot
)
slot
(
newValue
);
});
m_updaters
<<
[
=
]()
{
spinBox
->
updateValue
();
};
...
...
GUI/View/PlotUtil/IntensityDataPropertyWidget.cpp.autosave
deleted
100644 → 0
View file @
ce755230
// ************************************************************************************************
//
// 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();
}
GUI/View/PlotUtil/IntensityDataPropertyWidget.h
View file @
e7afdc40
...
...
@@ -40,7 +40,7 @@ public:
const
JobItem
*
jobItem
()
const
;
private:
QWidget
*
createDoubleSpinbox
(
DoubleDescriptor
d
);
QWidget
*
createDoubleSpinbox
(
DoubleDescriptor
d
,
function
<
void
(
double
)
>
slot
);
QWidget
*
createTextEdit
(
SessionItem
*
item
);
QWidget
*
createCheckBox
(
const
QString
&
title
,
SessionItem
*
item
);
QWidget
*
createCheckBox
(
const
QString
&
title
,
function
<
bool
()
>
getter
,
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment