diff --git a/GUI/Views/SampleDesigner/LayerOrientedSampleEditor.cpp b/GUI/Views/SampleDesigner/LayerOrientedSampleEditor.cpp index 1454570365f9b55c96756330c549dc1f25c28d12..2579c15c18aa87dcc3b5f3815552c9479a57b8d6 100644 --- a/GUI/Views/SampleDesigner/LayerOrientedSampleEditor.cpp +++ b/GUI/Views/SampleDesigner/LayerOrientedSampleEditor.cpp @@ -127,7 +127,7 @@ void LayerOrientedSampleEditor::setCurrentSample(MultiLayerItem* multiLayerItem) m_currentMultiLayerWidget->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); m_scrollArea->setWidget(m_currentMultiLayerWidget); m_currentMultiLayerWidget->showInlineEditButtons(m_showInlineEditButtonsAction->isChecked()); - m_currentMultiLayerWidget->useAngstrom(m_asAngstromAction->isChecked()); + m_currentMultiLayerWidget->setUseAngstrom(m_asAngstromAction->isChecked()); updateActionEnabling(); } @@ -146,7 +146,7 @@ void LayerOrientedSampleEditor::onShowInlineEditButtonsToggled(bool checked) void LayerOrientedSampleEditor::onUnitActionToggled() { if (m_currentMultiLayerWidget) - m_currentMultiLayerWidget->useAngstrom(m_asAngstromAction->isChecked()); + m_currentMultiLayerWidget->setUseAngstrom(m_asAngstromAction->isChecked()); } void LayerOrientedSampleEditor::createLayerColors() // #baLayerEditor move to better place diff --git a/GUI/Views/SampleDesigner/MultiLayerForm.cpp b/GUI/Views/SampleDesigner/MultiLayerForm.cpp index 06bc3d7b03432e802c1d53bc29e8c9b43e8edd2b..6fa7bc1186eca844c2b71eacd2a99afa0dfc3a1e 100644 --- a/GUI/Views/SampleDesigner/MultiLayerForm.cpp +++ b/GUI/Views/SampleDesigner/MultiLayerForm.cpp @@ -55,7 +55,11 @@ public: MultiLayerForm::MultiLayerForm(QWidget* parent, MultiLayerItem* multiLayerItem, SampleEditorController* ec) - : QWidget(parent), m_multiLayerItem(multiLayerItem), m_ec(ec) + : QWidget(parent) + , m_multiLayerItem(multiLayerItem) + , m_ec(ec) + , m_useAngstrom(false) + , m_useRadiant(false) { setObjectName("MultiLayerForm"); // important for style sheet addressing setAttribute(Qt::WA_StyledBackground, true); @@ -187,12 +191,8 @@ void MultiLayerForm::updateRowVisibilities() c->updateLayerPositionDependentElements(); } -void MultiLayerForm::ensureVisible(QWidget* /*w*/) -{ - // #baLayerEditor implement ensureVisible -} -void MultiLayerForm::useAngstrom(bool angstrom) +void MultiLayerForm::updateUnits() { const auto set = [](DoubleSpinBox* spinbox, Unit valueUnit, Unit displayUnit) { if (spinbox->baseUnit() == valueUnit) @@ -200,7 +200,7 @@ void MultiLayerForm::useAngstrom(bool angstrom) }; for (auto* editor : findChildren<DoubleSpinBox*>()) { - if (angstrom) { + if (m_useAngstrom) { set(editor, Unit::nanometer, Unit::angstrom); set(editor, Unit::angstrom, Unit::angstrom); set(editor, Unit::nanometerPower2, Unit::angstromPower2); @@ -215,20 +215,8 @@ void MultiLayerForm::useAngstrom(bool angstrom) set(editor, Unit::nanometerPowerMinus2, Unit::nanometerPowerMinus2); set(editor, Unit::angstromPowerMinus2, Unit::nanometerPowerMinus2); } - } - for (auto* label : findChildren<QLabel*>()) - LayerEditorUtils::updateLabelUnit(label); -} -void MultiLayerForm::useRadiant(bool radiant) -{ - const auto set = [](DoubleSpinBox* spinbox, Unit valueUnit, Unit displayUnit) { - if (spinbox->baseUnit() == valueUnit) - spinbox->setDisplayUnit(displayUnit); - }; - - for (auto* editor : findChildren<DoubleSpinBox*>()) { - if (radiant) { + if (m_useRadiant) { set(editor, Unit::degree, Unit::radiant); set(editor, Unit::radiant, Unit::radiant); } else { @@ -236,6 +224,35 @@ void MultiLayerForm::useRadiant(bool radiant) set(editor, Unit::radiant, Unit::degree); } } + for (auto* label : findChildren<QLabel*>()) + LayerEditorUtils::updateLabelUnit(label); +} + +void MultiLayerForm::ensureVisible(QWidget* /*w*/) +{ + // #baLayerEditor implement ensureVisible +} + +void MultiLayerForm::setUseAngstrom(bool angstrom) +{ + m_useAngstrom = angstrom; + updateUnits(); +} + +bool MultiLayerForm::useAngstrom() const +{ + return m_useAngstrom; +} + +void MultiLayerForm::setUseRadiant(bool radiant) +{ + m_useRadiant = radiant; + updateUnits(); +} + +bool MultiLayerForm::useRadiant() const +{ + return m_useRadiant; } void MultiLayerForm::showAddLayerButtons(bool show) diff --git a/GUI/Views/SampleDesigner/MultiLayerForm.h b/GUI/Views/SampleDesigner/MultiLayerForm.h index a680af25e21a1815427798737d234cd4d61daaa8..da122e8af2c5003018126f514bf8a640cde3d40d 100644 --- a/GUI/Views/SampleDesigner/MultiLayerForm.h +++ b/GUI/Views/SampleDesigner/MultiLayerForm.h @@ -48,13 +48,18 @@ public: void updateRowVisibilities(); + //! Update the presented units in all contained widgets according to current settings. + void updateUnits(); + void ensureVisible(QWidget* w); //! Show values in Angstrom or nanometers - void useAngstrom(bool angstrom); + void setUseAngstrom(bool angstrom); + bool useAngstrom() const; //! Show values in radiants or degrees - void useRadiant(bool radiant); + void setUseRadiant(bool radiant); + bool useRadiant() const; //! Shows or hides the "Add Layer" buttons. void showAddLayerButtons(bool show); @@ -70,6 +75,8 @@ private: MultiLayerItem* m_multiLayerItem; //!< Ptr is borrowed, don't delete SampleEditorController* m_ec; //!< Ptr is borrowed, don't delete bool m_showInlineEditButtons = false; + bool m_useAngstrom; + bool m_useRadiant; QList<QPushButton*> m_addLayerButtons; }; diff --git a/GUI/Views/SampleDesigner/SampleEditorController.cpp b/GUI/Views/SampleDesigner/SampleEditorController.cpp index 7d6ec3909ca56d7299574822921153b3cf23c690..db16be1d3dc719a89d5787baf37dd733123f47ab 100644 --- a/GUI/Views/SampleDesigner/SampleEditorController.cpp +++ b/GUI/Views/SampleDesigner/SampleEditorController.cpp @@ -60,6 +60,7 @@ void SampleEditorController::addLayer(LayerItem* before) ASSERT(m_multiLayerForm); m_multiLayerForm->onLayerAdded(layer); + m_multiLayerForm->updateUnits(); } void SampleEditorController::addLayout(LayerForm* layerItemWidget) @@ -68,6 +69,7 @@ void SampleEditorController::addLayout(LayerForm* layerItemWidget) layerItemWidget->layerItem()->model()->insertItem<ParticleLayoutItem>( layerItemWidget->layerItem()); layerItemWidget->onLayoutAdded(newLayoutItem); + m_multiLayerForm->updateUnits(); } void SampleEditorController::removeLayer(LayerItem* layerItem) @@ -101,6 +103,7 @@ void SampleEditorController::addParticle(ParticleLayoutItem* layoutItem, const Q for (auto w : m_multiLayerForm->findChildren<ParticleLayoutForm*>()) if (w->layoutItem() == layoutItem) w->onParticleAdded(newItem); + m_multiLayerForm->updateUnits(); } void SampleEditorController::addParticle(ParticleCompositionItem* compositionItem, @@ -125,6 +128,7 @@ void SampleEditorController::addParticle(ParticleCompositionItem* compositionIte for (auto c : m_multiLayerForm->findChildren<ParticleCompositionForm*>()) if (c->compositionItem() == compositionItem) c->onParticleAdded(newItem); + m_multiLayerForm->updateUnits(); } void SampleEditorController::setCoreFormFactor(ParticleCoreShellForm* widget, @@ -142,6 +146,7 @@ void SampleEditorController::setCoreFormFactor(ParticleCoreShellForm* widget, particleCoreShell->core()->setFormFactor(formFactorModelType); widget->createCoreWidgets(); + m_multiLayerForm->updateUnits(); } void SampleEditorController::setShellFormFactor(ParticleCoreShellForm* widget, @@ -159,6 +164,7 @@ void SampleEditorController::setShellFormFactor(ParticleCoreShellForm* widget, particleCoreShell->shell()->setFormFactor(formFactorModelType); widget->createShellWidgets(); + m_multiLayerForm->updateUnits(); } void SampleEditorController::removeParticle(ItemWithParticles* item) @@ -233,6 +239,7 @@ void SampleEditorController::setCurrentIndex(SelectionContainerForm* widget, int { d.setCurrentIndex(index); widget->createDoubleEdits(); + m_multiLayerForm->updateUnits(); } QUndoStack* SampleEditorController::undoStack() @@ -308,6 +315,7 @@ void SampleEditorController::setMesoCrystalBasis(MesoCrystalForm* widget, const particle->setFormFactor(classname); } widget->createBasisWidgets(); + m_multiLayerForm->updateUnits(); } void SampleEditorController::selectInterference(ParticleLayoutItem* layoutItem, int newIndex) @@ -315,4 +323,5 @@ void SampleEditorController::selectInterference(ParticleLayoutItem* layoutItem, // #baLayerEditor ++ change the visibility of particle density (compare to // ParticleLayoutItem::updateDensityAppearance() and ParticleLayoutItem::updateDensityValue()) layoutItem->interference().setCurrentIndex(newIndex); + m_multiLayerForm->updateUnits(); }