diff --git a/GUI/Model/Descriptor/PolyPtr.h b/GUI/Model/Descriptor/PolyPtr.h index a365dbd294543c8259b81fef3145f79de0695bc2..9b24cae436a634144c5f77ce5e4a11ff0fc5ba7b 100644 --- a/GUI/Model/Descriptor/PolyPtr.h +++ b/GUI/Model/Descriptor/PolyPtr.h @@ -24,7 +24,7 @@ public: QStringList menuEntries() const { return m_menu_entries; } virtual void setCertainIndex(int index) = 0; - virtual int currentIndex() const = 0; + virtual int certainIndex() const = 0; protected: QString m_label; //!< A label text (short, no trailing colon) @@ -47,7 +47,7 @@ public: template <typename... Args> void readFrom(QXmlStreamReader* r, Args... args); void setCertainIndex(int index) override { m_item.reset(Catalog::create(m_types[index])); } - int currentIndex() const override { return m_types.indexOf(Catalog::type(m_item.get())); } + int certainIndex() const override { return m_types.indexOf(Catalog::type(m_item.get())); } private: std::unique_ptr<BaseItem> m_item; //!< Current selection diff --git a/GUI/View/Device/DistributionSelector.cpp b/GUI/View/Device/DistributionSelector.cpp index b4c7b82ca3895d81770265d669cdec39029c3718..9b27266ca3fdbd1c49fd15cea8715f1927ffbc92 100644 --- a/GUI/View/Device/DistributionSelector.cpp +++ b/GUI/View/Device/DistributionSelector.cpp @@ -117,6 +117,6 @@ void DistributionSelector::createMeanSpinBox(DoubleProperty& d) void DistributionSelector::refresh() { QSignalBlocker b(m_distribution_combo); - m_distribution_combo->setCurrentIndex(m_item->distributionSelection().currentIndex()); + m_distribution_combo->setCurrentIndex(m_item->distributionSelection().certainIndex()); createDistributionWidgets(); } diff --git a/GUI/View/Numeric/ComboUtil.h b/GUI/View/Numeric/ComboUtil.h index a33ccd521785ef879debcbff6b833e6de3b7af5b..0a5fbeaf3114d5efe0ad4f490b6e916a3a94e02f 100644 --- a/GUI/View/Numeric/ComboUtil.h +++ b/GUI/View/Numeric/ComboUtil.h @@ -54,7 +54,7 @@ QComboBox* createComboBoxFromPolyPtr(PolyPtr<B, C>& d, std::function<void(int)> combo->addItems(d.menuEntries()); combo->setMaxCount(d.menuEntries().size()); combo->setToolTip(d.piTooltip()); - combo->setCurrentIndex(d.currentIndex()); + combo->setCurrentIndex(d.certainIndex()); if (inScrollArea) WheelEventEater::install(combo); diff --git a/GUI/View/Sample/ISelectionForm.h b/GUI/View/Sample/ISelectionForm.h index 4d763d4c45e5d3f5fcd80f1bf6dd7a02b311bc0d..4cd2b0b6559cd01861fac344bcb10955ed78fe45 100644 --- a/GUI/View/Sample/ISelectionForm.h +++ b/GUI/View/Sample/ISelectionForm.h @@ -43,7 +43,7 @@ protected: m_combo = new QComboBox; WheelEventEater::install(m_combo); m_combo->addItems(d.menuEntries()); - m_combo->setCurrentIndex(d.currentIndex()); + m_combo->setCurrentIndex(d.certainIndex()); m_combo->setMaxVisibleItems(m_combo->count()); QObject::connect(m_combo, &QComboBox::currentIndexChanged, [this, &d](int current) { diff --git a/GUI/View/Sample/InterferenceForm.cpp b/GUI/View/Sample/InterferenceForm.cpp index 51ac40db9d320436025fe228939c575310002fe3..9d0cc286134f56dc08d0f3d6ef80729434050464 100644 --- a/GUI/View/Sample/InterferenceForm.cpp +++ b/GUI/View/Sample/InterferenceForm.cpp @@ -25,28 +25,28 @@ InterferenceForm::InterferenceForm(QWidget* parent, ParticleLayoutItem* layoutItem, SampleEditorController* ec) : CollapsibleGroupBox("Interference Function", parent, layoutItem->expandInterference) - , m_interference_type_combo(new QComboBox(this)) + , m_cb(new QComboBox(this)) , m_layout_item(layoutItem) , m_ec(ec) { m_layout = new HeinzFormLayout(m_ec); body()->setLayout(m_layout); - - WheelEventEater::install(m_interference_type_combo); + WheelEventEater::install(m_cb); const auto& d = layoutItem->interferenceSelection(); - m_interference_type_combo->addItems(d.menuEntries()); - m_interference_type_combo->setCurrentIndex(d.currentIndex()); - m_interference_type_combo->setMaxVisibleItems(m_interference_type_combo->count()); - m_interference_type_combo->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed); - m_layout->addBoldRow("Type:", m_interference_type_combo); + m_cb->addItems(d.menuEntries()); + m_cb->setCurrentIndex(d.certainIndex()); + m_cb->setMaxVisibleItems(m_cb->count()); + m_cb->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed); + m_layout->addBoldRow("Type:", m_cb); createInterferenceWidgets(); updateTitle(); - connect(m_interference_type_combo, &QComboBox::currentIndexChanged, + connect(m_cb, &QComboBox::currentIndexChanged, [this](int newIndex) { m_ec->selectInterference(this, newIndex); }); } + void InterferenceForm::onInterferenceTypeChanged() { while (m_layout->rowCount() > 1) @@ -65,8 +65,10 @@ void InterferenceForm::createInterferenceWidgets() // SampleEditorController::setDensityRelatedValueValue has to be called (instead of // SampleEditorController::setDouble). For this we have the following lambda to add a value: const auto addDensityRelatedValue = [this, interference](DoubleProperty& d) { - m_layout->addValue(d, [this, interference, &d](double newValue) { - m_ec->setDensityRelatedValue(interference, newValue, d); + m_layout->addValue(d, [this, interference, &d](double value) { + d.setDVal(value); + emit gDoc->sampleChanged(); + m_ec->setDensityRelatedValue(interference); }); }; @@ -109,7 +111,6 @@ void InterferenceForm::createInterferenceWidgets() }, RealLimits::lowerLimited(1), "Domain size 2 in number of unit cells")); - auto* w = new LatticeTypeSelectionForm(this, itf, m_ec); m_layout->addBoldRow(itf->latticeTypeSelection().piLabel(), w); } else if (auto* itf = dynamic_cast<Interference2DParacrystalItem*>(interference)) { @@ -126,5 +127,5 @@ void InterferenceForm::createInterferenceWidgets() void InterferenceForm::updateTitle() { - setTitle("Interference Function (" + m_interference_type_combo->currentText() + ")"); + setTitle("Interference Function (" + m_cb->currentText() + ")"); } diff --git a/GUI/View/Sample/InterferenceForm.h b/GUI/View/Sample/InterferenceForm.h index 33cef82df16ffc94f38f6d43353c3ddb1b441013..eb0353866457c7c70e2f0ff6ac44fe118aa64150 100644 --- a/GUI/View/Sample/InterferenceForm.h +++ b/GUI/View/Sample/InterferenceForm.h @@ -36,7 +36,7 @@ private: void updateTitle(); HeinzFormLayout* m_layout; - QComboBox* m_interference_type_combo; + QComboBox* m_cb; ParticleLayoutItem* m_layout_item; SampleEditorController* m_ec; }; diff --git a/GUI/View/Sample/LatticeTypeSelectionForm.cpp b/GUI/View/Sample/LatticeTypeSelectionForm.cpp index c39de9062295e15190024499d405d522e9a91687..1d99b8aaa3f8036f11b5c56128af46104d71b7ba 100644 --- a/GUI/View/Sample/LatticeTypeSelectionForm.cpp +++ b/GUI/View/Sample/LatticeTypeSelectionForm.cpp @@ -31,8 +31,10 @@ void LatticeTypeSelectionForm::createContent() const auto valueProperties = currentLatticeType->geometryValues(false); const bool vertical = valueProperties.size() > 2; - const auto onValueChange = [this](double newValue, DoubleProperty& d) { - m_ec->setDensityRelatedValue(m_interference_item, newValue, d); + const auto onValueChange = [this](double value, DoubleProperty& d) { + d.setDVal(value); + emit gDoc->sampleChanged(); + m_ec->setDensityRelatedValue(m_interference_item); }; GUI::Util::Layer::addMultiPropertyToGrid(m_grid_layout, 1, valueProperties, onValueChange, vertical, false); @@ -40,8 +42,11 @@ void LatticeTypeSelectionForm::createContent() m_integrate_over_xi_check_box = new QCheckBox("Integrate over Xi", this); m_integrate_over_xi_check_box->setChecked(m_interference_item->xiIntegration()); m_grid_layout->addWidget(m_integrate_over_xi_check_box, 1, m_grid_layout->columnCount()); - connect(m_integrate_over_xi_check_box, &QCheckBox::stateChanged, - [this] { m_ec->setIntegrateOverXi(this, m_integrate_over_xi_check_box->isChecked()); }); + connect(m_integrate_over_xi_check_box, &QCheckBox::stateChanged, [this] { + interferenceItem()->setXiIntegration(m_integrate_over_xi_check_box->isChecked()); + onIntegrateOverXiChanged(); + emit gDoc->sampleChanged(); + }); const int colOfXiLabel = m_grid_layout->columnCount(); GUI::Util::Layer::addMultiPropertyToGrid(m_grid_layout, m_grid_layout->columnCount(), diff --git a/GUI/View/Sample/SampleEditorController.cpp b/GUI/View/Sample/SampleEditorController.cpp index d945590a69beeb04d623035f234310ae9b60f68a..47ab1f8d3d77d1315a50fdf21bc528cf35d58eb4 100644 --- a/GUI/View/Sample/SampleEditorController.cpp +++ b/GUI/View/Sample/SampleEditorController.cpp @@ -369,13 +369,10 @@ void SampleEditorController::setMaterialValue(ItemWithMaterial* item, double val emit gDoc->sampleChanged(); } -void SampleEditorController::setDensityRelatedValue(InterferenceItem* interferenceItem, - double value, DoubleProperty& d) -{ - d.setDVal(value); - emit gDoc->sampleChanged(); - // -- notify the containing particle layout UI about changed value +//! notify the containing particle layout UI about changed value +void SampleEditorController::setDensityRelatedValue(InterferenceItem* interferenceItem) +{ ASSERT(m_sample_form); for (auto* c : m_sample_form->findChildren<ParticleLayoutForm*>()) if (c->layoutItem()->interferenceSelection().certainItem() == interferenceItem) { @@ -437,10 +434,3 @@ void SampleEditorController::selectInterference(InterferenceForm* widget, int ne emit gDoc->sampleChanged(); } - -void SampleEditorController::setIntegrateOverXi(LatticeTypeSelectionForm* widget, bool value) -{ - widget->interferenceItem()->setXiIntegration(value); - widget->onIntegrateOverXiChanged(); - emit gDoc->sampleChanged(); -} diff --git a/GUI/View/Sample/SampleEditorController.h b/GUI/View/Sample/SampleEditorController.h index 6d5ad248866be23d67b0954542e83a4ce777860e..8bc51a2f7a39b26f86d9095c1ee0ad78e943be00 100644 --- a/GUI/View/Sample/SampleEditorController.h +++ b/GUI/View/Sample/SampleEditorController.h @@ -65,11 +65,6 @@ public: void duplicateLayerItem(const LayerItem* layer); void removeLayerItem(LayerItem* layer); - void onLayoutAdded(LayerForm* layerForm, ParticleLayoutItem* layout); - void addLayoutItem(LayerForm* layerForm); - void duplicateLayoutItem(LayerForm* layerForm, ParticleLayoutItem* layout); - void removeLayoutItem(LayerForm* layerForm, ParticleLayoutItem* layout); - void onParticleLayoutAdded(ParticleLayoutItem* layout, ItemWithParticles* newItem); void addParticleLayoutItem(ParticleLayoutItem* layout, ParticleCatalog::Type type); void addParticleLayoutItem(ParticleLayoutItem* layout, FormfactorCatalog::Type type); @@ -89,27 +84,25 @@ public: void setMesocrystalBasis(MesocrystalForm* widget, ParticleCatalog::Type type); void setMesocrystalBasis(MesocrystalForm* widget, FormfactorCatalog::Type type); void selectInterference(InterferenceForm* widget, int newIndex); - void setIntegrateOverXi(LatticeTypeSelectionForm* widget, bool value); void selectMaterial(ItemWithMaterial* item, const QString& newMaterialIdentifier); void setMaterialValue(ItemWithMaterial* item, double value, DoubleProperty& d); - //! Set an interference function's value which affects the total particle density of the - //! containing particle layout. - //! - //! Some values in interference settings affect the total density in the particle layout which - //! contains this interference function. Call this method to provide all the related updating - //! (data & UI). - void setDensityRelatedValue(InterferenceItem* interferenceItem, double value, - DoubleProperty& d); + void setDensityRelatedValue(InterferenceItem* interferenceItem); void onStoppedToMoveLayer(QWidget* widgetToMove, QWidget* moveAboveThisWidget); + static void addLayoutItem(LayerForm* layerForm); + static void duplicateLayoutItem(LayerForm* layerForm, ParticleLayoutItem* layout); + void removeLayoutItem(LayerForm* layerForm, ParticleLayoutItem* layout); + signals: void requestViewInRealspace(Item3D* item); void aboutToRemoveItem(Item3D* item); private: + static void onLayoutAdded(LayerForm* layerForm, ParticleLayoutItem* layout); + ItemWithParticles* createAndInitItem(FormfactorCatalog::Type formFactorType) const; ItemWithParticles* createAndInitItem(ParticleCatalog::Type itemType) const;