Skip to content
Snippets Groups Projects
Commit 1421a553 authored by t.knopff's avatar t.knopff
Browse files

Make Instrument2DItem::setDetectorGroup a template

parent 0c5b4e43
No related branches found
No related tags found
1 merge request!96Refactor model: detector items
Pipeline #38222 passed
......@@ -251,11 +251,6 @@ GroupItem* Instrument2DItem::detectorGroup()
return item<GroupItem>(P_DETECTOR);
}
void Instrument2DItem::setDetectorGroup(const QString& modelType)
{
setGroupProperty(P_DETECTOR, modelType);
}
void Instrument2DItem::clearMasks()
{
detectorItem()->clearMasks();
......
......@@ -101,7 +101,7 @@ public:
DetectorItem* detectorItem() const;
GroupItem* detectorGroup();
void setDetectorGroup(const QString& modelType);
template <typename T> T* setDetectorGroup();
void clearMasks() override;
void importMasks(const MaskContainerItem* maskContainer) override;
......@@ -177,4 +177,13 @@ T* InstrumentItem::setBackgroundType()
return setGroupPropertyType<T>(P_BACKGROUND);
}
template <typename T>
T* Instrument2DItem::setDetectorGroup()
{
static_assert(std::is_base_of<DetectorItem,T>::value,
"Class must be derived from DetectorItem");
return static_cast<T*>(setGroupProperty(P_DETECTOR, T::M_TYPE));
}
#endif // BORNAGAIN_GUI_MODELS_INSTRUMENTITEMS_H
......@@ -298,12 +298,10 @@ void TransformFromDomain::setDetectorGeometry(Instrument2DItem* instrument_item,
const IDetector& detector)
{
if (auto det = dynamic_cast<const SphericalDetector*>(&detector)) {
instrument_item->setDetectorGroup(SphericalDetectorItem::M_TYPE);
auto item = dynamic_cast<SphericalDetectorItem*>(instrument_item->detectorItem());
auto item = instrument_item->setDetectorGroup<SphericalDetectorItem>();
setSphericalDetector(item, *det);
} else if (auto det = dynamic_cast<const RectangularDetector*>(&detector)) {
instrument_item->setDetectorGroup(RectangularDetectorItem::M_TYPE);
auto item = dynamic_cast<RectangularDetectorItem*>(instrument_item->detectorItem());
auto item = instrument_item->setDetectorGroup<RectangularDetectorItem>();
setRectangularDetector(item, *det);
} else {
throw Error(
......
......@@ -37,7 +37,7 @@ TEST_F(TestLinkInstrument, test_canLinkToInstrument)
EXPECT_EQ(manager.linkedRealDataItems(instrument), QList<RealDataItem*>() << realData);
// changing detector type and checking that link remain
instrument->setDetectorGroup(RectangularDetectorItem::M_TYPE);
instrument->setDetectorGroup<RectangularDetectorItem>();
EXPECT_EQ(manager.linkedRealDataItems(instrument), QList<RealDataItem*>() << realData);
// changing detector binning and checking that link is destroyed
......
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