From 05d9a90ece593ae15d3dbd6e91ab193ff340583f Mon Sep 17 00:00:00 2001 From: Matthias Puchner <github@mpuchner.de> Date: Thu, 16 Dec 2021 09:52:37 +0100 Subject: [PATCH] adapt JobItem to MultiLayerItem changes --- GUI/Model/Job/JobItem.cpp | 20 +++++++++----------- GUI/Model/Job/JobItem.h | 6 ++---- GUI/Model/Job/JobModel.cpp | 5 ----- GUI/Model/Job/JobModelFunctions.cpp | 7 ------- GUI/Model/Job/JobModelFunctions.h | 2 -- GUI/Model/Job/ParameterTreeUtils.cpp | 1 + GUI/Model/Sample/MultiLayerItem.cpp | 5 +++++ GUI/Model/Sample/MultiLayerItem.h | 2 ++ 8 files changed, 19 insertions(+), 29 deletions(-) diff --git a/GUI/Model/Job/JobItem.cpp b/GUI/Model/Job/JobItem.cpp index c715d5d39bd..9a7ace929d2 100644 --- a/GUI/Model/Job/JobItem.cpp +++ b/GUI/Model/Job/JobItem.cpp @@ -38,6 +38,7 @@ namespace Tags { const QString SimulationOptions("SimulationOptions"); const QString Materials("Materials"); const QString ParameterContainer("ParameterContainer"); +const QString Sample("Sample"); } // namespace Tags } // namespace @@ -47,7 +48,6 @@ JobItem::JobItem() : SessionItem(M_TYPE) { setItemName(M_TYPE); addProperty(P_IDENTIFIER, QString())->setVisible(false); - addProperty(P_SAMPLE_NAME, QString())->setEditable(false); addProperty(P_INSTRUMENT_NAME, QString())->setEditable(false); addProperty(P_WITH_FITTING, false)->setVisible(false); @@ -60,7 +60,6 @@ JobItem::JobItem() : SessionItem(M_TYPE) addProperty(P_PROGRESS, 0)->setVisible(false); addProperty(P_PRESENTATION_TYPE, QVariant::Type::Invalid)->setVisible(false); - registerTag(T_SAMPLE, 1, 1, {MultiLayerItem::M_TYPE}); registerTag(T_INSTRUMENT, 1, 1, {GISASInstrumentItem::M_TYPE, OffSpecularInstrumentItem::M_TYPE, SpecularInstrumentItem::M_TYPE, DepthProbeInstrumentItem::M_TYPE}); @@ -245,12 +244,12 @@ bool JobItem::runInBackground() const MultiLayerItem* JobItem::sampleItem() { - return dynamic_cast<MultiLayerItem*>(getItem(T_SAMPLE)); + return &m_multiLayerItem; } MultiLayerItem* JobItem::copySampleIntoJob(const MultiLayerItem* sample) { - model()->copyItem(sample, this, T_SAMPLE); + m_multiLayerItem.initFrom(sample); // initialize finder-function of items with material for (auto* itemWithMaterial : sampleItem()->itemsWithMaterial()) { @@ -258,7 +257,7 @@ MultiLayerItem* JobItem::copySampleIntoJob(const MultiLayerItem* sample) [=](const QString& id) { return materialItems().materialFromIdentifier(id); }); } - return sampleItem(); + return &m_multiLayerItem; } InstrumentItem* JobItem::instrumentItem() const @@ -354,12 +353,7 @@ Data1DViewItem* JobItem::createDataViewItem() QString JobItem::sampleName() const { - return getItemValue(P_SAMPLE_NAME).toString(); -} - -void JobItem::setSampleName(const QString& name) -{ - getItem(P_SAMPLE_NAME)->setValue(name); + return m_multiLayerItem.sampleName(); } QString JobItem::instrumentName() const @@ -394,6 +388,10 @@ void JobItem::writeNonSessionItems(QXmlStreamWriter* writer) const m_materials.writeContentTo(writer); writer->writeEndElement(); + writer->writeStartElement(Tags::Sample); + m_multiLayerItem.writeContentTo(writer); + writer->writeEndElement(); + writer->writeStartElement(Tags::ParameterContainer); m_parameterContainer.writeContentTo(writer); writer->writeEndElement(); diff --git a/GUI/Model/Job/JobItem.h b/GUI/Model/Job/JobItem.h index bb02522df65..1f815d33f76 100644 --- a/GUI/Model/Job/JobItem.h +++ b/GUI/Model/Job/JobItem.h @@ -18,6 +18,7 @@ #include "GUI/Model/Fit/ParameterTreeItems.h" #include "GUI/Model/Job/JobStatus.h" // enum cannot be forward declared #include "GUI/Model/Material/MaterialModel.h" +#include "GUI/Model/Sample/MultiLayerItem.h" #include "GUI/Model/Session/SessionItem.h" #include "GUI/Model/Session/SessionModel.h" // call to model() from templated fct #include "GUI/Model/Session/SimulationOptionsItem.h" @@ -33,7 +34,6 @@ class Instrument2DItem; class InstrumentItem; class IntensityDataItem; class MaterialItemContainer; -class MultiLayerItem; class ParameterContainerItem; class RealDataItem; class SimulationOptionsItem; @@ -41,7 +41,6 @@ class SimulationOptionsItem; class BA_CORE_API_ JobItem : public SessionItem { private: static constexpr auto P_IDENTIFIER{"Identifier"}; - static constexpr auto P_SAMPLE_NAME{"Sample"}; static constexpr auto P_INSTRUMENT_NAME{"Instrument"}; static constexpr auto P_WITH_FITTING{"With fitting"}; static constexpr auto P_STATUS{"Status"}; @@ -50,7 +49,6 @@ private: static constexpr auto P_COMMENTS{"Comments"}; static constexpr auto P_PROGRESS{"Progress"}; static constexpr auto P_PRESENTATION_TYPE{"Presentation type"}; - static constexpr auto T_SAMPLE{"Sample tag"}; static constexpr auto T_MATERIAL_CONTAINER{"Material container tag"}; static constexpr auto T_INSTRUMENT{"Instrument tag"}; static constexpr auto T_OUTPUT{"Output tag"}; @@ -134,7 +132,6 @@ public: Data1DViewItem* createDataViewItem(); QString sampleName() const; - void setSampleName(const QString& name); QString instrumentName() const; void setInstrumentName(const QString& name); @@ -155,6 +152,7 @@ private: SimulationOptionsItem m_simulationOptionsItem; MaterialModel m_materials; ParameterContainerItem m_parameterContainer; + MultiLayerItem m_multiLayerItem; }; template <typename T> T* JobItem::setDataType() diff --git a/GUI/Model/Job/JobModel.cpp b/GUI/Model/Job/JobModel.cpp index 0cd310819d3..dcc28f6c342 100644 --- a/GUI/Model/Job/JobModel.cpp +++ b/GUI/Model/Job/JobModel.cpp @@ -62,13 +62,8 @@ JobItem* JobModel::addJob(const MultiLayerItem* multiLayerItem, GUI::Model::JobFunctions::setupJobItemSampleData(jobItem, multiLayerItem); GUI::Model::JobFunctions::setupJobItemInstrument(jobItem, instrumentItem); - // TODO: remove when specular instrument is ready for magnetization - if (instrumentItem->is<SpecularInstrumentItem>()) - GUI::Model::JobFunctions::muteMagnetizationData(jobItem); jobItem->copySimulationOptionsIntoJob(optionItem); - jobItem->setSampleName(multiLayerItem->sampleName()); - GUI::Model::ParameterTreeUtils::createParameterTree(jobItem, true); GUI::Model::JobFunctions::setupJobItemOutput(jobItem); diff --git a/GUI/Model/Job/JobModelFunctions.cpp b/GUI/Model/Job/JobModelFunctions.cpp index f2477f5367f..a31d862550b 100644 --- a/GUI/Model/Job/JobModelFunctions.cpp +++ b/GUI/Model/Job/JobModelFunctions.cpp @@ -126,7 +126,6 @@ void GUI::Model::JobFunctions::setupJobItemSampleData(JobItem* jobItem, const MultiLayerItem* sampleItem) { MultiLayerItem* multilayer = jobItem->copySampleIntoJob(sampleItem); - multilayer->setSampleName(MultiLayerItem::M_TYPE); // copy used materials into material container for (auto* itemWithMaterial : sampleItem->itemsWithMaterial()) { @@ -199,12 +198,6 @@ void GUI::Model::JobFunctions::setupJobItemForFit(JobItem* jobItem, createFitContainers(jobItem); } -void GUI::Model::JobFunctions::muteMagnetizationData(JobItem* jobItem) -{ - MultiLayerItem* sample = jobItem->sampleItem(); - sample->externalFieldItem()->setVisible(false); -} - void GUI::Model::JobFunctions::copyRealDataItem(JobItem* jobItem, const RealDataItem* realDataItem) { if (!realDataItem) diff --git a/GUI/Model/Job/JobModelFunctions.h b/GUI/Model/Job/JobModelFunctions.h index 8fe40c9b3b3..d88a9e8e206 100644 --- a/GUI/Model/Job/JobModelFunctions.h +++ b/GUI/Model/Job/JobModelFunctions.h @@ -39,8 +39,6 @@ void setupJobItemOutput(JobItem* jobItem); void setupJobItemForFit(JobItem* jobItem, const RealDataItem* realDataItem); -void muteMagnetizationData(JobItem* jobItem); - //! Copy RealDataItem to jobItem intended for fitting. void copyRealDataItem(JobItem* jobItem, const RealDataItem* realDataItem); diff --git a/GUI/Model/Job/ParameterTreeUtils.cpp b/GUI/Model/Job/ParameterTreeUtils.cpp index a6284b18a35..f6c45114402 100644 --- a/GUI/Model/Job/ParameterTreeUtils.cpp +++ b/GUI/Model/Job/ParameterTreeUtils.cpp @@ -150,6 +150,7 @@ void GUI::Model::ParameterTreeUtils::createParameterTree(JobItem* jobItem, // SessionModel migration. Compare also to handling in // LayerForm::updateLayerPositionDependentElements() // dto. for totalDensity of particle layout + // #baMigration if !jobItemIsSpecularJob() -> no external field of multilayer! for (auto* layer : jobItem->sampleItem()->layers()) { const bool isFirstLayer = jobItem->sampleItem()->layers().first() == layer; const bool isLastLayer = jobItem->sampleItem()->layers().last() == layer; diff --git a/GUI/Model/Sample/MultiLayerItem.cpp b/GUI/Model/Sample/MultiLayerItem.cpp index 9d2d040cab2..dac2e49dc2d 100644 --- a/GUI/Model/Sample/MultiLayerItem.cpp +++ b/GUI/Model/Sample/MultiLayerItem.cpp @@ -38,6 +38,11 @@ MultiLayerItem::MultiLayerItem() m_crossCorrelationLength = 0; } +void MultiLayerItem::initFrom(const MultiLayerItem* other) +{ + // #baMigration ++ implement +} + QVector<ItemWithMaterial*> MultiLayerItem::itemsWithMaterial() const { QVector<ItemWithMaterial*> result; diff --git a/GUI/Model/Sample/MultiLayerItem.h b/GUI/Model/Sample/MultiLayerItem.h index f0583178835..f0ca964f731 100644 --- a/GUI/Model/Sample/MultiLayerItem.h +++ b/GUI/Model/Sample/MultiLayerItem.h @@ -31,6 +31,8 @@ class MultiLayerItem { public: MultiLayerItem(); + void initFrom(const MultiLayerItem* other); + QVector<ItemWithMaterial*> itemsWithMaterial() const; QString sampleName() const; -- GitLab