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

reduce SessionItem usage, reduce SessionItem signaling

parent ae0746d1
No related branches found
No related tags found
1 merge request!532Reduce SessionItem signaling
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "GUI/Model/Sample/MultiLayerItem.h" #include "GUI/Model/Sample/MultiLayerItem.h"
#include "GUI/Model/Sample/ParticleCoreShellItem.h" #include "GUI/Model/Sample/ParticleCoreShellItem.h"
#include "GUI/Model/Sample/ParticleItem.h" #include "GUI/Model/Sample/ParticleItem.h"
#include "GUI/Model/Sample/ParticleLayoutItem.h"
#include "GUI/Model/Session/ModelPath.h" #include "GUI/Model/Session/ModelPath.h"
#include "GUI/Model/Types/VectorDescriptor.h" #include "GUI/Model/Types/VectorDescriptor.h"
#include "GUI/Util/Error.h" #include "GUI/Util/Error.h"
...@@ -139,12 +140,16 @@ void GUI::Model::ParameterTreeUtils::createParameterTree(JobItem* jobItem, ...@@ -139,12 +140,16 @@ void GUI::Model::ParameterTreeUtils::createParameterTree(JobItem* jobItem,
// #baMigration To ignore thickness/roughness, they are disabled. This has to be changed after // #baMigration To ignore thickness/roughness, they are disabled. This has to be changed after
// SessionModel migration. Compare also to handling in // SessionModel migration. Compare also to handling in
// LayerForm::updateLayerPositionDependentElements() // LayerForm::updateLayerPositionDependentElements()
// dto. for totalDensity of particle layout
for (auto* layer : jobItem->sampleItem()->layers()) { for (auto* layer : jobItem->sampleItem()->layers()) {
const bool isFirstLayer = jobItem->sampleItem()->layers().first() == layer; const bool isFirstLayer = jobItem->sampleItem()->layers().first() == layer;
const bool isLastLayer = jobItem->sampleItem()->layers().last() == layer; const bool isLastLayer = jobItem->sampleItem()->layers().last() == layer;
layer->setRoughnessEnabled(!isFirstLayer); layer->setRoughnessEnabled(!isFirstLayer);
layer->setThicknessEnabled(!isFirstLayer && !isLastLayer); layer->setThicknessEnabled(!isFirstLayer && !isLastLayer);
for (auto* layout : layer->layouts())
layout->enableDensity(!layout->totalDensityIsDefinedByInterference());
} }
populateParameterContainer(container, jobItem->sampleItem(), recreateBackupValues); populateParameterContainer(container, jobItem->sampleItem(), recreateBackupValues);
......
...@@ -23,21 +23,6 @@ ...@@ -23,21 +23,6 @@
namespace { namespace {
//! Returns true if name is related to 2D interference functions.
bool isInterference2D(const QString& model_type)
{
return model_type == Interference2DLatticeItem::M_TYPE
|| model_type == Interference2DParaCrystalItem::M_TYPE
|| model_type == InterferenceFinite2DLatticeItem::M_TYPE
|| model_type == InterferenceHardDiskItem::M_TYPE;
}
//! Returns true if name is related to 2D interference functions.
bool isLattice2D(SessionItem* item)
{
return dynamic_cast<Lattice2DItem*>(item);
}
const QString density_tooltip = const QString density_tooltip =
"Number of particles per square nanometer (particle surface density).\n " "Number of particles per square nanometer (particle surface density).\n "
"Should be defined for disordered and 1d-ordered particle collections."; "Should be defined for disordered and 1d-ordered particle collections.";
...@@ -64,15 +49,7 @@ ParticleLayoutItem::ParticleLayoutItem() : SessionItem(M_TYPE) ...@@ -64,15 +49,7 @@ ParticleLayoutItem::ParticleLayoutItem() : SessionItem(M_TYPE)
Interference2DParaCrystalItem::M_TYPE, InterferenceFinite2DLatticeItem::M_TYPE, Interference2DParaCrystalItem::M_TYPE, InterferenceFinite2DLatticeItem::M_TYPE,
InterferenceHardDiskItem::M_TYPE, InterferenceRadialParaCrystalItem::M_TYPE}); InterferenceHardDiskItem::M_TYPE, InterferenceRadialParaCrystalItem::M_TYPE});
mapper()->setOnChildrenChange([this](SessionItem*) { mapper()->setOnAnyChildChange([this](SessionItem*) { updateDensityValue(); });
updateDensityAppearance();
updateDensityValue();
});
mapper()->setOnAnyChildChange([this](SessionItem* item) {
if (isLattice2D(item) || (item && isLattice2D(item->parent())))
updateDensityValue();
});
} }
DoubleDescriptor ParticleLayoutItem::totalDensity() const DoubleDescriptor ParticleLayoutItem::totalDensity() const
...@@ -157,18 +134,6 @@ void ParticleLayoutItem::removeInterference() ...@@ -157,18 +134,6 @@ void ParticleLayoutItem::removeInterference()
model()->removeItem(item); model()->removeItem(item);
} }
//! Disables/enables total density property, depending on type of interference function.
//! Two dimensional interference calculates density automatically, so property should
//! be disabled.
void ParticleLayoutItem::updateDensityAppearance()
{
getItem(P_TOTAL_DENSITY)->setEnabled(true);
if (auto* interferenceItem = getItem(T_INTERFERENCE))
if (isInterference2D(interferenceItem->modelType()))
getItem(P_TOTAL_DENSITY)->setEnabled(false);
}
//! Updates the value of TotalSurfaceDensity on lattice type change. //! Updates the value of TotalSurfaceDensity on lattice type change.
void ParticleLayoutItem::updateDensityValue() void ParticleLayoutItem::updateDensityValue()
...@@ -190,3 +155,15 @@ void ParticleLayoutItem::updateDensityValue() ...@@ -190,3 +155,15 @@ void ParticleLayoutItem::updateDensityValue()
} }
} }
} }
void ParticleLayoutItem::enableDensity(bool b)
{
getItem(P_TOTAL_DENSITY)->setEnabled(b);
}
bool ParticleLayoutItem::totalDensityIsDefinedByInterference() const
{
const auto* interferenceItem = getItem(T_INTERFERENCE);
return dynamic_cast<const Interference2DAbstractLatticeItem*>(interferenceItem)
|| dynamic_cast<const InterferenceHardDiskItem*>(interferenceItem);
}
...@@ -48,8 +48,14 @@ public: ...@@ -48,8 +48,14 @@ public:
void updateDensityValue(); void updateDensityValue();
private: // #baMigration Use only while not migrated to SessionModel!
void updateDensityAppearance(); void enableDensity(bool b);
//! Returns whether total density is defined by the currently selected interference.
//!
//! Two dimensional interference calculates density automatically; in these cases the "own"
//! total density value should not be edited but set by the one from the interference.
bool totalDensityIsDefinedByInterference() const;
}; };
template <typename T> T* ParticleLayoutItem::createInterference() template <typename T> T* ParticleLayoutItem::createInterference()
......
...@@ -100,15 +100,7 @@ void ParticleLayoutForm::onAboutToRemoveParticle(ItemWithParticles* item) ...@@ -100,15 +100,7 @@ void ParticleLayoutForm::onAboutToRemoveParticle(ItemWithParticles* item)
void ParticleLayoutForm::updateDensityEnabling() void ParticleLayoutForm::updateDensityEnabling()
{ {
const auto* currentInterference = m_layoutItem->interference().currentItem(); m_totalDensitySpinBox->setEnabled(!m_layoutItem->totalDensityIsDefinedByInterference());
const bool enableTotalDensityInParticleLayout =
currentInterference == nullptr
|| (!dynamic_cast<const Interference2DLatticeItem*>(currentInterference)
&& !dynamic_cast<const Interference2DParaCrystalItem*>(currentInterference)
&& !dynamic_cast<const InterferenceFinite2DLatticeItem*>(currentInterference)
&& !dynamic_cast<const InterferenceHardDiskItem*>(currentInterference));
m_totalDensitySpinBox->setEnabled(enableTotalDensityInParticleLayout);
} }
void ParticleLayoutForm::updateDensityValue() void ParticleLayoutForm::updateDensityValue()
......
...@@ -421,8 +421,10 @@ void SampleEditorController::selectInterference(InterferenceForm* widget, int ne ...@@ -421,8 +421,10 @@ void SampleEditorController::selectInterference(InterferenceForm* widget, int ne
while (parent != nullptr && dynamic_cast<ParticleLayoutForm*>(parent) == nullptr) while (parent != nullptr && dynamic_cast<ParticleLayoutForm*>(parent) == nullptr)
parent = parent->parentWidget(); parent = parent->parentWidget();
if (auto* particleLayoutForm = dynamic_cast<ParticleLayoutForm*>(parent)) if (auto* particleLayoutForm = dynamic_cast<ParticleLayoutForm*>(parent)) {
particleLayoutForm->updateDensityEnabling(); particleLayoutForm->updateDensityEnabling();
particleLayoutForm->layoutItem()->updateDensityValue();
}
} }
void SampleEditorController::setIntegrateOverXi(LatticeTypeSelectionForm* widget, bool newValue) void SampleEditorController::setIntegrateOverXi(LatticeTypeSelectionForm* widget, bool newValue)
......
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