diff --git a/GUI/Model/Fit/ParameterTreeItems.cpp b/GUI/Model/Fit/ParameterTreeItems.cpp index 395e4e0428bb0ed3633d27aa0b211e7e61de0042..6a0173746fe039d18113babd5ddd8ea9837942db 100644 --- a/GUI/Model/Fit/ParameterTreeItems.cpp +++ b/GUI/Model/Fit/ParameterTreeItems.cpp @@ -138,12 +138,12 @@ QString ParameterItem::titleForFitItem() const // ---------------------------------------------------------------------------- -ParameterContainerItem::ParameterContainerItem() : SessionItem(M_TYPE) +ParameterContainerItem::ParameterContainerItem() { m_parameterTreeRoot.reset(new QObject()); } -void ParameterContainerItem::writeNonSessionItems(QXmlStreamWriter* writer) const +void ParameterContainerItem::writeContentTo(QXmlStreamWriter* writer) const { writeAttribute(writer, GUI::Session::XML::Version, int(1)); @@ -157,7 +157,7 @@ void ParameterContainerItem::writeNonSessionItems(QXmlStreamWriter* writer) cons writer->writeEndElement(); } -void ParameterContainerItem::readNonSessionItems(QXmlStreamReader* reader) +void ParameterContainerItem::readContentFrom(QXmlStreamReader* reader) { m_backupValues.clear(); const int version = reader->attributes().value(GUI::Session::XML::Version).toInt(); @@ -183,18 +183,12 @@ void ParameterContainerItem::readNonSessionItems(QXmlStreamReader* reader) } } -bool ParameterContainerItem::allowWritingChildToXml(SessionItem* /*child*/) const -{ - // no children are written. The contained tree is always generated - return false; -} - void ParameterContainerItem::setBackupValue(const QString& link, double d) { m_backupValues[link] = d; } -void ParameterContainerItem::restoreBackupValue(SessionItem* item) +void ParameterContainerItem::restoreBackupValue(QObject* item) { ASSERT(item); if (auto* parameter = dynamic_cast<ParameterItem*>(item)) @@ -207,7 +201,7 @@ void ParameterContainerItem::restoreBackupValue(SessionItem* item) void ParameterContainerItem::restoreBackupValues() { - for (auto* child : children()) + for (auto* child : m_parameterTreeRoot->children()) restoreBackupValue(child); } diff --git a/GUI/Model/Fit/ParameterTreeItems.h b/GUI/Model/Fit/ParameterTreeItems.h index cb3066a3a100864d4328f8e54ad8818e6e238796..cc4475f53129f2f07bb548e92e56ba4b5a0875a2 100644 --- a/GUI/Model/Fit/ParameterTreeItems.h +++ b/GUI/Model/Fit/ParameterTreeItems.h @@ -77,15 +77,12 @@ private: //! The ParameterContainerItem is a top item to hold all ParameterItem, represents an entry //! point to parameter tuning tree. Part of JobItem. -class ParameterContainerItem : public SessionItem { +class ParameterContainerItem { public: - static constexpr auto M_TYPE{"Parameter Container"}; - ParameterContainerItem(); - void writeNonSessionItems(QXmlStreamWriter* writer) const override; - void readNonSessionItems(QXmlStreamReader* reader) override; - bool allowWritingChildToXml(SessionItem* child) const override; + void writeContentTo(QXmlStreamWriter* writer) const; + void readContentFrom(QXmlStreamReader* reader); void setBackupValue(const QString& link, double d); void restoreBackupValues(); @@ -95,7 +92,7 @@ public: QObject* parameterTreeRoot(); private: - void restoreBackupValue(SessionItem* item); + void restoreBackupValue(QObject* item); QMap<QString, double> m_backupValues; std::unique_ptr<QObject> m_parameterTreeRoot; diff --git a/GUI/Model/Group/ItemCatalog.cpp b/GUI/Model/Group/ItemCatalog.cpp index 7717431af6836628af13ae6e88dd58cff0b3d527..8ee6bac7bd3cca6a7f3899846a28900261c8f69e 100644 --- a/GUI/Model/Group/ItemCatalog.cpp +++ b/GUI/Model/Group/ItemCatalog.cpp @@ -292,7 +292,6 @@ ItemCatalog::ItemCatalog() addItem<GroupItem>(); - addItem<ParameterContainerItem>(); addItem<FitParameterContainerItem>(); addItem<FitParameterItem>(); addItem<FitParameterLinkItem>(); diff --git a/GUI/Model/Job/JobItem.cpp b/GUI/Model/Job/JobItem.cpp index 8e6434ac367236f4c9f878d2e9b2426c7f8ad5df..c715d5d39bdac562e5cec23afa483e413c382b9a 100644 --- a/GUI/Model/Job/JobItem.cpp +++ b/GUI/Model/Job/JobItem.cpp @@ -33,10 +33,13 @@ using namespace GUI::Session::XML; namespace { +namespace Tags { -const QString SimulationOptionsTag("SimulationOptions"); -const QString MaterialsTag("Materials"); +const QString SimulationOptions("SimulationOptions"); +const QString Materials("Materials"); +const QString ParameterContainer("ParameterContainer"); +} // namespace Tags } // namespace @@ -64,7 +67,6 @@ JobItem::JobItem() : SessionItem(M_TYPE) registerTag(T_OUTPUT, 1, 1, {IntensityDataItem::M_TYPE, SpecularDataItem::M_TYPE}); registerTag(T_REALDATA, 1, 1, {RealDataItem::M_TYPE}); registerTag(T_DATAVIEW, 1, 1, {Data1DViewItem::M_TYPE}); - registerTag(T_PARAMETER_TREE, 0, -1, {ParameterContainerItem::M_TYPE}); registerTag(T_FIT_SUITE, 1, 1, {FitSuiteItem::M_TYPE}); @@ -304,7 +306,7 @@ ParameterContainerItem* JobItem::parameterContainerItem() const ParameterContainerItem* JobItem::parameterContainerItem() const { - return dynamic_cast<ParameterContainerItem*>(getItem(T_PARAMETER_TREE)); + return &m_parameterContainer; } FitParameterContainerItem* JobItem::fitParameterContainerItem() @@ -315,11 +317,6 @@ FitParameterContainerItem* JobItem::fitParameterContainerItem() return nullptr; } -ParameterContainerItem* JobItem::createParameterContainerItem() -{ - return model()->insertItem<ParameterContainerItem>(this, -1, T_PARAMETER_TREE); -} - RealDataItem* JobItem::realDataItem() { return dynamic_cast<RealDataItem*>(getItem(JobItem::T_REALDATA)); @@ -389,13 +386,17 @@ void JobItem::writeNonSessionItems(QXmlStreamWriter* writer) const { writeAttribute(writer, GUI::Session::XML::Version, int(1)); - writer->writeStartElement(SimulationOptionsTag); + writer->writeStartElement(Tags::SimulationOptions); m_simulationOptionsItem.writeContentTo(writer); writer->writeEndElement(); - writer->writeStartElement(MaterialsTag); + writer->writeStartElement(Tags::Materials); m_materials.writeContentTo(writer); writer->writeEndElement(); + + writer->writeStartElement(Tags::ParameterContainer); + m_parameterContainer.writeContentTo(writer); + writer->writeEndElement(); } void JobItem::readNonSessionItems(QXmlStreamReader* reader) @@ -409,12 +410,13 @@ void JobItem::readNonSessionItems(QXmlStreamReader* reader) throw DeserializationException::tooNew(); while (reader->readNextStartElement()) { - if (reader->name() == SimulationOptionsTag) { + if (reader->name() == Tags::SimulationOptions) { m_simulationOptionsItem.readContentFrom(reader); reader->skipCurrentElement(); - } else if (reader->name() == MaterialsTag) { + } else if (reader->name() == Tags::Materials) m_materials.readContentFrom(reader); - } + else if (reader->name() == Tags::ParameterContainer) + m_parameterContainer.readContentFrom(reader); } } diff --git a/GUI/Model/Job/JobItem.h b/GUI/Model/Job/JobItem.h index 62c857d526a588d361fbf82a59640467674e6e94..bb02522df654021ed49aae2ef32f69798a438f63 100644 --- a/GUI/Model/Job/JobItem.h +++ b/GUI/Model/Job/JobItem.h @@ -15,6 +15,7 @@ #ifndef BORNAGAIN_GUI_MODEL_JOB_JOBITEM_H #define BORNAGAIN_GUI_MODEL_JOB_JOBITEM_H +#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/Session/SessionItem.h" @@ -55,7 +56,6 @@ private: static constexpr auto T_OUTPUT{"Output tag"}; static constexpr auto T_REALDATA{"Real Data tag"}; static constexpr auto T_DATAVIEW{"Data View tag"}; - static constexpr auto T_PARAMETER_TREE{"Parameter tree tag"}; static constexpr auto T_FIT_SUITE{"Fit suite tag"}; public: @@ -123,7 +123,6 @@ public: ParameterContainerItem* parameterContainerItem(); const ParameterContainerItem* parameterContainerItem() const; FitParameterContainerItem* fitParameterContainerItem(); - ParameterContainerItem* createParameterContainerItem(); RealDataItem* realDataItem(); RealDataItem* copyRealDataIntoJob(const RealDataItem* real_data); @@ -155,6 +154,7 @@ private: SimulationOptionsItem m_simulationOptionsItem; MaterialModel m_materials; + ParameterContainerItem m_parameterContainer; }; template <typename T> T* JobItem::setDataType() diff --git a/GUI/Model/Job/ParameterTreeUtils.cpp b/GUI/Model/Job/ParameterTreeUtils.cpp index d872132852d169e00b6637be10e7f861b124d577..a6284b18a35ddffa0c664f75865c93b42e4d4e34 100644 --- a/GUI/Model/Job/ParameterTreeUtils.cpp +++ b/GUI/Model/Job/ParameterTreeUtils.cpp @@ -117,8 +117,6 @@ void GUI::Model::ParameterTreeUtils::createParameterTree(JobItem* jobItem, bool recreateBackupValues) { auto* container = jobItem->parameterContainerItem(); - if (!container) - container = jobItem->createParameterContainerItem(); // add the job's materials auto* materialTopLabel = new ParameterLabelItem(container->parameterTreeRoot());