diff --git a/GUI/Models/JobItem.cpp b/GUI/Models/JobItem.cpp index 6f434f7902c77a8d7e78f0a4fdb2bfe0e7af74d6..ba852bf2afc3e15dd80dc9ad6f6799d470269e69 100644 --- a/GUI/Models/JobItem.cpp +++ b/GUI/Models/JobItem.cpp @@ -239,6 +239,11 @@ InstrumentItem* JobItem::instrumentItem() return dynamic_cast<InstrumentItem*>(getItem(T_INSTRUMENT)); } +InstrumentItem* JobItem::copyInstrumentIntoJob(const InstrumentItem* instrument) +{ + return model()->copyItem(instrument, this, T_INSTRUMENT); +} + void JobItem::setResults(const ISimulation* simulation) { JobItemUtils::setResults(dataItem(), simulation); diff --git a/GUI/Models/JobItem.h b/GUI/Models/JobItem.h index 2ac7195e5b61014dbef7b867e1d60104c84f841b..be60f0130aa4a00c68e5380dd3034c4428769c47 100644 --- a/GUI/Models/JobItem.h +++ b/GUI/Models/JobItem.h @@ -46,9 +46,9 @@ private: static const QString P_PRESENTATION_TYPE; static const QString T_SAMPLE; static const QString T_MATERIAL_CONTAINER; + static const QString T_INSTRUMENT; public: - static const QString T_INSTRUMENT; static const QString T_OUTPUT; static const QString T_REALDATA; static const QString T_DATAVIEW; @@ -95,6 +95,7 @@ public: MultiLayerItem* copySampleIntoJob(const MultiLayerItem* sample); InstrumentItem* instrumentItem(); + InstrumentItem* copyInstrumentIntoJob(const InstrumentItem* instrument); SimulationOptionsItem* simulationOptionsItem(); diff --git a/GUI/Models/JobModel.cpp b/GUI/Models/JobModel.cpp index d597b10605ea0f756352bdd3616f74f48b2cec8d..77aaec9c05853bd1d811bb113fc1fb47a919c903 100644 --- a/GUI/Models/JobModel.cpp +++ b/GUI/Models/JobModel.cpp @@ -149,7 +149,7 @@ QVector<SessionItem*> JobModel::nonXMLItems() const } auto instrument = - dynamic_cast<SpecularInstrumentItem*>(jobItem->getItem(JobItem::T_INSTRUMENT)); + dynamic_cast<SpecularInstrumentItem*>(jobItem->instrumentItem()); if (instrument) { auto axis_group = instrument->beamItem()->inclinationAxisGroup(); result.push_back(axis_group->firstChildOfType<PointwiseAxisItem>()); diff --git a/GUI/Models/JobModelFunctions.cpp b/GUI/Models/JobModelFunctions.cpp index 8cb6e03502dee0d79459bb8ea86805373857f57a..60efe22a8523e3d86cb8ccd9063bbe9f30730c30 100644 --- a/GUI/Models/JobModelFunctions.cpp +++ b/GUI/Models/JobModelFunctions.cpp @@ -109,8 +109,7 @@ void JobModelFunctions::setupJobItemSampleData(JobItem* jobItem, const MultiLaye void JobModelFunctions::setupJobItemInstrument(JobItem* jobItem, const InstrumentItem* from) { - auto model = jobItem->model(); - auto copiedInstrument = model->copyItem(from, jobItem, JobItem::T_INSTRUMENT); + auto copiedInstrument = jobItem->copyInstrumentIntoJob(from); copiedInstrument->setItemName(from->modelType()); copiedInstrument->setId(GUIHelpers::createUuid()); jobItem->setInstrumentName(from->itemName()); diff --git a/GUI/Models/ModelPath.cpp b/GUI/Models/ModelPath.cpp index 126f7ab7308498b1f65fbada22a948fb7629a883..d257975357bb51b2b3eff8439dea226184c3f4a5 100644 --- a/GUI/Models/ModelPath.cpp +++ b/GUI/Models/ModelPath.cpp @@ -13,6 +13,7 @@ // ************************************************************************************************ #include "GUI/Models/ModelPath.h" +#include "GUI/Models/InstrumentItems.h" #include "GUI/Models/JobItem.h" #include "GUI/Models/SessionModel.h" @@ -40,7 +41,7 @@ QModelIndex ModelPath::getIndexFromPath(const SessionModel* model, const QString SessionItem* t = model->rootItem(); for (int i = 0; i < parts.length(); i++) { if (t->modelType() == "JobItem" && parts[i] == "GISASInstrument") { - t = t->getItem(JobItem::T_INSTRUMENT); + t = dynamic_cast<JobItem*>(t)->instrumentItem(); continue; } for (int j = 0; j < t->numberOfChildren(); j++) { diff --git a/GUI/Models/ParameterTreeUtils.cpp b/GUI/Models/ParameterTreeUtils.cpp index 087d74eee951eca8661a438f75f29d720c41b10b..f07106cc620afb6ad674fc9c13a0398d60db3b8e 100644 --- a/GUI/Models/ParameterTreeUtils.cpp +++ b/GUI/Models/ParameterTreeUtils.cpp @@ -16,6 +16,7 @@ #include "GUI/Models/Error.h" #include "GUI/Models/FitParameterHelper.h" #include "GUI/Models/GroupItem.h" +#include "GUI/Models/InstrumentItems.h" #include "GUI/Models/JobItem.h" #include "GUI/Models/MaterialItemContainer.h" #include "GUI/Models/ModelPath.h" @@ -94,5 +95,5 @@ void ParameterTreeUtils::createParameterTree(JobItem* jobItem) populateParameterContainer(container, jobItem->sampleItem()); - populateParameterContainer(container, jobItem->getItem(JobItem::T_INSTRUMENT)); + populateParameterContainer(container, jobItem->instrumentItem()); } diff --git a/Tests/UnitTests/GUI/TestSavingSpecularData.cpp b/Tests/UnitTests/GUI/TestSavingSpecularData.cpp index 201a05db000a56d0375afb08a77fb8044cb4b1ed..fdc16c8cbd3d9944a73d8a89c908d98cf42230f5 100644 --- a/Tests/UnitTests/GUI/TestSavingSpecularData.cpp +++ b/Tests/UnitTests/GUI/TestSavingSpecularData.cpp @@ -106,7 +106,7 @@ TEST_F(TestSavingSpecularData, test_InstrumentInJobItem) // adding instrument auto instrument = - models.jobModel()->insertItem<SpecularInstrumentItem>(jobItem, -1, JobItem::T_INSTRUMENT); + models.jobModel()->insertItem<SpecularInstrumentItem>(jobItem, -1, "Instrument tag"); // instrument contains hidden pointwise axis item EXPECT_EQ(models.jobModel()->nonXMLItems().size(), 2); @@ -264,7 +264,7 @@ TEST_F(TestSavingSpecularData, test_CopyInstrumentToJobItem) auto jobItem = models.jobModel()->insertItem<JobItem>(); JobModelFunctions::setupJobItemInstrument(jobItem, instrument); auto job_instrument = - dynamic_cast<SpecularInstrumentItem*>(jobItem->getItem(JobItem::T_INSTRUMENT)); + dynamic_cast<SpecularInstrumentItem*>(jobItem->instrumentItem()); PointwiseAxisItem* job_axis_item = getAxisGroup(job_instrument)->firstChildOfType<PointwiseAxisItem>(); diff --git a/Tests/UnitTests/GUI/TestSessionModel.cpp b/Tests/UnitTests/GUI/TestSessionModel.cpp index 42b842a4a0e2eccce637d0c639bc290b3d1366d8..fa59a9979019af90fbec4643a02bdcfb20d2a193 100644 --- a/Tests/UnitTests/GUI/TestSessionModel.cpp +++ b/Tests/UnitTests/GUI/TestSessionModel.cpp @@ -144,8 +144,8 @@ TEST_F(TestSessionModel, copyItem) jobItem->copySampleIntoJob(multilayer1); EXPECT_NE(jobItem->sampleItem(), nullptr); - jobModel.copyItem(instrument1, jobItem, JobItem::T_INSTRUMENT); - EXPECT_EQ(jobItem->sessionItemTags()->childCount(JobItem::T_INSTRUMENT), 1); + jobItem->copyInstrumentIntoJob(instrument1); + EXPECT_NE(jobItem->instrumentItem(), nullptr); } TEST_F(TestSessionModel, moveItemFromRoot)