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

assure edits/labels on added forms show correct units

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