diff --git a/GUI/Model/Data/IntensityDataItem.cpp b/GUI/Model/Data/IntensityDataItem.cpp index cb8b01926c6c8347ad750571bb73525cc5c9c5dd..5127ae125fdb46e501dd21321d426e5dce660da6 100644 --- a/GUI/Model/Data/IntensityDataItem.cpp +++ b/GUI/Model/Data/IntensityDataItem.cpp @@ -418,10 +418,9 @@ const MaskContainerItem* IntensityDataItem::maskContainerItem() const MaskContainerItem* IntensityDataItem::getOrCreateMaskContainerItem() { - if (!m_maskContainerItem) { + if (!m_maskContainerItem) m_maskContainerItem.reset(new MaskContainerItem); - m_maskContainerItem->setParent(this); - } + return m_maskContainerItem.get(); } @@ -437,10 +436,9 @@ const ProjectionContainerItem* IntensityDataItem::projectionContainerItem() cons ProjectionContainerItem* IntensityDataItem::getOrCreateProjectionContainerItem() { - if (!m_projectionContainerItem) { + if (!m_projectionContainerItem) m_projectionContainerItem.reset(new ProjectionContainerItem); - m_projectionContainerItem->setParent(this); - } + return m_projectionContainerItem.get(); } diff --git a/GUI/Model/Device/MaskItems.cpp b/GUI/Model/Device/MaskItems.cpp index 69958f0b4ea9a9c20a7939020220b23bc88e1075..755afb079adafef4bb06ce547778651416bf9735 100644 --- a/GUI/Model/Device/MaskItems.cpp +++ b/GUI/Model/Device/MaskItems.cpp @@ -49,6 +49,7 @@ const QString Mask("Mask"); MaskContainerItem::MaskContainerItem() : MaskItemObject() + , m_model(new MaskContainerModel(this)) { } @@ -126,13 +127,7 @@ void MaskContainerItem::copyFrom(const MaskContainerItem* maskContainer) MaskContainerModel* MaskContainerItem::model() { - return m_model; -} - -void MaskContainerItem::setModel(MaskContainerModel* model) -{ - m_model = model; - model->maskContainer = this; + return m_model.get(); } void MaskContainerItem::updateMaskNames() @@ -896,7 +891,10 @@ MaskItemObject::~MaskItemObject() // Implementation of MaskContainerModel is based on the Qt source code for QStringListModel -MaskContainerModel::MaskContainerModel() {} +MaskContainerModel::MaskContainerModel(MaskContainerItem *container) + : maskContainer(container) +{ +} MaskContainerModel::~MaskContainerModel() {} @@ -925,11 +923,6 @@ QVariant MaskContainerModel::data(const QModelIndex& index, int role) const // End overridden methods from QAbstractListModel -void MaskContainerModel::setParent(QObject* parent) -{ - QAbstractListModel::setParent(parent); -} - void MaskContainerModel::insertMask(int row, MaskItem* maskItem) { QAbstractListModel::beginInsertRows(maskContainer->rootIndex, row, row); diff --git a/GUI/Model/Device/MaskItems.h b/GUI/Model/Device/MaskItems.h index 8bed4c218a98db3ade98cec307117f4011ac9846..3f084cd1d9c2a44a6916192fdb5a126b90a427b5 100644 --- a/GUI/Model/Device/MaskItems.h +++ b/GUI/Model/Device/MaskItems.h @@ -253,9 +253,6 @@ public: //! Return the corresponding MaskContainerModel MaskContainerModel* model(); - //! Set the corresponding MaskContainerModel - void setModel(MaskContainerModel* model); - //! Update numbers in mask names void updateMaskNames(); @@ -264,19 +261,15 @@ public: protected: SelectionVector<MaskItemCatalog> m_maskItems; - MaskContainerModel* m_model = nullptr; + std::unique_ptr<MaskContainerModel> m_model; }; -//! MaskContainerModel -//! This class is only for migration away from `SessionModel`, to keep the list `QIndex`es -//! refering to `MaskItems`, needed to cooperate with `QItemSelectionModel`. -//! After removal of `SessionModel`, if this class is still needed, it should be derived -//! directly from `QAbstractItemModel`. +//! Provides interfaces to a MaskContainerItem, allowing its contents to be displayed and modified using the Qt mechanisms. class MaskContainerModel : public QAbstractListModel { public: - MaskContainerModel(); + MaskContainerModel(MaskContainerItem* container); ~MaskContainerModel(); //! Insert mask at given row. @@ -306,8 +299,6 @@ public: RegionOfInterestItem* regionOfInterestItem() const; - void setParent(QObject* parent); - public: MaskContainerItem* maskContainer = nullptr; }; diff --git a/GUI/View/Import/RealDataMaskWidget.cpp b/GUI/View/Import/RealDataMaskWidget.cpp index 552ac10e28f114bd19a2028a8d7aad7a54c4a95b..d62c48199c110b938423b07659f8202eebc4cd88 100644 --- a/GUI/View/Import/RealDataMaskWidget.cpp +++ b/GUI/View/Import/RealDataMaskWidget.cpp @@ -80,18 +80,13 @@ void RealDataMaskWidget::setContext() ASSERT(currentIntensityDataItem()); MaskContainerItem* containerItem = currentIntensityDataItem()->getOrCreateMaskContainerItem(); - MaskContainerModel* containerModel = containerItem->model(); + ASSERT(containerItem); - // TODO: Proper memory release of the MaskContainerModel instance - if (!containerModel) { - containerModel = new MaskContainerModel; - containerModel->setParent(containerItem); - containerItem->setModel(containerModel); - } + MaskContainerModel* containerModel = containerItem->model(); + ASSERT(containerModel); m_editorPropertyPanel->setMaskContext(containerModel); - ASSERT(dynamic_cast<MaskContainerItem*>(containerItem)); m_editorCanvas->setSelectionModel(m_editorPropertyPanel->selectionModel()); m_editorCanvas->setMaskContext(currentIntensityDataItem()); diff --git a/GUI/View/Mask/MaskGraphicsScene.cpp b/GUI/View/Mask/MaskGraphicsScene.cpp index 4f0432967fb0636f746e35f3847588e3dfa47a9f..581c61e5d53d0585bae9a914791e9dbdff62d718 100644 --- a/GUI/View/Mask/MaskGraphicsScene.cpp +++ b/GUI/View/Mask/MaskGraphicsScene.cpp @@ -61,8 +61,9 @@ void MaskGraphicsScene::setMaskContext(IntensityDataItem* intensityItem, MaskCon return; MaskContainerModel* maskContainerModel = maskContainerItem->model(); + ASSERT(maskContainerModel); - if (maskContainerModel && maskContainerModel != m_maskContainerModel) { + if (maskContainerModel != m_maskContainerModel) { disconnectMaskContainer(m_maskContainerModel); m_maskContainerItem = maskContainerItem; m_maskContainerModel = maskContainerModel; diff --git a/GUI/View/Projection/IntensityDataProjectionsWidget.cpp b/GUI/View/Projection/IntensityDataProjectionsWidget.cpp index 897a0787fcd547bc789a23015cf7e6c19a50b54d..e7de5e852da7eca3e49566c9b91ed314f0253e2f 100644 --- a/GUI/View/Projection/IntensityDataProjectionsWidget.cpp +++ b/GUI/View/Projection/IntensityDataProjectionsWidget.cpp @@ -66,15 +66,10 @@ void IntensityDataProjectionsWidget::setContext() ProjectionContainerItem* containerItem = currentIntensityDataItem()->getOrCreateProjectionContainerItem(); + ASSERT(containerItem); MaskContainerModel* containerModel = containerItem->model(); - - // TODO: Proper memory release of the MaskContainerModel instance - if (!containerModel) { - containerModel = new MaskContainerModel; - containerModel->setParent(containerItem); - containerItem->setModel(containerModel); - } + ASSERT(containerModel); m_selectionModel.reset(new QItemSelectionModel(containerModel)); diff --git a/GUI/View/Projection/ProjectionsEditorCanvas.cpp b/GUI/View/Projection/ProjectionsEditorCanvas.cpp index 4782eec59be4f47428e0fd2b15a27b600041a919..7e4f31b727af53506d068cdb1cbd1d131d1f4d87 100644 --- a/GUI/View/Projection/ProjectionsEditorCanvas.cpp +++ b/GUI/View/Projection/ProjectionsEditorCanvas.cpp @@ -56,13 +56,7 @@ ProjectionsEditorCanvas::ProjectionsEditorCanvas(QWidget* parent) void ProjectionsEditorCanvas::setContext(IntensityDataItem* intensityItem) { ProjectionContainerItem* containerItem = intensityItem->getOrCreateProjectionContainerItem(); - - // TODO: Proper memory release of the MaskContainerModel instance - if (!containerItem->model()) { - MaskContainerModel* containerModel = new MaskContainerModel; - containerModel->setParent(containerItem); - containerItem->setModel(containerModel); - } + ASSERT(containerItem); m_scene->setMaskContext(intensityItem, containerItem);