From 34331ccd12e4efc99c6472de7453e251035510d8 Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Fri, 25 Jan 2019 16:19:43 +1300 Subject: [PATCH] Raw CellML view: make sure that a file is still valid before actually reloading it. --- .../RawCellMLView/src/rawcellmlviewplugin.cpp | 12 ++---------- .../RawCellMLView/src/rawcellmlviewwidget.cpp | 19 +++++++++++++++++-- .../RawCellMLView/src/rawcellmlviewwidget.h | 2 ++ 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/plugins/editing/RawCellMLView/src/rawcellmlviewplugin.cpp b/src/plugins/editing/RawCellMLView/src/rawcellmlviewplugin.cpp index 0cea3284b3..7f82544a8f 100644 --- a/src/plugins/editing/RawCellMLView/src/rawcellmlviewplugin.cpp +++ b/src/plugins/editing/RawCellMLView/src/rawcellmlviewplugin.cpp @@ -21,9 +21,7 @@ along with this program. If not, see . // Raw CellML view plugin //============================================================================== -#include "cellmlfilemanager.h" #include "cellmlsupportplugin.h" -#include "corecliutils.h" #include "coreguiutils.h" #include "filemanager.h" #include "rawcellmlviewplugin.h" @@ -335,16 +333,10 @@ QString RawCellMLViewPlugin::viewDefaultFileExtension() const QWidget * RawCellMLViewPlugin::viewWidget(const QString &pFileName) { - // Make sure that we are dealing with either a new file or a CellML 1.0/1.1 - // file + // Make sure that we are dealing with a valid file - CellMLSupport::CellmlFile::Version cellmlVersion = CellMLSupport::CellmlFile::fileVersion(pFileName); - - if ( !Core::FileManager::instance()->isNew(pFileName) - && (cellmlVersion != CellMLSupport::CellmlFile::Cellml_1_0) - && (cellmlVersion != CellMLSupport::CellmlFile::Cellml_1_1)) { + if (!mViewWidget->isValid(pFileName)) return nullptr; - } // Update and return our Raw CellML view widget using the given CellML file diff --git a/src/plugins/editing/RawCellMLView/src/rawcellmlviewwidget.cpp b/src/plugins/editing/RawCellMLView/src/rawcellmlviewwidget.cpp index aa365744af..9bdf38e3b2 100644 --- a/src/plugins/editing/RawCellMLView/src/rawcellmlviewwidget.cpp +++ b/src/plugins/editing/RawCellMLView/src/rawcellmlviewwidget.cpp @@ -102,6 +102,20 @@ void RawCellmlViewWidget::retranslateUi() //============================================================================== +bool RawCellmlViewWidget::isValid(const QString &pFileName) const +{ + // Return whether we are dealing with a new file or a CellML 1.0/1.1 file + + CellMLSupport::CellmlFile::Version cellmlVersion = CellMLSupport::CellmlFile::fileVersion(pFileName); + + return Core::FileManager::instance()->isNew(pFileName) + || (cellmlVersion == CellMLSupport::CellmlFile::Cellml_1_0) + || (cellmlVersion == CellMLSupport::CellmlFile::Cellml_1_1); +} + +//============================================================================== + + void RawCellmlViewWidget::initialize(const QString &pFileName, bool pUpdate) { // Retrieve the editing widget associated with the given file, if any @@ -224,14 +238,15 @@ void RawCellmlViewWidget::fileSaved(const QString &pFileName) void RawCellmlViewWidget::fileReloaded(const QString &pFileName) { - // The given file has been reloaded, so reload it, should it be managed + // The given file has been reloaded, so reload it, should it be managed and + // still valid // Note: if the view for the given file is not the active view, then to call // finalize() and then initialize() would activate the contents of the // view (but the file tab would still point to the previously active // file). However, we want to the 'old' file to remain the active one, // hence the extra argument we pass to initialize()... - if (mEditingWidgets.contains(pFileName)) { + if (mEditingWidgets.contains(pFileName) && isValid(pFileName)) { bool update = mEditingWidget == mEditingWidgets.value(pFileName); finalize(pFileName); diff --git a/src/plugins/editing/RawCellMLView/src/rawcellmlviewwidget.h b/src/plugins/editing/RawCellMLView/src/rawcellmlviewwidget.h index 723b8ca6ff..5c710fa630 100644 --- a/src/plugins/editing/RawCellMLView/src/rawcellmlviewwidget.h +++ b/src/plugins/editing/RawCellMLView/src/rawcellmlviewwidget.h @@ -67,6 +67,8 @@ class RawCellmlViewWidget : public Core::ViewWidget void retranslateUi() override; + bool isValid(const QString &pFileName) const; + void initialize(const QString &pFileName, bool pUpdate = true); void finalize(const QString &pFileName);