diff --git a/MantidPlot/src/Mantid/MantidMatrix.cpp b/MantidPlot/src/Mantid/MantidMatrix.cpp index 577746f4aa5913232d0b50c491be75e131153e0f..a52fa2b12ef132e513e8160bd4eb6fb7c9efd0c1 100644 --- a/MantidPlot/src/Mantid/MantidMatrix.cpp +++ b/MantidPlot/src/Mantid/MantidMatrix.cpp @@ -1292,21 +1292,19 @@ void MantidMatrix::setupNewExtension(MantidMatrixModel::Type type) { // We need to hook up the extension extension.model = new MantidMatrixModel(this, m_workspace.get(), m_rows, m_cols, m_startRow, type); - extension.tableView = new QTableView(); - - // Add it to the extension collection, so we can set it up in place - m_extensions.emplace(type, extension); - auto mapped_extension = m_extensions[type]; + extension.tableView = Mantid::Kernel::make_unique<QTableView>(); // Add a new tab - m_tabs->insertTab(modelTypeToInt(type), mapped_extension.tableView, - mapped_extension.label); + m_tabs->insertTab(modelTypeToInt(type), extension.tableView.get(), + extension.label); // Install the eventfilter - mapped_extension.tableView->installEventFilter(this); + extension.tableView->installEventFilter(this); // Connect Table View - connectTableView(mapped_extension.tableView, mapped_extension.model); + connectTableView(extension.tableView.get(), extension.model); + + m_extensions.emplace(type, std::move(extension)); // Set the column width auto columnWidth = m_extensionRequest.getColumnWidthPreference( @@ -1334,12 +1332,11 @@ void MantidMatrix::updateExtensions(Mantid::API::MatrixWorkspace_sptr ws) { auto &extension = it->second; extension.model = new MantidMatrixModel(this, ws.get(), m_rows, m_cols, m_startRow, it->first); - connectTableView(extension.tableView, extension.model); + connectTableView(extension.tableView.get(), extension.model); ++it; } else { closeDependants(); m_tabs->removeTab(modelTypeToInt(it->first)); - delete it->second.tableView; it = m_extensions.erase(it); } break; diff --git a/MantidPlot/src/Mantid/MantidMatrixDxExtensionHandler.cpp b/MantidPlot/src/Mantid/MantidMatrixDxExtensionHandler.cpp index b261b76f9566ce4f0a431897ff89a4394f41f23e..99aa9c101785054c4004fd69dbf5a9268c8e2185 100644 --- a/MantidPlot/src/Mantid/MantidMatrixDxExtensionHandler.cpp +++ b/MantidPlot/src/Mantid/MantidMatrixDxExtensionHandler.cpp @@ -76,7 +76,7 @@ int MantidMatrixDxExtensionHandler::getPrecision( void MantidMatrixDxExtensionHandler::setColumnWidth( MantidMatrixTabExtension &extension, int width, int numberOfColumns) { if (extension.type == m_type) { - auto table_view = extension.tableView; + auto &table_view = extension.tableView; table_view->horizontalHeader()->setDefaultSectionSize(width); for (int i = 0; i < numberOfColumns; i++) { table_view->setColumnWidth(i, width); @@ -94,7 +94,7 @@ void MantidMatrixDxExtensionHandler::setColumnWidth( int MantidMatrixDxExtensionHandler::getColumnWidth( MantidMatrixTabExtension &extension) { if (extension.type == m_type) { - auto table_view = extension.tableView; + auto &table_view = extension.tableView; return table_view->columnWidth(0); } else { return m_successor->getColumnWidth(extension); @@ -109,7 +109,7 @@ int MantidMatrixDxExtensionHandler::getColumnWidth( QTableView *MantidMatrixDxExtensionHandler::getTableView( MantidMatrixTabExtension &extension) { if (extension.type == m_type) { - return extension.tableView; + return extension.tableView.get(); } else { return m_successor->getTableView(extension); } diff --git a/MantidPlot/src/Mantid/MantidMatrixExtensionRequest.cpp b/MantidPlot/src/Mantid/MantidMatrixExtensionRequest.cpp index 799d1abb246407e88ad85daed53e0e604193bbb7..01b297c9b7376e57a6c60b8eff9d4080013cc5b8 100644 --- a/MantidPlot/src/Mantid/MantidMatrixExtensionRequest.cpp +++ b/MantidPlot/src/Mantid/MantidMatrixExtensionRequest.cpp @@ -215,7 +215,7 @@ bool MantidMatrixExtensionRequest::tableViewMatchesObject( MantidMatrixTabExtensionMap &extensions, QObject *object) { for (auto it = extensions.begin(); it != extensions.end(); ++it) { auto &extension = it->second; - if (extension.tableView == object) { + if (extension.tableView.get() == object) { return true; } } @@ -234,7 +234,7 @@ QTableView *MantidMatrixExtensionRequest::getActiveView( QTableView *defaultValue) { if (extensions.count(type) > 0) { auto &extension = extensions[type]; - return extension.tableView; + return extension.tableView.get(); } else { return defaultValue; } diff --git a/MantidPlot/src/Mantid/MantidMatrixTabExtension.h b/MantidPlot/src/Mantid/MantidMatrixTabExtension.h index bc91ba0bf59c5a263817d2e3abd0e7d5bcfc07e8..811109353441ec3d711c2c9c94731544a4cacae1 100644 --- a/MantidPlot/src/Mantid/MantidMatrixTabExtension.h +++ b/MantidPlot/src/Mantid/MantidMatrixTabExtension.h @@ -15,10 +15,10 @@ struct MantidMatrixTabExtension { MantidMatrixModel::Type type) : label(label), tableView(tableView), model(model), type(type) {} MantidMatrixTabExtension() - : label(""), tableView(NULL), model(NULL), + : label(""), tableView(), model(NULL), type(MantidMatrixModel::Type::DX) {} QString label; - QTableView *tableView; + std::unique_ptr<QTableView> tableView; QPointer<MantidMatrixModel> model; MantidMatrixModel::Type type; };