diff --git a/GUI/coregui/Views/ImportDataWidgets/RealDataSelectorActions.cpp b/GUI/coregui/Views/ImportDataWidgets/RealDataSelectorActions.cpp index c5df94e6dd8de4d7493fb29c0123810f209e671a..c72aa6267a3d8b8bace2437164a8d730849ddbdf 100644 --- a/GUI/coregui/Views/ImportDataWidgets/RealDataSelectorActions.cpp +++ b/GUI/coregui/Views/ImportDataWidgets/RealDataSelectorActions.cpp @@ -151,8 +151,7 @@ void RealDataSelectorActions::importDataLoop(int ndim) if (ndim == 2) { std::unique_ptr<OutputData<double>> data = ImportDataUtils::Import2dData(fileName); if (data) { - RealDataItem* realDataItem = - dynamic_cast<RealDataItem*>(m_realDataModel->insertNewItem("RealData")); + auto realDataItem = m_realDataModel->insertItem<RealDataItem>(); realDataItem->setItemName(baseNameOfLoadedFile); realDataItem->setOutputData(data.release()); m_selectionModel->clearSelection(); @@ -161,8 +160,7 @@ void RealDataSelectorActions::importDataLoop(int ndim) } else if (ndim == 1) { auto data = ImportDataUtils::Import1dData(fileName); if (data) { - RealDataItem* realDataItem = - dynamic_cast<RealDataItem*>(m_realDataModel->insertNewItem("RealData")); + auto realDataItem = m_realDataModel->insertItem<RealDataItem>(); realDataItem->setItemName(baseNameOfLoadedFile); realDataItem->setImportData(std::move(data)); m_selectionModel->clearSelection(); diff --git a/GUI/coregui/Views/InstrumentWidgets/DetectorMaskDelegate.cpp b/GUI/coregui/Views/InstrumentWidgets/DetectorMaskDelegate.cpp index ce6d38109dc2ef784ab6e9d4f8e029c37e9b85dc..5b13035657b82f8a3ac30d6289f552b0855311e3 100644 --- a/GUI/coregui/Views/InstrumentWidgets/DetectorMaskDelegate.cpp +++ b/GUI/coregui/Views/InstrumentWidgets/DetectorMaskDelegate.cpp @@ -56,11 +56,7 @@ void DetectorMaskDelegate::initMaskEditorContext(MaskEditor* maskEditor, void DetectorMaskDelegate::createIntensityDataItem() { m_tempIntensityDataModel->clear(); - - m_intensityItem = - dynamic_cast<IntensityDataItem*>(m_tempIntensityDataModel->insertNewItem("IntensityData")); - ASSERT(m_intensityItem); - + m_intensityItem = m_tempIntensityDataModel->insertItem<IntensityDataItem>(); m_intensityItem->getItem(IntensityDataItem::P_PROJECTIONS_FLAG)->setEnabled(false); m_intensityItem->setItemValue(IntensityDataItem::P_IS_INTERPOLATED, false); diff --git a/GUI/coregui/Views/IntensityDataWidgets/IntensityDataFFTPresenter.cpp b/GUI/coregui/Views/IntensityDataWidgets/IntensityDataFFTPresenter.cpp index 5bd0ee964bb3548593a62b546437d4d9b5485dae..c5afb3ab317f74442bd4a155b8d9fcec9ad5a255 100644 --- a/GUI/coregui/Views/IntensityDataWidgets/IntensityDataFFTPresenter.cpp +++ b/GUI/coregui/Views/IntensityDataWidgets/IntensityDataFFTPresenter.cpp @@ -28,8 +28,7 @@ IntensityDataFFTPresenter::IntensityDataFFTPresenter(QWidget* parent) , m_fftItem(nullptr) , m_in_fft_mode(false) { - m_fftItem = dynamic_cast<IntensityDataItem*>(m_fftModel->insertNewItem("IntensityData")); - + m_fftItem = m_fftModel->insertItem<IntensityDataItem>(); m_fftAction = new QAction(this); m_fftAction->setText("Fourier"); m_fftAction->setIcon(QIcon(":/images/alpha-f-box.svg")); diff --git a/GUI/coregui/Views/PropertyEditor/TestComponentView.cpp b/GUI/coregui/Views/PropertyEditor/TestComponentView.cpp index 6fbada385725648e2c98f1956b8981775d3de32d..86cf56f4d1456c8b9882bc8e7d951bead61ecf3a 100644 --- a/GUI/coregui/Views/PropertyEditor/TestComponentView.cpp +++ b/GUI/coregui/Views/PropertyEditor/TestComponentView.cpp @@ -13,9 +13,12 @@ // ************************************************************************************************ #include "GUI/coregui/Views/PropertyEditor/TestComponentView.h" +#include "GUI/coregui/Models/BeamItems.h" #include "GUI/coregui/Models/GUIObjectBuilder.h" +#include "GUI/coregui/Models/IntensityDataItem.h" #include "GUI/coregui/Models/MaterialDataItems.h" #include "GUI/coregui/Models/MaterialModel.h" +#include "GUI/coregui/Models/ParticleItem.h" #include "GUI/coregui/Models/SampleModel.h" #include "GUI/coregui/Models/SessionModelDelegate.h" #include "GUI/coregui/Views/MaterialEditor/MaterialItemUtils.h" @@ -88,7 +91,7 @@ void TestComponentView::onUpdateRequest() void TestComponentView::onAddItemRequest() { - m_sampleModel->insertNewItem("Particle"); + m_sampleModel->insertItem<ParticleItem>(); } void TestComponentView::onExpandRequest() @@ -121,11 +124,9 @@ void TestComponentView::init_source() const std::unique_ptr<MultiLayer> sample( factory.createSampleByName("CylindersWithSizeDistributionBuilder")); GUIObjectBuilder::populateSampleModel(m_sampleModel, m_materialModel, *sample); - m_sampleModel->insertNewItem("Vector"); - m_sampleModel->insertNewItem("GISASBeam"); - - // adding intensity data item - m_sampleModel->insertNewItem("IntensityData"); + m_sampleModel->insertItem<VectorItem>(); + m_sampleModel->insertItem<GISASBeamItem>(); + m_sampleModel->insertItem<IntensityDataItem>(); } void TestComponentView::onSelectionChanged(const QItemSelection& selected, const QItemSelection&) diff --git a/GUI/coregui/Views/SampleDesigner/DesignerScene.cpp b/GUI/coregui/Views/SampleDesigner/DesignerScene.cpp index 1e44024ac128617f054077dd65d9f78756c6d281..18d108e769b4ad3990bfa91cec5e187e324bf0dc 100644 --- a/GUI/coregui/Views/SampleDesigner/DesignerScene.cpp +++ b/GUI/coregui/Views/SampleDesigner/DesignerScene.cpp @@ -413,7 +413,7 @@ void DesignerScene::dropEvent(QGraphicsSceneDragDropEvent* event) SessionItem* new_item(0); if (mimeData->getClassName().startsWith("FormFactor")) { - new_item = m_sampleModel->insertNewItem("Particle"); + new_item = m_sampleModel->insertItem<ParticleItem>(); QString ffName = mimeData->getClassName(); ffName.remove("FormFactor"); new_item->setGroupProperty(ParticleItem::P_FORM_FACTOR, ffName); diff --git a/GUI/coregui/Views/TestView.cpp b/GUI/coregui/Views/TestView.cpp index 9dec7bdff26e456573d5cc4459cc7d07cf1aa87d..072116408fdecb1fe6bd04b06b4e7f78c3562587 100644 --- a/GUI/coregui/Views/TestView.cpp +++ b/GUI/coregui/Views/TestView.cpp @@ -85,8 +85,7 @@ void TestView::test_MinimizerSettings() setLayout(layout); SessionModel* model = new SessionModel("TempModel", this); - MinimizerContainerItem* minimizerItem = - dynamic_cast<MinimizerContainerItem*>(model->insertNewItem("MinimizerContainer")); + auto minimizerItem = model->insertItem<MinimizerContainerItem>(); widget->setItem(minimizerItem); } @@ -181,7 +180,7 @@ void TestView::test_specular_data_widget() SessionModel* tempModel = new SessionModel("Test", this); // creating job item - auto job_item = dynamic_cast<JobItem*>(tempModel->insertNewItem("JobItem")); + auto job_item = tempModel->insertItem<JobItem>(); // creating "simulation" data auto data_item = new SpecularDataItem(); diff --git a/Tests/UnitTests/GUI/TestComponentProxyModel.cpp b/Tests/UnitTests/GUI/TestComponentProxyModel.cpp index 683b37e13470bf8be29f1cf9904fadb5248649ed..7584a92f86bde0dd4ae3e2f26cb91bdcb930ec11 100644 --- a/Tests/UnitTests/GUI/TestComponentProxyModel.cpp +++ b/Tests/UnitTests/GUI/TestComponentProxyModel.cpp @@ -3,8 +3,11 @@ #include "GUI/coregui/Models/ComponentProxyStrategy.h" #include "GUI/coregui/Models/FormFactorItems.h" #include "GUI/coregui/Models/GroupItem.h" +#include "GUI/coregui/Models/LayerItem.h" #include "GUI/coregui/Models/ModelUtils.h" +#include "GUI/coregui/Models/MultiLayerItem.h" #include "GUI/coregui/Models/ParticleItem.h" +#include "GUI/coregui/Models/ParticleLayoutItem.h" #include "GUI/coregui/Models/SessionModel.h" #include "GUI/coregui/Models/VectorItem.h" #include "Tests/GTestWrapper/google_test.h" @@ -46,7 +49,7 @@ TEST_F(TestComponentProxyModel, test_setModel) TEST_F(TestComponentProxyModel, test_setModelWithItem) { SessionModel model("TestModel"); - model.insertNewItem("Property"); + model.insertItem<PropertyItem>(); ComponentProxyModel proxy; proxy.setSessionModel(&model); @@ -155,9 +158,9 @@ TEST_F(TestComponentProxyModel, test_setModelWithVector) TEST_F(TestComponentProxyModel, test_displayRole) { SessionModel model("TestModel"); - SessionItem* item1 = model.insertNewItem("Property"); + auto item1 = model.insertItem<PropertyItem>(); item1->setValue(1.0); - SessionItem* item2 = model.insertNewItem("Property"); + auto item2 = model.insertItem<PropertyItem>(); item2->setValue(2.0); EXPECT_EQ(model.data(model.index(0, 1, QModelIndex()), Qt::DisplayRole).toDouble(), 1.0); @@ -175,7 +178,7 @@ TEST_F(TestComponentProxyModel, test_displayRole) TEST_F(TestComponentProxyModel, test_setData) { SessionModel model("TestModel"); - SessionItem* item = model.insertNewItem("Property"); + auto item = model.insertItem<PropertyItem>(); item->setValue(1.0); ComponentProxyModel proxy; @@ -226,7 +229,7 @@ TEST_F(TestComponentProxyModel, test_insertRows) QSignalSpy spyProxy(&proxy, &ComponentProxyModel::layoutChanged); // inserting item in the source - model.insertNewItem("Property"); + model.insertItem<PropertyItem>(); EXPECT_EQ(spyProxy.count(), 1); EXPECT_EQ(proxy.rowCount(QModelIndex()), 1); } @@ -243,7 +246,7 @@ TEST_F(TestComponentProxyModel, test_componentStrategy) proxy.setSessionModel(&model); // inserting particle - SessionItem* item = model.insertNewItem("Particle"); + auto item = model.insertItem<ParticleItem>(); auto group = dynamic_cast<GroupItem*>(item->getItem(ParticleItem::P_FORM_FACTOR)); SessionItem* ffItem = item->getGroupItem(ParticleItem::P_FORM_FACTOR); EXPECT_TRUE(ffItem->parent() == group); @@ -288,7 +291,7 @@ TEST_F(TestComponentProxyModel, test_componentStrategyFormFactorChanges) proxy.setSessionModel(&model); // inserting particle - SessionItem* item = model.insertNewItem("Particle"); + auto item = model.insertItem<ParticleItem>(); auto group = dynamic_cast<GroupItem*>(item->getItem(ParticleItem::P_FORM_FACTOR)); SessionItem* ffItem = item->getGroupItem(ParticleItem::P_FORM_FACTOR); EXPECT_TRUE(ffItem->parent() == group); @@ -321,7 +324,7 @@ TEST_F(TestComponentProxyModel, test_setRootPropertyItem) proxy.setSessionModel(&model); // inserting simple property item - SessionItem* item = model.insertNewItem("Property"); + auto item = model.insertItem<PropertyItem>(); item->setValue(42.0); proxy.setRootIndex(model.indexOfItem(item)); @@ -358,10 +361,10 @@ TEST_F(TestComponentProxyModel, test_setRootIndexLayer) proxy.setSessionModel(&model); // inserting multilayer with two layers - auto multilayer = model.insertNewItem("MultiLayer"); - auto layer1 = model.insertNewItem("Layer", model.indexOfItem(multilayer)); - auto layout = model.insertNewItem("ParticleLayout", model.indexOfItem(layer1)); - model.insertNewItem("Layer", model.indexOfItem(multilayer)); + auto multilayer = model.insertItem<MultiLayerItem>(); + auto layer1 = model.insertItem<LayerItem>(model.indexOfItem(multilayer)); + auto layout = model.insertItem<ParticleLayoutItem>(model.indexOfItem(layer1)); + model.insertItem<LayerItem>(model.indexOfItem(multilayer)); proxy.setRootIndex(model.indexOfItem(layer1)); EXPECT_EQ(proxy.rowCount(QModelIndex()), 1);