Skip to content
Snippets Groups Projects
Commit 36dc7249 authored by Pete Peterson's avatar Pete Peterson Committed by GitHub
Browse files

Merge pull request #20649 from mantidproject/20632_MantidMatrix_DX_fixes

Fix crash in MantidPlot's data view
parents b6f4adec 70a5f6f7
No related branches found
No related tags found
No related merge requests found
......@@ -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(
......@@ -1326,11 +1324,24 @@ void MantidMatrix::setupNewExtension(MantidMatrixModel::Type type) {
* @param ws: the new workspace
*/
void MantidMatrix::updateExtensions(Mantid::API::MatrixWorkspace_sptr ws) {
// Remove the tabs
for (auto it = m_extensions.begin(); it != m_extensions.end(); ++it) {
auto &extension = it->second;
extension.model = new MantidMatrixModel(this, ws.get(), m_rows, m_cols,
m_startRow, it->first);
connectTableView(extension.tableView, extension.model);
auto it = m_extensions.begin();
while (it != m_extensions.cend()) {
switch (it->first) {
case MantidMatrixModel::DX:
if (ws->hasDx(0)) {
auto &extension = it->second;
extension.model = new MantidMatrixModel(this, ws.get(), m_rows, m_cols,
m_startRow, it->first);
connectTableView(extension.tableView.get(), extension.model);
++it;
} else {
closeDependants();
m_tabs->removeTab(modelTypeToInt(it->first));
it = m_extensions.erase(it);
}
break;
default:
throw std::runtime_error("Unknown MantidMatrix extension.");
}
}
}
......@@ -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);
}
......
......@@ -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;
}
......
......@@ -15,10 +15,10 @@ struct MantidMatrixTabExtension {
MantidMatrixModel::Type type)
: label(label), tableView(tableView), model(model), type(type) {}
MantidMatrixTabExtension()
: label(""), tableView(nullptr), model(nullptr),
: label(""), tableView(), model(nullptr),
type(MantidMatrixModel::Type::DX) {}
QString label;
QTableView *tableView;
std::unique_ptr<QTableView> tableView;
QPointer<MantidMatrixModel> model;
MantidMatrixModel::Type type;
};
......
......@@ -15,7 +15,10 @@ Installation
Workbench
---------
- Fixed a bug where replacing a workspace with X errors with a workspace without the errors while Data View was open would result in a crash.
SliceViewer and Vates Simple Interface
--------------------------------------
:ref:`Release 3.12.0 <v3.12.0>`
\ No newline at end of file
:ref:`Release 3.12.0 <v3.12.0>`
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