diff --git a/GUI/Model/Sample/ParticleLayoutItem.cpp b/GUI/Model/Sample/ParticleLayoutItem.cpp index a42046c9c8c0b07889b7b9a98d9918dfa5a69b5d..94e835697f78c99cb22f3262fe85af48e2548b61 100644 --- a/GUI/Model/Sample/ParticleLayoutItem.cpp +++ b/GUI/Model/Sample/ParticleLayoutItem.cpp @@ -41,7 +41,20 @@ DoubleDescriptor ParticleLayoutItem::ownDensity() const return m_ownDensity; } -double ParticleLayoutItem::totalDensity() const +DoubleDescriptor ParticleLayoutItem::totalDensity() const +{ + // create descriptor with same value as own density, then change the getter and setter + DoubleDescriptor d = ownDensity(); + d.set = [=](double d) { + if (!totalDensityIsDefinedByInterference()) + const_cast<DoubleProperty*>(&m_ownDensity)->set(d); + }; + d.get = [=]() { return totalDensityValue(); }; + d.path = [=]() { return m_ownDensity.uid() + "/totalDensity"; }; + return d; +} + +double ParticleLayoutItem::totalDensityValue() const { if (!totalDensityIsDefinedByInterference()) return m_ownDensity; @@ -63,7 +76,6 @@ double ParticleLayoutItem::totalDensity() const if (const auto* hd = dynamic_cast<const InterferenceHardDiskItem*>(m_interference.get())) return hd->density(); - ASSERT(false); } diff --git a/GUI/Model/Sample/ParticleLayoutItem.h b/GUI/Model/Sample/ParticleLayoutItem.h index 3f03e306017ec88c262b36a3fde74848bc2a9432..b107adf047018ea5b8cded021d2c5fe7cadc2f35 100644 --- a/GUI/Model/Sample/ParticleLayoutItem.h +++ b/GUI/Model/Sample/ParticleLayoutItem.h @@ -42,8 +42,8 @@ public: //! //! Returns ownDensity() if the interference is not influencing the density. If the //! interference is defining the density, this is the interference-calculated density. - double totalDensity() const; - + DoubleDescriptor totalDensity() const; + double totalDensityValue() const; DoubleDescriptor weight() const; //! The particles this layout contains. diff --git a/GUI/View/SampleDesigner/ParticleLayoutForm.cpp b/GUI/View/SampleDesigner/ParticleLayoutForm.cpp index 797df9fa6fff0f7fa009fea43f182d28c5ce1c40..7420d22e679a3eb6814c1e32571420f7c7d49a98 100644 --- a/GUI/View/SampleDesigner/ParticleLayoutForm.cpp +++ b/GUI/View/SampleDesigner/ParticleLayoutForm.cpp @@ -34,7 +34,7 @@ ParticleLayoutForm::ParticleLayoutForm(LayerForm* parent, ParticleLayoutItem* la { FormLayouter layouter(this, ec); layouter.setContentsMargins(30, 6, 0, 0); - int rowOfTotalDensity = layouter.addValue(m_layoutItem->ownDensity()); + int rowOfTotalDensity = layouter.addValue(m_layoutItem->totalDensity()); m_totalDensitySpinBox = layouter.widgetAt<DoubleSpinBox*>(rowOfTotalDensity, QFormLayout::FieldRole); ASSERT(m_totalDensitySpinBox); @@ -63,7 +63,6 @@ ParticleLayoutForm::ParticleLayoutForm(LayerForm* parent, ParticleLayoutItem* la m_layout = layouter.layout(); updateDensityEnabling(); - updateDensityValue(); updateTitle(parent->layerItem()); } @@ -105,11 +104,7 @@ void ParticleLayoutForm::updateDensityEnabling() void ParticleLayoutForm::updateDensityValue() { - if (m_layoutItem->totalDensityIsDefinedByInterference()) { - QSignalBlocker b(m_totalDensitySpinBox); - m_totalDensitySpinBox->setBaseValue(m_layoutItem->totalDensity()); - } else - m_totalDensitySpinBox->updateValue(); + m_totalDensitySpinBox->updateValue(); } void ParticleLayoutForm::updateTitle(const LayerItem* layerItem)