Skip to content
Snippets Groups Projects
Commit e580a0ce authored by Matthias Puchner's avatar Matthias Puchner
Browse files

implement density of InterferenceHardDiskItem

parent ae2884bf
Branches
Tags
1 merge request!460Complete editors for interference
...@@ -45,10 +45,10 @@ public: ...@@ -45,10 +45,10 @@ public:
SelectionDescriptor<InterferenceItem*> interference() const; SelectionDescriptor<InterferenceItem*> interference() const;
template <typename T> T* createInterference(); template <typename T> T* createInterference();
void setInterference(InterferenceItem* interference); void setInterference(InterferenceItem* interference);
void updateDensityValue();
private: private:
void updateDensityAppearance(); void updateDensityAppearance();
void updateDensityValue();
}; };
template <typename T> T* ParticleLayoutItem::createInterference() template <typename T> T* ParticleLayoutItem::createInterference()
......
...@@ -97,3 +97,9 @@ Unit DoubleSpinBox::baseUnit() const ...@@ -97,3 +97,9 @@ Unit DoubleSpinBox::baseUnit() const
return std::get<Unit>(m_valueDescriptor.unit); return std::get<Unit>(m_valueDescriptor.unit);
} }
void DoubleSpinBox::updateValue()
{
QSignalBlocker b(this);
setBaseValue(m_valueDescriptor.get());
}
...@@ -45,6 +45,11 @@ public: ...@@ -45,6 +45,11 @@ public:
//! valueDescriptor().unit //! valueDescriptor().unit
Unit baseUnit() const; Unit baseUnit() const;
//! Update the shown value to the one contained in the value descriptor.
//!
//! No signal will be emitted if the new value has changed.
void updateValue();
signals: signals:
//! Emitted whenever the value changes. //! Emitted whenever the value changes.
//! //!
......
...@@ -159,7 +159,20 @@ int FormLayouter::addValue(const DoubleDescriptor& d) ...@@ -159,7 +159,20 @@ int FormLayouter::addValue(const DoubleDescriptor& d)
return m_formLayout->rowCount() - 1; return m_formLayout->rowCount() - 1;
} }
int FormLayouter::addValue(const DoubleDescriptor& d, function<void(double)> onValueChange)
{
insertValue(m_formLayout->rowCount(), d, onValueChange);
return m_formLayout->rowCount() - 1;
}
void FormLayouter::insertValue(int row, const DoubleDescriptor& d) void FormLayouter::insertValue(int row, const DoubleDescriptor& d)
{
auto* ec = m_ec; // to allow copy-capture in the following lambda
insertValue(row, d, [ec, d](double newValue) { ec->setDouble(newValue, d); });
}
void FormLayouter::insertValue(int row, const DoubleDescriptor& d,
function<void(double)> onValueChange)
{ {
auto labelText = d.label; auto labelText = d.label;
if (!labelText.endsWith(":")) if (!labelText.endsWith(":"))
...@@ -170,9 +183,7 @@ void FormLayouter::insertValue(int row, const DoubleDescriptor& d) ...@@ -170,9 +183,7 @@ void FormLayouter::insertValue(int row, const DoubleDescriptor& d)
label->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::MinimumExpanding); label->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::MinimumExpanding);
auto* editor = new DoubleSpinBox(m_formLayout->parentWidget(), d); auto* editor = new DoubleSpinBox(m_formLayout->parentWidget(), d);
auto* ec = m_ec; // to allow copy-capture in the following lambda QObject::connect(editor, &DoubleSpinBox::baseValueChanged, onValueChange);
QObject::connect(editor, &DoubleSpinBox::baseValueChanged,
[ec, d](double newValue) { ec->setDouble(newValue, d); });
label->setBuddy(editor); label->setBuddy(editor);
......
...@@ -93,9 +93,17 @@ public: ...@@ -93,9 +93,17 @@ public:
//! to the SampleEditorController which has been overhanded in the constructor of this //! to the SampleEditorController which has been overhanded in the constructor of this
//! FormLayouter. It is connected to SampleEditorController::setDouble(). If a different method //! FormLayouter. It is connected to SampleEditorController::setDouble(). If a different method
//! should be called (e.g. for a special undo functionality), this method is not sufficient. It //! should be called (e.g. for a special undo functionality), this method is not sufficient. It
//! would have to be done "manually". Returns the newly added row. //! would have to be done "manually" or with the overload which takes a slot (see below).
//! Returns the newly added row.
int addValue(const DoubleDescriptor& d); int addValue(const DoubleDescriptor& d);
//! Adds a row with a bold printed label and a DoubleSpinBox.
//!
//! Same as above, but the called slot in case of a value change has to be overhanded.
//! Use this only if the standard (calling SampleEditorController::setDouble()) is not
//! sufficient.
int addValue(const DoubleDescriptor& d, function<void(double)> onValueChange);
//! Adds a row with a bold printed label and a QSpinBox. //! Adds a row with a bold printed label and a QSpinBox.
//! //!
//! Right now in the sample model there is no uint value which has a unit, therefore no unit //! Right now in the sample model there is no uint value which has a unit, therefore no unit
...@@ -108,6 +116,11 @@ public: ...@@ -108,6 +116,11 @@ public:
//! Same functionality as addValue(), please read there. //! Same functionality as addValue(), please read there.
void insertValue(int row, const DoubleDescriptor& d); void insertValue(int row, const DoubleDescriptor& d);
//! Inserts a row with a bold printed label and a DoubleSpinBox.
//!
//! Same functionality as addValue(), please read there.
void insertValue(int row, const DoubleDescriptor& d, function<void(double)> onValueChange);
//! Adds a row with a bold printed label and a set of DoubleDescriptors. //! Adds a row with a bold printed label and a set of DoubleDescriptors.
//! //!
//! The label describes the set of the Descriptors and is located in the first column of the //! The label describes the set of the Descriptors and is located in the first column of the
......
...@@ -66,6 +66,16 @@ void InterferenceForm::createInterferenceWidgets() ...@@ -66,6 +66,16 @@ void InterferenceForm::createInterferenceWidgets()
{ {
FormLayouter layouter(this, m_ec); FormLayouter layouter(this, m_ec);
auto* interference = m_layoutItem->interference().currentItem(); auto* interference = m_layoutItem->interference().currentItem();
// Some values in interference settings affect the total density in the particle layout. To
// provide all the updating (data & UI), the method
// SampleEditorController::setDensityRelatedValueValue has to be called (instead of
// SampleEditorController::setDouble). For this we have the following lambda to add a value:
const auto addDensityRelatedValue = [&](DoubleDescriptor d) {
layouter.addValue(
d, [=](double newValue) { m_ec->setDensityRelatedValue(interference, newValue, d); });
};
if (auto* itf = dynamic_cast<Interference1DLatticeItem*>(interference)) { if (auto* itf = dynamic_cast<Interference1DLatticeItem*>(interference)) {
layouter.addValue(itf->positionVariance()); layouter.addValue(itf->positionVariance());
layouter.addValue(itf->length()); layouter.addValue(itf->length());
...@@ -81,6 +91,7 @@ void InterferenceForm::createInterferenceWidgets() ...@@ -81,6 +91,7 @@ void InterferenceForm::createInterferenceWidgets()
} else if (auto* itf = dynamic_cast<InterferenceHardDiskItem*>(interference)) { } else if (auto* itf = dynamic_cast<InterferenceHardDiskItem*>(interference)) {
layouter.addValue(itf->positionVariance()); layouter.addValue(itf->positionVariance());
layouter.addValue(itf->radius()); layouter.addValue(itf->radius());
addDensityRelatedValue(itf->density());
} }
// #baLayerEditor implement missing interference function types // #baLayerEditor implement missing interference function types
} }
......
...@@ -109,3 +109,8 @@ void ParticleLayoutForm::updateDensityEnabling() ...@@ -109,3 +109,8 @@ void ParticleLayoutForm::updateDensityEnabling()
m_totalDensitySpinBox->setEnabled(enableTotalDensityInParticleLayout); m_totalDensitySpinBox->setEnabled(enableTotalDensityInParticleLayout);
} }
void ParticleLayoutForm::updateDensityValue()
{
m_totalDensitySpinBox->updateValue();
}
...@@ -45,6 +45,11 @@ public: ...@@ -45,6 +45,11 @@ public:
//! the property shown in the particle layout shall be disabled. //! the property shown in the particle layout shall be disabled.
void updateDensityEnabling(); void updateDensityEnabling();
//! Update the shown density value.
//!
//! This does not update any internal values, it only refreshes the shown value.
void updateDensityValue();
private: private:
QFormLayout* m_layout; QFormLayout* m_layout;
ParticleLayoutItem* m_layoutItem; ParticleLayoutItem* m_layoutItem;
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
// ************************************************************************************************ // ************************************************************************************************
#include "GUI/View/SampleDesigner/SampleEditorController.h" #include "GUI/View/SampleDesigner/SampleEditorController.h"
#include "GUI/Model/Sample/InterferenceItems.h"
#include "GUI/Model/Sample/LayerItem.h" #include "GUI/Model/Sample/LayerItem.h"
#include "GUI/Model/Sample/MesoCrystalItem.h" #include "GUI/Model/Sample/MesoCrystalItem.h"
#include "GUI/Model/Sample/MultiLayerItem.h" #include "GUI/Model/Sample/MultiLayerItem.h"
...@@ -309,6 +310,26 @@ void SampleEditorController::setMaterialValue(ItemWithMaterial* item, double new ...@@ -309,6 +310,26 @@ void SampleEditorController::setMaterialValue(ItemWithMaterial* item, double new
c->updateValues(); c->updateValues();
} }
void SampleEditorController::setDensityRelatedValue(InterferenceItem* interferenceItem,
double newValue, DoubleDescriptor d)
{
setDouble(newValue, d);
// -- notify the containing particle layout about changed value
auto* particlelayoutItem = dynamic_cast<ParticleLayoutItem*>(interferenceItem->parent());
if (!particlelayoutItem)
return;
particlelayoutItem->updateDensityValue();
// -- notify the containing particle layout UI about changed value
ASSERT(m_multiLayerForm);
for (auto* c : m_multiLayerForm->findChildren<ParticleLayoutForm*>())
if (c->layoutItem() == particlelayoutItem) {
c->updateDensityValue();
break;
}
}
void SampleEditorController::onStartingToMoveLayer() void SampleEditorController::onStartingToMoveLayer()
{ {
ASSERT(m_multiLayerForm); ASSERT(m_multiLayerForm);
......
...@@ -33,6 +33,7 @@ class SelectionContainerForm; ...@@ -33,6 +33,7 @@ class SelectionContainerForm;
class AbstractSelectionDescriptor; class AbstractSelectionDescriptor;
class InterferenceForm; class InterferenceForm;
class SessionItem; class SessionItem;
class InterferenceItem;
//! Class to modify a sample from the layer oriented sample editor. //! Class to modify a sample from the layer oriented sample editor.
//! //!
...@@ -82,6 +83,15 @@ public: ...@@ -82,6 +83,15 @@ public:
void selectMaterial(ItemWithMaterial* item, const QString& newMaterialIdentifier); void selectMaterial(ItemWithMaterial* item, const QString& newMaterialIdentifier);
void setMaterialValue(ItemWithMaterial* item, double newValue, DoubleDescriptor d); void setMaterialValue(ItemWithMaterial* item, double newValue, DoubleDescriptor d);
//! Set an interference function's value which affects the total particle density of the
//! containing particle layout.
//!
//! Some values in interference settings affect the total density in the particle layout which
//! contains this interference function. Call this method to provide all the related updating
//! (data & UI).
void setDensityRelatedValue(InterferenceItem* interferenceItem, double newValue,
DoubleDescriptor d);
void onStartingToMoveLayer(); void onStartingToMoveLayer();
void onStoppedToMoveLayer(QWidget* widgetToMove, QWidget* moveAboveThisWidget); void onStoppedToMoveLayer(QWidget* widgetToMove, QWidget* moveAboveThisWidget);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment