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

reduce SessionItem usage for particle layout, improve title of particle layout

parent fe9a5a6b
No related branches found
No related tags found
1 merge request!513Refactor sample model
......@@ -15,6 +15,7 @@
#include "GUI/View/SampleDesigner/ParticleLayoutForm.h"
#include "GUI/Model/Sample/InterferenceItems.h"
#include "GUI/Model/Sample/ItemWithParticles.h"
#include "GUI/Model/Sample/LayerItem.h"
#include "GUI/Model/Sample/ParticleLayoutItem.h"
#include "GUI/Util/ActionFactory.h"
#include "GUI/View/Edit/DoubleSpinBox.h"
......@@ -31,8 +32,6 @@ ParticleLayoutForm::ParticleLayoutForm(LayerForm* parent, ParticleLayoutItem* la
SampleEditorController* ec)
: QGroupBox(parent), m_layoutItem(layoutItem), m_ec(ec)
{
setTitle(m_layoutItem->itemName());
FormLayouter layouter(this, ec);
layouter.setContentsMargins(30, 6, 0, 0);
int rowOfTotalDensity = layouter.addValue(m_layoutItem->totalDensity());
......@@ -57,12 +56,13 @@ ParticleLayoutForm::ParticleLayoutForm(LayerForm* parent, ParticleLayoutItem* la
auto* showInRealSpaceAction = ActionFactory::createShowInRealSpaceAction(
this, "particle layout", [=] { ec->requestViewInRealSpace(layoutItem); });
auto* collapser = GroupBoxCollapser::installIntoGroupBox(this);
collapser->addAction(showInRealSpaceAction);
collapser->addAction(m_removeAction);
m_collapser = GroupBoxCollapser::installIntoGroupBox(this);
m_collapser->addAction(showInRealSpaceAction);
m_collapser->addAction(m_removeAction);
m_layout = layouter.layout();
updateDensityEnabling();
updateTitle(parent->layerItem());
}
void ParticleLayoutForm::enableStructureEditing(bool b)
......@@ -115,3 +115,13 @@ void ParticleLayoutForm::updateDensityValue()
{
m_totalDensitySpinBox->updateValue();
}
void ParticleLayoutForm::updateTitle(const LayerItem* layerItem)
{
const auto layouts = layerItem->layouts();
if (layouts.size() > 1)
m_collapser->setTitle("Particle layout "
+ QString::number(layouts.indexOf(m_layoutItem) + 1));
else
m_collapser->setTitle("Particle layout");
}
......@@ -26,6 +26,8 @@ class LayerForm;
class SessionItem;
class ItemWithParticles;
class DoubleSpinBox;
class LayerItem;
class GroupBoxCollapser;
//! Form for editing a particle layout
class ParticleLayoutForm : public QGroupBox {
......@@ -50,6 +52,8 @@ public:
//! This does not update any internal values, it only refreshes the shown value.
void updateDensityValue();
void updateTitle(const LayerItem* layerItem);
private:
QFormLayout* m_layout;
ParticleLayoutItem* m_layoutItem;
......@@ -57,6 +61,7 @@ private:
SampleEditorController* m_ec;
QList<QWidget*> m_structureEditingWidgets;
DoubleSpinBox* m_totalDensitySpinBox;
GroupBoxCollapser* m_collapser;
};
#endif // BORNAGAIN_GUI_VIEW_SAMPLEDESIGNER_PARTICLELAYOUTFORM_H
......@@ -111,6 +111,9 @@ void SampleEditorController::addLayout(LayerForm* layerItemWidget)
auto* newLayoutItem = layerItemWidget->layerItem()->addLayout();
layerItemWidget->onLayoutAdded(newLayoutItem);
m_multiLayerForm->updateUnits();
for (auto* layoutForms : layerItemWidget->findChildren<ParticleLayoutForm*>())
layoutForms->updateTitle(layerItemWidget->layerItem());
}
void SampleEditorController::removeLayer(LayerItem* layerItem)
......@@ -122,6 +125,9 @@ void SampleEditorController::removeLayout(LayerForm* layerItemWidget, ParticleLa
{
layerItemWidget->onAboutToRemoveLayout(layout);
layerItemWidget->layerItem()->removeLayout(layout);
for (auto* layoutForms : layerItemWidget->findChildren<ParticleLayoutForm*>())
layoutForms->updateTitle(layerItemWidget->layerItem());
}
void SampleEditorController::addParticle(ParticleLayoutItem* layoutItem, const QString& classname)
......
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